PHP security-simplicity is beautiful

黄舟
Release: 2023-03-05 22:30:01
Original
1212 people have browsed it


Simple is beautiful

Complexity breeds errors, and errors can lead to security vulnerabilities. This simple fact illustrates why simplicity is so important for a secure application. Unnecessary complexity is just as bad as unnecessary risk.

For example, the following code is excerpted from a recent security vulnerability advisory:

##CODE:

  <?php
 
  $search = (isset($_GET[&#39;search&#39;]) ?
$_GET[&#39;search&#39;] : &#39;&#39;);
 
?>
Copy after login

This process can confuse the fact that the $search variable is tainted*, especially to inexperienced developers. The above statement is equivalent to the following program:

CODE:

 
  <?php
 
  $search = &#39;&#39;;
 
  if (isset($_GET[&#39;search&#39;]))
  {
    $search = $_GET[&#39;search&#39;];
  }
 
  ?>
Copy after login

## The above The two processing flows are exactly the same. Now please pay attention to the following statement:

  $search = $_GET[&#39;search&#39;];
Copy after login

Using this statement ensures that the state of the $search variable remains intact without affecting the process, and it can also be seen whether it is contaminated.

* Annotation: A contaminated variable means that during program execution, the value of the variable is not directly specified by the assignment statement, but comes from other sources, such as console entry, database, etc.

The above is the content of PHP Security-Simplicity is Beautiful. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!