<?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 Anton Lawrence on Medium]]></title>
        <description><![CDATA[Stories by Anton Lawrence on Medium]]></description>
        <link>https://medium.com/@A-Lawrence?source=rss-a7bd0c352203------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WoSG4tpwYls9QSD4t0XKTQ.png</url>
            <title>Stories by Anton Lawrence on Medium</title>
            <link>https://medium.com/@A-Lawrence?source=rss-a7bd0c352203------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 13:30:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@A-Lawrence/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[Use These Tools to Scan Public and Private GitHub Repositories]]></title>
            <link>https://gopensource.com/use-these-tools-to-scan-public-and-private-github-repositories-7d9dcd9ab56d?source=rss-a7bd0c352203------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d9dcd9ab56d</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[vulnerability-management]]></category>
            <category><![CDATA[sql-injection]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Anton Lawrence]]></dc:creator>
            <pubDate>Sat, 29 May 2021 06:29:04 GMT</pubDate>
            <atom:updated>2021-05-29T06:29:04.855Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*inVYm6To1SwZ8LMY" /><figcaption>Photo by <a href="https://unsplash.com/@nubelsondev?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Nubelson Fernandes</a> on <a href="https://unsplash.com/s/photos/code?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>As more and more developers discover the benefits of open source, there has been a staggering growth in the number of users using Github. An increasing number of users are making their code open source. Hence, it becomes increasingly crucial for maintainers to scan their public and private Github repositories for vulnerabilities.</p><h3>Risks of Open Source</h3><p>Open Source software is great — you get to support other developers while minimizing the amount of time you need to spend to build something from scratch. Many open-source tools make your build process much easier and faster because somebody else has already done the grunt work for you. However, because it’s built by strangers, you don’t know how safe or well-kept the libraries and repositories are. This can lead to some <a href="https://corporate.findlaw.com/business-operations/the-risks-of-open-source-software.html">major risks</a>.</p><h4>Issues</h4><p>An open-source project is maintained by the Github organization’s admins. This open-source library, which one of the multinational companies use in their product, may have other dependencies, like another open-source library dependent on, say httplib2. These stacked dependencies can bring vulnerabilities to your application.</p><h4>Dependencies</h4><p>If the project admin of httplib2 updates the version, some functions will be deprecated. This may affect the dependent libraries, and consequently, all other larger projects dependent on the other library, including one of the multinational companies’ projects. This can have global repercussions.</p><h4>Security Risks</h4><p>Apart from this, there are several risks associated with using open-source software. Not following the proper development practices may lead to security risks like malware injections and personal or privileged data exposure, which can affect millions of users across the globe. This makes the software prone to attacks by cybercriminals. Some security risks are SQL injections, XSS, CSRF, etc.</p><ul><li><strong>SQL Injections:</strong> <a href="https://www.acunetix.com/websitesecurity/sql-injection/">SQL injections</a> can destroy your database. Whenever a user enters some data like a username, an SQL statement runs unknowingly on your database. A hacker may get access to all records in a database through an SQL database.</li><li><strong>XSS:</strong> <a href="https://owasp.org/www-community/attacks/xss/">XSS</a> is cross-site scripting, where a user executes a script unknowingly. The attacker can access sensitive information, cookies, etc.</li><li><strong>CSRF:</strong> <a href="https://en.wikipedia.org/wiki/Cross-site_request_forgery">CSRF</a> is a cross-site request forgery. The attacker can make the user perform unintentional actions like changing password details or make a monetary transaction. Depending on this user’s privileges, the attacker can ever control the complete site and associated databases.</li></ul><p>How do we make sure that these vulnerabilities are detected and fixed before hackers get a chance to exploit them? Every organization should start scanning their code repositories for vulnerabilities to ensure that their product’s security and personal data stay protected.</p><h3>Open Source Vulnerability Scanning</h3><p>An open-source vulnerability scanner helps organizations identify <strong>potential security risks </strong>and <strong>dependencies</strong> associated with open source components. It also checks if the project complies with the <strong>licenses</strong> of all the open-source features used in the project and suggests quick <strong>suitable fixes </strong>for issues.</p><p>There are several tools for open source vulnerability scanning. <strong>Gittyleaks</strong> finds personal details like username, password, email, etc. <strong>Github</strong> has a secret-scanning feature that scans public and private repositories for secrets that may have been incorporated accidentally.</p><p>There are several more tools like Git-Hound, TruffleHog, Watchtower, and GitGuardian for open source vulnerability scanning. Here are the top three scanners I personally recommend.</p><h3>1. WhiteSource Renovate</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SBQ6IHQ8mZPPkxK2" /></figure><p><a href="https://www.whitesourcesoftware.com/free-developer-tools/renovate">WhiteSource Renovate</a> is a free Github app that scans through all public and private Github repositories to identify vulnerabilities and suggests fixes in real-time. It reduces risk by identifying dependencies. The automated CLI tool creates PRs with the latest available versions of libraries automatically when dependencies need to be updated. It supports GitHub, GitLab, Bitbucket, Azure DevOps, and Gitea.</p><p>Once you connect your Github account to WhiteSource Renovate, it will automatically start scanning all public and private repositories and open PRs to fix vulnerabilities.</p><p>Both dependency updates and security fixes are suggested for the code in your Github repo.</p><p>Open Source allows people to modify and integrate another person’s work in their applications, thus increasing development speed. Several applications, integrations, and plugins created by developers worldwide for their own projects have been integrated into larger projects of several multinational companies and organizations.</p><p>As these integrations help projects of larger companies, they invest in open source projects. This results in creating complicated applications without having to write code from scratch.</p><h3>2. GittyLeaks</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ojdbLhyTasZFtdJ2" /></figure><p><a href="https://github.com/kootenpv/gittyleaks">GittyLeaks</a> detects config files, usernames, API keys, passwords in the code. You can run Gittyleaks on your git repo to scan it for unintentionally added personal data.</p><p>GittyLeaks cam is installed for python3:</p><blockquote>python3 -m pip install gittyleaks</blockquote><p>After successful installation, any file inside your code folder can be simply called by gittyleaks.</p><p>Gittyleaks — find-anything can be used to identify general threats. gittyleaks — excluding $ . [ example statement can be used to exclude some string matches, for example, in case “$” occurs. gittyleaks — case-sensitive is to set it to be strict about cases.</p><h3>3. Github Secrets</h3><p>Github scans repositories for private credentials, e.g., an API key that may have been mistakenly uploaded with the code. It scans public repositories automatically for <a href="https://docs.github.com/en/actions/reference/encrypted-secrets">secrets</a>. Secret scanning can also be enabled explicitly on private repositories.</p><p>When a secret is found in the code, the repository admins are alerted. They can view and manage the scanning results on Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/0*7vych-U1O4grWxY3" /><figcaption><a href="https://docs.github.com/en/developers/overview/secret-scanning">Image source</a></figcaption></figure><p>I hope you learned something new from this article. Open Source software is wonderful when it’s safe, so you must make sure to scan repositories before using them and keep your application updated to prevent any security breaches or cyberattacks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d9dcd9ab56d" width="1" height="1" alt=""><hr><p><a href="https://gopensource.com/use-these-tools-to-scan-public-and-private-github-repositories-7d9dcd9ab56d">Use These Tools to Scan Public and Private GitHub Repositories</a> was originally published in <a href="https://gopensource.com/">GopenSource</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conducting SAST for Java Applications]]></title>
            <link>https://itnext.io/conducting-sast-for-java-applications-5b0ac381cb4a?source=rss-a7bd0c352203------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b0ac381cb4a</guid>
            <category><![CDATA[sast]]></category>
            <category><![CDATA[bugs]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Anton Lawrence]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 07:46:46 GMT</pubDate>
            <atom:updated>2021-04-14T07:46:46.539Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*De-LoWr-wT6Vcb1hFhyv1A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@flyd2069?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">FLY:D</a> on <a href="https://unsplash.com/s/photos/security?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Bugs are an inevitable part of every developer’s journey. If not given enough time to resolve, bugs can detrimentally harm your users’ experiences by making your application hard-to-use, or by harming any processes leading to system malfunctions. To minimize bugs in a program, it’s important to conduct thorough testing before deployment.</p><p>In this piece, you will learn to carry out <a href="https://www.perforce.com/blog/kw/what-is-sast">SAST</a> (static application security testing) in your Java application using SpotBugs. SAST is essential in tackling the following problems:</p><ul><li>source code vulnerabilities</li><li>late diagnosis of problems</li><li>lack of root-cause analysis</li></ul><p><a href="https://spotbugs.github.io/">SpotBugs</a> is an open-source tool for static analysis. It helps find common bad and dodgy codes as well as common security vulnerabilities. One major advantage of SpotBugs is that it comes with great integrations support for the following:</p><ul><li>Eclipse</li><li>Ant</li><li>Gradle</li><li>Maven</li></ul><p>You can use it as a stand-alone program or as a plugin inside your project. This promotes flexibility as you can run it in your project based on your own preferences.</p><p>Let’s proceed to the next section and start installing SpotBugs.</p><h3>Setup</h3><p>By default, SpotBugs is platform-independent and runnable on GNU/Linux, Windows, and macOS X. It is built using JDK8 and runs on JRE8 and later versions.</p><h3>Requirement</h3><p>Make sure that your machine fulfills the following requirements:</p><ul><li>runtime environment compatible with Java version 1.8 or newer</li><li>at least 512MB memory (large projects require more memory)</li></ul><p>Besides this, SpotBugs supports scanning of bytecode (class files) generated by JDK11 or newer.</p><h3>Installing SpotBugs</h3><p>You can easily install SpotBugs by downloading the binary distribution. It comes in two different formats:</p><ul><li><a href="https://github.com/spotbugs/spotbugs/releases/download/4.2.1/spotbugs-4.2.1.tgz">gzipped tar</a></li><li><a href="https://github.com/spotbugs/spotbugs/releases/download/4.2.1/spotbugs-4.2.1.zip">zip</a></li></ul><p>Then, extract the compressed file into a folder via the following code (modify the name of the file accordingly):</p><pre># gzipped tar<br>gunzip -c spotbugs-4.2.1.tgz | tar xvf -<br># zip<br>unzip spotbugs-4.2.1.zip</pre><p>You should have a new folder called spotbugs-4.2.1 depending on the version that you downloaded.</p><h3>Building Your Own Java Class for Beginners</h3><p>In this section, you will learn the basics of building your own Java class. If you are an experienced Java developer, kindly skip to the next section and use SpotBugs directly on your existing project.</p><h3>Creating a Java File</h3><p>Create a new Java file called TestJava.java and append the following code inside it (make sure that class name is the same as the file name):</p><pre>import java.util.Arrays;<br>public class TestJava {<br>}</pre><p>It will serve as the main Java file, which contains the following functions (some of the functions names are purposely written in title case):</p><ul><li>empty statement block for a conditional statement:</li></ul><pre>public void BadCode() {<br>   int length = 1;<br>   if (length == 0) {<br>      // TODO: handle this case<br>   }<br>}</pre><ul><li>code that is confusing or written in a way that often leads to errors:</li></ul><pre>public void DodgyCode() {<br>   Number[] arr = new Integer[10];<br>   arr[0] = 1.0;<br>}</pre><ul><li>mutable:</li></ul><pre>public void maliciousCode(String[] stringArg) {<br>   // bad<br>   arrString = stringArg;</pre><pre>   // good<br>   // arrString = Arrays.copyOf(stringArg, stringArg.length);<br>}</pre><p>You can find the complete code at the <a href="https://gist.github.com/wfng92/0e8f52bdb805aa9f7f1bfc3e216de320">following link</a>:</p><pre>import java.util.Arrays; </pre><pre>public class TestJava {<br>   private String[] arrString; </pre><pre>   public void BadCode() { <br>      int length = 1; <br>      if (length == 0) { <br>         // TODO: handle this case<br>      } <br>   } </pre><pre>   public void DodgyCode() { <br>      Number[] arr = new Integer[10]; <br>      arr[0] = 1.0; <br>   } </pre><pre>   public void maliciousCode(String[] stringArg) { <br>      arrString = stringArg; <br>      // arrString = Arrays.copyOf(stringArg, stringArg.length); <br>   }<br>}</pre><h3>Building a Java Class</h3><p>Next, let’s generate a Java class file from the code that you created earlier. Change the working directory to the root location of your TestJava.java.</p><p>Run the following command:</p><pre>javac TestJava.java</pre><p>It will generate a new file called TestJava.class. A Java class file can be invoked directly inside the command prompt or compiled into a Java archive file such as .jar.</p><h3>Using SpotBugs</h3><p>This section covers the basics of using SpotBugs.</p><h3>Running SpotBugs</h3><p>The recommended method to run SpotBugs is via the following command line (assuming that you are at the root folder which contains spotbugs-4.2.1):</p><p>java -jar spotbugs-4.2.1\lib\spotbugs.jar -gui</p><p>For Windows users, there is an option to run it directly by double-clicking on …\lib\spotbugs.jar file.</p><p>You should see the following user interface:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*h2Agf6soOoNXko4ZMvrF6A.png" /></figure><h3>Creating New Project</h3><p>Now click File &gt; New Project menu which is located at the top left. It will show the following user interface:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*rJtUEdhFyTUMhiEhmsWAXw.png" /></figure><p>The most important field to be filled are:</p><ul><li>classpath for analysis</li><li>source directories</li></ul><p>You can select individual Java archive files or a directory. The latest version does support Java class file although it is not stated in the user interface.</p><p>Let’s start by filling the classpath for analysis. Click on add and fill in the directory where your Java class is located. Repeat the same step for source directories. The second step is important as failing to do so will prevent code from showing in the user interface.</p><h3>Analyze the Result</h3><p>Once you are done, click on the Analyze button and wait for the analysis. Large projects might take quite a while for this.</p><p>You should see the following result when it finishes running:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*RUY4pi62gPz32p81LlLZmA.png" /></figure><p>Notice that SpotBugs has identified a total of 8 bugs:</p><ul><li>2 bad practice codes:</li></ul><pre>Method names should start with a lower case letter<br>public void BadCode()<br>public void DodgyCode()</pre><ul><li>1 malicious code vulnerability:</li></ul><pre>May expose internal representation by incorporating reference to mutable object<br>line 19: arrString = stringArg;</pre><ul><li>1 performance issue:</li></ul><pre>Unread field<br>line 19: arrString = stringArg;</pre><ul><li>4 dodgy codes:</li></ul><pre>Useless object created<br>line 14: Number[] arr = new Integer[10];<br>Useless non-empty void method<br>public void BadCode()<br>public void DodgyCode()<br>Useless control flow<br>line 8: if (length == 0)</pre><h3>Saving and Opening Result</h3><p>In order to save the result, go to the menu and click File &gt; Save As. Fill in the desired file directory and file name. Next, hit Save and it will generate an XML file for you.</p><p>In addition, SpotBugs comes with other saving options, such as:</p><ul><li>project files only (.fbp)</li><li>analysis files only (.fba)</li><li>HTML output (.html)</li></ul><p>You can easily load the output result back into SpotBugs with File &gt; Open.</p><h3>Conclusion</h3><p>Let’s recap what we have covered today.</p><p>This article started off with a brief explanation on SAST and the features of SpotBugs.</p><p>After that, it continued with installation steps, which include downloading the binary distribution from the official links and extracting it to local storage.</p><p>There is an optional section on creating your own Java file and building it into a Java class.</p><p>Finally, this article wrapped up with the basics of SpotBugs where you analyzed the code and obtained the security and bug analysis as output.</p><p>Thank you for reading this piece. Hope you come back to read the next article!</p><h3>Reference</h3><ol><li><a href="https://github.com/spotbugs/spotbugs">Spotbugs — Github</a></li><li><a href="https://spotbugs.readthedocs.io/en/latest/">Spotbugs — Documentation</a></li><li><a href="http://findbugs.sourceforge.net/manual/gui.html#d0e1087">Spotbugs — GUI</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b0ac381cb4a" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/conducting-sast-for-java-applications-5b0ac381cb4a">Conducting SAST for Java Applications</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common JavaScript Debugging Problems and How to Solve Them]]></title>
            <link>https://javascript.plainenglish.io/common-javascript-debugging-problems-and-how-to-solve-them-300316d949d5?source=rss-a7bd0c352203------2</link>
            <guid isPermaLink="false">https://medium.com/p/300316d949d5</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Anton Lawrence]]></dc:creator>
            <pubDate>Thu, 02 Jul 2020 11:08:24 GMT</pubDate>
            <atom:updated>2020-07-09T10:34:09.509Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*biLs0r8qLhaaorteiG6Dxg.jpeg" /></figure><p>When working with <a href="https://web.cs.ucdavis.edu/~filkov/papers/lang_github.pdf">any programming language</a>, there will be a phase where you would have to deal with annoying bugs and errors. JavaScript especially has many hidden bugs and errors waiting for the best time to erupt in production. Whether you’re doing local or <a href="https://www.rookout.com/blog/remote-debugging">remote debugging</a>, knowing how to fix these common JavaScript bugs will make your life easier.</p><p>In this article, we’ll explore various common JavaScript problems and how to solve them.</p><h3>Uncaught ReferenceError: ‘x’ is not defined</h3><p>This is one of the most common JavaScript errors, and it usually happens when there is a non-existent variable referenced somewhere in the code.</p><p>The variable is either not declared well, or declared in the wrong scope.</p><p>Look at the code below:</p><pre>console.log(foo) // Uncaught ReferenceError: &#39;foo&#39; is not defined</pre><p>It would throw Uncaught ReferenceError: ‘foo’ is not defined since we don’t have foo declared. This can be fixed by declaring the variable foo:</p><pre>var foo = &quot;foobar&quot;;</pre><pre>console.log(foo) // foobar</pre><p>Another example is the code below:</p><pre>function add() {<br>  var x = 5, y = 1;<br>  return x + y;<br>}</pre><pre>console.log(x); // Uncaught ReferenceError: x is not defined</pre><p>The issue here is x is only available in the scope of add function and cannot be used outside that function. However, the add function can access any global variable and its local variable.</p><p>To fix it, you will need to declare variable x as global variable.</p><pre>var x = 5, y = 1</pre><pre>function add() {<br>  return x + y;<br>}</pre><pre>console.log(x); // 5</pre><p>There you go! It’s fixed.</p><h3>Uncaught TypeError: Cannot read property ‘x’ of undefined</h3><p>This is another common annoying JavaScript error that bugs JavaScript developers and it usually happens when you are trying to access a property of an <a href="https://en.wikipedia.org/wiki/Undefined_variable">undefined value or variable</a>.</p><p>There are many reasons this could occur. Let’s look at the code below:</p><pre>var x = &quot;foobar&quot;;</pre><pre>console.log(x.substring(1)) // oobar</pre><pre>console.log(x.foobar) // undefined</pre><pre>console.log(x.foobar.substring(1))  // Uncaught TypeError: Cannot read property &#39;substring&#39; of undefined</pre><p>In the above example, in lines 3 and 4, we are trying to access an undefined value of x. x.foobar on line 3 would give undefined since x doesn’t have the property foobar, and trying to access substring of the value undefined would result in an error.</p><p>Sometimes, this error occurs when dealing with JavaScript objects like for instance:</p><pre>const state = {<br>  common: {<br>    auth: {<br>      user: {<br>        name: &quot;John Smith&quot;,<br>      },<br>      token: {<br>        jwt: &quot;eyJAD.LAKDIDCWECUWJKDSnlwpihfwpfo&quot;,<br>        bearer: &quot;LAKDIDCWECUWJKDSnlwpihfwpfo&quot;,<br>      }<br>    }<br>  }<br>}</pre><pre>console.log(state.common.auth.user.name) // John Smith</pre><pre>console.log(state.common.auth.tokne.jwt) // Uncaught TypeError: Cannot read property &#39;jwt&#39; of undefined</pre><p>On line 15, we made a typo of the property name token as tokne, which would result in undefined and accessing the property jwt would result in uncaught typeerror. This can be fixed by fixing the typo name.</p><pre>console.log(state.common.auth.tokne.jwt)</pre><h3>Uncaught TypeError: Cannot read property ‘x’ of null</h3><p>This is similar to the previous error, but this happens when you are trying to access a property of a null value or variable.</p><pre>var x = null;</pre><pre>console.log(x.substring()) // Uncaught TypeError: Cannot read property &#39;substring&#39; of null</pre><p>Another thing is if, for instance, a variable, an object is set to null at initial while loading data from ajax or api and you try to access it before the data is loaded.</p><pre>const data = {<br>  messages: null<br>};</pre><pre>fetch(&quot;https://medrum.herokuapp.com/messages/birthday_message/&quot;)<br>.then((r) =&gt; r.json())<br>.then((d) =&gt; {<br>  data.messages = d<br>})</pre><pre>setTimeout(() =&gt; {<br>  console.log(data.messages.messages)<br>}, 1500)</pre><pre>console.log(data.messages.messages) // Uncaught TypeError: Cannot read property &#39;messages&#39; of null</pre><p>In the above code, we want to fetch data from an endpoint into the messages property in the data object. The messages is set to null at first since there’s no data yet.</p><p>If you try to access it when the data is not ready, you’ll get the error Uncaught TypeError: Cannot read property ‘messages’ of null. To fix, you can do a check if the messages is not null and access it.</p><pre>if(data.messages){<br>  console.log(data.messages.messages)<br>}</pre><h3>Uncaught TypeError: x is not a function</h3><p>This is also another error that usually occurs when you try to call a non-function/method variable.</p><pre>const add = 1 + 2;</pre><pre>console.log(add); // 3</pre><pre>console.log(add()) // Uncaught TypeError: add is not a function</pre><p>Line 3 will surely throw an error if you try to call add as add() function or method.</p><h3>Wrong references to this</h3><p>This isn’t an error but more like a bug that could give all kinds of errors. You usually have this bug present in most JavaScript code referencing this in top-level methods (different from top-level functions). Top-level methods in JavaScript could be nested functions in functions, objects, class, and so on.</p><p>this is a very good way of self-referencing an object, and its scope may be different each time the function is called and how it’s being called within callbacks and closures can also differ.</p><pre>function mainFunction() {<br>  this.someMethod1 = function() {<br>    var elementBtn = document.getElementById(&#39;myBtn&#39;);<br>    elementBtn.onclick = function() {<br>      this.someMethod2(); <br>      //Uncaught TypeError: undefined is not a function<br>    };<br>  };<br>  this.someMethod2 = function() {<br>    alert(&#39;OK&#39;);<br>  };<br>}</pre><p>Anytime myBtn is clicked, it will try to call this.someMethod2(), which is currently referencing the elementBtn object and not mainFunction. The scope of this has changed in the onclick method to the current element object.</p><p>To fix this, you will need to keep a reference of mainFunction and use it to call someMethod2().</p><pre>function mainFunction() {<br>  const _this = this;<br>  this.someMethod1 = function() {<br>    var elementBtn = document.getElementById(&#39;myBtn&#39;);<br>    elementBtn.onclick = function() {<br>      _this.someMethod2();<br>    };<br>  };<br>  this.someMethod2 = function() {<br>    alert(&#39;OK&#39;);<br>  };<br>}</pre><p>Another example is:</p><pre>function App() {<br>  this.data = null<br>}</pre><pre>App.prototype.getLocalData = function () {<br>  const data = {<br>    user: {<br>      name: &quot;Smith&quot;<br>    }<br>  }<br>  return data<br>}</pre><pre>App.prototype.setData = function (data) {<br>  this.data = data<br>}</pre><pre>App.prototype.loadApp = function () {<br>  const data = this.getLocalData();<br>  this.load = setTimeout(function() {<br>    this.setData(data);<br>  }, 0);<br>}</pre><pre>App.prototype.loadApp()</pre><p>In the example above, you get the error because you are calling this.setData in setTimeout, which is the same thing as window.setTimeout and has its own this reference.</p><p>The context you are calling this is no longer in loadApp but in the context of window.</p><p>To fix this, you will need to save a reference of this as we did previously:</p><pre>App.prototype.loadApp = function () {</pre><pre>const _this = this</pre><pre>const data = this.getLocalData()</pre><pre>this.load = setTimeout(function() {</pre><pre>_this.setData(data);</pre><pre>}, 0);</pre><pre>}</pre><p>Alternatively, you can call the bind() method to pass in the correct this reference in modern browsers:</p><pre>App.prototype.loadApp = function () {</pre><pre>const data = this.getLocalData()</pre><pre>this.load = setTimeout(this.reset.bind(this, data), 0);</pre><pre>}</pre><pre>App.prototype.reset = function(data){</pre><pre>this.setData(data)</pre><pre>}</pre><h3>Uncaught RangeError: Maximum call stack size exceeded</h3><p>This is one of the least expected errors that usually occurs due to a bug in handling recursion or out of range operations. There are various types of Uncaught RangeError errors that occur depending on what operation you are performing.</p><p>Most common one is Maximum call stack size exceeded which usually occurs in non-terminating recursion functions. See the code below:</p><pre>function iRecurse(){</pre><pre>iRecurse();</pre><pre>}</pre><pre>iRecurse(); // Uncaught RangeError: Maximum call stack size exceeded</pre><p>The above example is a non-terminating <a href="https://javascript.info/recursion">recursion</a> and keeps calling itself in an infinite loop until it reaches the maximum call stack.</p><p>There are many ways we can introduce bugs into this even if we add conditions to terminate the recursion:</p><pre>x = 1</pre><pre>function iRecurse(){</pre><pre>x+=2;</pre><pre>if(x%2==0) return;</pre><pre>iRecurse();</pre><pre>}</pre><pre>iRecurse(); // Uncaught RangeError: Maximum call stack size exceeded</pre><p>The above example won’t terminate because every increment of x modulus 2 won’t result to 0 since x is initially 1 and every increment will be odd numbers.</p><pre>x = 0</pre><pre>function iRecurse(){</pre><pre>x+=2;</pre><pre>if(x%2==0) return;</pre><pre>iRecurse();</pre><pre>}</pre><pre>iRecurse();</pre><p>By setting x to 0 we are able to fix this bug.</p><p>Other range errors are:</p><pre>// Array</pre><pre>var arrEx = new Array(2) // ok</pre><pre>var arrExErr = new Array(-2) // Uncaught RangeError: Invalid array length</pre><pre>// Number</pre><pre>var num = Number(5.45);</pre><pre>console.log(num.toFixed(20)) // 5.45000000000000017764</pre><pre>console.log(num.toFixed(120)) // Uncaught RangeError: toFixed() digits argument must be between 0 and 100</pre><pre>console.log(num.isPrecision(20)) // &quot;5.4500000000000001776&quot;</pre><pre>console.log(num.isPrecision(120)) // Uncaught RangeError: isPrecision() digits argument must be between 1 and 100</pre><pre>console.log(num.toExponential(20)) // &quot;5.45000000000000017764e+0&quot;</pre><pre>console.log(num.toExponential(120)) // Uncaught RangeError: toExponential() argument must be between 0 and 100</pre><h3>Uncaught TypeError: Converting circular structure to JSON</h3><p>This is also another common JavaScript error and bugs when dealing with JSON data. If you are working with JSON data, there’s a chance that you have encountered this type of error.</p><p>This usually happens when you try to JSON.stringify objects that have circular references to each other.</p><p>For instance:</p><pre>var a = {}</pre><pre>var b = {a:b}</pre><pre>a.b = b</pre><pre>b.a = a</pre><p>If you try this:</p><pre>JSON.stringify(b) // Uncaught TypeError: Converting circular structure to JSON</pre><p>You would get the error: Uncaught TypeError: Converting circular structure to JSON. Since both a and b have a reference to each other, either b or a cannot be converted into JSON.</p><p>The easiest way to fix this is to check for and prevent circular references of objects before JSON.stringifying your objects. You can also specify a custom serializer function that detects and cleans up circular references.</p><p>You really don’t need to write that yourself, there are existing solutions you can use like this one on <a href="https://github.com/isaacs/json-stringify-safe">Github</a> or <a href="https://www.rookout.com/">Rookout</a>, which can help identify circular references.</p><h3>Conclusion</h3><p>JavaScript errors/bugs can be annoying, confusing, and time-consuming if you don’t know where the error is coming from and how to solve it. We have been able to explore some basic JavaScript bugs and how we can fix them.</p><p>When debugging JavaScript errors, I suggest you have <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a> turned on as it helps with handling errors faster and use <a href="https://developers.google.com/web/tools/chrome-devtools">Chrome DevTools</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=300316d949d5" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/common-javascript-debugging-problems-and-how-to-solve-them-300316d949d5">Common JavaScript Debugging Problems and How to Solve Them</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All You Need to Know About End to End Testing]]></title>
            <link>https://itnext.io/end-to-end-testing-78033fb768a8?source=rss-a7bd0c352203------2</link>
            <guid isPermaLink="false">https://medium.com/p/78033fb768a8</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[e2e]]></category>
            <category><![CDATA[qa]]></category>
            <category><![CDATA[end-to-end-testing]]></category>
            <category><![CDATA[software-testing]]></category>
            <dc:creator><![CDATA[Anton Lawrence]]></dc:creator>
            <pubDate>Mon, 02 Mar 2020 08:05:40 GMT</pubDate>
            <atom:updated>2020-04-22T13:02:30.498Z</atom:updated>
            <content:encoded><![CDATA[<p>End-to-End tests have become quite common in today’s software engineering industry. They are performed by teams of various sizes with the aim of ensuring that all components, internal and external, of the software product, been developed functions as stipulated in the requirements specification.</p><p>Various kinds of tests are carried out by software teams to ensure their product performs as expected. These tests may be unit tests, regression tests, integration tests, and so on. Software systems today can become very complex with several interconnections to a host of external services and internal services by other teams in the same company hence the need for a way to ensure that all parts of the system work in unison.</p><p>End to End tests is usually carried out using similar parameters used by Production environments with the aim of ensuring the correct flow of data within the system.</p><p>In this article, we would learn a lot about End to End tests and find out some exciting tools that can help us accomplish these tests.</p><p><strong>What does End-to-End testing Entail</strong></p><p>The details about End-to-End testing included by teams during the testing phase are very important to the success of an End-to-End test.</p><p>The first step to a successful End-to-End test would be to create user functions that correctly simulate real-world activities carried out with the software product to be tested. This would enable the test team to set up conditions for the success or failure of the test based on the parameters that are passed to these user functions.</p><p>Once these are in place, it is then possible to set up test cases that model real-life workflows and also provide a performance benchmark against test conditions.</p><p>To measure the success of these tests, teams could take into account the number of tests completed per week, while noting the successes and failures, against the total number of tests planned. Other things to note include:</p><ul><li>The current state of the test case preparation in comparison to the number of test cases that have been planned.</li><li>The number of detects that have been attended to or left unattended at the end of the week. Distribution of these defects based on priority and severity should also be noted.</li><li>The time spent in executing tests in comparison to the total time scheduled for test execution.</li></ul><p><strong>The End-to-End Testing Process</strong></p><p>End-to-End tests vary for different organizations due to the uniqueness of engineering processes carried out across these organizations. However, the main activities involved in End to End testing include the following:</p><ul><li>An analysis of the existing systems and their testing requirements</li><li>An outline of the hardware/software requirements in setting up the test environment as well as the responsibilities of all team members involved.</li><li>Analysis and design of test cases for each subsystem.</li><li>Ability to record input and output data for each system and compare them with target metrics.</li></ul><p><strong>How to Do End-to-End Testing</strong></p><p>In the previous section, we looked at key activities often carried out during End to End testing. Here, we look at practical ways in which these activities can be implemented.</p><p>Implementing End to end tests can be a laborious process especially for large organizations with several interconnected systems to test. Hence, as a first step in implementing End to end tests, it would be wise to identify tests for the most critical business components or components most prone to defect and design test cases for these components as quickly as possible.</p><p>The next step would be to choose a test framework. Several test frameworks exist for various technologies used in system design by teams across the globe. Some of these test frameworks are technology dependent while others are not.</p><p>A common solution is <a href="https://www.selenium.dev/">Selenium</a>. As described by Wikipedia,</p><ul><li><strong><em>Selenium</em></strong><em> is a portable framework for testing web applications. Selenium provides a playback tool for authoring functional tests without the need to learn a test scripting language (Selenium IDE).</em></li></ul><p>It is an open-source test framework that focuses on web applications. Developing a Selenium automation framework for End to end tests involve a series of considerations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*av9x00L0RJAK71nT.png" /></figure><p>Firstly, the framework needs to be set from the ground up and made to fit into the product’s needs. This could be done in-house or outsourced.</p><p>Next, the time and cost of doing this also need to be considered. Developing this test suite could vary in months and this depends on the complexity and size of the operation. When outsourced, the cost would usually be more.</p><p>Integrating this automation framework into the overall development workflow is also a hassle as there would be a need to create new processes that incorporate the work in the framework and define specific conditions.</p><p>Other considerations include the cost of creating new work processes, setting up a test lab, and the cost of setting up test and development teams and ensuring the gel together.</p><p>A better alternative would be a codeless test automation platform. A good example of this is <a href="https://www.testcraft.io/">Testcraft</a>. It offers test automation for End to end testing as a software service with an easy to use interface hence there is no need for an automation specialist to set up the framework or a need to outsource the job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oAWEWoHUvbp2q1Ss.png" /></figure><p>It uses machine learning techniques to cut down the time and resources needed to effectively maintain a team’s Selenium test flows and generates detailed reports on every run. The details included in these reports are screenshots and videos indicating what needs to be fixed.</p><p>Test executions could also be easily scheduled and the built-in test lab saves time and costs in setting up test labs for conventional automation frameworks.</p><p>Other noteworthy features include smooth integration with <a href="https://en.wikipedia.org/wiki/CI/CD">CI/CD</a> tools eases integration with a team’s existing <a href="https://en.wikipedia.org/wiki/Systems_development_life_cycle">Software Development Lifecycle (SDLC)</a>, smart bindings which prevent tests from breaking when the web product changes, and interactive UI elements which ease the maintenance process.</p><p><strong>Safe Practices for End-to-End Testing</strong></p><p>To ensure software teams can get the best from performing End to end tests on their systems, the following practices may be helpful:</p><ul><li>Test the systems involved from the user’s point of view. This helps in the proper design of test cases.</li><li>Only typical user activities should be tested with End to end testing. Integration testing and unit testing may be carried out to ensure the system doesn’t perform abnormally.</li><li>Concentrate on high risks parts of the system or parts which form a critical part of the business. It would be helpful to analyze the risks each system component offers.</li></ul><p><strong>Conclusion</strong></p><p>We have looked at End to End testing and how it could ensure a network of systems work as expected.</p><p>Today’s software applications are built upon several layers and the failure of a particular component could cripple the entire product. Ensuring End to End tests are properly carried out could point out these points of failure in complex systems and prevent massive damage and loss in revenue.</p><p><strong>Further Reads</strong></p><ul><li><a href="https://dzone.com/articles/what-is-end-to-end-testing-1">https://dzone.com/articles/what-is-end-to-end-testing-1</a></li><li><a href="https://www.testcraft.io/ui-testing/">https://www.testcraft.io/ui-testing/</a></li><li><a href="https://www.freecodecamp.org/news/why-end-to-end-testing-is-important-for-your-team-cb7eb0ec1504/">https://www.freecodecamp.org/news/why-end-to-end-testing-is-important-for-your-team-cb7eb0ec1504/</a></li><li><a href="https://www.softwaretestinghelp.com/what-is-end-to-end-testing/">https://www.softwaretestinghelp.com/what-is-end-to-end-testing/</a></li><li><a href="https://www.guru99.com/introduction-to-selenium.html">https://www.guru99.com/introduction-to-selenium.html</a></li><li><a href="https://www.testcraft.io/resources/">https://www.testcraft.io/resources/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78033fb768a8" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/end-to-end-testing-78033fb768a8">All You Need to Know About End to End Testing</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy Ways to Eliminate Vulnerabilities in your Repository]]></title>
            <link>https://medium.com/@A-Lawrence/vulnerabilities-in-your-repository-bb5b11221a6a?source=rss-a7bd0c352203------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb5b11221a6a</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[repositories]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[security-vulnerabilities]]></category>
            <dc:creator><![CDATA[Anton Lawrence]]></dc:creator>
            <pubDate>Sun, 01 Mar 2020 06:22:27 GMT</pubDate>
            <atom:updated>2020-03-01T06:22:27.839Z</atom:updated>
            <content:encoded><![CDATA[<p>There’s a rise of vulnerability tools lately and since I’ve never fiddled around with it I was wondering what’s up with it. Now seems like a good opportunity to check it out.</p><p>You have probably seen these alerts in your repositories on GitHub lately (and most probably you’ve ignored them the whole time):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aoRn5vnVgEwpMTzm" /></figure><p>To be frank, I never paid attention to these until I looked into the alerts for one of my university projects — and surprise, surprise: GitHub recommends to update one of the core packages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PbVmNaPrRk8g4bvD" /></figure><p>Looking further, I noticed that it offers more hidden gems — you can even open up a security advisory and privately discuss vulnerabilities with your collaborators.</p><p>That got me curious; so I’ve wanted to explore. In this article, we are going to compare some various tools and see how they get their job done.</p><h3>GitHub’s Vulnerability Alerts</h3><p>GitHub maintains a database full of known <a href="https://github.com/advisories">vulnerabilities</a><a href="https://github.blog/2019-12-11-behind-the-scenes-github-vulnerability-alerts/">¹</a>.</p><p>The way it works is that GitHub is constantly checking for your dependency manifest files every time you push to your repository. A background task checks whether or not the dependency is already known, and if not, it will add it to the dependency graph and gather more information that is associated with the specific package. You can read more about that <a href="https://github.blog/2019-12-11-behind-the-scenes-github-vulnerability-alerts/">on their blog</a> if you like to.</p><p>Here’s a quick TL;DR: A machine learning model determines whether or not there are known vulnerabilities and if it’s impacting the open-source toolchain. If that’s the case, GitHub manually reviews it before it’s submitted to their database. Afterward, a bot creates alerts and pull requests for all affected repositories (just think about the load for every affected project that uses popular libraries — devastating).</p><p>Okay, that’s for the basics of GitHub’s Vulnerability Alerts. Let’s see how we can use it from a dev’s perspective. If we hit the Security tab on our repository’s page we can select a vulnerability and create an automated resolution. This will summon the almighty <a href="https://dependabot.com/">dependeabot</a> that creates a new pull request as elaborated above. dependabot was used to be offered as a separate third-party product but it has been acquired by GitHub and is now free of charge. It supports several languages, plus it’s possible to <a href="https://dependabot.com/docs/config-file/">configure</a> its behavior manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1atF8VU2DgxdmYbl" /></figure><p>Within the PR’s commits above, we can spot the updated dependency in the manifest file. All that’s left to do is to hit the merge button. And we’re done.</p><h3>Bolt &amp; Renovate</h3><p>Since GitHub is collaborating with WhiteSource I was wondering what else they are offering. Seems like they are offering standalone tools that are independent of GitHub’s ecosystem. This is great, especially for companies that are working with Azure DevOps, GitLab, Bitbucket, you name it, instead of GitHub.</p><p>So let’s give it a shot.</p><p>WhiteSource has two different tools, <a href="https://bolt.whitesourcesoftware.com/">Bolt</a> and <a href="https://renovate.whitesourcesoftware.com/">Renovate</a>.</p><ul><li>Bolt finds and fixes open source vulnerabilities based on their database similar to what GitHub does.</li><li>Renovate keeps your dependencies up-to-date and creates pull requests rich with changelogs &amp; commit histories.</li></ul><p>Seems like both tools are a great addition to any DevOps workload.</p><p>I added Bolt to one of my on-going university projects and shortly afterward it has created a few issues. All of them are labeled as security vulnerabilities. If we click on one of them, we will spot more details and even references to the vulnerability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cuJihlVHf67Xp2JZ" /></figure><p>Furthermore, we can even choose to enable Bolt as a status check in our project’s branch policies. This way we can ensure that it will check for vulnerabilities whenever we merge into the protected branch. Quite nifty.</p><p>Okay, so, on the one hand, Bolt <em>scans, notifies us about vulnerabilities and creates a pull request that fixes it</em>. On the other, Renovate <em>keeps dependencies up-to-date</em> like dependabot, regardless of whether or not it’s about a security vulnerability.</p><p>Renovate opens a pull request just like Bolt that adds a file with the initial configuration. After the successful merge, the first bunch of actual pull requests rolls in. In here, the bot lists all updated dependencies and suggests to update them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/0*k2yGYjgh6AsrUC1A" /></figure><p>Pretty cool. Guess that’s one way to automate dependency updates so you don’t need to anymore™.</p><h3>Verdict</h3><ul><li>dependabot looks great as a simple drop-in solution that doesn’t require further customization. It’s neatly integrated into GitHub since it was acquired — everything is there at a glance. In my opinion, this is a great tool for popular open-source projects that must stay healthy without potential vulnerabilities.</li><li>WhiteSource’s own set of tools is also great and isn’t limited to GitHub. I use Azure DevOps for some of my private projects and at work. Next to third-party support, it’s possible to self host their tools as an npm package or Docker image. I could think of it as a neat addition that updates my dependencies without my intervention because often it’s just a pain in the butt to go through the update process right in the middle of development (<em>glares at Angular</em>). Bolt and Renovate also convince with their deep customization options.</li></ul><p>In regards to Bolt and Renovate — I like the distinct separation of fixing open source vulnerabilities and updating dependencies just to keep them recent — it doesn’t do both at the same time, but it plays well together if that’s how you want to roll. That makes it comfortable.</p><p>I hope I could offer a glimpse look at how you can counteract against vulnerabilities with ease. You might want to consider to use these tools for your heavy-duty projects since it’s easy as 123 once you know how it works and what it does. There’s nothing more repetitive (and annoying) than manual dependency updates. Please feel free to share your ideas and thoughts with me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb5b11221a6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Key To Improve Your API’s Quality]]></title>
            <link>https://itnext.io/the-key-to-improve-your-apis-quality-31c5d5a32505?source=rss-a7bd0c352203------2</link>
            <guid isPermaLink="false">https://medium.com/p/31c5d5a32505</guid>
            <category><![CDATA[automation-testing]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Anton Lawrence]]></dc:creator>
            <pubDate>Sun, 23 Feb 2020 21:46:20 GMT</pubDate>
            <atom:updated>2020-02-25T19:28:25.411Z</atom:updated>
            <content:encoded><![CDATA[<p>You are probably considering or doing various tests for your latest critical API project. This can go from unit to integration tests.</p><p><strong>Great!</strong> You also want to test the behavior of your API once it’s connected to your front end by a dedicated team. You plan to test it right from your UI.</p><p>However, you don’t feel confident enough to ship your product even though you and your QA team have tested various aspects there. <br>Why? Because you don’t know how it behaves in the real world when it’s out for your consumers.</p><p><strong>To understand why you don’t feel confident, let’s look at some failures your API could have at some point:</strong></p><ul><li>Long API response times</li><li>You might get outdated responses from cache</li><li>External services are not available</li><li>Worst of all: you don’t get the expected response</li></ul><p>It’s pretty hard to measure these things in production without anything covering your back. You will probably know about it when your consumer eventually reports it or when you dig deep in your logs.</p><p>To mitigate this, you could gear up with additional testing. If we look into the Agile Testing Quadrants, you are probably able to strike out those approaches you are already doing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*y83gyzmRQunu6n47" /><figcaption><a href="https://lisacrispin.com/2011/11/08/using-the-agile-testing-quadrants/">Agile Testing Quadrants by lisacrispin.com</a></figcaption></figure><p>We want something that is criticizing our product and supporting the team. Based on the testing quadrants our best choice is to go with <em>technology faced approaches</em>, a perfect split between automated testing and tools that support our development journey.</p><p>Many tools can assist to achieve this task. You are probably looking for something free, well documented, easy to use and feature-rich, yet something lightweight. <a href="https://www.loadmill.com/">Loadmill</a> for instance has a free tool to run Automated API and Load Tests with ease and without the need to revamp your whole API project.</p><p>To get started, you can simply sign up for a free plan on Loadmill’s site. After you have signed up, go to your API Tests and create your first Test Suite.</p><h3>A short rundown of all features:</h3><ul><li>In Flows you can create individual Flows that <em>execute requests one after another</em>. For each request, you can set additional headers, provide validation parameters and assign variables in your current test session.</li><li>Based on Flows, you can set a Login Flow that gets executed each time you access a route that requires some sort of authentication. You don’t need to re-authenticate each time you are executing specific requests.</li><li>Parameters allow you to set session-wide parameters for your Test Suite. These can be changed during runtime. This is helpful if you like to store certain tokens or simple parameters such as IDs and so on.</li><li>The CI section instructs you on how to run API tests in CI environments. Loadmill comes with an npm package. You just need to run it accompanied with your Test Suite’s token.</li></ul><p>This is all you need to know about Loadmill’s API Testing features.</p><h3>Action Time</h3><p>Let’s get our hands on. For this, we are going to use our beloved API, GitHub’s API, so you don’t need to set your environment just yet for the scope of this quick introduction.</p><p>What do we want to do? We want to query our organization and its repositories and dig into details. For this, we want to be as flexible as possible and allow ourselves to swap out certain parameters like the organization’s ID. We also want to measure response times and set parameters during runtime.</p><p>First things first, let us store the organization as a parameter and access it later on. We go to the Parameters and add a new one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/0*9pR2ReI4n5ZNWP9c" /></figure><p>We go back to the Flows and create our first one. For this, we simply want to query our organization’s repositories.</p><p>This is an easy task because we already know the URL and the parameters for it. To query the repositories, we need to call <a href="https://api.github.com/orgs/loadmill/repos">https://api.github.com/orgs/loadmill/repos</a>.</p><p>We want to be as flexible as possible with the organization’s name, so we swap it out like this by using our parameter’s name: <a href="https://api.github.com/orgs/$%7Borg%7D/repos">https://api.github.com/orgs/${org}/repos</a></p><p>If we click on the Run button, you will notice that our test passes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/0*of4tG8CExn8AOiMN" /></figure><p>To validate our request, we expand the Advanced options and look into the ‘Verify Response’ section. In here, we can validate our response message with JSONPath. For testing purposes, we can validate the topmost repository with a JSONPath similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/0*AKyaBVJZ6ZD4CJ1L" /></figure><p>Here we simply store the repository canonical name as a new session parameter and validate it against our test bench below. We hit run again and see our test passing in all its glory.</p><p>(Oh, you can also inspect the request and response headers there)</p><p>Great, let’s move on. Now we want to query the topmost repository and see how that behaves. We have already stored the repository ID so there’s nothing else missing. We know that we can access it by requesting https://api.github.com/repos/loadmill/express-loadmill. A bit of transformation like https://api.github.com/repos/${org}/${repoId} puts it to the way we need it. Loadmill populates the parameters for us automatically.</p><p>Since we expect our API to return the same name of the repository, we can validate it against it in the Response Handling section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/0*86gPAlvK-dV1bfS-" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/0*2o1OnhkoiFMRgQ-e" /></figure><p>Once we run the suite, we notice that the Flow passes without errors.</p><p>You have hopefully noticed that it’s easy to create these tests. There’s no reason that you should be afraid of doing it, nor are you wasting your or anyone’s time with it.</p><p>Feel free to play around and make sure to check out <a href="https://docs.loadmill.com/">Loadmill’s docs</a> for more information.</p><p>Happy testing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31c5d5a32505" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/the-key-to-improve-your-apis-quality-31c5d5a32505">The Key To Improve Your API’s Quality</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Most common JavaScript vulnerabilities and how to fix them]]></title>
            <link>https://levelup.gitconnected.com/javascript-vulnerabilities-e5391a746c90?source=rss-a7bd0c352203------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5391a746c90</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[security-vulnerabilities]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Anton Lawrence]]></dc:creator>
            <pubDate>Wed, 19 Feb 2020 07:14:11 GMT</pubDate>
            <atom:updated>2020-02-21T16:19:44.819Z</atom:updated>
            <content:encoded><![CDATA[<p>JavaScript is the most popular programming language used to build everything from backend servers to interactive front-facing web applications which make up 95% of the web as stated by <a href="https://w3techs.com/technologies/details/cp-javascript">w3tech</a>. While Javascript is extremely popular because of its usefulness in building dynamic web applications, certain security concerns arise because of its popularity. Staying ahead of these security loopholes/vulnerabilities will help companies preempt common security fails and provide secure applications to their users.</p><p>In the course of this article, We will take a look at some of the most common JavaScript vulnerabilities and also learn the necessary steps to take in resolving them.</p><h3>What are Common Vulnerabilities?</h3><p>Most security vulnerabilities in javascript come as a result of end-user interaction. Malicious users can input query strings into forms to access or contaminate protected data. It is, therefore, a responsibility on engineering teams to add a validation middleware on user inputs.</p><p>Listed below are the most common JavaScript vulnerabilities:</p><ol><li>Cross-Site Scripting (XSS)</li><li>SQL injection (SQLi)</li><li>Open-source vulnerabilities</li></ol><p><strong>Cross-Site Scripting (XSS)</strong></p><p>One of the most common attacks involving web applications and JavaScript are Cross-site Scripting vulnerabilities which are included in the<a href="https://resources.whitesourcesoftware.com/blog-whitesource/owasp-top-10-vulnerabilities"> OWASP Top 10</a> web application security risks.</p><p>An XSS attack is a flaw in web applications which allow malicious users to execute JavaScript code on a website hence its popularity because almost every website requires JavaScript turned on in users browsers.</p><p>Cross-Site Scripting is primarily of two types namely:</p><ul><li>Client XSS</li><li>Server XSS</li></ul><p><strong>Client XSS</strong></p><p>This type of vulnerability occurs when untrusted data supplied from a remote location (mostly APIs) is used to update the DOM with an unsafe JavaScript call.</p><p>As an example, the following snippet below gets weather information from an untrusted API to display current weather information.</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>&lt;html&gt;</pre><pre>&lt;head&gt;</pre><pre>&lt;meta charset=&quot;utf-8&quot;&gt;</pre><pre>&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;</pre><pre>&lt;title&gt;DEMO XSS&lt;/title&gt;</pre><pre>&lt;/head&gt;</pre><pre>&lt;body&gt;</pre><pre>  &lt;p&gt;Today&#39;s weather information reads: &lt;/br&gt;</pre><pre>    &lt;div id=&quot;temp&quot;&gt;&lt;/div&gt;</pre><pre>  &lt;/p&gt;</pre><pre>  &lt;script type=&quot;text/javascript&quot;&gt;</pre><pre>    let untrusted_ajax_res = document.write(location.replace(&quot;https://www.w3schools.com&quot;));</pre><pre>    document.getElementById(&quot;temp&quot;).innerHTML=untrusted_ajax_res;</pre><pre>  &lt;/script&gt;</pre><pre>&lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><p>The snippet above shows how malicious code from an untrusted API can be injected into the DOM.</p><p>To prevent client xss attacks, developers can install <a href="https://www.npmjs.com/package/xss-filters">secure xss filters</a> which can be used to sanitise inputs gotten from untrusted domains/locations. A snippet for a web use-case can be seen below:</p><pre>&lt;!DOCTYPE html&gt;</pre><pre>...</pre><pre>&lt;script <strong>src</strong>=&quot;dist/xss-filters.min.js&quot;&gt;&lt;/script&gt;</pre><pre>&lt;script&gt;</pre><pre>let untrusted_ajax_res = document.write(location.replace(&quot;https://www.w3schools.com&quot;));</pre><pre>document.getElementById(&quot;temp&quot;).innerHTML=xssFilters.inHTMLData(untrusted_ajax_res);</pre><pre>&lt;/script&gt;</pre><ul><li><em>The xss-filters package must only be applied to UTF-8 encoded documents. HTML5 mode is also required.</em></li></ul><p><strong>Server XSS</strong></p><p>This type of vulnerability occurs when untrusted data is included as user input and sent into the backend to be stored on the database. This data is used to compute a response to be sent back to the user which contains malicious JavaScript code when sent back to the user.</p><p>An example of a server XSS attack on an <a href="https://www.npmjs.com/package/express">express</a> based <a href="https://nodejs.org/">node</a> server can be seen in the snippet below:</p><pre>...</pre><pre>app.get(&#39;/search&#39;, (req, res) =&gt; {</pre><pre>const results = db.search(req.query.product);</pre><pre>if (results.length === 0) {</pre><pre>  return res.send(&#39;&lt;p&gt;No results found for &quot;&#39; + req.query.product + &#39;&quot;&lt;/p&gt;&#39;);</pre><pre>}</pre><pre>...</pre><pre>});</pre><p>The snippet above shows the definition of a products search route for <a href="http://www.domain.com./">http://www.domain.com.</a> An XSS attack can be performed by passing javascript code as a query for the server like so:</p><pre>https://www.domain.com/search?product=&lt;script&gt;alert(XSS:Gat Ya!!)&lt;/script&gt;</pre><p>Since there wouldn’t be any record like</p><pre>&lt;script&gt;alert(XSS:Gat Ya!!)&lt;/script&gt;</pre><p>on the database, the server’s response will be:</p><pre>&lt;p&gt;No results found for &quot;&lt;script&gt;alert(XSS:Gat Ya!!)&lt;/script&gt; &lt;/p&gt;</pre><p>After the server’s response is received and No results found for is displayed, the script is then injected into the DOM to give the output shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/0*QVEuOJ-6j7bwIRrN.png" /></figure><p>Even though this doesn’t look very severe as this script doesn’t pose any serious threat of sort.</p><p>Attackers, however, can save malicious code as “comments” in blogs/social media sites. These so-called comments, when served to other users, is then injected into the DOM and performs the wishes of the attacker.</p><p>To fix this vulnerability we can install the xss-filter package using npm like so:</p><pre>$ npm i xss-filters --save</pre><p>After installing, we can now filter the user’s input in our server’s response like so:</p><pre>...</pre><pre>var xssFilters <strong>=</strong> require(&#39;xss-filters&#39;);</pre><pre>app.get(&#39;/search&#39;, (req, res) =&gt; {</pre><pre>var productParam <strong>=</strong> req.query.product;</pre><pre>const results = db.search(req.query.product);</pre><pre>if (results.length === 0) {</pre><pre>res.send(&#39;&lt;p&gt;No result found for &quot;&#39; + xssFilters.inHTMLData(productParam) + &#39;&quot;&lt;/p&gt;&#39;);</pre><pre>}</pre><pre>});</pre><pre>...</pre><ul><li><em>Using the xss-filters packages comes with certain warnings that can be found on its </em><a href="https://www.npmjs.com/package/xss-filters#api-documentations"><em>installation page</em></a></li></ul><p><strong>SQL Injection</strong></p><p>SQL Injection is a type of attack which makes it possible to execute SQL statements to control a database behind a web application.</p><p>An SQL Injection attack can be seen in the code snippet below:</p><pre>...</pre><pre>const db = require(&#39;./db&#39;);</pre><pre>app.get(&#39;/products&#39;, (req, res) =&gt; {</pre><pre>db.query(&#39;SELECT * FROM products WHERE id = &#39; + req.query.id);</pre><pre>.then((product) =&gt; {</pre><pre>...</pre><pre>res.send(product);</pre><pre>})</pre><pre>});</pre><p>There are two things wrong with the code snippet above:</p><ol><li>The user’s input which is not to be trusted is directly concatenated with the query string.</li><li>The database query is built via string concatenation.</li></ol><p>If the user passes in 10;DROP TABLE Users — as the req.query.id what will happen is that an ID of 10 will be passed, but right after an SQL query of DROP TABLE Users — is executed. This is proof that user inputs should always be treated as unsafe and as such, validated accordingly.</p><ul><li><em>Although handling user input validation is outside the scope article, you can read about </em><a href="https://blog.logrocket.com/how-to-handle-data-validation-in-node-using-validatorjs/"><em>how to handle data validation in node</em></a><em>.</em></li></ul><p>To fix problem number 2, you can secure database query strings by writing prepared SQL statements. An example of a prepared/parameterized query in <a href="https://node-postgres.com/features/queries#parameterized-query">Postgres</a> can be seen below:</p><pre>db.query(&#39;SELECT * FROM products WHERE id = $1&#39;, req.query.id);</pre><p>In the snippet above, the database client will pass in the req.query.id as the first argument.</p><p>Although the MySQL package for node doesn’t support parameterised queries, you can escape users input (i.e remove all special characters ) before it’s concatenated with the query string like so:</p><pre>const query = &#39;SELECT * FROM products WHERE id = &#39; + connection.escape(req.query.id);</pre><h3>Open-source vulnerabilities</h3><p>The JavaScript ecosystem is filled with a lot of open-source packages that make product development easier software engineers. Open-source packages help speed up development time as different packages brought together with some proprietary code can help companies/software engineers build a viable MVP. Though the time to market is shortened, these packages leave a huge deposit of security vulnerabilities which attackers can put in malicious code to steal/compromise users data.</p><p>Package managers (e.g <a href="https://www.npmjs.com/">npm</a>) and security-focused companies have built tools and products that help software engineers scan and fix vulnerabilities in their projects.</p><p>In this section, we will discuss how to stay ahead of vulnerabilities using npm and bolt.</p><p><strong>Using NPM</strong></p><p>Package managers (e.g <a href="https://www.npmjs.com/">npm</a>) helps manage to a certain degree these vulnerabilities from packages installed from npm by providing vulnerability reports and providing a fix for them.</p><p>When we run the $ npm audit command in our project directory, npm provides an audit report for all installed dependencies like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*tm8-nIuqZDCiqh1N.png" /></figure><p>To fix these vulnerabilities, we will run the $ npm audit fix command. This command, unfortunately, can not fix all the vulnerabilities and most cases will require developers to manually install and update these packages.</p><p><strong>Using bolt</strong></p><p><a href="https://bolt.whitesourcesoftware.com/">Bolt</a> is a free <a href="https://github.com/apps/whitesource-bolt-for-github">GitHub</a> app which helps continuously scan repositories (public and private) for vulnerabilities in open-source packages and infers fixes. This is done by scanning repositories multiple (limited to 5 times a day) times and with each vulnerability found, a GitHub issue is opened to that effect. Reference links, vulnerability information and fix suggestions are also provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F8SYBb4SSkWWaHXB.png" /></figure><h3>Conclusion</h3><p>Building software with JavaScript poses a lot of security threat which often overlooked by developers unconsciously because the pressing need to continuously ship out new features.</p><p>Open-source packages make up a large percentage of the JavaScript ecosystem and are used by companies who provide proprietary products to consumers. By using security measures provided by package managers ( such as npm ) and security solutions, companies can stay ahead of the vulnerabilities which arise from using these open-source packages.</p><h3>Further reads</h3><ul><li><a href="https://owasp.org/www-project-top-ten/OWASP_Top_Ten_2017/Top_10-2017_A7-Cross-Site_Scripting_(XSS">https://owasp.org/www-project-top-ten/OWASP_Top_Ten_2017/Top_10-2017_A7-Cross-Site_Scripting_(XSS</a>)</li><li><a href="https://www.netsparker.com/blog/web-security/sql-injection-cheat-sheet/#LineCommentAttacks">https://www.netsparker.com/blog/web-security/sql-injection-cheat-sheet/#LineCommentAttacks</a></li><li><a href="https://www.csoonline.com/article/3157377/open-source-software-security-challenges-persist.html">https://www.csoonline.com/article/3157377/open-source-software-security-challenges-persist.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5391a746c90" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/javascript-vulnerabilities-e5391a746c90">Most common JavaScript vulnerabilities and how to fix them</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>