<?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: Asif Uddin</title>
    <description>The latest articles on DEV Community by Asif Uddin (@asif0228).</description>
    <link>https://dev.to/asif0228</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%2F497905%2F66bc9faf-8260-4f1e-a620-140d0a26bf68.jpeg</url>
      <title>DEV Community: Asif Uddin</title>
      <link>https://dev.to/asif0228</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/asif0228"/>
    <language>en</language>
    <item>
      <title>Text over Background Image with Viewport Width (vw)</title>
      <dc:creator>Asif Uddin</dc:creator>
      <pubDate>Mon, 12 Apr 2021 16:13:57 +0000</pubDate>
      <link>https://dev.to/asif0228/text-over-background-image-with-viewport-width-vw-4f4k</link>
      <guid>https://dev.to/asif0228/text-over-background-image-with-viewport-width-vw-4f4k</guid>
      <description>&lt;h1&gt;
  
  
  Plan
&lt;/h1&gt;

&lt;p&gt;Many time we show texts over images. We will define three background images and then write text above (top, middle and bottom) it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Basic Structure
&lt;/h1&gt;

&lt;p&gt;Our site will contain a table with 3 column. Each will contain a background image with text above it.&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;style type="text/css"&amp;gt;
    table{
        width: 100%;
    }
    tr{
        width: 100%;
        vertical-align: top;
    }
&amp;lt;/style&amp;gt;
&amp;lt;table&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;
            &amp;lt;p&amp;gt;Road to Heaven&amp;lt;/p&amp;gt;
        &amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;
            &amp;lt;p&amp;gt;Road to Heaven&amp;lt;/p&amp;gt;
        &amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;
            &amp;lt;p&amp;gt;Road to Heaven&amp;lt;/p&amp;gt;
        &amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Background image
&lt;/h1&gt;

&lt;p&gt;Let's add the background image first.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;td{
        background-image: url("https://images.unsplash.com/photo-1526512340740-9217d0159da9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&amp;amp;ixlib=rb-1.2.1&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=1545&amp;amp;q=80");
        background-repeat: no-repeat;
        background-size: 100%;
        text-align: center;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Text above image
&lt;/h1&gt;

&lt;p&gt;Also let's design the text a bit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p{
        font-size: 2vw;
        padding: 20px;
        background-color: #000000b5;
        border: 1px solid #ffffff;
        border-radius: 15px;
        color: white;
        text-shadow: 0px 1px #eff1f4;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Position the text
&lt;/h1&gt;

&lt;p&gt;Now we will position 1st text on top, 2nd text in middle and 3rd text on bottom.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;td:nth-child(1) p{
      margin-top: 0vw;
      margin-bottom: 40vw;
}
td:nth-child(2) p{
      margin-top: 20vw;
      margin-bottom: 20vw;
}
td:nth-child(3) p{
      margin-top: 40vw;
      margin-bottom: 0vw;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Result
&lt;/h1&gt;

&lt;p&gt;Let's see the result in different screen widths.&lt;/p&gt;

&lt;h2&gt;
  
  
  1200px
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2F2xbhjzzj2vdqyvkyt76k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F2xbhjzzj2vdqyvkyt76k.png" alt="1200px"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  800px
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fp67ql45j3rq350htpcz1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fp67ql45j3rq350htpcz1.png" alt="800px"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  400px
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fbi2huuoxufgkw0sa9xrh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fbi2huuoxufgkw0sa9xrh.png" alt="400px"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Full Code
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;style type="text/css"&amp;gt;
    table{
        width: 100%;
    }
    tr{
        width: 100%;
        vertical-align: top;
    }
    td{
        background-image: url("https://images.unsplash.com/photo-1526512340740-9217d0159da9?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&amp;amp;ixlib=rb-1.2.1&amp;amp;auto=format&amp;amp;fit=crop&amp;amp;w=1545&amp;amp;q=80");
        background-repeat: no-repeat;
        background-size: 100%;
        text-align: center;
    }
    p{
        font-size: 2vw;
        padding: 20px;
        background-color: #000000b5;
        border: 1px solid #ffffff;
        border-radius: 15px;
        color: white;
        text-shadow: 0px 1px #eff1f4;
    }
    td:nth-child(1) p{
      margin-top: 0vw;
      margin-bottom: 40vw;
    }
    td:nth-child(2) p{
      margin-top: 20vw;
      margin-bottom: 20vw;
    }
    td:nth-child(3) p{
      margin-top: 40vw;
      margin-bottom: 0vw;
    }
&amp;lt;/style&amp;gt;
&amp;lt;table&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;
            &amp;lt;p&amp;gt;Road to Heaven&amp;lt;/p&amp;gt;
        &amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;
            &amp;lt;p&amp;gt;Road to Heaven&amp;lt;/p&amp;gt;
        &amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;
            &amp;lt;p&amp;gt;Road to Heaven&amp;lt;/p&amp;gt;
        &amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>css</category>
      <category>html</category>
      <category>website</category>
      <category>design</category>
    </item>
    <item>
      <title>OWASP Secure Coding Practices</title>
      <dc:creator>Asif Uddin</dc:creator>
      <pubDate>Sat, 20 Feb 2021 13:48:16 +0000</pubDate>
      <link>https://dev.to/asif0228/owasp-secure-coding-practices-494l</link>
      <guid>https://dev.to/asif0228/owasp-secure-coding-practices-494l</guid>
      <description>&lt;h1&gt;
  
  
  Before We Start
&lt;/h1&gt;

&lt;p&gt;This is just a few points cropped from &lt;strong&gt;&lt;em&gt;OWASP Secure Coding Practices&lt;/em&gt;&lt;/strong&gt; to refresh everyone's mind about Secure Coding Practices. Reading the main resource is advised and more appreciated. Please find the main resource in this &lt;a href="https://owasp.org/www-project-secure-coding-practices-quick-reference-guide/migrated_content"&gt;Link&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Secure Coding Practices
&lt;/h1&gt;

&lt;p&gt;These are not something new. These are the &lt;strong&gt;&lt;em&gt;industry best practices&lt;/em&gt;&lt;/strong&gt; that many of you already know. But it's better to refresh this knowledge once in a while. So Without any further talking let's go to the point.&lt;/p&gt;

&lt;h3&gt;
  
  
  Input Validation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Validation must be included both in &lt;strong&gt;&lt;em&gt;server and client side&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Data can be classified in trusted and un-trusted section.&lt;/li&gt;
&lt;li&gt;Proper character sets &lt;strong&gt;&lt;em&gt;(e.g. UTF-8)&lt;/em&gt;&lt;/strong&gt; should be specified for all input.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;UTF-8 encoding/decoding&lt;/em&gt;&lt;/strong&gt; can be used for security from malicious character.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Hazardous characters&lt;/em&gt;&lt;/strong&gt; should not be allowed (e.g. &amp;lt;&amp;gt; " ' % ( ) &amp;amp; + \ \' \"*#;--).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Output Encoding
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Translate &lt;strong&gt;&lt;em&gt;special characters&lt;/em&gt;&lt;/strong&gt; into non-dangerous character for interpreter / server.&lt;/li&gt;
&lt;li&gt;All characters should be encoded unless they are known to be safe for the intended interpreter.&lt;/li&gt;
&lt;li&gt;All data going for &lt;strong&gt;SQL, XML, and LDAP&lt;/strong&gt;* should be sanitized.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Authentication and Password Management
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Passwords should be saved as &lt;strong&gt;&lt;em&gt;one-way salted hash&lt;/em&gt;&lt;/strong&gt; (MD5 is easy to break).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Password hashing&lt;/em&gt;&lt;/strong&gt; should be done on server.&lt;/li&gt;
&lt;li&gt;Instead showing "Invalid username" or "Invalid password" just use "Invalid username and/or password“.&lt;/li&gt;
&lt;li&gt;Authentication for connections to &lt;strong&gt;&lt;em&gt;external systems&lt;/em&gt;&lt;/strong&gt; should be implemented.&lt;/li&gt;
&lt;li&gt;To transmit authentication credentials use &lt;strong&gt;&lt;em&gt;HTTP/HTTPS POST request&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Changing &lt;strong&gt;&lt;em&gt;temporary passwords&lt;/em&gt;&lt;/strong&gt; &amp;amp; &lt;strong&gt;&lt;em&gt;Strong password policy&lt;/em&gt;&lt;/strong&gt; should be enforced.&lt;/li&gt;
&lt;li&gt;Account should be temporarily disabled after a number of &lt;strong&gt;&lt;em&gt;invalid login attempt&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Temporary information (e.g. OTP)&lt;/em&gt;&lt;/strong&gt; should have expiration time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Multi-Factor Authentication&lt;/em&gt;&lt;/strong&gt; can be used.&lt;/li&gt;
&lt;li&gt;Third party codes for authentication must be inspected carefully.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Session Management
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Sessions should be created on server with &lt;strong&gt;&lt;em&gt;well vetted algorithms&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Logout should &lt;strong&gt;&lt;em&gt;terminate session&lt;/em&gt;&lt;/strong&gt; and generate new on any re-authentication.&lt;/li&gt;
&lt;li&gt;Concurrent logins with the same user ID should be discouraged.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Session identifiers&lt;/em&gt;&lt;/strong&gt; should not be exposed and easy guessable.&lt;/li&gt;
&lt;li&gt;It is recommended to consistently utilize HTTPS rather than switching between HTTP.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Cross-Site Request Forgery (CSRF)&lt;/em&gt;&lt;/strong&gt; should be prevented.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Access Control
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Authorization decisions should be made from server side.&lt;/li&gt;
&lt;li&gt;Access to files or other resources should be authorized.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;User role&lt;/em&gt;&lt;/strong&gt; should be implemented in terms of access.&lt;/li&gt;
&lt;li&gt;Number of &lt;strong&gt;&lt;em&gt;transactions&lt;/em&gt;&lt;/strong&gt; a single user or device can perform in a given period of time should be limited.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Auditing and disabling&lt;/em&gt;&lt;/strong&gt; of unused accounts should be implemented.&lt;/li&gt;
&lt;li&gt;Create an &lt;strong&gt;&lt;em&gt;Access Control Policy&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cryptographic Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;All &lt;strong&gt;&lt;em&gt;cryptographic functions&lt;/em&gt;&lt;/strong&gt; should be implemented on Server.&lt;/li&gt;
&lt;li&gt;A policy to manage &lt;strong&gt;&lt;em&gt;cryptographic keys&lt;/em&gt;&lt;/strong&gt; should be established.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Error Handling and Logging
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Sensitive information like &lt;strong&gt;&lt;em&gt;stack trace&lt;/em&gt;&lt;/strong&gt; should not be disclosed in error responses.&lt;/li&gt;
&lt;li&gt;Try to handle most of the error on client side and &lt;strong&gt;&lt;em&gt;custom error pages&lt;/em&gt;&lt;/strong&gt; should be constructed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Allocated memory&lt;/em&gt;&lt;/strong&gt; should be securely released when error conditions occur.&lt;/li&gt;
&lt;li&gt;Logs should contain &lt;strong&gt;&lt;em&gt;log event data&lt;/em&gt;&lt;/strong&gt; like validation failures, authentication attempts, apparent tampering events, exceptions, administrative functions failures.&lt;/li&gt;
&lt;li&gt;Sensitive informatio should not be logged and log access should be restricted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Log analysis&lt;/em&gt;&lt;/strong&gt; should be done and non-printable characters should be encoded in log entries.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Data Protection
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Users should get only required data that is needed to perform their tasks.&lt;/li&gt;
&lt;li&gt;Sensitive data should be identified to establish a policy to control it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Cached or Temporary&lt;/em&gt;&lt;/strong&gt; copies of sensitive data stored on the server should be protected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Highly sensitive information&lt;/em&gt;&lt;/strong&gt; should be encrypted.&lt;/li&gt;
&lt;li&gt;Server-side source-code should be protected from being downloaded by a user.&lt;/li&gt;
&lt;li&gt;Unnecessary application and system documentation should be removed from &lt;strong&gt;&lt;em&gt;production server&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Sensitive information should not be in HTTP GET request parameters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Communication Security
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;SSL&lt;/em&gt;&lt;/strong&gt; should be enabled with non expired, proper domain certificate.&lt;/li&gt;
&lt;li&gt;External systems should also have SSL.&lt;/li&gt;
&lt;li&gt;At minimum operations like &lt;strong&gt;&lt;em&gt;Login, Registration, Access to personal data , Change of password &amp;amp; Password reminder function&lt;/em&gt;&lt;/strong&gt; should be encrypted.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  System Configuration
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Servers, frameworks and system&lt;/em&gt;&lt;/strong&gt; should be in latest stable version with security patch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Directory &amp;amp; directory structure listings&lt;/em&gt;&lt;/strong&gt; should be turned off and unnecessary functionality,
files test code or any functionality should not be in production.&lt;/li&gt;
&lt;li&gt;Info related to &lt;strong&gt;&lt;em&gt;OS, server &amp;amp; app framework&lt;/em&gt;&lt;/strong&gt; should be removed from HTTP response headers.&lt;/li&gt;
&lt;li&gt;An asset management system should be implemented (like Git).&lt;/li&gt;
&lt;li&gt;Isolate development from production.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Database Security
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Databases should be hardened in accordance with &lt;strong&gt;&lt;em&gt;CIS benchmarks&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Variables should be strongly verified before sending into queries.&lt;/li&gt;
&lt;li&gt;Database should be accessed using secured user with &lt;strong&gt;&lt;em&gt;lowest privileged&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Connection strings should not be hard coded and should be encrypted.&lt;/li&gt;
&lt;li&gt;DB connection should be closed as soon as possible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Default passwords&lt;/em&gt;&lt;/strong&gt; should be changed.&lt;/li&gt;
&lt;li&gt;Any accounts that are not required should be disabled.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  File Management
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;User supplied data should not be passed to &lt;strong&gt;&lt;em&gt;dynamic execution function (ex - Eval)&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Authentication is required before providing files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Execution privileges&lt;/em&gt;&lt;/strong&gt; should be turned off on file upload directories.&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;&lt;em&gt;Secure Upload&lt;/em&gt;&lt;/strong&gt; (check file size, change file name, check extension).&lt;/li&gt;
&lt;li&gt;Directory or file paths should not be passed, use index values mapped to pre-defined list.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Memory Management
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Double check that &lt;strong&gt;&lt;em&gt;buffer size&lt;/em&gt;&lt;/strong&gt; and do not write past the allocated space.&lt;/li&gt;
&lt;li&gt;All input strings should be truncated to a reasonable length.&lt;/li&gt;
&lt;li&gt;Specifically close resources, don’t rely on &lt;strong&gt;&lt;em&gt;garbage collection&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Do not use known &lt;strong&gt;&lt;em&gt;vulnerable functions&lt;/em&gt;&lt;/strong&gt; (e.g., printf, strcat, strcpy etc.).&lt;/li&gt;
&lt;li&gt;Allocated memory should be securely freed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  General Coding Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Tested and approved code should be prioritized over new code.&lt;/li&gt;
&lt;li&gt;Verify Integrity of &lt;strong&gt;&lt;em&gt;interpreted code, libraries, executables, and configuration files&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Use variables &amp;amp; resources carefully and initialize during declaration or before usage.&lt;/li&gt;
&lt;li&gt;Calculation errors should be avoided by understanding how the language handles numbers.&lt;/li&gt;
&lt;li&gt;User supplied data should not be passed to &lt;strong&gt;&lt;em&gt;dynamic execution function (ex - Eval)&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Secondary applications, third party codes and libraries safety should be reviewed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Encrypted and Secured channels&lt;/em&gt;&lt;/strong&gt; should be used to transfer the code from the host server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;Frameworks&lt;/em&gt;&lt;/strong&gt; should be updated to latest stable version.&lt;/li&gt;
&lt;li&gt;Developers should be trained on secure coding practices periodically.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kwTKIZFE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/llw7c8fk7qv4m6x4udte.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kwTKIZFE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/llw7c8fk7qv4m6x4udte.jpg" alt="Alt Text" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>owasp</category>
      <category>goodpractices</category>
      <category>programming</category>
    </item>
    <item>
      <title>PHP: Few Good Practices</title>
      <dc:creator>Asif Uddin</dc:creator>
      <pubDate>Fri, 30 Oct 2020 16:24:23 +0000</pubDate>
      <link>https://dev.to/asif0228/php-few-good-practices-1000</link>
      <guid>https://dev.to/asif0228/php-few-good-practices-1000</guid>
      <description>&lt;h1&gt;
  
  
  What is PHP ?
&lt;/h1&gt;

&lt;p&gt;The full meaning of &lt;strong&gt;PHP&lt;/strong&gt; is &lt;strong&gt;PHP Hypertext Preprocessor&lt;/strong&gt;. It is a Server side scripting language used for web development. Means it processes the client request in the server and returns response. It is free to download and use. There are many server side languages like &lt;strong&gt;ASP.NET&lt;/strong&gt;, &lt;strong&gt;JSP&lt;/strong&gt;, &lt;strong&gt;Python&lt;/strong&gt; etc.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fle6ebm4ektifcz370xvd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fle6ebm4ektifcz370xvd.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  History
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;PHP&lt;/strong&gt; we know was developed in 1994 by &lt;strong&gt;Rasmus Lerdorf&lt;/strong&gt;. He built this language to keep the trace of visitors came in his site. He named it &lt;strong&gt;Personal Home Page Tool&lt;/strong&gt; which in short is &lt;strong&gt;PHP Tool&lt;/strong&gt;. Afterwards Ramos enriched this programming language and in 1995 He made it &lt;strong&gt;Open Source&lt;/strong&gt;. This brought vast fame and enrichment to &lt;strong&gt;PHP&lt;/strong&gt;. Till the date of writing this article, the latest version of &lt;strong&gt;PHP&lt;/strong&gt; is 7 whereas  &lt;strong&gt;PHP 8&lt;/strong&gt; is in testing phase.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6am73ltezmxqid6xrt9c.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6am73ltezmxqid6xrt9c.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  How does it work
&lt;/h1&gt;

&lt;p&gt;In general &lt;strong&gt;PHP&lt;/strong&gt; resides with &lt;strong&gt;HTML&lt;/strong&gt;, &lt;strong&gt;CSS&lt;/strong&gt;, &lt;strong&gt;JavaScript&lt;/strong&gt; etc. The files containing &lt;strong&gt;PHP&lt;/strong&gt; codes are given the extension &lt;strong&gt;".php"&lt;/strong&gt; for example &lt;strong&gt;"index.php"&lt;/strong&gt;, &lt;strong&gt;"abc.php"&lt;/strong&gt; etc. &lt;strong&gt;PHP&lt;/strong&gt; codes are written in between &lt;strong&gt;"&amp;lt;?php"&lt;/strong&gt; and &lt;strong&gt;"?&amp;gt;"&lt;/strong&gt;. All the codes inside that are processed by &lt;strong&gt;PHP Interpreter&lt;/strong&gt; and returned a result to the client.  &lt;/p&gt;

&lt;p&gt;Let's see an image of how &lt;strong&gt;PHP&lt;/strong&gt; works:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffs41bshfp680rxfuktc8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffs41bshfp680rxfuktc8.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Popularity
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;PHP&lt;/strong&gt; is a popular web development language. Even worlds biggest social networking site &lt;strong&gt;Facebook&lt;/strong&gt; uses PHP. Sites/Tools like &lt;strong&gt;Wordpress&lt;/strong&gt;, &lt;strong&gt;Blogging&lt;/strong&gt; etc. are based on PHP. It can be installed on any type of server available. It also gained fame because of being &lt;strong&gt;Free&lt;/strong&gt;, &lt;strong&gt;Open Source&lt;/strong&gt; and &lt;strong&gt;Easy to Learn&lt;/strong&gt;. Many renowned &lt;strong&gt;Framework&lt;/strong&gt;, &lt;strong&gt;CMS: Content Management System&lt;/strong&gt; &amp;amp; &lt;strong&gt;E-Commerce&lt;/strong&gt; sites are developed in PHP. Among them &lt;strong&gt;Codeigniter&lt;/strong&gt;, &lt;strong&gt;CakePhp&lt;/strong&gt;, &lt;strong&gt;Wordpress&lt;/strong&gt; etc. are worth mentioning.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdt5o0rorc2soyx8gb4wl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdt5o0rorc2soyx8gb4wl.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Security
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt; is a buzz word now a days. The security in PHP depends on some factors. As PHP is open source, so the &lt;strong&gt;bugs&lt;/strong&gt; are addressed and resolve frequently but majority of the security depends on &lt;strong&gt;server configuration&lt;/strong&gt;. Most of the security issues are found in &lt;strong&gt;server configuration&lt;/strong&gt;. The security also depends on how the website was developed. Like, a lot of websites has user login facility where users can login and do different things. Defining user roles will limit user activities (What they can do and can not do).&lt;/p&gt;
&lt;h1&gt;
  
  
  Good Practices
&lt;/h1&gt;

&lt;p&gt;Few &lt;strong&gt;good practices&lt;/strong&gt; can ensure the security of a PHP site. Right &lt;strong&gt;configuration&lt;/strong&gt; can maintain a good security layer. Let's see some good practices that may help you securing your PHP site. &lt;/p&gt;

&lt;p&gt;Note that examples are more suited for &lt;strong&gt;Linux&lt;/strong&gt;, &lt;strong&gt;Redhat&lt;/strong&gt; etc. And every-time after changing configuration &lt;strong&gt;httpd&lt;/strong&gt;, &lt;strong&gt;Nginx&lt;/strong&gt; etc. will be needed to restart for enforcing changes. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Always use the &lt;strong&gt;latest Stable Version&lt;/strong&gt; of PHP. Older versions can have &lt;strong&gt;bugs&lt;/strong&gt; or &lt;strong&gt;exploits&lt;/strong&gt;. To see the version of PHP we can write the command in cmd &lt;strong&gt;"php -v"&lt;/strong&gt;. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvge9wvbw0j2dnb2p1ry1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvge9wvbw0j2dnb2p1ry1.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It is very important to determine the &lt;strong&gt;Document Root&lt;/strong&gt; of a site. This is the location where &lt;strong&gt;source code&lt;/strong&gt; of all the web sites are kept. Generally in &lt;strong&gt;Linux&lt;/strong&gt;, &lt;strong&gt;Redhat&lt;/strong&gt; etc. Operating system default document root is &lt;strong&gt;"/var/www/html"&lt;/strong&gt;. Other than web site source code nothing else should be kept in this location. This configuration can be found in &lt;strong&gt;"httpd.conf"&lt;/strong&gt; file.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff4kp7c176ikw8fn7xmb5.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff4kp7c176ikw8fn7xmb5.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Websites are vulnerable to different types of attacks. Few of them mentioned below:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;3.1 &lt;strong&gt;XSS: Cross Site Scripting&lt;/strong&gt; is an attack in which attacker inserts script inside information requested from a user. Like while entering the full name of a user, attacker can embed   &lt;strong&gt;JS: Java Script&lt;/strong&gt; inside. As a result when the full name of that user gets printed then the script get executed in the client/user side because &lt;strong&gt;JS&lt;/strong&gt; is client side language. Using this attacker can divert user towards a &lt;strong&gt;malicious site&lt;/strong&gt;, can try to &lt;strong&gt;theft data&lt;/strong&gt; etc. To get rid of this kind of attack, any data getting from users are needed to be &lt;strong&gt;verified&lt;/strong&gt; and &lt;strong&gt;filtered&lt;/strong&gt; properly. Like a input field destined to take number should be validated on both &lt;strong&gt;client side&lt;/strong&gt; and &lt;strong&gt;server side&lt;/strong&gt; that the input given by user is a number.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7zh5zemcysonz851s17f.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7zh5zemcysonz851s17f.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.2 &lt;strong&gt;SQL Injection&lt;/strong&gt; is a well known threat to websites. Due to this attack the information stored in &lt;strong&gt;Database&lt;/strong&gt; can be hampered. It is also like &lt;strong&gt;XSS&lt;/strong&gt; but in this case &lt;strong&gt;SQL Query&lt;/strong&gt; is embedded. Think about a site where users search for people by typing phone number like below:&lt;br&gt;
 &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0xlm8ofncoumrygy762x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0xlm8ofncoumrygy762x.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
When users types phone number and clicks search button then in the server below query is executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name,phone FROM people WHERE phone=01****;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But in order to inject &lt;strong&gt;SQL&lt;/strong&gt; we can enter "01**** OR 1=1". As a result the &lt;strong&gt;SQL Query&lt;/strong&gt; will look like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name,phone FROM people WHERE phone=01**** OR 1=1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which will in return reveal all the user and their phone numbers. It is a &lt;strong&gt;security&lt;/strong&gt; threat. Moreover &lt;strong&gt;SQL Injection&lt;/strong&gt; can be used to &lt;strong&gt;destroy database&lt;/strong&gt;, &lt;strong&gt;remove information&lt;/strong&gt;, reveal &lt;strong&gt;database structure&lt;/strong&gt; etc.&lt;/p&gt;

&lt;p&gt;3.3 Allowing users to &lt;strong&gt;upload file&lt;/strong&gt; can also be a medium of attack. If attacker gets to upload any type of file then the attacker may upload &lt;strong&gt;malicious file&lt;/strong&gt;. To get rid of this kind of attack site owners can disable file upload from &lt;strong&gt;PHP configuration&lt;/strong&gt;. OR during file upload user should only be allowed to upload defined types of &lt;strong&gt;files (pdf, jpeg, png etc.)&lt;/strong&gt; and within defined &lt;strong&gt;size (5mb, 3mb etc.)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;3.4 If &lt;strong&gt;Remote Execution&lt;/strong&gt; is enabled then attacker will be able to run &lt;strong&gt;PHP Script&lt;/strong&gt; in the server from a remote location. &lt;strong&gt;eval()&lt;/strong&gt; can be used to hide PHP codes inside server. These two can be prevented by changing &lt;strong&gt;PHP Configuration&lt;/strong&gt;. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr4ceippsm5v6rpftpyf7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr4ceippsm5v6rpftpyf7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4. &lt;strong&gt;PHP&lt;/strong&gt; has many different &lt;strong&gt;Module&lt;/strong&gt; to accomplish different tasks Like to work with &lt;strong&gt;MYSQL&lt;/strong&gt; php has &lt;strong&gt;"mysqli"&lt;/strong&gt; Module. To see all these modules just type &lt;strong&gt;"php -m"&lt;/strong&gt; in servers cmd. As a result a list of all modules will be printed. The unnecessary modules can be removed from this list. It will increase the &lt;strong&gt;efficiency&lt;/strong&gt; and &lt;strong&gt;security&lt;/strong&gt; of PHP. Module enable/disable can be found in &lt;strong&gt;php.ini&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[PHP Modules]
apc
bcmath
bz2
calendar
Core
ctype
curl
date
dom
........
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5. &lt;strong&gt;PHP&lt;/strong&gt; send its version information in &lt;strong&gt;HTTP header&lt;/strong&gt;. It can be disabled from &lt;strong&gt;PHP configuration&lt;/strong&gt;. To do that in &lt;strong&gt;php.ini&lt;/strong&gt; below lines should be mentioned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;expose_php=Off
ServerSignature Off
ServerTokens Prod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvuhifnjla42k70epau1w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvuhifnjla42k70epau1w.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6. It is important not to show &lt;strong&gt;error details&lt;/strong&gt; to users. Because in error details there it is mentioned in which line of which file the error occurred as well as the &lt;strong&gt;stack trace&lt;/strong&gt; is printed. This info is of no use to users also can be &lt;strong&gt;security risk&lt;/strong&gt;. It can be disabled from &lt;strong&gt;PHP configuration&lt;/strong&gt;. To do that in &lt;strong&gt;php.ini&lt;/strong&gt; below lines should be mentioned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;display_errors=Off
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdti1q7i061dkonedc271.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdti1q7i061dkonedc271.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;7. Another important configuration in PHP is determining &lt;strong&gt;HTTP Post size&lt;/strong&gt;. Bigger requests requires more time for server to process. Attacker can take advantage and send bigger requests to keep &lt;strong&gt;system resources&lt;/strong&gt; busy. It can be mentioned in &lt;strong&gt;PHP configuration&lt;/strong&gt;. To do that in &lt;strong&gt;php.ini&lt;/strong&gt; below lines should be mentioned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;post_max_size=1K
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of &lt;strong&gt;"1K"&lt;/strong&gt; server administrator can write the desired size.&lt;/p&gt;

&lt;p&gt;8. There are many &lt;strong&gt;files&lt;/strong&gt; related activities takes place in server like &lt;strong&gt;reading/writing&lt;/strong&gt; a file etc. But if reading/writing in any file is permitted then it will be a &lt;strong&gt;security threat&lt;/strong&gt;. Because all files in a server is not for the website. There are &lt;strong&gt;OS files&lt;/strong&gt;, &lt;strong&gt;Nginx/Httpd&lt;/strong&gt;, &lt;strong&gt;MYSQL&lt;/strong&gt; etc. So a specific directory for websites should be selected where no other files will be kept. The configuration is given below.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fj9rvfa3ffufgoyyeserg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fj9rvfa3ffufgoyyeserg.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;9. Most of us are aware about &lt;strong&gt;PHP Session&lt;/strong&gt;. Session saves some temporary information of user into server. PHP keeps this session data in file. The location where PHP will keep this session can be mentioned in &lt;strong&gt;PHP configuration&lt;/strong&gt;. Keeping these session files in a public location can pose security threat. It can be mentioned in &lt;strong&gt;PHP configuration&lt;/strong&gt;. To do that in &lt;strong&gt;php.ini&lt;/strong&gt; below lines should be mentioned.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff9x9m0y1a9bkbj79fwhr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff9x9m0y1a9bkbj79fwhr.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;10. It is important to define the &lt;strong&gt;Directory Permission&lt;/strong&gt; of &lt;strong&gt;Document Root&lt;/strong&gt; in PHP configuration. Most of the case the user running PHP is &lt;strong&gt;apache&lt;/strong&gt; or &lt;strong&gt;www-data&lt;/strong&gt;. So the &lt;strong&gt;Owner&lt;/strong&gt; and &lt;strong&gt;Group&lt;/strong&gt; of the document root should be those users.&lt;/p&gt;

&lt;p&gt;11. OS like &lt;strong&gt;Linux&lt;/strong&gt; has its own security features Like &lt;strong&gt;SELinux&lt;/strong&gt;. It provides safety against faulty configuration and malicious software.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F11b1kmwzcqkd66uioex3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F11b1kmwzcqkd66uioex3.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;12. OS like &lt;strong&gt;Linux&lt;/strong&gt; has its own &lt;strong&gt;Firewall&lt;/strong&gt; which can monitor server traffic.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fif18j1bg00rcvcsmcfvw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fif18j1bg00rcvcsmcfvw.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;13. Another way of ensuring security is &lt;strong&gt;SSL certificate&lt;/strong&gt;. It creates a &lt;em&gt;Secure Channel&lt;/em&gt; between user and server. It stops &lt;strong&gt;Man in the Middle Attack&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fynfecbyhckjju38csbso.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fynfecbyhckjju38csbso.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;14. &lt;strong&gt;Always keep OS and other software updated.&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.php.net/manual/en/security.php" rel="noopener noreferrer"&gt;php.net&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://phpsec.org/projects/guide/" rel="noopener noreferrer"&gt;phpsec.org&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/sql/sql_injection.asp" rel="noopener noreferrer"&gt;w3schools&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>php</category>
      <category>goodpractices</category>
      <category>programming</category>
      <category>security</category>
    </item>
  </channel>
</rss>
