<?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>Forem: Protego Labs</title>
    <description>The latest articles on Forem by Protego Labs (@protego).</description>
    <link>https://forem.com/protego</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%2Forganization%2Fprofile_image%2F1235%2F56c372a2-7195-47a2-86f0-64233ab19f06.png</url>
      <title>Forem: Protego Labs</title>
      <link>https://forem.com/protego</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/protego"/>
    <language>en</language>
    <item>
      <title>Azure Functions Security: Best Practices</title>
      <dc:creator>Tal Melamed</dc:creator>
      <pubDate>Thu, 26 Sep 2019 20:12:47 +0000</pubDate>
      <link>https://forem.com/protego/azure-functions-security-best-practices-5og</link>
      <guid>https://forem.com/protego/azure-functions-security-best-practices-5og</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This article is part of &lt;a href="https://dev.to/azure/serverless-september-content-collection-2fhb"&gt;#ServerlessSeptember&lt;/a&gt;. You'll find other helpful articles, detailed tutorials, and videos in this all-things-Serverless content collection. New articles are published every day — that's right, every day — from community members and cloud advocates in the month of September. &lt;/p&gt;

&lt;p&gt;Find out more about how Microsoft Azure enables your Serverless functions at &lt;a href="https://docs.microsoft.com/azure/azure-functions/?WT.mc_id=servsept_devto-blog-cxa" rel="noopener noreferrer"&gt;https://docs.microsoft.com/azure/azure-functions/&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Favk9z12ih4j9y5vqepdu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Favk9z12ih4j9y5vqepdu.png" alt="azure-function-security"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What are we going to learn?
&lt;/h2&gt;

&lt;p&gt;You’ve been hearing about Serverless literally all month long. So, there’s really no need to go further in details about how the advantages and disadvantages (are there?) of moving into serverless architecture. This post will be purely about &lt;strong&gt;security&lt;/strong&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Do you deploy azure functions? (&lt;em&gt;I'm here, aren't I?&lt;/em&gt;). Do you want to secure your functions? (&lt;em&gt;still here...&lt;/em&gt;). Great! make sure you:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Perform input validation&lt;/li&gt;
&lt;li&gt;Follow Least Privilege principle&lt;/li&gt;
&lt;li&gt;Monitor 3rd-party dependencies&lt;/li&gt;
&lt;li&gt;Secure your cloud storage&lt;/li&gt;
&lt;li&gt;Secure your function secrets&lt;/li&gt;
&lt;li&gt;Enforce Authentication and Authorization&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Specifically, I will discuss security best practices for serverless development. Mostly that means application security with a sprinkle of configuration. Because that what serverless is all about, no?! Because we shift most of the responsibilities to the cloud provider and what’s left for us to protect, is our code.&lt;/p&gt;

&lt;p&gt;A dream come true, some might say. We no longer continuously check that our server has the latest OS security patches installed. That’s now Microsoft’s problem (If you are unfamiliar with the &lt;a href="https://aka.ms/sharedresponsibility" rel="noopener noreferrer"&gt;Shared Responsibilities for Cloud Computing&lt;/a&gt;, I strongly suggest you review it).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FoHgbEop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FoHgbEop.png" alt="false-prophecy?"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Security exists, but differently
&lt;/h2&gt;

&lt;p&gt;Hold your horses. That is definitely one of the many security advantages of moving to serverless development. But don't get too comfortable... we still need security, it is just a little different. Even without provisioning or managing servers, Azure functions still execute code. If this code is poorly written, the function could still be vulnerable to application-level attacks. &lt;/p&gt;

&lt;p&gt;An attacker could run malicious code in your account which could lead to sensitive data leakage, performing unauthorized actions in the cloud and in some extreme cases, it could even lead to a complete application takeover. If your Azure function is vulnerable and has the permissions to do so, the attacker could interact with other cloud resources and could end up owning them.&lt;/p&gt;

&lt;p&gt;I hope that by now you agree with me that we need to address Serverless security. So, let’s get a little more technical and discuss some security best practices that will help you keep your Azure functions protected.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FbUBN8Or.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FbUBN8Or.png" alt="get-technical"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Perform input validation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Code_injection" rel="noopener noreferrer"&gt;Injection flaws&lt;/a&gt; attacks are one of the most common risks in applications and they are part of most secure coding best practice guides. Injection attacks try to exploit code which passes untrusted inputs directly to an interpreter before being executed or evaluated.&lt;/p&gt;

&lt;p&gt;Since serverless functions can be &lt;a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings" rel="noopener noreferrer"&gt;triggered from different events sources&lt;/a&gt; like Cloud storage (Blob), NoSQL database (CosmosDB), Event Hubs, Queue, Graph events and more, injections are not strictly limited to inputs coming directly from the API calls and functions can consume input from each type of the possible event sources.&lt;/p&gt;

&lt;h4&gt;
  
  
  What should you do?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;In general, never trust input or make any assumptions about its validity.&lt;/li&gt;
&lt;li&gt;Always use safe APIs that sanitize or validate the input. When possible, use APIs which bind or parameterize variables (e.g. using &lt;a href="https://docs.microsoft.com/en-us/sql/relational-databases/security/sql-injection?view=sql-server-2017#use-parameterized-input-with-stored-procedures" rel="noopener noreferrer"&gt;prepared statements&lt;/a&gt; for SQL queries).&lt;/li&gt;
&lt;/ul&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Net&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AspNetCore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Mvc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Extensions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Primitives&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;Newtonsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Json&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;using&lt;/span&gt; &lt;span class="nx"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;RegularExpressions&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   

&lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;IActionResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;HttpRequest&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ILogger&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LogInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C# HTTP trigger function processed a request.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Query&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="nx"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;validate_name_pattern&lt;/span&gt; &lt;span class="o"&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;^[a-zA-Z-.' ]{2,64}$&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;requestBody&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;StreamReader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nc"&gt;ReadToEndAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;dynamic&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JsonConvert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DeserializeObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;requestBody&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;bool&lt;/span&gt; &lt;span class="nx"&gt;isNameValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Regex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsMatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;validate_name_pattern&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      
    &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LogInformation&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 validation result for &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;isNameValid&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;name&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;isNameValid&lt;/span&gt;
        &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ActionResult&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OkObjectResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, {name}&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BadRequestObjectResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid name&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;
  
  
  2. Follow Least Privilege principle
&lt;/h2&gt;

&lt;p&gt;Bottom line: A serverless function should have only the privileges essential to performing its intended logic, following the &lt;em&gt;"&lt;a href="https://en.wikipedia.org/wiki/Principle_of_least_privilege" rel="noopener noreferrer"&gt;Principle of least privilege&lt;/a&gt;"&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Since serverless functions are usually designed as micro-services, it is very common to have dozens, hundreds or even thousands of functions as part of the application. Managing function permissions and roles is a difficult and tedious task. &lt;/p&gt;

&lt;p&gt;In many cases, developers are forced to use a single permission model or security role for all functions, which grants them access to other system components which are not actually required by the function. Exploiting an over-privileged function could lead into a security catastrophe in your organization's cloud.&lt;/p&gt;

&lt;p&gt;Designating groups or individual roles responsible for specific functions in Azure helps avoid confusion that can lead to human and automation errors that create security risks. &lt;/p&gt;

&lt;h4&gt;
  
  
  What should you do?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Review each function before deployment to identify excessive permissions&lt;/li&gt;
&lt;li&gt;Carefully examine functions to apply “least privilege” permissions, giving each function exactly, and only what is required for the function to successfully execute its task&lt;/li&gt;
&lt;li&gt;It is recommended to use a tool to automate the permission 
configuration process, like we do at &lt;a href="https://protego.io" rel="noopener noreferrer"&gt;Protego&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/h4NwuHxFyIb54EUNAF/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/h4NwuHxFyIb54EUNAF/giphy.gif" alt="proteg-proact"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://docs.microsoft.com/en-us/azure/role-based-access-control/overview" rel="noopener noreferrer"&gt;RBAC&lt;/a&gt; to assign permissions to users, groups, and applications at a certain scope. The scope of a role assignment can be a subscription, a resource group, or a single resource and avoid using wildcards (&lt;code&gt;*&lt;/code&gt;) whenever possible &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Frole-based-access-control%2Fmedia%2Foverview%2Frbac-overview.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Frole-based-access-control%2Fmedia%2Foverview%2Frbac-overview.png" alt="RBAC"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://docs.microsoft.com/en-us/azure/storage/common/storage-sas-overview" rel="noopener noreferrer"&gt;Shared Access Signature (SAS)&lt;/a&gt; tokens to get limited access to other resources and services&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F9PvFRu3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2F9PvFRu3.png" alt="SAS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Monitor 3rd-party dependencies
&lt;/h2&gt;

&lt;p&gt;A serverless function's code is usually small. However, to be able to execute the desired tasks, functions make use of many dependencies and 3rd-party libraries. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://npm.anvaka.com/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FsJJmpbM.gif" alt="npm-request-dependencies"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vulnerability introduced by the supply chain is one of the most common risks these days and attackers will target code that makes use of vulnerable libraries as an entry point to the application. &lt;/p&gt;

&lt;p&gt;Additionally, in what we refer to as ‘Poisoning the Well,’ attackers aim to gain more long-term persistence in the application by means of an upstream attack. After poisoning the well, they patiently wait as the new version makes its way into cloud applications.&lt;/p&gt;

&lt;p&gt;If you use .NET, Microsoft will announce about NuGet packages with known vulnerabilities, just like &lt;a href="https://github.com/dotnet/announcements/issues/12" rel="noopener noreferrer"&gt;this one&lt;/a&gt;. But, this is valid for all runtimes. Whether you are using Python (pip), Java (Maven), Node (npm) or any other package management.&lt;/p&gt;

&lt;h4&gt;
  
  
  What should you do?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Continuously monitor dependencies and their versions throughout the system using OWASP &lt;a href="https://dependencytrack.org/" rel="noopener noreferrer"&gt;Dependency Track&lt;/a&gt; or any other system&lt;/li&gt;
&lt;li&gt;Obtain components only from official sources over secure links. &lt;/li&gt;
&lt;li&gt;Prefer signed packages to reduce the chance of including a modified, malicious component&lt;/li&gt;
&lt;li&gt;Continuously monitor packages with vulnerability databases like &lt;a href="https://cve.mitre.org/index.html" rel="noopener noreferrer"&gt;MITRE CVE&lt;/a&gt; and &lt;a href="https://nvd.nist.gov/vuln/" rel="noopener noreferrer"&gt;NVD&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;It is recommended to scan dependencies for known vulnerabilities using tools such as OWASP &lt;a href="https://jeremylong.github.io/DependencyCheck/" rel="noopener noreferrer"&gt;Dependency Check&lt;/a&gt; or a commercial solution.&lt;/li&gt;
&lt;li&gt;For dotnet, Use &lt;a href="https://www.nuget.org/packages/dotnet-retire" rel="noopener noreferrer"&gt;dotnet-retire&lt;/a&gt;. A tool to check dependencies for versions with known vulnerabilities&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FngAyrAg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FngAyrAg.png" alt="dotnet-retire"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Check NuGet package vulnerabilities with OWASP &lt;a href="https://github.com/OWASP/SafeNuGet" rel="noopener noreferrer"&gt;SafeNuGet&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Use runtime-dependent security databases such as &lt;a href="https://github.com/pyupio/safety-db" rel="noopener noreferrer"&gt;pyup&lt;/a&gt; for Python and &lt;a href="https://www.npmjs.com/advisories" rel="noopener noreferrer"&gt;npm Security Advisories&lt;/a&gt; For Node&lt;/li&gt;
&lt;li&gt;Use &lt;a href="https://github.com/OSSIndex/audit.net" rel="noopener noreferrer"&gt;Audit.NET&lt;/a&gt; which integrates with VS to identify known vulnerabilities in .Net NuGet dependencies&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  4. Secure your cloud storage
&lt;/h2&gt;

&lt;p&gt;Misconfigured cloud storage authentication/authorization is a widespread weakness affecting applications. There are numerous incidents of insecure cloud storage configurations have exposed sensitive, confidential information to unauthorized users. Occasionally, this data can even become public after being indexed by search engines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.theregister.co.uk/2019/09/20/tesco_parking_app_10s_millions_anpr_photos_exposed/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FXZixO7E.png" alt="blob-breach"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since serverless functions are usually stateless, many applications have an architecture that rely on cloud storage infrastructure to store and persist data between executions.&lt;/p&gt;

&lt;p&gt;If the cloud storage does not enforce proper access controls, user might be able to upload files directly into it, leading into consuming high quotas and triggering internal functionalities.&lt;/p&gt;

&lt;h4&gt;
  
  
  What should you do?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Identify and classify sensitive data&lt;/li&gt;
&lt;li&gt;Minimize storage of sensitive data to only what is absolutely necessary&lt;/li&gt;
&lt;li&gt;For sensitive data storage, add multi-factor authentication, and data encryption (in transit and at rest)&lt;/li&gt;
&lt;li&gt;Review &lt;a href="https://docs.microsoft.com/en-us/azure/storage/common/storage-security-guide" rel="noopener noreferrer"&gt;Azure Storage security guide&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Grant limited access to Azure Storage resources using &lt;a href="https://docs.microsoft.com/en-us/azure/storage/common/storage-sas-overview?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json" rel="noopener noreferrer"&gt;shared access signatures (SAS)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Fcommon%2Fmedia%2Fstorage-sas-overview%2Fsas-storage-provider-service.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Fcommon%2Fmedia%2Fstorage-sas-overview%2Fsas-storage-provider-service.png" alt="blob-sas"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Secure your function secrets
&lt;/h2&gt;

&lt;p&gt;There is always a need to store and maintain &lt;em&gt;secrets&lt;/em&gt; in our application. Secrets could be API Keys, credentials to other resources (e.g. database), Crypto-keys (Encryption/Decryption) and sensitive configuration settings.&lt;/p&gt;

&lt;p&gt;Storing such secrets in a plain text configuration file could end up being uploaded to and &lt;a href="https://www.zdnet.com/article/over-100000-github-repos-have-leaked-api-or-cryptographic-keys/" rel="noopener noreferrer"&gt;leaked through shared repositories&lt;/a&gt; (e.g. Github). There &lt;a href="https://securitytrails.com/blog/github-dorks" rel="noopener noreferrer"&gt;multiple tools&lt;/a&gt; that hackers use to try and identify such leaked keys. There are many storied &lt;/p&gt;

&lt;p&gt;While environment variables are a useful way to persist data across serverless function executions, in some cases, such environment variables can leak and reach the wrong hands.&lt;/p&gt;

&lt;p&gt;It is critical to store such secrets in a secure, encrypted storage environment.&lt;/p&gt;

&lt;h4&gt;
  
  
  What should you do?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Use Microsoft &lt;a href="https://secdevtools.azurewebsites.net/helpcredscan.html" rel="noopener noreferrer"&gt;CredScan&lt;/a&gt; tool to identify credential leaks&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/azure/key-vault/vs-secure-secret-appsettings" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fvsidedevopsmsft.gallerycdn.vsassets.io%2Fextensions%2Fvsidedevopsmsft%2Fcontinuousdeliverytoolsforvisualstudio%2F0.4.211.1649%2F1562150364758%2F287302%2F1%2FCredScan.png" alt="credscan"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Whenever possible, manage encryption keys in a centralized encryption key management infrastructure or service like Azure &lt;a href="https://docs.microsoft.com/en-us/azure/key-vault/" rel="noopener noreferrer"&gt;Key-vault&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fldf6Pnb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Fldf6Pnb.png" alt="azure-key-vault"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;You can read &lt;a href="https://jan-v.nl/post/working-with-azure-key-vault-in-azure-functions" rel="noopener noreferrer"&gt;Working with Azure Key Vault in Azure Functions&lt;/a&gt; by Jan de Vries, a Microsoft MVP&lt;/li&gt;
&lt;li&gt;Read &lt;a href="https://david-obrien.net/2016/09/azure-functions-secrets/" rel="noopener noreferrer"&gt;How to handle secrets with Azure Functions&lt;/a&gt; by David O'Brien, MVP for Microsoft Azure &lt;/li&gt;
&lt;li&gt;When using configuration file with sensitive information over Git, make sure to add them to the &lt;code&gt;.gitignore&lt;/code&gt; file&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  6. Enforce Authentication and Authorization
&lt;/h2&gt;

&lt;p&gt;Serverless architecture require that we orchestrate all our functions and services to form the overall system logic. While some functions expose public APIs, others serve as a pipe between processes and there are multiple ways to trigger them, including internal triggers events. &lt;/p&gt;

&lt;p&gt;The stateless nature of serverless architecture requires a careful access control configuration for each of the resources, which could be onerous. &lt;/p&gt;

&lt;p&gt;Imagine a serverless application which exposes a set of public APIs, all of which enforce proper authentication. At the other end of the system, the application reads files from a blob storage service where file contents are consumed as input to specific serverless functions. If proper authentication is not applied to the cloud storage service, the system is exposing an unauthenticated rogue entry point—an element not considered during system design.&lt;/p&gt;

&lt;h4&gt;
  
  
  What should you do?
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Review and apply &lt;a href="https://docs.microsoft.com/en-us/azure/app-service/overview-authentication-authorization" rel="noopener noreferrer"&gt;Authentication and authorization in Azure App Service&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Follow &lt;a href="https://docs.microsoft.com/en-us/azure/security/fundamentals/identity-management-best-practices" rel="noopener noreferrer"&gt;Azure Identity Management and access control security best practices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;External-facing resources should require authentication and access control. Review &lt;a href="https://www.red-gate.com/simple-talk/cloud/cloud-development/azure-api-management-part-2-safeguarding-your-api/" rel="noopener noreferrer"&gt;Azure API Management Safeguarding&lt;/a&gt; by Stuart Leeks, Principal Software Development Engineer at Microsoft&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FKWCuZoj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FKWCuZoj.png" alt="OAuth-Configure-API"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;For service authentication between internal resources and services, use known secure methods, such as Federated Identity (e.g. SAML, OAuth2, Security Tokens)&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;I could go on and on about this topic. But I believe that concentrating on a few, high impact, practical security enforcement could do a great deal in making your Azure functions safe.&lt;/p&gt;

&lt;p&gt;For those of you who &lt;em&gt;do&lt;/em&gt; want to learn more, I can suggest:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Follow to the open-source &lt;a href="https://github.com/OWASP/Serverless-Top-10-Project" rel="noopener noreferrer"&gt;OWASP Serverless Top 10&lt;/a&gt; risk project&lt;/li&gt;
&lt;li&gt;Come to &lt;a href="https://appsec.it/talks" rel="noopener noreferrer"&gt;my talks&lt;/a&gt; or watch them virtually (when available)&lt;/li&gt;
&lt;li&gt;Follow me on &lt;a href="https://twitter.com/_nu11p0inter" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; to learn more about new security research, demos, challenges, talks, ideas and references.&lt;/li&gt;
&lt;li&gt;If you want to see how the &lt;em&gt;villains&lt;/em&gt; thinks. This is my #ServerlessHacking talk from the last &lt;a href="https://www.derbycon.com/" rel="noopener noreferrer"&gt;@DerbyCon&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/EbPu-Mmvxqc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>azure</category>
      <category>security</category>
      <category>serverless</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
