<?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[Marko’s dev blog - Medium]]></title>
        <description><![CDATA[Sharing some thoughts on web programming - Medium]]></description>
        <link>https://medium.com/markos-dev-blog?source=rss----71c32d2ed9e1---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Marko’s dev blog - Medium</title>
            <link>https://medium.com/markos-dev-blog?source=rss----71c32d2ed9e1---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:42:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/markos-dev-blog" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why you should consider going serverless]]></title>
            <link>https://medium.com/markos-dev-blog/why-you-should-consider-going-serverless-3af679b63d7d?source=rss----71c32d2ed9e1---4</link>
            <guid isPermaLink="false">https://medium.com/p/3af679b63d7d</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Marko Barić]]></dc:creator>
            <pubDate>Sun, 22 Jan 2017 20:18:24 GMT</pubDate>
            <atom:updated>2017-01-23T08:54:51.431Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*nB0AU6_rfo8Sslb_QcgEIw.png" /></figure><p>If you happen to be a developer and have been following tech scene over the past two years or so, you must have heard of the new <strong><em>serverless</em></strong> thing at some point. There’s quite a hype going on around it and it seems like everyone has something to say about it in about every dev/tech conference these days.</p><p>It all starting emerging as a new approach in designing application architectures for cloud around two years ago (see Google trends below) when it was made possible primarily by the huge expansion of cloud services, AWS being the leader here. Just as everything else “as-a-service”, cloud providers gave us code execution as a service which proved to be much-welcomed innovation by many development teams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TVrf1GJY1UWVtj1WSlaVhQ.png" /><figcaption>Google search trends for “serverless” in the last three years</figcaption></figure><p>And even though it’s still in its early phase, there are many companies that are already running production workloads and designing very interesting applications (from the architectural point of view) around <em>serverless</em> principle.</p><p>If you’re not familiar with the the whole <em>serverless</em> concept, the idea is that you write your code as a set of micro modules or functions and execute it in a managed environment provided by the cloud provider, in which you are not responsible nor you have any control of the underlying server infrastructure. Your application will scale seamlessly and be able to automatically handle any load without requiring you to do anything.</p><p>So should you consider this design for your next app?<br>I say “<strong>yes, with some caveats though</strong>”, and let’s see why.</p><h4>It makes you do what you do best</h4><p>Development teams were never good in designing and managing IT infrastructure that runs their applications.</p><ul><li>What server size do we choose?</li><li>How do we plan server capacity?</li><li>Which OS?</li><li>What’s the plan for patching the servers?</li><li>When do we patch them? (<strong>downtime!</strong>)</li><li>How much remaining capacity should we have?</li><li>Tuning server performance</li><li>Handling server failures</li><li>etc.</li></ul><p>This is simply not the realm of expertise for a typical development team. Developers lack the skills to manage infrastructure, mostly because they were never thought to do so and many teams are drawn into this aspect of their work by the fact that it needs to be done and for many teams there is no one around to do it for them.</p><p>Development team should focus on one thing they do best — <strong>writing code</strong>! Or if we want to say it in agile/lean terms:</p><blockquote>Developers bring value when they write code</blockquote><p>Everything else is a distraction to the team and puts an unnecessary burden on them, impacting their ability to deliver code, which is what they should be doing.</p><h4>It pushes you towards good application design</h4><p>When you go <em>serverless</em>, you will inescapably have to design your application around event-driven microservices. Your code will become a set of micro functions, each handling its own responsibilities (or a single one if you do it properly) and the application will become one big orchestration being run by streams of events which will be triggering (either synchronous or asynchronous) function execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*0fr1Xaqxhz3-W3IciJu7Aw.jpeg" /></figure><p>What <em>serverless</em> will force you to do, by the nature of it, is to create a well designed and maintainable microservices/microfunctions architecture for your application. This will give you several benefits out of the box:</p><ul><li>clear separation of responsibility between functions</li><li>clearly defined contracts for intercommunication between functions</li><li>functions can be easily rewritten and replaced without affecting the rest of the application</li><li>individual deployment of functions</li></ul><p>If done right, <em>serverless</em> architecture is how a good distributed application architecture should look like.</p><h4>Reduce running costs, pay for code execution time only</h4><p>If you’re running applications in cloud, it typically means that you’re provisioning a fleet of virtual machines configured to to run it. Since most applications don’t have constant load and you don’t plan your capacity to fully utilise servers when the load hits you (you have to give your servers some leeway), you typically end up with highly under-utilised servers. Most cloud providers will charge you (in most cases) for server up time (by hour) regardless of server utilisation. As a result you will be paying for server idle time, or in other words, your application is incurring costs even when it’s not running.</p><p>When you switch to <em>serverless</em>, you are only paying for the actual execution time of your functions. The price will depend on other factors as well, like allocated memory and CPU, but nevertheless you will only be paying for the time application is executing something. When the application is not running, you’re not paying anything.</p><p>This might significantly reduce the cost of running, although there are cases where it’s not true, so you need to see if it will work for your specific case cost-wise.</p><h4>Scale seamlessly</h4><p>In a <em>serverless</em> environment, since you are not managing any server infrastructure, you don’t have to do any capacity planning. Cloud provider will automatically provision sufficient resources to run and scale your functions reliably. When the load increases, and it can increase dramatically in very short period of time, additional resources will be made available for your functions automatically without you even knowing that the load has increased.</p><h4>Scale partially</h4><p>Since your application is broken down into number of small functions, each handling its own aspect of application functionality, when the load suddenly increases but only in certain parts of your application (e.g. you need to handle increased load on registrations of new customers because of ongoing marketing campaign), only those functions affected by the increased load will be scaled. The rest of the functions won’t be scaled because there is no need for it.</p><p>This means that the application can partially scale which in turn reduces the total cost of running since you don’t have to scale (and pay) for parts of your architecture that don’t require additional resources.</p><p>But it’s not all unicorns and rainbows in the <em>serverless</em> land. There are some limitations that might impede your path to <em>serverless</em> and you should consider it wisely.</p><p>Some of the limitations include:</p><ul><li>insufficient learning resources on the web due to immaturity of the technology and frequent changes</li><li>in some cases, running costs might in fact increase when you go <em>serverless</em></li><li>complicated version management for functions</li><li>complicated CI and deployment</li><li>harder to develop and test locally since it heavily relies on cloud resources</li><li>no well-proven patterns to follow, everyone is still experimenting</li></ul><p>So, should you adopt it, be sure although there are clear benefits of the technology, there are also some caveats along the <em>serverless</em> path that you need to be aware of. But it is definitely the new big thing and something you won’t be able to run away from in forthcoming years.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3af679b63d7d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/markos-dev-blog/why-you-should-consider-going-serverless-3af679b63d7d">Why you should consider going serverless</a> was originally published in <a href="https://medium.com/markos-dev-blog">Marko’s dev blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices are much more than just another name for SOA]]></title>
            <link>https://medium.com/markos-dev-blog/microservices-are-much-more-than-just-another-name-for-soa-ac77b4b82aab?source=rss----71c32d2ed9e1---4</link>
            <guid isPermaLink="false">https://medium.com/p/ac77b4b82aab</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Marko Barić]]></dc:creator>
            <pubDate>Fri, 14 Oct 2016 07:12:21 GMT</pubDate>
            <atom:updated>2016-10-18T13:06:31.927Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RK3nWlE_mbsVZqXYmpJNjA.jpeg" /></figure><p>One thing I’ve heard in a couple of tech meetups lately made me write this blog post. What those speakers were saying, albeit each in their own way, can be summed up to this:</p><blockquote>“Microservices are just a different name for SOA”</blockquote><p>I can’t express how much I disagree with this statement. <br>So firstly let’s start by looking at what SOA is. Wikipedia says:</p><blockquote>…a style of computer software where services are provided to the other components through a communication protocol over a network…</blockquote><blockquote>…separates functions into distinct units, or services, which developers make accessible over a network in order to allow users to combine and reuse them…</blockquote><p>All clear, right? In order to build a complex software system we break it up into smaller logical chunks (i.e. services) and by linking those together we build up more complex system. Pretty much the same thing can be said for microservices, right? While the fundamental idea is indeed the same, when we look at reasons which led to those architectural principles, why we are doing it and how does it affect our development, that’s when things start to diverge.</p><p>The main idea behind original SOA was <strong>reusability</strong>! We wanted to design our applications as a set of discrete components in order to later reuse functionalities of those components. Think “logging service”. If we created “logging service” as an independent service, then later down the line we should be able to utilize this logging infrastructure when adding a new functionality which might require logging.</p><p>So even though SOA architectural approach shares the similar foundation as microservices, SOA was never about independent development and testing of individual services, nor was it about autonomous teams, automated testing and automated delivery and deployment of services. And that’s precisely what microservices are all about.</p><p>The basic idea behind microservices, if done right, is about having autonomous pieces of logic, built around <a href="http://martinfowler.com/bliki/BoundedContext.html">bounded context</a>, independent of other services and components of the application. Each service should live its own life (possibly with own code base in it’s own repository), be built using any technology stack required regardless of what other services are built on, tested independently and in the end deployed on its own without having any dependency on other services or any other kind of internal dependency (like database). So despite it being purely an architectural pattern, microservices are what makes correctly aligned teams working on the same system truly flourish whereby it became more than just about architecture - in a way it became the philosophy for organizing teams and changing team culture.</p><p>Microservices have thought us to think about other non-architectural problems and solve them properly, ultimately making us create better software and doing it in the most efficient way. So these days we can say that a good microservices project is based around these principles:</p><ul><li><strong>Autonomous teams</strong> — in a well structured agile-driven organization, each microservice should be owned by a single team. There shouldn’t be a case where two teams have overlapping responsibilities over one service. There are many reasons for this, but the main one has to be reducing the number of dependencies to a minimum (zero). And sharing your code base with another team and syncing code changes with them is a dependency. Additionally, each team should ideally be fully autonomous in their choice of technology stack, the way they organize their work, the way they automate testing and deployment, which tools they’re using, etc. Although teams should have as much autonomy as possible, there need to be some baseline principles agreed that all teams should adhere to.</li><li><strong>Polyglot</strong> — choice of technology stack for one service should not by all means influence the technology stack in another service. Each service is built with specific purpose in mind and provides specific set of functionalities to the rest of the application. Since no two services are doing the same thing and in the same way, they should not be constrained by having to use the same technology stack. Of course, here we talk about ideal situation, in the real world you also have to take your team knowledge and experience with some technology and familiarity with existing tools into account.</li><li><strong>Strong contracts </strong>— since we want to independently develop and deploy individual services, having different lifecycle and being developed at a different pace by different teams, the only way we can make sure it will all fit together in the end and work as a whole is by having strictly defined contracts. Whether it’s REST or event streams, synchronous or asynchronous, we need to agree on the contract for intercommunication. Only after we know how to get the data from a dependent service (or push the data to it) we can start to build our own service.</li><li><strong>Autonomous testing </strong>— since the end goal is to deploy the service on its own, we should be able to test it independently. If we end up having to run the whole system to be able to test one service, we will very soon end up deploying it all (or partially) together. You won’t be able to get away from it. We also risk causing more problems since we don’t control other services - which version of the dependent service are we testing against? It can soon become a nightmare. And it will. The only viable approach is to test the service independently in an automated fashion and then perform real integration testing when we get close to production environment or in the actual production with blue/green or canary deployment. Any other way is simply not efficient and will create more problems in the end. Also, testing should be done in a fully automated manner with minimal (if any) manual testing apart from exploratory tests.</li><li><strong>Automate everything</strong>— automation is one the cornerstones of a successful microservices projects. If you set up the project correctly, you should have completely automated delivery and deployment pipeline in place. No other way of testing and deployment can guarantee such level of confidence in your code with so little effort. You will put significant effort in writing the tests in the first place though, but down the line it will give you incredible possibilities in terms of reducing the cycle time. As each build progresses through the pipeline, we are getting more and more confidence in it and ideally, in the end, it is ready to go straight to production. Automated testing and deployment will allow you to do continuous daily deployments to production, I’ve seen companies that are doing 40+ deployments daily, with no manual testing at all.</li><li><strong>Efficient scaling </strong>— what microservices are making possible is partial scaling of the application. Individual services can be easily scaled when they get under load without having to worry about less used parts of the application. We can focus our scaling efforts to parts of the application, not the entire system as a whole. This will ultimately result in lower operational costs for the underlying infrastructure (especially in the cloud) because we are paying only for those things that we have to pay for.</li><li><strong>Monitoring</strong> — good monitoring of your services is essential if you want to be aware of how your system behaves. If you have a system that comprises 40 microservices, without good monitoring in place you will have absolutely no idea what is going on when problems start occurring because now your application logic is broken down into pieces that are running in different processes and on different machines. And I don’t mean just monitoring the state of single service. Aggregation of metrics and logs is essential here, it will allow you to easily nail down problems by collating logs from different sources and correlating them. It’s essential to think about proper logging early on in the project because it will become an essential debugging tool once we go live.</li></ul><p>So, by embracing basic microservices principles we are essentially becoming better developers regardless of the actual architecture that we’re building on, be it microservices or something else, ultimately making our teams create better software based on a stable foundations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac77b4b82aab" width="1" height="1" alt=""><hr><p><a href="https://medium.com/markos-dev-blog/microservices-are-much-more-than-just-another-name-for-soa-ac77b4b82aab">Microservices are much more than just another name for SOA</a> was originally published in <a href="https://medium.com/markos-dev-blog">Marko’s dev blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why should we care about HTTP/2]]></title>
            <link>https://medium.com/markos-dev-blog/why-should-we-care-about-http-2-6eebd2a6cd6e?source=rss----71c32d2ed9e1---4</link>
            <guid isPermaLink="false">https://medium.com/p/6eebd2a6cd6e</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[http2]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Marko Barić]]></dc:creator>
            <pubDate>Tue, 11 Oct 2016 07:45:42 GMT</pubDate>
            <atom:updated>2016-10-11T12:31:09.340Z</atom:updated>
            <content:encoded><![CDATA[<p>As a major revision, maybe the biggest one so far, of the ancient HTTP/1.x protocol, HTTP/2 is now here and the adoption has already started. Based on Google’s SPDY protocol which has nicely laid all the foundation to build HTTP/2 upon, we can clearly say that it’s truly a revolutionary step which will inevitably change the way we build stuff for the web.</p><p>But what does this actually mean for us web developers and why should we care about it? More importantly, how should we rethink the way we design websites and the underlying infrastructure to leverage all the power that HTTP/2 gives us? If you want to know, keep reading.</p><p>But first, the one question we could ask ourselves is why we had to move from HTTP/1.x in the first place? Well, just by looking at <a href="http://httparchive.org/trends.php">HTTP Archive</a> trends over last 5 years, it is more than obvious that the amount of data that modern websites are loading from the server has increased dramatically from ~700kB to over 2MB on average. And this data needs to be transferred to browser somehow, which explains the increase in the number of requests. In today’s mobile-first web and with ever-demanding customers the trusty old HTTP/1.x workhorse proved to no longer be fit for purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*vAua0hbaPjvsuDSl3lYBgQ.png" /></figure><p>HTTP/2 tries to address this by making on-the-wire exchange of data more in sync with what websites need. To begin with, let’s list some of the strongest points in the HTTP/2 arsenal of features:</p><ul><li>Binary nature of protocol</li><li>Enforcing TLS</li><li>Connection multiplexing (and server push)</li><li>Header compression</li></ul><p>They all aim to improve the overall performance of websites. And by performance we can think about different things: maybe it’s the time to get the first response back, maybe it’s the time to load the entire DOM, etc. Whatever it is that we want to improve, we should be able to get instant performance boost by simply switching from HTTP/1.x to HTTP/2 without having to change the single thing in our code. If you just play around with the code a bit, increase in performance of the website could become significant.</p><h4>Binary protocol</h4><p>By its nature, HTTP/2 is a binary communication protocol. Compared to textual HTTP/1.x which essentially transports ASCII text over wire, HTTP/2 binary nature makes it more compact and lighter bandwidth-wise. There is not much a typical developer will have to do to make use of this binary nature of HTTP/2 unless you are working on the socket level making your HTTP readers/writers. In which case you would benefit from not having to worry about transfer encodings when parsing text from the wire any more. Nevertheless it’s good to be aware of this fundamental difference between those two protocols.</p><h4>Enforcing TLS</h4><p>Even though TLS is not compulsory by HTTP/2 spec, major browsers (e.g. Chrome, Firefox) and servers (Nginx) do not allow insecure connections with HTTP/2. However, spec does define stricter TLS requirements, (e.g. min TLS 1.2). This fact alone will significantly improve security on the web once everyone starts switching to HTTP/2 making many types of attacks more difficult than it is today. Be amazed (as I am) with the fact that only around 14% out of 1M top websites today are served over HTTPS. For developers, this enforcing of TLS means that we should start putting more effort in web deployments and automation because it will have to include setting up TLS certificates on the server. Btw, if you are running your web applications in AWS it is very straightforward and totally free with ACM managed service, so it won’t incur any additional costs.</p><h4>Connection multiplexing</h4><p>Request-response nature of web communication means that the browser has to send one request to the server for each and every resource that it requires. And for each of those requests underlying TCP connection has to be established with the server. The problem here is that while the browser is waiting for the response this connection cannot be reused. Which results in huge underutilization of TCP connections. This “one-resource-at-a-time” principle proved to be a huge bottleneck which made us resort to all sorts of workarounds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Z7h2Xor3_44Zq_LevsNMg.jpeg" /><figcaption>Loading multiple resources from the server over one TCP connection</figcaption></figure><p>Over time we managed to work around this problem by allowing browsers to maintain multiple connections to the same server host, initially it was 2, these days we allow around 6 concurrent connections to the same host. This gave us slightly better connection utilization, but we can hardly solve the problem by just rumping up max number of concurrent connections. Otherwise we would create network congestion problem and browsers would become small-scale DDoS attack clients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pEtXx82lEgg1md2aJWoVYA.jpeg" /><figcaption>Loading multiple resources from the server over 3 connections</figcaption></figure><p>We also introduced other techniques to mitigate these problems like image sprites, loading images inline, bundling multiple JS files into single file, etc. But these are all just hacks and workarounds with the same goal: to reduce number of requests to the server. And what we need is a proper solution for the problem.</p><p>Welcome, connection multiplexing! HTTP/2 allows reuse of the same TCP connection for making multiple concurrent requests to server. Moreover, responses that are coming back from the server can be interleaved and occur in any order. HTTP/2 even allows us also to prioritize requests so the server knows to return some resources before other. There are many resources on the web about how this works on the low level with frames and control of flow for those who want to know more.</p><p>But what does this mean to developers? We can simply get rid of sprite images, hostname sharding, JS bundling and pretty much all other techniques that we are used to doing to overcome limitations of HTTP/1.x. Simply write your code like there is unlimited number of concurrent connections available. This feature is the one that will affect the way we develop websites the most.</p><h4>Server push</h4><p>Server push is a server feature that comes off the back of connection multiplexing. It basically allows us to have “<em>smart</em>” servers which will be able to make a guess about the next resource the browser might request and start sending it to the client before it is even requested. Typical example would be when the browser requests HTML page, server can inspect &lt;head&gt; and conclude that browser will probably start asking for referenced CSS and JS files with next request and start sending it immediately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGcxfl5Cx3fwjtA2IWV4Eg.jpeg" /><figcaption>Server guesses what could browser request next and starts to push it immediately.</figcaption></figure><p>There is a caveat here though, if the browser already has those resources cached we might end up taking the bandwidth for something that’s not really needed. But HTTP/2 clients are able to cancel those response frames when they figure out it’s not needed so it’s a trade off we have to live with. We will have to wait before this catches on in popular web servers but it certainly looks like it could be a game changer in terms of web performance.</p><h4>Header compression</h4><p>One pattern that is noticeable in <em>request</em>-<em>response </em>sequence of almost every website is that most of the headers are repeating over and over again with the same value in every request and response. Typically it’s <em>User-Agent</em>, <em>Cookie</em>, <em>Referer</em>, <em>Accept-Language</em>, etc. And even though we allowed content to be GZIPed, it is not the case with headers. Good news is that HTTP/2 brings us header compression. I won’t go into details of how it works, you have plenty of resources on the web, also interesting to see why they chose HPACK algorithm over GZIP for headers.</p><h4>Conclusion</h4><p>It is clear that HTTP/2 will change how we reason about developing for web. And it is already here, being adopted rapidly. E.g. AWS already supports it in CDN (CloudFront) distributions and ELB load balancers. So it’s time to embrace this new thing and start using all the power it gives us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6eebd2a6cd6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/markos-dev-blog/why-should-we-care-about-http-2-6eebd2a6cd6e">Why should we care about HTTP/2</a> was originally published in <a href="https://medium.com/markos-dev-blog">Marko’s dev blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing websites with HTTP Strict Transport Security]]></title>
            <link>https://medium.com/markos-dev-blog/securing-websites-with-http-strict-transport-security-dc89e2301f6e?source=rss----71c32d2ed9e1---4</link>
            <guid isPermaLink="false">https://medium.com/p/dc89e2301f6e</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[web-security]]></category>
            <dc:creator><![CDATA[Marko Barić]]></dc:creator>
            <pubDate>Sun, 09 Oct 2016 14:07:16 GMT</pubDate>
            <atom:updated>2016-10-19T07:34:50.419Z</atom:updated>
            <content:encoded><![CDATA[<p>I was very surprised to learn how so few websites are using some of security features built into modern browsers. Some of those features proved to be a really powerful tool against attackers and can significantly improve security of your website. And yet most of the web is not leveraging this.</p><p>In this post I’ll go into the details of one of those browser features — <strong>Strict-Transport-Security</strong> HTTP response header, also known by its short name <strong>HSTS</strong>. With very simple mechanics this header increases security of your website by mitigating typical risks of man in the middle (MITM) attacks, particularly SSL/TLS stripping. It is widely adopted by most modern browsers today and they even ship with one neat HSTS feature — preloading. More on that a bit below.</p><p>So what is HSTS? In short, it’s a form of “directive” which instructs your browser to load all resources from a given domain only over secure channel. And by secure channel, we mean HTTPS. So essentially it forces your browser to send all requests to a given host exclusively using HTTPS protocol even if you (or a man in the middle) explicitly request a resource over plain HTTP, which is as we know pretty insecure.</p><p>Let’s dig straight in and see how it works. For this we will look at request-response sequence of <a href="https://urbpic.com/">http://urbpic.com</a> website, which is HSTS enabled. To be honest it took me quite some time to find a website that uses HSTS to show it here. That shows how little this feature is used. The communication sequence looks like this:</p><ol><li>Browser requests a resource (let’s say a web page) over insecure HTTP</li><li>Server responds with <strong>HTTP 301</strong> (Moved Permanently) instructing the browser to load the page over HTTPS</li><li>After SSL/TLS handshake takes place and we are secure, browser requests the same web page over HTTPS</li><li>Server responds with the response (a web page) with <strong>Strict-Transport-Security</strong> header in the response itself</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qMnDH_Emg2u9jLskVVX91Q.png" /><figcaption>First request (over HTTP): server returns HTTP 301. Note the <em>location in response header — server essentially instructs the browser to “upgrade” connection to HTTPS and request the same resource, but this time securely.</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A764rrEYYKJEsCOpj6TlCw.png" /><figcaption>Second request (this one is secure over HTTPS): reloads the same resource. Note the “Strict-Transport-Security” response header which instructs the browser to make any subsequent request to this domain over HTTPS.</figcaption></figure><p>Presence of HSTS response header will instruct the browser to “upgrade” to HTTPS and to request any future resource from this domain over HTTPS. So even if you explicitly type in HTTP url or do not specify scheme in URL which will make the browser default to HTTP or even when some image or script file is referenced from the web page content as HTTP url, the browser will convert this request to HTTPS. HSTS header is one of few so called <em>TOFU</em> headers — “<em>trust on first use</em>”. It means that the first request might (or might not, as we will see) go unsecured over plain HTTP, but any subsequent request must and will go over HTTPS. This still leaves a small space for possible attack with the first insecure request, but that’s the best we can do with this implementation.</p><p>It’s important to notice that HSTS header is returned in the second response after we establish secure channel with the server. The reason is obvious; man in the middle could have stripped this header if it was returned in the first insecure response.</p><h4>The header</h4><p>Typically HSTS response header looks like this:</p><pre>Strict-Transport-Security: max-age=31536000; includeSubDomains;</pre><p>The header contains couple of directives for our browser:</p><ul><li><strong><em>max-age</em></strong> tells the browser for how long it should continue requesting all the resources from this domain over HTTPS. Value is specified in seconds. After this period expires, browser will not continue enforcing HTTPS, but it’s very likely that the first following insecure HTTP request will do the same thing all over again and browser will continue to enforce HTTPS onwards. So in practise it will become a sliding window expiration.</li><li><strong><em>includeSubDomains</em></strong> will instruct the browser to enforce the same behaviour for any requests for resources from this domain’s sub-domains. Which may or may not be desirable. Maybe you don’t want to carry the TLS burden on some insignificant sub-domain. Or your certificate is not a wildcard one and you want your sub-domain resources to be loaded insecurely. On the other hand, by specifying <em>includeSubDomains</em> you implicitly make every future sub-domain secure because the browser will request those resources using HTTPS even if we don’t explicitly tell it to do so. For as long as we are within <em>max-age</em> window at least.</li></ul><h4>Preloaded HSTS</h4><p>But is there a way to make not even a single insecure HTTP request? Not even the first request? Well, the answer is “yes” and what makes it possible is the list of preloaded HSTS websites inside your browser. Most of the browsers come with the hardcoded list of HSTS-enabled websites. List is maintained under Chromium project which allows anyone to submit their web site to the list <a href="https://hstspreload.appspot.com/">here</a> if they meet all the requirements. Good news is that most of the browsers (including Chrome, Firefox, Edge, etc.) get this data from the same Chromium source, which will make your site’s HSTS prerequisite be known to all of them. Be aware, though, that it takes some time for your submitted site to appear in the future release of the browser.</p><p>Let’s load PayPal website which comes preloaded in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tY58SKfhWtuziP3z3SO15g.png" /><figcaption>Network communication sequence for a website whose HSTS preference is already preloaded in the browser.</figcaption></figure><p>Note that even though we requested PayPal web page over HTTP, we got <strong>HTTP 307</strong> (Internal Redirect) which “upgraded” our request to HTTPS. It’s interesting to note that <strong>HTTP 307</strong> did not come as a response from the server, it was in fact returned internally by the browser because PayPal is preloaded in the browser’s HSTS list — note the time column in the following figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KjmP-X1EfzNM3mG215RlDw.png" /><figcaption>Note that HTTP 307 request executed almost immediately because it did not even go out to the server.</figcaption></figure><p>Since HSTS is still not widely adopted by websites, this concept works for now. But there is a concern how will this work once HSTS becomes ever present on the web.</p><h4>Conclusion</h4><p>As it stands, by SSL Pulse stats only around 14% websites among worldwide top 1M are served over HTTPS and out of those 14% only around 10% implement HSTS. This means that roughly <strong>1% of the web uses HSTS header</strong>. Very disappointing adoption knowing how well aware we are these days of all the threats and attacks out there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc89e2301f6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/markos-dev-blog/securing-websites-with-http-strict-transport-security-dc89e2301f6e">Securing websites with HTTP Strict Transport Security</a> was originally published in <a href="https://medium.com/markos-dev-blog">Marko’s dev blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>