<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Patrick Spiegel on Medium]]></title>
        <description><![CDATA[Stories by Patrick Spiegel on Medium]]></description>
        <link>https://medium.com/@PatrickSpiegel?source=rss-1c260b43e73c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I__WzGHLNA-s-k4JstTrdg.jpeg</url>
            <title>Stories by Patrick Spiegel on Medium</title>
            <link>https://medium.com/@PatrickSpiegel?source=rss-1c260b43e73c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 16:50:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@PatrickSpiegel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Secure-by-default Headers with Envoy and Istio]]></title>
            <link>https://medium.com/@PatrickSpiegel/secure-by-default-headers-with-envoy-and-istio-5b973ed8b675?source=rss-1c260b43e73c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b973ed8b675</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[envoy-proxy]]></category>
            <dc:creator><![CDATA[Patrick Spiegel]]></dc:creator>
            <pubDate>Thu, 22 Aug 2019 18:50:44 GMT</pubDate>
            <atom:updated>2019-08-22T18:50:44.460Z</atom:updated>
            <content:encoded><![CDATA[<p>When organizations move to a new platform such as Kubernetes to build their applications upon, a lot of things have to be reconsidered. Security, access control and monitoring are just a few examples. Envoy and Istio bring a lot to the table when it comes to solving these challenges in a Kubernetes environment. Even Google’s envisioned Knative PaaS builds its foundation on Istio and Envoy running on Kubernetes. That’s why we selected a relatively simple security requirement — HTTP Security Headers — and want to exemplify how to implement it in a secure-by-default manner for this emerging technology stack.</p><h3>Why use Security Headers?</h3><p>Well, the web evolved a lot over the years. Many new technologies were introduced, but they were also accompanied by new attack vectors such as Clickjacking and Cross-site Scripting as well as privacy issues. Browser vendors addressed these problems with new security and privacy features. Unfortunately, enabling them by default would break existing websites. As a result, each site has to take the decision which features to enable and how to configure them. This is accomplished by sending respective HTTP response headers that inform the browser which features to enable for your site. The following snippet gives an example of setting a security header.</p><pre>HTTP/1.1 200 OK<br>Content-Length: 88<br>Content-Type: text/html<br>X-Frame-Options: deny<br><br>&lt;html&gt; ...</pre><p>The given HTTP response tells the browser to not frame its contents by setting theX-Frame-Options header. This prevents clickjacking attacks against your page. In case you really need to be framed by certain sites, you can explicitly allow them by replacing deny with the respective origin of the page you would like to be framed by. By explicitly allowing origins the risk of being framed by an attacker-controlled origin is minimized.</p><h3>Why set Security Headers secure-by-default?</h3><p>The problem of breaking legacy applications changes when you move to a new platform and build your applications from scratch — or at least you have to set them up for the new platform. The point is, there won’t be too many legacy applications which break because of the security and privacy features of the browser. These circumstances allow us to turn around the status quo and set security headers secure-by-default. Each application that requires different behavior can overrule this new default by explicitly setting more relaxed security headers.</p><h3>Which Security Headers should be set?</h3><p>When searching the internet for security headers you will find a lot of advice. OWASP provides best-practice <a href="https://www.owasp.org/index.php/OWASP_Secure_Headers_Project#tab=Headers">guidelines</a> and programming frameworks, which describe how to secure apps with security headers. There are even services that directly rate the security and privacy headers of your deployment. Although most of these guidelines fit our requirements, a few are also very application-specific and cannot be set without context-specific knowledge of the app. Taking in mind that probably multiple applications run on a single cluster, the solution should be kept generic. Also, some headers handling HTTPS/TLS specifics are left out, certificates for load balancers exposing clusters are not configured by default.</p><p>Boiling it down to the security and privacy headers that can be set centrally for an entire cluster and do not handle HTTPS specifics:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KeCK-h_TMwHvTr60Ns0MxQ.png" /></figure><p>This list of default headers might be extended for productive usage with HTTPS enabled endpoints as well as stricter Content-Security-Policyor Feature-Policiy settings. But for now, this is our baseline setting.</p><h3>Where to implement Security Headers in Istio’s Architecture?</h3><p>We have a list of security headers to be deployed cluster-wide and now the question is how to integrate them into Envoy resp. the Istio programming model. If you are completely new to Istio and Envoy and how they interact, take a look at the <a href="https://istio.io/docs/concepts/what-is-istio/">docs</a> page. The following illustration describes how Istio handles Ingress and Egress via proxies and gateway and helps to get an overview where headers could be set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rf37njT738vYb-Bf.png" /><figcaption>(Source: <a href="https://istio.io/docs/concepts/traffic-management/#ingress-and-egress">https://istio.io/docs/concepts/traffic-management/#ingress-and-egress</a>)</figcaption></figure><p>Incoming requests to the cluster and the service mesh and outgoing responses route through the Ingress gateway. Service to service communication within the service mesh is handled through the Envoy sidecars placed in each pod. Outgoing requests and incoming responses route through the optional Egress gateway. Gateways, as well as sidecars, are instances of the Envoy proxy running in the cluster.</p><p>Service to service calls within the mesh does not require security headers interpreted by the browser. So, the Envoy sidecars are probably not the best place to check and set our headers when we don’t want to cause unnecessary processing and cluster-internal traffic overhead. Also, requests leaving the mesh through the optional Egress gateway do not communicate with browsers in a way security headers would make sense. The outbound handler of the Ingress gateway is where responses may end up in a browser and where we should set security headers. Therefore, the Ingress gateway(s) is the sweet spot to set security headers secure-by-default for the browser.</p><p>Be well aware: There are other ways of exposing services with Kubernetes, but this article focuses on Istio’s programming model!</p><h3>Implementation as an Envoy Filter</h3><p>As previously outlined, the Ingress gateway is actually realized as an Envoy proxy. In order to implement the secure-by-default header concept, functionality for response manipulation offered by Envoy can be leveraged. According to the Envoy <a href="https://www.envoyproxy.io/docs/envoy/v1.7.0/configuration/http_filters/lua_filter.html?highlight=lua#overview">documentation</a>, header manipulation can be accomplished through response handlers defined as a Lua filter. A Lua filter is basically a snippet of Lua code that is executed for each request or response it is registered for. With Istio, this Lua filter can be configured centrally and is distributed to the respective Envoy instance of the Ingress gateway. The documentation for using Envoy filters within Istio can be found <a href="https://istio.io/docs/reference/config/istio.networking.v1alpha3/#EnvoyFilter">here</a>. The below resource (complete code on <a href="https://gist.github.com/dacappo/5cfea0e41993aefda0d8e4e0a29e79ec">GitHub</a>) gives an example of how to configure the secure-by-default header filter for the Ingress gateway via Istio:</p><pre>apiVersion: networking.istio.io/v1alpha3<br>kind: EnvoyFilter<br>metadata:<br>  name: security-by-default-header-filter<br>spec:<br>  filters:<br>  - listenerMatch:<br>      listenerType: GATEWAY<br>    filterType: HTTP<br>    filterName: envoy.lua<br>    filterConfig:<br>      inlineCode: |<br>        function ...</pre><p>The complete filter definition can be found on <a href="https://gist.github.com/dacappo/5cfea0e41993aefda0d8e4e0a29e79ec">GitHub</a>.</p><p>This <a href="https://gist.github.com/dacappo/5cfea0e41993aefda0d8e4e0a29e79ec">configuration file</a> defines an HTTP filter in contrast to the also available lower-level network filters. The HTTP filter should be executed on the GATEWAY listener – the Ingress gateway. Further, the type indicates that a Lua script defines the behavior of the filter. The Lua script itself registers itself onto the envoy_on_response event which means the filter is only invoked for outgoing traffic and not incoming requests. The logic of the Lua code is quite simple: When a security header is already defined by the application do nothing. Otherwise, add the security header with a strict setting. Take into account that only parts of the Content-Security-Policy and Feature-Policy are set by the filter.</p><p>Just apply the <a href="https://gist.github.com/dacappo/5cfea0e41993aefda0d8e4e0a29e79ec">upper YAML</a> (secure-http-headers.yaml) to an Istio cluster and the secure-by-default headers are ready to go.</p><pre>$ kubectl apply -f secure-http-headers.yaml</pre><p>You can see the installed Envoy filter by running.</p><pre>$ kubectl get envoyfilter<br><br>NAME                                 AGE<br>security-by-default-header-filter    1m</pre><h3>Fallback Option</h3><p>Now, the filter takes care that the headers are set strictly, but what if a single application requires standard behavior of the browser no matter which security implications it brings? — No problem! But in a secure-by-default environment, the application has to explicitly set the respective headers to the fallback value to inform browsers to return to their default behavior and turn security and privacy features off.</p><h3>Test it yourself</h3><p>Do you have an application running and exposed via the Istio gateway? Just deploy the filter and see how your app rates on <a href="https://securityheaders.com/">securityheaders.com</a>. Great service!</p><h3>TL;DR</h3><p>To have the basic HTTP security headers set secure-by-default on an Istio cluster’s Ingress gateway deploy the <a href="https://gist.github.com/dacappo/5cfea0e41993aefda0d8e4e0a29e79ec">referenced resource</a> with kubectl apply. The secure-by-default headers can be overruled by setting them explicitly within your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b973ed8b675" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NoSQL Injection > Redis]]></title>
            <link>https://medium.com/@PatrickSpiegel/https-medium-com-patrickspiegel-nosql-injection-redis-25b332d09e58?source=rss-1c260b43e73c------2</link>
            <guid isPermaLink="false">https://medium.com/p/25b332d09e58</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Patrick Spiegel]]></dc:creator>
            <pubDate>Thu, 10 Aug 2017 11:45:49 GMT</pubDate>
            <atom:updated>2017-08-27T21:10:20.179Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQqupXl5bUHf7Vf_DTmZ5Q.jpeg" /></figure><p>In the last decade, the emerging cloud platforms changed the way we design and build applications. This new situation gave a rise to lightweight and scalable databases such as MongoDB and Redis. These NoSQL databases present a solution for many cloud scenarios, but do they provide security? Ever considered injection a problem for NoSQL databases? - Probably not. Within this post, I would like to show you a simple approach for injection attacks against applications running on <strong>Redis</strong> and <strong>Node.js</strong>.</p><p>Chances are you have heard about SQL Injection - but do NoSQL databases provide better security? Regarding injection, there exists a prevalent opinion:</p><blockquote>“We are not building queries from strings, so we do not have to worry about conventional injection vulnerabilities!”</blockquote><p>The emphasis lays on <strong>conventional </strong>injection vulnerabilities. Many NoSQL databases employ non-SQL query techniques. So maybe we will find some rather <strong>unconventional</strong> cases of injection attacks. Admittedly, a few <a href="https://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb.html">injection techniques</a> against the document store MongoDB are already known and have proven that NoSQL Injection represents a real issue - but one might not think of injection as a problem for simple key-value stores like Redis. Let’s see what an attacker may be able to achieve.</p><p><strong>Redis </strong>is just a key-value store … so what’s the worst that could happen? Well, let’s have a closer look. The most prevalent <a href="https://www.npmjs.com/package/redis">driver</a> for Redis on Node.js gives us a great point to start from. Its documentations says:</p><blockquote>All functions take either an args array plus optional callback function or a variable number of individual arguments followed by an optional callback.</blockquote><p>This feature allows multiple distinct ways to invoke the exact same functionality. Suchlike preconditions are perfect for injection attacks. For example, the following two calls lead to the exact same database query.</p><pre>client.set(&quot;some_key&quot;, &quot;some_val&quot;); <br>client.set([&quot;some_key&quot;, &quot;some_val&quot;]);</pre><p>The first line is where our injection approach applies. When an attacker is in control of any comma separated parameter, he may be able to overwrite all following parameters by injecting an array instead of a string or integer value. <strong>Basically, we try to transform the first line (individual arguments) into the second line (arguments array)</strong>. The following examples illustrate this approach in the context of an <a href="https://www.npmjs.com/package/express">express</a> app.</p><h4><strong>Example 1 &gt; JSON</strong></h4><p>We assume an application that takes an arbitrary key from the request and sets a default, hard-coded value. In this first example, the key is provided by the <strong>JSON</strong> body.</p><pre>app.use(bodyParser.json());</pre><pre>app.post(&#39;/&#39;, function (req, res) {<br>    redis.set(<strong>req.body.key</strong>, &quot;default&quot;);<br>});</pre><p><strong><em>Normal request </em></strong>sets the JSON body to {key : &quot;foo&quot;} and results in redis.set(&quot;foo&quot;, &quot;default&quot;);</p><p><strong><em>Injection request</em></strong><em> </em>sets the JSON body to {key : [&quot;foo&quot;, &quot;evil&quot;]} and results in redis.set([&quot;foo&quot;, &quot;evil&quot;], &quot;default&quot;);</p><p>In contrast to the string value in the normal request, an array containing two strings is passed in the injection request. This injected array is inserted as the first parameter req.body.key of the database driver call. The driver interprets the injected array as arguments array and store foo=evil as a key-value pair. On the other hand, the now trailing &quot;default&quot; value is ignored*.</p><h4>Example 2 &gt; Query-string</h4><p>We assume the same application, but this time the key is provided by the <strong>query-string </strong>parameter.</p><pre>app.post(&#39;/&#39;, function (req, res) {  <br>    redis.set(<strong>req.query.key</strong>, &quot;default&quot;);<br>});</pre><p><strong><em>Normal request </em></strong>sets the query-string t0 ?key=foo and results in redis.set(&quot;foo&quot;, &quot;default&quot;);</p><p><strong><em>Injection request </em></strong>sets the query-string to ?key[]=foo&amp;key[]=evil and results in redis.set([&quot;foo&quot;, &quot;evil&quot;], &quot;default&quot;);</p><p>The injection attack via query-string parameter works similar to the one shown with JSON, but this time an arguments array cannot be injected directly. Instead, we can make use of the widespread qs<strong> </strong>module. This module enables an extended query-string syntax that allows users to pass objects or arrays as parameters. And the best of all - prevalent frameworks like <a href="https://www.npmjs.com/package/express">express</a> enable this module by default. In these cases, ?key[]=foo&amp;key[]=evil is transformed to an array that in turn is interpreted as an arguments array by the driver. As a result, foo=evil is stored as key-value pair and the trailing &quot;default&quot; value is scraped*.</p><h4>Example 3 &gt; Form-Url Encoded</h4><p>We assume the same application, but this time the key is provided by a <strong>form-url encoded </strong>body parameter.</p><pre>app.use(bodyParser.urlencoded());</pre><pre>app.post(&#39;/&#39;, function (req, res) {<br>    redis.set(<strong>req.body.key</strong>, &quot;default&quot;);<br>});</pre><p><strong><em>Normal request </em></strong>sets the query-string t0 key=foo and results in redis.set(&quot;foo&quot;, &quot;default&quot;);</p><p><strong><em>Injection request </em></strong>sets the query-string to key[]=foo&amp;key[]=evil and results in redis.set([&quot;foo&quot;, &quot;evil&quot;], &quot;default&quot;);</p><p>This injection vector exploits the behavior of the bodyParser which enables the injection of arrays by the same extended syntax (shown in the second example) applied to form-url encoded request bodies. The result corresponds to the two previously outlined examples.</p><p><strong><em>*</em></strong><em> The trailing parameter may be interpreted as callback but does not represent a function. Therefore, the database call will not return to the application.</em></p><h4>The bottom line …</h4><p>The three examples show that injection attacks against Redis are possible when certain preconditions are met. An attacker may be able to overwrite each query parameter that is preceded by user-controlled input. The outlined attack approach works for all database calls provided by the driver interface ( expire , rename , delete …). One might argue that these attacks require specific preconditions like qs, body-parser, a certain driver and driver invocations with comma separated parameters. When looking at the download numbers the required packages are used all over the place, so actual vulnerabilities may not only exist in theory.</p><p>Cheers, Patrick</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25b332d09e58" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>