Skip to content

Security Rules

This document details the rules available in the Security category.

Available Rules

RuleCode
Disallowed Functionsdisallowed-functions
No Debug Symbolsno-debug-symbols
No Insecure Comparisonno-insecure-comparison
No Literal Passwordno-literal-password
No Short Opening Tagno-short-opening-tag
Tainted Data to Sinktainted-data-to-sink

disallowed-functions

Flags calls to functions that are disallowed via rule configuration.

You can specify which functions or extensions should be disallowed through the functions or extensions options. This helps enforce coding standards, security restrictions, or the usage of preferred alternatives.

Configuration

OptionTypeDefault
enabledbooleantrue
levelstring"warning"
functionsarray[]
extensionsarray[]

Examples

Correct Code

php
<?php

function allowed_function(): void {
    // ...
}

allowed_function(); // Not flagged

Incorrect Code

php
<?php

curl_init(); // Error: part of a disallowed extension

no-debug-symbols

Flags calls to debug functions like var_dump, print_r, dd, etc.

These functions are useful for debugging, but they should not be committed to version control as they can expose sensitive information and are generally not intended for production environments.

Configuration

OptionTypeDefault
enabledbooleantrue
levelstring"note"

Examples

Correct Code

php
<?php

// Production-safe code
error_log('Processing user request.');

Incorrect Code

php
<?php

function process_request(array $data) {
    var_dump($data); // Debug call that should be removed
    // ...
}

no-insecure-comparison

Detects insecure comparison of passwords or tokens using ==, !=, ===, or !==.

These operators are vulnerable to timing attacks, which can expose sensitive information. Instead, use hash_equals for comparing strings or password_verify for validating hashes.

Configuration

OptionTypeDefault
enabledbooleantrue
levelstring"error"

Examples

Correct Code

php
<?php

if (hash_equals($storedToken, $userToken)) {
    // Valid token
}

Incorrect Code

php
<?php

if ($storedToken == $userToken) {
    // Vulnerable to timing attacks
}

no-literal-password

Detects the use of literal values for passwords or sensitive data. Storing passwords or sensitive information as literals in code is a security risk and should be avoided. Use environment variables or secure configuration management instead.

Configuration

OptionTypeDefault
enabledbooleantrue
levelstring"error"

Examples

Correct Code

php
<?php

$password = getenv('DB_PASSWORD');

Incorrect Code

php
<?php

$password = "supersecret";

no-short-opening-tag

Disallows the use of short opening tags (<?).

The availability of <? depends on the short_open_tag directive in php.ini. If this setting is disabled on a server, any code within the short tags will be exposed as plain text, which is a significant security risk. Using the full <?php opening tag is the only guaranteed portable way to ensure your code is always interpreted correctly.

Configuration

OptionTypeDefault
enabledbooleantrue
levelstring"warning"

Examples

Correct Code

php
<?php

echo "Hello, World!";

Incorrect Code

php
<?

echo "Hello, World!";

tainted-data-to-sink

Detects user (tainted) data being passed directly to sink functions or constructs (such as echo, print, or user-defined "log" functions). If these functions emit or store data without sanitization, it could lead to Cross-Site Scripting (XSS) or other injection attacks.

Configuration

OptionTypeDefault
enabledbooleantrue
levelstring"error"
known-sink-functionsarray["printf"]

Examples

Correct Code

php
<?php

// Properly escape data before using a sink like `echo`
echo htmlspecialchars($_GET['name'] ?? '', ENT_QUOTES, 'UTF-8');

Incorrect Code

php
<?php

// This is considered unsafe:
echo $_GET['name'] ?? '';