<?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>DEV Community: Elvis O.</title>
    <description>The latest articles on DEV Community by Elvis O. (@bigveezus).</description>
    <link>https://dev.to/bigveezus</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%2F1141573%2F28396ddb-b999-4493-b8a8-b10b0fb62bba.jpeg</url>
      <title>DEV Community: Elvis O.</title>
      <link>https://dev.to/bigveezus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bigveezus"/>
    <language>en</language>
    <item>
      <title>Difference between TLS, SSL and HTTPS</title>
      <dc:creator>Elvis O.</dc:creator>
      <pubDate>Fri, 15 Sep 2023 17:19:24 +0000</pubDate>
      <link>https://dev.to/bigveezus/difference-between-tls-ssl-and-https-2pkm</link>
      <guid>https://dev.to/bigveezus/difference-between-tls-ssl-and-https-2pkm</guid>
      <description>&lt;p&gt;&lt;strong&gt;Their differences, best use cases and how they protect our websites&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What is HTTPS&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We may be familiar with HTTP (Hypertext Transfer Protocol) as a request that browsers or internet devices use to communicate with data on the internet and load webpages.&lt;/p&gt;

&lt;p&gt;HTTPS (Hypertext Transfer Protocol Secure) is a more secure way of communication between internet devices and data. Any website that handles sensitive data, such as login credentials and other personal information, should use &lt;strong&gt;HTTPS&lt;/strong&gt;. Websites that are not secure are marked as 'Not Secure,' alerting users to exercise caution when sending information to such websites.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2k6oQuam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1rpdphfx2g4dcami78t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2k6oQuam--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1rpdphfx2g4dcami78t.png" alt="Image description" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This communication is secured by digital certificates, which are typically obtained from security service providers known as Transport Layer Security (TLS), formerly known as Secure Sockets Layer (SSL).&lt;/p&gt;

&lt;p&gt;TLS employs a cryptographic method called asymmetric encryption, which utilizes two keys: the public key and the private key.&lt;/p&gt;

&lt;p&gt;The private key is owned by the website owner and resides on the web server. It is used to decrypt information that has been encrypted with the public key. The public key is visible to all individuals interacting with the website legally, and only the private key can decrypt information encrypted by the public key. Both keys work in tandem to maintain the security of information on the website.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Public key encrypts, private key decrypts!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;How HTTPS works&lt;/strong&gt;&lt;br&gt;
Under the hood, when a user opens a webpage, the webpage will send its SSL certificate, which contains the public key necessary to initiate a secure session. The two computers, the client and the server, then undergo a process called an SSL/TLS handshake, a series of back-and-forth communications used to establish a secure connection.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Specify the version of TLS (TLS 1.0, 1.2, 1.3, etc.) they will use.&lt;/li&gt;
&lt;li&gt;Decide on the cipher suites to be used.&lt;/li&gt;
&lt;li&gt;Authenticate the server's identity using the server's public key and the SSL certificate authority's digital signature.&lt;/li&gt;
&lt;li&gt;Generate session keys to enable symmetric encryption after the handshake is completed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Importance of HTTPS&lt;/strong&gt;&lt;br&gt;
Since data transferred through the internet is basically in text i.e. &lt;em&gt;Hyper-text protocol&lt;/em&gt;, HTTPS prevents websites from having their information broadcast in a way that’s easily viewed by anyone snooping on the network.&lt;/p&gt;

&lt;p&gt;HTTPS also prevents ISP (Internet service providers) from adding or displaying unnecessary content (Ads) to the users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to get TLS/SSL Certificates?&lt;/strong&gt;&lt;br&gt;
There are handful of popular SSL certificate vendors like &lt;a href="https://www.hostinger.com/free-ssl-certificate"&gt;Hostinger&lt;/a&gt;, &lt;a href="https://www.googleadservices.com/pagead/aclk?sa=L&amp;amp;ai=DChcSEwiK3-zKj62BAxVa4u0KHaBYAgcYABAAGgJkZw&amp;amp;ae=2&amp;amp;gclid=CjwKCAjwgZCoBhBnEiwAz35Rwno6aQNCTNjRlSwTCbtsOSAFbMdMUOZYGGbnL9nl9gOEbyNI6cHO5xoCIfEQAvD_BwE&amp;amp;ohost=www.google.com&amp;amp;cid=CAESa-D2lGCaxkXE1OvBztPLvegixuG4IPXNf8s4BUSeEySiOoB0tv56lEYU01kJ1jJejK2V_ZPnMMB362VVXiyvXlHgA-EBhc0skkwpSvHw_zkpAFcpf8d1_c4WH8kKocHgvAtnX0KGM8VOw1QR&amp;amp;sig=AOD64_1bpaGRImjJ6jisNow3YU_XFRnyVA&amp;amp;q&amp;amp;adurl&amp;amp;ved=2ahUKEwiw9-bKj62BAxU1YEEAHecsAIMQ0Qx6BAgNEAE"&gt;NameCheap&lt;/a&gt;, &lt;a href="https://www.googleadservices.com/pagead/aclk?sa=L&amp;amp;ai=DChcSEwi83KPgj62BAxU3iVAGHY1zCRwYABACGgJkZw&amp;amp;ae=2&amp;amp;gclid=CjwKCAjwgZCoBhBnEiwAz35Rwr_YxM6hBWJN-AvrL_bZo-MxPhXrXMEi2t8fE8y5ixff55sU_py1vhoC91EQAvD_BwE&amp;amp;ohost=www.google.com&amp;amp;cid=CAESa-D2mENlhFMzWY2KtQiVjHDhyw5O62QXX3nTAg4eI1DOcIZD1QNHoSLhLIaQm_-P18l4KB30tNFOcXffTwLUr0vzXW9aWr-oxB835j3Axm8ReF32GgIvtPdumrQzzDGhh3O8VkqRoMlii4HC&amp;amp;sig=AOD64_2ScIw23VLBTt59H5g7NCqLyWw5qw&amp;amp;q&amp;amp;adurl&amp;amp;ved=2ahUKEwiO5Z7gj62BAxXKWEEAHYA_BRsQ0Qx6BAgIEAE"&gt;Domain&lt;/a&gt; to name a few and they offer affordable prices. &lt;/p&gt;

&lt;p&gt;Hopefully you learned about SSL certificates and how important they are for your websites. To learn more about cryptography or asymmetric encryption, pls check out my &lt;a href="https://github.com/BigVeezus/cryptography-101"&gt;GitHub repo&lt;/a&gt; and leave a star. Thank you &lt;/p&gt;

</description>
      <category>backenddevelopment</category>
      <category>datasecurity</category>
      <category>tls</category>
    </item>
    <item>
      <title>SQL &amp; No-SQL injections.</title>
      <dc:creator>Elvis O.</dc:creator>
      <pubDate>Sun, 20 Aug 2023 05:44:46 +0000</pubDate>
      <link>https://dev.to/bigveezus/sql-no-sql-injections-52ad</link>
      <guid>https://dev.to/bigveezus/sql-no-sql-injections-52ad</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Whats an SQL Injection?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An SQL Injection attack involves the insertion or injection of a SQL query through input data from the client to a backend server. A successful SQL injection exploit can enable the reading of sensitive data from the database, altering database data (Insert/Update/Delete), executing administrative operations on the database (such as shutting down the DBMS), retrieving the contents of a specific file within the DBMS file system, and, in some cases, issuing commands to the operating system. SQL injection attacks are a type of injection attack, where SQL commands are inserted into data-plane inputs to manipulate the execution of predefined SQL commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---4F9Ee4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1ipqkvxr7b8md7behjz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---4F9Ee4o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1ipqkvxr7b8md7behjz.png" alt="Image description" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Difference between SQL vs No-SQL Attacks&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SQL is a standardized language employed to access and manipulate databases, creating customizable data views for individual users. SQL queries execute commands like data retrieval, updates, and record removal, utilizing various SQL components for these functions. SQL attacks refer to SQL injections targeting databases associated with SQL, such as MySQL, PostgreSQL, Oracle, MS SQL, MariaDB, and others.&lt;/p&gt;

&lt;p&gt;NoSQL databases, on the other hand, encompass a variety of database systems like MongoDB, DynamoDB etc that store and retrieve data without using a traditional SQL-based relational model. NoSQL attacks are specifically directed at these types of databases, exploiting vulnerabilities within their unique structures and characteristics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Type of SQL attacks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Boolean-based SQLI :&lt;/strong&gt; This type of SQL attack involves sending a SQL query to the database that prompts the application to return a result. Attackers can exploit vulnerabilities in the application’s response to infer information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time-based SQLI :&lt;/strong&gt; In this scenario, the attacker sends a SQL query to the database, causing it to introduce a delay (for a specific period in seconds) before responding. By observing the delay in the response, the attacker can deduce certain information from the timing.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NoSQL Injection is a security vulnerability that affects web applications utilizing a NoSQL database. NoSQL (Not Only SQL) databases are characterized by their use of flexible data formats and lack of support for Structured Query Language (SQL). These databases typically manage data as key-value pairs, documents, or data graphs. Examples of such databases include MongoDB, OrientDB, DynamoDB (AWS), Redis, and others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Normal Backend Interaction — SQL Databases&lt;br&gt;
(How SQL injections work)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When prompted by an application, a user enters:&lt;/p&gt;

&lt;p&gt;username: &lt;em&gt;JohnDoe&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;password: &lt;em&gt;password&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The application processes the input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;username = getRequestString("username")
password = getRequestString("userpassword")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sql = 'SELECT * FROM Users WHERE name ="' + username + '" AND pass = "' + password + '"'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It translates to the SQL Query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users WHERE name = "JohnDoe" AND pass = "password"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But in the case of SQL Attacks...&lt;br&gt;
An attacker can:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;1. Retrieving an Entire Table&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A malicious individual could gain access to usernames and passwords within a database.&lt;/p&gt;

&lt;p&gt;A user enters:&lt;/p&gt;

&lt;p&gt;username: " OR ""="&lt;/p&gt;

&lt;p&gt;password: " OR ""="&lt;/p&gt;

&lt;p&gt;Query becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users WHERE name = "" OR ""="" AND pass = "" OR ""=""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This SQL statement will retrieve all rows from the users table, as the condition OR ""="" always evaluates to true.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Delete a Table Using a Batched SQL Statements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A malicious individual could delete an entire table from a database.&lt;/p&gt;

&lt;p&gt;A user enters:&lt;/p&gt;

&lt;p&gt;username: &lt;em&gt;nuclearfusion; DROP TABLE Suppliers&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;password: &lt;em&gt;password&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Query becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM users WHERE username = "nuclearfusion"; DROP TABLE stockPortfolio;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Preventing SQL Injection Attacks
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Several common methods can help prevent SQL injection attacks:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Avoid allowing multiple statements. For instance:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const connection = await mysql.createConnection({
  uri: process.env.DATABASE_URL,
  multipleStatements: false
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Employ prepared statements or placeholders instead of variable interpolation. This involves using a &lt;em&gt;question mark “?”&lt;/em&gt; in place of the actual value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate user input rigorously.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement allow-lists for user input.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Choose databases with restricted user access.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Utilize an ORM (Object Relational Mapping) system, such as Sequelize, Knex.js, Hibernate for Spring JPA frameworks, and others. ORMs provide a way to align programming code with database structures, making it easier to interact with databases while also reducing the likelihood of vulnerabilities like injection attacks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Preventing No-SQL Injection Attacks:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Avoid Directly Passing Request Objects to ODM or ORM Functions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One of the worst practices is passing something like req.body or req.query directly to our ODM/ORM functions like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = await collection.findOne(req.body); // Bad Practice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the very least, we should use specific fields such as req.body.id&lt;/p&gt;

&lt;p&gt;This helps mitigate the risk of NoSQL injection attacks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = await collection.findOne({ userId: req.body.id });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use input validations like &lt;em&gt;Zod&lt;/em&gt;, &lt;em&gt;Yup&lt;/em&gt; or &lt;em&gt;express validator&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sanitize User Inputs and Filters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Utilize the latest versions of technologies and database drivers.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;To learn more about SQL and No-SQL injections, how to detect them and prevent them, click the &lt;a href="https://medium.com/@elvis.osujic/good-practices-to-prevent-security-vulnerabilities-on-your-backend-servers-pt-1-8bcb6c5122f1"&gt;original link&lt;/a&gt; published on medium by me.&lt;br&gt;
and check out the GitHub repo for Injections &lt;a href="https://github.com/BigVeezus/SQL-NoSQL-Injection"&gt;here&lt;/a&gt;&lt;br&gt;
Thank you.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>nosql</category>
      <category>cybersecurity</category>
      <category>sqlinjections</category>
    </item>
  </channel>
</rss>
