<?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 Nuno Bernardes on Medium]]></title>
        <description><![CDATA[Stories by Nuno Bernardes on Medium]]></description>
        <link>https://medium.com/@nuno.jmbernardes?source=rss-13b324f5f790------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*AviL5D05A03GC4nWisvQKw.jpeg</url>
            <title>Stories by Nuno Bernardes on Medium</title>
            <link>https://medium.com/@nuno.jmbernardes?source=rss-13b324f5f790------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:17:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nuno.jmbernardes/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[Securing Application Webhooks in Elixir]]></title>
            <link>https://medium.com/@nuno.jmbernardes/securing-application-webhooks-in-elixir-bed7e50416e4?source=rss-13b324f5f790------2</link>
            <guid isPermaLink="false">https://medium.com/p/bed7e50416e4</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[plug]]></category>
            <category><![CDATA[sha-256]]></category>
            <category><![CDATA[webhooks]]></category>
            <category><![CDATA[security-token]]></category>
            <dc:creator><![CDATA[Nuno Bernardes]]></dc:creator>
            <pubDate>Tue, 07 Jul 2020 08:01:02 GMT</pubDate>
            <atom:updated>2020-07-07T08:01:02.795Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sKb6B4PhiwtD5Xf9YLw8GQ.png" /><figcaption>Securing Application Webhooks in Elixir — Coletiv</figcaption></figure><p>Not long ago, I had a task that involved securing a <a href="https://en.wikipedia.org/wiki/Webhook">webhook</a> from an external API, making it possible to verify if the request was coming from the allowed application (authenticity) and if the received payload matched the one sent from the application, by verifying if the hashes matched (<a href="https://en.wikipedia.org/wiki/Data_integrity">integrity</a>).</p><p>Using <a href="https://en.wikipedia.org/wiki/SHA-2">SHA256</a> <a href="https://en.wikipedia.org/wiki/HMAC">HMAC</a> payload verification, the flow from the validation was as follows:</p><ol><li>Receive an incoming request from the external API.</li><li>Extract the text payload as an array of bytes. The entire body of the POST request is used.</li><li>Compute a SHA256 HMAC digest for the array of bytes. If your external API implementation has multiple HMAC keys, compute one digest for each of the HMAC keys.</li><li>Base64 encodes each of the digests.</li><li>Compare the base 64 digest(s) to the values of the signature headers. Compare the one you computed using your application’s key(s). At least one of the computed digests must exactly match its corresponding header value. If there is no match then the notification may be compromised and it should not be trusted. Only one match is required.</li></ol><p>Knowing this I started to code the first iteration to ensure if the request was valid…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/528ecd37d562afa485f9dc42db98cd3f/href">https://medium.com/media/528ecd37d562afa485f9dc42db98cd3f/href</a></iframe><p>When testing this approach, the result was invariably a False boolean ☹️. When debugging the code, the expected JSON (already decoded in a map) was returned with no errors whatsoever. Everything looked well coded. What was happening? Time to investigate!</p><h3>Problem-solving</h3><p>As software developers, we are constantly faced with new problems and new challenges to solve, and this was not outside of that spectrum. Working at <a href="https://coletiv.com/">Coletiv</a>, and always having my peers at my back (even in times of social isolation), I confronted the problem with them! Without removing the challenge from the problem they suggested I should analyze the Plug dependency more carefully.</p><p>I started looking for clues 🕵🏽 in <a href="https://hexdocs.pm/plug/readme.html">Plug hexdocs</a> to see if I could find “the murder weapon”. As it seems, the guilty party was the payload! <a href="https://hexdocs.pm/plug/readme.html">The plug provides a specification for web application components and adapters for web servers.</a> When we receive the request, our Plug parses the content from it with <a href="https://hexdocs.pm/poison/Poison.html">Poison</a> (our parser of choice).</p><p>The representation of the parsed data in Elixir is different from the representation of the raw received data. Decoding a byte array and encoding it again will not yield the same result as the original byte array had, even though it encodes the same objects. This happens because the in-memory representation of the parsed data in Elixir may order the objects differently from the byte array. When computing the hash function, it could not match the signatures in the request header. So, is there a way to access a raw unparsed version of this endpoint’s payload? Removing the parsing function from the Plug would surely break all of our other endpoints which rely on it…</p><h4>Cache, I choose you!</h4><p>Digging up the problem, I found out that the <a href="https://hexdocs.pm/plug/Plug.Parsers.html">Parsers Plug supports cache body reading</a>, making it possible to cache the raw body to perform verifications later, by storing the cached body in the connection. Following the example at hexdocs…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a505cfa842f228cac11489a4b90bd738/href">https://medium.com/media/a505cfa842f228cac11489a4b90bd738/href</a></iframe><p>This way, our requests can access the normal parsed body, but also additionally have access to the raw body, if needed. After this change, we had to alter some code in our request validation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a14263277f7de554d676089715f2b39/href">https://medium.com/media/0a14263277f7de554d676089715f2b39/href</a></iframe><p>Finally, when testing the webhook, everything was working as intended and the requests made by the external API were being accepted by our application!</p><h3>Thank you for reading!</h3><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialized in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bed7e50416e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First month learning curve at elixir]]></title>
            <link>https://medium.com/@nuno.jmbernardes/first-month-learning-curve-at-elixir-b99f839a032d?source=rss-13b324f5f790------2</link>
            <guid isPermaLink="false">https://medium.com/p/b99f839a032d</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[elixirlang]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Nuno Bernardes]]></dc:creator>
            <pubDate>Tue, 03 Mar 2020 10:01:01 GMT</pubDate>
            <atom:updated>2020-03-03T10:01:01.628Z</atom:updated>
            <content:encoded><![CDATA[<h3>First impressions while learning Elixir</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwKbtwJ8bBWGEHw9bndsEw.png" /><figcaption>My Experience Learning Elixir</figcaption></figure><h3>A month ago…</h3><p>Coming from college with a very strong foundation of Object Oriented Programming (OOP), I was a bit scared to jump into the Functional Programming wave. Haskell was the first and only functional language that I’ve learned and I didn’t like it to be honest with you. But now, I had to get out my comfort zone and accept this huge challenge. <strong>My first job as an Elixir developer</strong>.</p><p>A lot of things had to change. My line of thought. The way that I’m used to writing code. But all of that was easily overcome by my desire to learn, and my expectations about what Elixir would provide in terms of knowledge were huge!</p><h3>Online Tutorials 💻</h3><p>I’ve started my learning by watching online tutorials. Followed from beginning to the end, these videos, provided in the learning plan defined by my peers at Coletiv, aided to understand the basic concepts of Elixir and Phoenix. If you’re looking for a good course, <a href="https://www.udemy.com/course/the-complete-elixir-and-phoenix-bootcamp-and-tutorial/"><strong>this</strong></a> was the one I did on Udemy. It’s a great Elixir learning path for people that prefer learning by watching tutorials!</p><p>In the first days, the motivation to start working was dominating and increased the determination of finishing the tutorials with success. However, after finishing them, the retained knowledge was very vague. I was tired and did not feel the challenge of wanting to do more …</p><h3>Elixir and Phoenix Books 📚</h3><p>A coworker heard my feedback about the online tutorials and we quickly started looking for alternatives.</p><p>A certain day, sitting at my desk, was an Elixir/Phoenix book called “Programming Phoenix 1.4” written by <a href="https://twitter.com/chris_mccord">Chris McCord</a>, <a href="https://twitter.com/redrapids">Bruce Tate</a> and <a href="https://twitter.com/josevalim">José Valim</a>. After skimming through the book, I was already thinking <em>“Here we go again!”. </em>Opposite to my thoughts, the book really motivated me, pushing me to keep learning about Elixir and without doubt, in a few days, I was getting more comfortable with Functional Programming.</p><p>I finished the book with a completely different posture compared to the previous experience. Understanding the code was now easier, and the fear of doing mistakes was close to none. I was more confident! Adding to that, I managed to take part in the conversations about elixir at <a href="https://coletiv.com/services/#backend-development">Coletiv</a>. I was now ready to start my first project!</p><p>Notes: The books I read until now at Coletiv were <a href="https://pragprog.com/book/phoenix14/programming-phoenix-1-4"><strong>Programming Phoenix 1.4</strong></a><strong> </strong>and <a href="https://pragprog.com/book/wwgraphql/craft-graphql-apis-in-elixir-with-absinthe"><strong>Craft GraphQL APIs in Elixir with Absinthe</strong></a>.</p><h3>THE PROJECT 🤩</h3><p>The time had come to test my knowledge. I was confident it would go well, that I had a good funcional thinking and satisfactory code quality (for a junior that was afraid of the language)! My coworkers helped me a lot to expand my knowledge and gave me the necessary tools to start my journey with Elixir.</p><p><a href="https://en.wikipedia.org/wiki/Fernando_Pessoa">Fernando Pessoa</a>, a famous Portuguese poet once wrote:</p><blockquote>“First you find it strange. Then you can’t get enough of it.”</blockquote><p>This is exactly how I describe the path that led me to where I am now. Looking back to the Nuno from a month ago, I really couldn’t recognise myself. The fear of making mistakes, the discomfort and the lack of security no longer existed. Two weeks passed since the beginning of the project and, each day, my desire to learn increases. Everyday, a new challenge appears peeking at the door, and I feel able to confront it (sometimes with help of my colleagues 😄) without fear. Now I have the confidence to implement features, solve bugs, do refactoring and test my code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQowbOo3QzH-ULKcUemczQ.png" /><figcaption>My learning curve 😄</figcaption></figure><h3>Lesson learned</h3><p>I feel that the function that defines my learning curve is too complex, because during this month I went through many ups and downs, but at this moment I’m in exponential growth stage, and I wish I can sustain it!</p><p>I have to thank every single one of my colleagues at <a href="https://coletiv.com/about-us/">Coletiv</a>. They helped since the beginning to the end of this first learning process, and I can undoubtedly state that this is a first dream job!</p><blockquote>Nuno, do you prefer iOS or Elixir? Elixir!</blockquote><h3>Thank you for reading!</h3><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialised in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b99f839a032d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>