<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rami</title>
    <description>The latest articles on DEV Community by Rami (@rami000).</description>
    <link>https://dev.to/rami000</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1010202%2Fd198c3f9-e63f-4990-951a-824213ddc785.png</url>
      <title>DEV Community: Rami</title>
      <link>https://dev.to/rami000</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rami000"/>
    <language>en</language>
    <item>
      <title>Securing GraphQL APIs with Shield: Best Practices and Common Pitfalls</title>
      <dc:creator>Rami</dc:creator>
      <pubDate>Thu, 04 May 2023 22:30:04 +0000</pubDate>
      <link>https://dev.to/ciscoemerge/securing-graphql-apis-with-shield-best-practices-and-common-pitfalls-2gjb</link>
      <guid>https://dev.to/ciscoemerge/securing-graphql-apis-with-shield-best-practices-and-common-pitfalls-2gjb</guid>
      <description>&lt;p&gt;GraphQL is a query language used to interact with APIs, and it has gained popularity among developers for its flexibility and efficiency. As an alternative to REST, GraphQL is known to be great in terms of usability, flexibility, and developer-friendliness. It comes with a powerful declarative-style architecture, allowing you to query only the bits of data that you want to retrieve, making GraphQL a specialised tool to build and consume APIs. &lt;br&gt;
 &lt;br&gt;
However, just like any technology, GraphQL has its own security shortcomings that developers need to be aware of to protect their applications from vulnerabilities.&lt;br&gt;
 &lt;br&gt;
In this deep dive, we will go over some of the top security issues with GraphQL and showcase how GraphQL Shield can be used for security best practices to avoid the common pitfalls that lead to breaches. GraphQL’s differentiators in data exchange are also directly its attack vectors. &lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Denial of Service Attacks&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;are attacks meant to impact the availability of a resource. In GraphQL, queries are complex and can be nested, making them susceptible to DoS attacks. A malicious user can construct a query that is so complex that it takes a long time to execute, causing the server to become unresponsive and stuck in an ‘infinite loop of computing’. To prevent this, developers should limit the complexity of queries by setting a maximum depth, complexity, and execution time. Certain Denial of Service attacks are built and executed as Injection Attacks, motivated by the ultimate goal of causing the Denial of Service. However, these are not the typical Denial of Service attacks (Fragments attacks, Direct Injection Attacks).&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Injection Attacks&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;are common web attacks where a malicious query is injected into a mutation or query that can execute arbitrary code. These attacks can result in various security threats, such as unauthorised access to sensitive data, privilege escalation, and remote code execution.&lt;br&gt;
 &lt;br&gt;
Malicious actors conduct injection attacks by targeting a specific stage of the query.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Query Depth Attacks&lt;/strong&gt;&lt;br&gt;
Typical GraphQL DoS attack risking resource exhaustion and availability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Query Timeouts&lt;/strong&gt;&lt;br&gt;
Common DoS attack due to a long-running query, causing server queue congestion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fragment attacks&lt;/strong&gt;&lt;br&gt;
Data leakage risks or access control bypass, if an attacker modifies the structure in a query using fragments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Direct injection attacks&lt;/strong&gt;&lt;br&gt;
Exploiting input validation measures to inject malicious payloads into the query or mutation parameters, lead&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To prevent GraphQL injection attacks, developers should ensure that inputs are properly sanitised and validated before execution. Additionally, indirect security measures are essential to the availability and security of your environment, setting query complexity limits and rate limiting impacts the performance/availability and the security of your data. Finally, active (automated/manual) testing of your environment is necessary to test the implemented measures for stability, correctness, and conformity to security standards.&lt;br&gt;
 &lt;br&gt;
Consider the following example, the input for password includes SQL injection code that can drop the table "Users." To prevent this, developers should sanitise and validate input parameters before executing queries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;mutation&lt;/span&gt; &lt;span class="nx"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CreateUserInput&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;$input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;id&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;johndoe@example.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;password&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;password123'; DROP TABLE Users; --&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Excessive Data Exposure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;occurs when sensitive Personally Identifiable Information (PII) is revealed in API responses. GraphQL allows clients to request only the data they need, but it also allows them to request multiple queries at once, which can result in excessive data exposure. For example, consider the following GraphQL query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;allUsers&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;id&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;name&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;email&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;password&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

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

&lt;/div&gt;



&lt;p&gt;In this query, the client is requesting all user data, including the password, which is a sensitive piece of information. To prevent this, developers should ensure that sensitive information is not included in the schema, and authentication and authorization mechanisms are implemented to control access to sensitive data. Overly permissive queries or mutations, such as in the given example are common in GraphQL APIs. These are easily exploitable and can have the highest yield for an attacker, returning all data for a specific resource, rather than only the data that the user is authorized to view, allowing the attack to obtain sensitive data, such as passwords, or payment information, that they should not have access to. &lt;br&gt;
 &lt;br&gt;
Another way that excessive data exposure can occur is through poorly designed authorization mechanisms. For example, if an API relies on cookies or other client-side storage mechanisms to authenticate users, an attacker could potentially obtain sensitive data by manipulating or intercepting these mechanisms.&lt;br&gt;
 &lt;br&gt;
With GraphQL Shield, you can define authorization rules to enforce granular access control rules on query operations. Once these authorization rules are defined, GraphQL shield can wrap your GraphQL schema and enforce those rules, ensuring that incoming query requests are validated against your authorization rules before they are executed. If the authorization requirements are not met by the request, GraphQL shield will intervene and return an error response preventing the data from being accessed.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Over-fetching and Under-fetching&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;are issues where clients request more or less data than they need, which can result in inefficient queries and reduced performance. GraphQL was originally designed to address the issues of over-fetching and under-fetching, that are commonly associated with the use of REST APIs, but it does require developers to use the appropriate tools and code methods that will allow GraphQL to prevent over-fetching and under-fetching. &lt;br&gt;
 &lt;br&gt;
For example, when fetching data about a user, a REST API might return not only the user's name and email address but also their entire address and phone number. This results in unnecessary data being transferred over the network, which can slow down the response time, increase data usage, and put data in-transit, which directly puts that data in an additional layer of risk.&lt;br&gt;
 &lt;br&gt;
GraphQL solves these issues by allowing clients to specify exactly what data they need, and only that data is returned in the response. This is achieved by defining a GraphQL schema that describes the available data and operations, and allowing clients to specify queries that request only the necessary data.&lt;/p&gt;

&lt;p&gt;Security risks typically arise from over-fetching, as additional unwanted data is passed in the response data. To prevent this, developers should optimize queries by ensuring that clients only request the data they need and no more.  &lt;/p&gt;

&lt;p&gt;Another fetching related risk is the behavioural predictability of a GraphQL Schema, if an attacker understands the logic flow of a schema, they can construct a query that will retrieve additional data such as e-mail address fields, or PII.&lt;/p&gt;

&lt;p&gt;There are several open-source solutions available for improving GraphQL security. One such solution is the graphql-shield library, which provides a declarative syntax for defining and enforcing access control rules. It allows developers to define rules based on the type of operation, the type of user, or any other arbitrary criteria.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;GraphQL Shield examples&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;GraphQL Shield is a tool that helps you create a permission layer around your GraphQL APIs.&lt;/p&gt;

&lt;p&gt;This code demonstrates how GraphQL shield can be used to define fine-grained permissions for a GraphQL API, helping to prevent unauthorised access to sensitive data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shield&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-shield&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a rule to check if the user is authenticated&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isAuthenticated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;contextual&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})(&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Define permissions using GraphQL Shield&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shield&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="c1"&gt;// Restrict access to certain fields based on the type of user&lt;/span&gt;
  &lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Allow all fields to be accessed by authenticated users&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isAuthenticated&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// Restrict access to password field to only the authenticated user&lt;/span&gt;
    &lt;span class="na"&gt;password&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;contextual&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})(&lt;/span&gt;
      &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The rule ‘isAuthenticated’ verifies whether the ‘user’ object is not ‘null’. If the ‘user’ object is not ‘null’, the user is authenticated, so the rule remains ‘true’. Otherwise, it returns ‘false’.&lt;br&gt;
 &lt;br&gt;
The ‘cache: ‘contextual’ option is used to set the caching behavior of the rule. In this case, the caching is based on the ‘context’ object, which means that the rule will be re-evaluated for each request.&lt;br&gt;
 &lt;br&gt;
The '*': isAuthenticated line allows authenticated users to access all fields of the User type. The password field, however, is restricted to only the authenticated user. This is achieved by defining another rule that checks whether the id of the authenticated user matches the id of the User object being queried. If the ids match, the rule returns true and allows the query to proceed. Otherwise, it returns false, and the query is denied.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Denial of Service (DoS) attacks:&lt;/strong&gt;&lt;br&gt;
 &lt;br&gt;
In this example, a rule is defined to limit the maximum number of items that can be fetched in a single query. The maxItems rule takes a limit parameter and returns a rule that checks if the length of the query result is less than or equal to the limit.&lt;br&gt;
 &lt;br&gt;
Permissions are then defined using GraphQL Shield, and the allUsers query is restricted to a maximum of 100 items that can be fetched in a single query.&lt;br&gt;
 &lt;br&gt;
By doing this, GraphQL Shield makes the application more resistant against DoS attacks, as the number of items that can be fetched in a single query is limited, preventing an attacker from overwhelming the server with a large number of queries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shield&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-shield&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a rule to limit the maximum number of items that can be fetched in a single query&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;maxItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;contextual&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})(&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mergeInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;delegateToSchema&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;operation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;query&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fieldName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;info&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Define permissions using GraphQL Shield&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shield&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Restrict the number of items that can be fetched by the `allUsers` query to 100&lt;/span&gt;
    &lt;span class="na"&gt;allUsers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;maxItems&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Injection Attacks&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;In this code snippet, a rule is defined to sanitise and validate input parameters before executing the createUser mutation. This helps prevent injection attacks that can execute arbitrary code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shield&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;deny&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-shield&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;sanitize&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sanitize-html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sanitizeInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;()(&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sanitizedInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sanitize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;allowedTags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;sanitizedInput&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shield&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;Mutation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;createUser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;sanitizeInput&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;deny&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, a rule is defined to check if the user is an admin, and then permissions are defined using GraphQL Shield. The permissions restrict access to certain fields based on the type of user. The Query type has two rules: the first one allows users to access their own data, while the second rule restricts access to the allUsers query to only admins. The User type has a rule that allows all fields to be accessed by authenticated users.&lt;br&gt;
 &lt;br&gt;
By doing this, the security risks involved with Over-fetching and Under-fetching are mitigated. Users can only access the data they need, and admins have the necessary permissions to access all user data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Over-fetching and Under-fetching&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;shield&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;allow&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;graphql-shield&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Define a rule to check if the user is an admin&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isAdmin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;contextual&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;})(&lt;/span&gt;
  &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;role&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Define permissions using GraphQL Shield&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shield&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="c1"&gt;// Restrict access to certain fields based on the type of user&lt;/span&gt;
  &lt;span class="na"&gt;Query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Allow all users to access their own data&lt;/span&gt;
    &lt;span class="na"&gt;me&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;allow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// Restrict access to allUsers query to only admins&lt;/span&gt;
    &lt;span class="na"&gt;allUsers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isAdmin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Allow all fields to be accessed by authenticated users&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;allow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example, a rule is defined to check if the user is authenticated, and then permissions are defined using GraphQL Shield. The permissions restrict access to certain fields based on the type of user. The User type has two rules: the first one allows all fields to be accessed by authenticated users, while the second rule restricts access to the password field to only the authenticated user who owns the password. By doing this, the Excessive Data Exposure vulnerability is mitigated, as sensitive data such as passwords cannot be accessed by unauthorised users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Great! Should we rely on GraphQL Shield now?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tools are a means to an end, and it should not be the aim to risk everything on a single tool. GraphQL shield helps you in securing in defining and enforcing the best-practice security measures for GraphQL APIs. Ultimately, it comes down to the developers, and their awareness of these vulnerabilities to spot the creation of attack vectors in their APIs. What Shield can do, is help you in grasping the nature of these attack vectors, and what it takes to take control of them.&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>api</category>
      <category>security</category>
    </item>
    <item>
      <title>Risk scoring your API Specification with Panoptica</title>
      <dc:creator>Rami</dc:creator>
      <pubDate>Thu, 19 Jan 2023 14:20:33 +0000</pubDate>
      <link>https://dev.to/ciscoemerge/risk-scoring-your-api-specification-with-panoptica-5d5n</link>
      <guid>https://dev.to/ciscoemerge/risk-scoring-your-api-specification-with-panoptica-5d5n</guid>
      <description>&lt;p&gt;Every API has distinct capabilities. As a developer, we want to know what an API can do and what its limitations are. These characteristics can be outlined in an API definition file, known as a specification. An API specification is the skeleton of an API, providing a logical outline of an APIs behaviour, and how the API can be consumed, often generating documentation providing developers with a guide to correctly interact with the API.&lt;/p&gt;

&lt;p&gt;Your API Specification can prove to be a gem in risk scoring your APIs to gain insight into the Critical, High, Medium and Low risks. This can be the detection of root privileges enabled to certain users/processes, modified templates/images, privilege escalation capabilities, etc. These findings are related to the CIA Triad: Confidentiality, Integrity, Availability, helping you in the prevention of confidentiality and integrity breach, as well as having deeper visibility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uwLr16uY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jb61ibh29z7kwz8r0yiq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uwLr16uY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jb61ibh29z7kwz8r0yiq.gif" alt="Image description" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following the walk-through will require a couple of set-up scripts, If you wish to see the actual product capabilities, skip to the Intro section.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-requisites&lt;/strong&gt;&lt;br&gt;
1x AWS instance_type": "c5.2xlarge (or similar computing power)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Set up&lt;/strong&gt;&lt;br&gt;
To evaluate the specification, we first need to initialise an environment to perform these series of tests. Our environment needs Docker, KinD, Terraform, and the Kubernetes CLI (kubectl). We will use KinD and Docker to install our Kubernetes cluster. Then we will use Terraform and the Kubernetes CLI to provision the Panoptica controller and microservices (Sock Shop) application into the cluster. Then we will use Locust to generate synthetic traffic.&lt;/p&gt;

&lt;p&gt;(You can also try to re-create this capability in your own environment, on your own microservices/APIs by deploying the Panoptica controller and singing up to Panoptica)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;br&gt;
In this walk-through demo, we will look at how Panoptica (a developer security tool), can grant &lt;br&gt;
deeper visibility and security controls of your API, by evaluating your API specification and risk scoring it to determine the security posture of your APIs. &lt;/p&gt;

&lt;p&gt;Consider an example web application, a sock-shop.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3aCFMMEB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oytqlg7uxj21jihopu8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3aCFMMEB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oytqlg7uxj21jihopu8i.png" alt="Image description" width="800" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This web application has activity in the form of customers accessing its site, browsing through the catalog of socks, and placing orders. (API activity). Panoptica displays run-time workloads, including their risk score, related security threats, events that may have caused these threats, and many more details that help reduce the Mean Time To Response (MTTR).&lt;/p&gt;

&lt;p&gt;1: In the Panoptica UI, from the Panoptica homepage select RUNTIME. Here we see all our workloads with vulnerability and risk scores.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uzzYyIa2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gdhhwqh25txwj1p490b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uzzYyIa2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gdhhwqh25txwj1p490b.png" alt="Image description" width="406" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2: Click on the Connections tab, you can now view the connections between pods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AGGbX2NU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kkvvkbkukqay6nty6duu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AGGbX2NU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kkvvkbkukqay6nty6duu.png" alt="Image description" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3: From the menu, select APIs. Under Internal APIs you can view the workloads. This is where we will be analysing our API security posture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DvuHX6DI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1s45zsywtra2s7f2qgqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DvuHX6DI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1s45zsywtra2s7f2qgqq.png" alt="Image description" width="800" height="255"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The APIs security results are listed. ‘httpbin’ has been found to have a high-risk security vulnerability, and two medium risk findings in cluster shmcfarl-aio-1. &lt;br&gt;
 &lt;br&gt;
&lt;u&gt;&lt;strong&gt;High Risk&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Workload can run as root (1x occurrence)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Medium Risk&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Workload template has been modified (1x occurrence)&lt;/li&gt;
&lt;li&gt;Workload can escalate its privileges (1x occurrence)
 
These are common, yet highly sensitive risks in the form of misconfigurations, that otherwise would have gone unnoticed, or perhaps detected after damage has been done. Risks can also present themselves in the form of CVE detected vulnerabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A7hMGmhO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tlwhk7v5s0ruihyrct7p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A7hMGmhO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tlwhk7v5s0ruihyrct7p.png" alt="Image description" width="800" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scoring the API Specification&lt;/strong&gt;&lt;br&gt;
Panoptica analyses APIs used by workloads in your environments and assigns a risk score to them. This includes both internal, and external APIs. Internal API traffic between workloads (microservices communication). You can also upload API specs to Panoptica (OAS format). The spec will be analysed to generate a risk score, the analysis is performed whenever a spec is uploaded or modified. Panoptica also performs a trace analysis on actual API traffic(internal, and external), to identify security issues, and uses this in calculating the risk scores.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Uploading the API Specification&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this scenario, we will upload the API specification of the API we wish to have Panoptica analyse for security posture/risk scoring.&lt;/p&gt;

&lt;p&gt;1: From the Panoptica Dashboard select APIs from the menu. Here you will see all the workload APIs running in the Kubernetes cluster. Double-click on the front-end workload and you will be taken to the API inventory page. Here we will see details once we upload the API Spec.&lt;br&gt;
2: Download the API spec files from Github. Go to (&lt;a href="https://github.com/rami000/devtoAPISpec"&gt;https://github.com/rami000/devtoAPISpec&lt;/a&gt;) and download the repo to your local desktop.&lt;br&gt;
3: Extract the file. In the api-spec directory there are 4 JSON files. We will upload the frontend.json file to the Panoptica UI&lt;br&gt;
4: Go back into the Panoptica UI. Make sure you are in APIs &amp;gt; Internal APIs &amp;gt; front-end. From this page select the SPECS tab. Click on Upload a spec and upload the frontend.json file and click Finish – this may take a while.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qjue0qz2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqecy6pc6q1uxln54o5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qjue0qz2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gqecy6pc6q1uxln54o5l.png" alt="Image description" width="800" height="298"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;5: Dive deeper into what the spec analysis found for API Structure. Click on &lt;strong&gt;Definitions &amp;gt; _embedded&lt;/strong&gt; to find more info about this risk. Click through other risks to see what else Panoptica found.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Dp0q3PxG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uur6dc6p7xsk4fbjr60f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Dp0q3PxG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uur6dc6p7xsk4fbjr60f.png" alt="Image description" width="468" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6: Click on the &lt;strong&gt;Risk Findings &amp;gt; Security Posture&lt;/strong&gt; tabs. Select &lt;strong&gt;api-specification&lt;/strong&gt; to learn more about the Security Posture of the API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xzs0Zgp0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lympwou2kspse1tswjp8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xzs0Zgp0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lympwou2kspse1tswjp8.png" alt="Image description" width="468" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;7: Click through the &lt;strong&gt;7 Critical Risks Findings&lt;/strong&gt; to get more details. This detail shows 7 API paths have missing or misconfigured Authentication and Authorization controls. The first identified path is a GET to &lt;strong&gt;/addresses/{param1}&lt;/strong&gt;. Click on other occurrences to see what other paths can be accessed without any adequate security controls. Click through other risks to see what else Panoptica found.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B1f2nqNs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tx1becndnmtr9vg64yy4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B1f2nqNs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tx1becndnmtr9vg64yy4.png" alt="Image description" width="468" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xezhn3BL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3lav67bhg3pm0zfcxqk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xezhn3BL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3lav67bhg3pm0zfcxqk.png" alt="Image description" width="468" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Congratulations on completing this tutorial! You were able to upload the API Spec to get analysed and risk scored by Panoptica API Security.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this walk-through tutorial, we learned how API specs are useful in risk scoring your APIs, and how Panoptica can be used to achieve a security posture overview of your APIs. &lt;/p&gt;

&lt;p&gt;First we evaluated the API specification by manually uploading the spec file. Once Panoptica had the API specification, it was able to find Security Risks on the configured APIs. These risks were categorised into Critical, High, Medium, and Low under the APIs security posture. Each finding provided a description, remediation, and how many occurrences were found.&lt;/p&gt;

&lt;p&gt;As a next step, you can use the traces to generate a specification during run-time and enforce (automated) security on-the-fly for your APIs, and K8 workloads.&lt;/p&gt;

&lt;p&gt;This feature is available in the open-source tool &lt;a href="https://github.com/openclarity/apiclarity"&gt;APIClarity&lt;/a&gt;, as part of the OpenClarity initiative. &lt;/p&gt;

&lt;p&gt;APIClarity is a modular tool that addresses several aspects of API Security, focusing specifically on OpenAPI based APIs.&lt;/p&gt;

&lt;p&gt;APIClarity approaches API Security in 2 different ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Captures all API traffic in a given environment and performs a set of security analyses to discover all potential security problems with detected APIs&lt;/li&gt;
&lt;li&gt;Actively tests API endpoints to detect security issues in the implementation of such APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MiRVco-T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/165565ny4jiwqhcxi89z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MiRVco-T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/165565ny4jiwqhcxi89z.png" alt="Image description" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The commercial SaaS version of this product offers many more advanced features covering deeper APIsec features, K8sec, Serverless functions, Software-Supply Chain, and other visibility/security controls.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting started&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;The most advanced cloud-native security, now free for everyone! Sign up and get started with Panoptica right away.&lt;/strong&gt;&lt;br&gt;
    • No credit card required&lt;br&gt;
    • Get started in no time&lt;br&gt;
    • Up to 15 nodes, 1 cluster&lt;br&gt;
Sign up here to get Started &lt;a href="https://www.panoptica.app/sign-up"&gt;Panoptica&lt;/a&gt;!!!&lt;/p&gt;

</description>
      <category>api</category>
      <category>apisecurity</category>
      <category>security</category>
    </item>
  </channel>
</rss>
