Issues (58)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/LangFulltextBooleanFilter.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @author    Donatas Navidonskis <[email protected]>
5
 * @since     2017
6
 * @class     LangFulltextBooleanFilter
7
 *
8
 */
9
class LangFulltextBooleanFilter extends FulltextFilter {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
11
    /**
12
     * @param DataQuery $query
13
     *
14
     * @return DataQuery
15
     */
16
    protected function applyOne(DataQuery $query) {
17
        $this->model = $query->applyRelation($this->relation);
0 ignored issues
show
Documentation Bug introduced by
It seems like $query->applyRelation($this->relation) of type object<The> is incompatible with the declared type string of property $model.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
18
        $predicate = sprintf("MATCH (%s) AGAINST (? IN BOOLEAN MODE)", $this->getDbName());
19
20
        $keywords = $this->convertForeignToLatin($this->getValue());
0 ignored issues
show
It seems like $this->getValue() targeting SearchFilter::getValue() can also be of type array; however, LangFulltextBooleanFilter::convertForeignToLatin() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
21
22
        $andProcessor = create_function('$matches', '
0 ignored issues
show
Security Best Practice introduced by
The use of create_function is highly discouraged, better use a closure.

create_function can pose a great security vulnerability as it is similar to eval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.

// Instead of
$function = create_function('$a, $b', 'return $a + $b');

// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
23
	 		return " +" . $matches[2] . " +" . $matches[4] . " ";
24
	 	');
25
        $notProcessor = create_function('$matches', '
0 ignored issues
show
Security Best Practice introduced by
The use of create_function is highly discouraged, better use a closure.

create_function can pose a great security vulnerability as it is similar to eval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.

// Instead of
$function = create_function('$a, $b', 'return $a + $b');

// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
26
	 		return " -" . $matches[3];
27
	 	');
28
29
        $keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords);
30
        $keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords);
31
        $keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords);
32
        $keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords);
33
34
        $keywords = $this->addStarsToKeywords($keywords);
35
36
        return $query->where([$predicate => $keywords]);
37
    }
38
39
    /**
40
     * @param string $keywords
41
     *
42
     * @return string
43
     */
44
    protected function addStarsToKeywords($keywords) {
45
        if (! trim($keywords)) {
46
            return "";
47
        }
48
        // Add * to each keyword
49
        $splitWords = preg_split("/ +/", trim($keywords));
50
        while (list($i, $word) = each($splitWords)) {
0 ignored issues
show
The assignment to $i is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
51
            if ($word[0] == '"') {
52
                while (list($i, $subword) = each($splitWords)) {
0 ignored issues
show
The assignment to $i is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
53
                    $word .= ' '.$subword;
54
                    if (substr($subword, -1) == '"') {
55
                        break;
56
                    }
57
                }
58
            } else {
59
                $word .= '*';
60
            }
61
            $newWords[] = $word;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$newWords was never initialized. Although not strictly required by PHP, it is generally a good practice to add $newWords = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
62
        }
63
64
        return implode(" ", $newWords);
0 ignored issues
show
The variable $newWords does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
65
    }
66
67
    /**
68
     * Convert Foreign symbols to Latin
69
     *
70
     * @param string $str .
71
     *
72
     * @return string with only Latin Symbols
73
     */
74
    public static function convertForeignToLatin($str) {
75
        $tr = [
76
            "А" => "a", "Б" => "b", "В" => "v", "Г" => "g", "Д" => "d",
77
            "Е" => "e", "Ё" => "yo", "Ж" => "zh", "З" => "z", "И" => "i",
78
            "Й" => "j", "К" => "k", "Л" => "l", "М" => "m", "Н" => "n",
79
            "О" => "o", "П" => "p", "Р" => "r", "С" => "s", "Т" => "t",
80
            "У" => "u", "Ф" => "f", "Х" => "kh", "Ц" => "ts", "Ч" => "ch",
81
            "Ш" => "sh", "Щ" => "sch", "Ъ" => "", "Ы" => "y", "Ь" => "",
82
            "Э" => "e", "Ю" => "yu", "Я" => "ya", "а" => "a", "б" => "b",
83
            "в" => "v", "г" => "g", "д" => "d", "е" => "e", "ё" => "yo",
84
            "ж" => "zh", "з" => "z", "и" => "i", "й" => "j", "к" => "k",
85
            "л" => "l", "м" => "m", "н" => "n", "о" => "o", "п" => "p",
86
            "р" => "r", "с" => "s", "т" => "t", "у" => "u", "ф" => "f",
87
            "х" => "kh", "ц" => "ts", "ч" => "ch", "ш" => "sh", "щ" => "sch",
88
            "ъ" => "", "ы" => "y", "ь" => "", "э" => "e", "ю" => "yu",
89
            "я" => "ya", "ą" => "a", "č" => "c", "ę" => "e", "ė" => "e",
90
            "į" => "i", "š" => "s", "ų" => "u", "ū" => "u", "ž" => "z",
91
        ];
92
93
        return strtr($str, $tr);
94
    }
95
}