This rule is a security-oriented rule that discourages the use of functions like rand() and mt_rand(). These functions generate pseudo-random numbers, which are not truly random and can be predictable, making them a weak choice for any situation where security is a concern, such as generating random passwords or tokens.
Using pseudo-random numbers can lead to vulnerabilities in your code. An attacker might be able to predict the output of these functions and exploit this predictability.
To maintain secure coding practices, you can use the random_int() function instead. This function generates cryptographically secure random integers, making it a much safer choice. For example, instead of using $var = rand();, you can use $var = random_int(20, 40);. By following this rule, you can help to ensure that your code is as secure as possible.
Non-Compliant Code Examples
<?php$var=rand();$var=mt_rand(20,40);
Compliant Code Examples
<?php$var=random_int(20,40);
シームレスな統合。 Datadog Code Security をお試しください
Datadog Code Security
このルールを試し、Datadog Code Security でコードを解析する
このルールの使用方法
1
2
rulesets:- php-security # Rules to enforce PHP security.