\Drupflare\Anachron\Php LegacyRisk

Counts the code patterns in legacy PHP that anachron does not make safe.

Running old code on a current core leaves the module's own logic as it was, so a query built by concatenation is still one. The scan is a token pass and counts patterns that need a reviewer; a count is not a finding. Names of functions that take a query string come from the caller, so this file names no CMS.

Summary

Methods
Properties
Constants
__construct
scan
count
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
isCall
callPattern
firstArgumentIsBuilt
echoesInput
next
previous
queryFunctions
SHELL
INPUT
ESCAPERS

Constant

SHELL

SHELL = ['exec', 'shell_exec', 'system', 'passthru', 'popen', 'proc_open']

INPUT

INPUT = ['$_GET', '$_POST', '$_REQUEST', '$_COOKIE']

ESCAPERS

ESCAPERS = ['htmlspecialchars', 'htmlentities', 'check_plain', 'filter_xss', 'filter_xss_admin', 'intval', 'urlencode']

Properties

$queryFunctions

$queryFunctions : array

Type

array<string|int, mixed>

Methods

__construct()

__construct(list  $queryFunctions = []) : mixed

Creates the object.

Parameters

list $queryFunctions

Functions whose first argument is a query string.

Returns

mixed —

scan()

scan(string  $code) : list<array{pattern: string, line: int}>

Lists every risky pattern with its line.

Parameters

string $code

Returns

list —

One entry per match.

count()

count(string  $code) : array<string,int>

Counts every risky pattern.

Parameters

string $code

Returns

array —

Counts keyed by pattern.

isCall()

isCall(array  $tokens, int  $i) : bool

Tells whether the token at an index is a function call.

Parameters

array $tokens

The token list.

int $i

Index of the token.

Returns

bool —

callPattern()

callPattern(array  $tokens, int  $i, string  $name) : ?string

Names the risky pattern a call matches.

Parameters

array $tokens

The token list.

int $i

Index of the token.

string $name

The lowercased function name.

Returns

?string —

firstArgumentIsBuilt()

firstArgumentIsBuilt(array  $tokens, int  $i) : bool

Tells whether the first argument is built by concatenation or interpolation.

Parameters

array $tokens

The token list.

int $i

Index of the token.

Returns

bool —

echoesInput()

echoesInput(array  $tokens, int  $i) : bool

Tells whether an echo statement prints request input unescaped.

Parameters

array $tokens

The token list.

int $i

Index of the token.

Returns

bool —

next()

next(array  $tokens, int  $i) : ?int

Finds the next token that is not whitespace.

Parameters

array $tokens

The token list.

int $i

Index of the token.

Returns

?int —

previous()

previous(array  $tokens, int  $i) : ?int

Finds the previous token that is not whitespace.

Parameters

array $tokens

The token list.

int $i

Index of the token.

Returns

?int —