Issues (23)

Security Analysis    no request data  

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.

Strings/VariableInDoubleQuotedStringSniff.php (2 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
 * This file is part of the mo4-coding-standard (phpcs standard)
5
 *
6
 * PHP version 5
7
 *
8
 * @category PHP
9
 * @package  PHP_CodeSniffer-MO4
10
 * @author   Xaver Loppenstedt <[email protected]>
11
 * @license  http://spdx.org/licenses/MIT MIT License
12
 * @version  GIT: master
13
 * @link     https://github.com/Mayflower/mo4-coding-standard
14
 */
15
16
namespace MO4\Sniffs\Strings;
17
18
use PHP_CodeSniffer\Sniffs\Sniff;
19
use PHP_CodeSniffer\Files\File;
20
21
/**
22
 * Variable in Double Quoted String sniff.
23
 *
24
 * Variables in double quoted strings must be surrounded by { }
25
 *
26
 * @category  PHP
27
 * @package   PHP_CodeSniffer-MO4
28
 * @author    Xaver Loppenstedt <[email protected]>
29
 * @copyright 2013 Xaver Loppenstedt, some rights reserved.
30
 * @license   http://spdx.org/licenses/MIT MIT License
31
 * @link      https://github.com/Mayflower/mo4-coding-standard
32
 */
33
class VariableInDoubleQuotedStringSniff implements Sniff
34
{
35
    /**
36
     * The PHP_CodeSniffer object controlling this run.
37
     *
38
     * @var File
39
     */
40
    private $phpCsFile = null;
41
42
43
    /**
44
     * Registers the tokens that this sniff wants to listen for.
45
     *
46
     * @return array(int)
0 ignored issues
show
The doc-type array(int) could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
47
     * @see    Tokens.php
48
     */
49
    public function register()
50
    {
51
        return array(T_DOUBLE_QUOTED_STRING);
52
53
    }//end register()
54
55
56
    /**
57
     * Called when one of the token types that this sniff is listening for
58
     * is found.
59
     *
60
     * @param File $phpcsFile The PHP_CodeSniffer file where the
61
     *                        token was found.
62
     * @param int  $stackPtr  The position in the PHP_CodeSniffer
63
     *                        file's token stack where the token
64
     *                        was found.
65
     *
66
     * @return void
67
     */
68
    public function process(File $phpcsFile, $stackPtr)
69
    {
70
        $this->phpCsFile = $phpcsFile;
71
72
        $varRegExp = '/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/';
73
74
        $tokens  = $phpcsFile->getTokens();
75
        $content = $tokens[$stackPtr]['content'];
76
77
        $matches = array();
78
79
        preg_match_all($varRegExp, $content, $matches, PREG_OFFSET_CAPTURE);
80
81
        foreach ($matches as $match) {
0 ignored issues
show
The expression $matches of type null|array<integer,array<integer,string>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
82
            foreach ($match as $info) {
83
                list($var, $pos) = $info;
84
85
                if ($pos === 1 || $content[($pos - 1)] !== '{') {
86
                    if (strpos(substr($content, 0, $pos), '{') > 0
87
                        && strpos(substr($content, 0, $pos), '}') === false
88
                    ) {
89
                        continue;
90
                    }
91
92
                    $lastOpeningBrace = strrpos(substr($content, 0, $pos), '{');
93
                    if ($lastOpeningBrace !== false
94
                        && $content[($lastOpeningBrace + 1)] === '$'
95
                    ) {
96
                        $lastClosingBrace = strrpos(substr($content, 0, $pos), '}');
97
98
                        if ($lastClosingBrace !== false
99
                            && $lastClosingBrace < $lastOpeningBrace
100
                        ) {
101
                            continue;
102
                        }
103
                    }
104
105
                    $fix = $this->phpCsFile->addFixableError(
106
                        sprintf(
107
                            'must surround variable %s with { }',
108
                            $var
109
                        ),
110
                        $stackPtr,
111
                        'NotSurroundedWithBraces'
112
                    );
113
114
                    if ($fix === true) {
115
                        $correctVariable = $this->surroundVariableWithBraces(
116
                            $content,
117
                            $pos,
118
                            $var
119
                        );
120
                        $this->fixPhpCsFile($stackPtr, $correctVariable);
121
                    }
122
                }//end if
123
            }//end foreach
124
        }//end foreach
125
126
    }//end process()
127
128
129
    /**
130
     * Surrounds a variable with curly brackets
131
     *
132
     * @param string $content content
133
     * @param int    $pos     position
134
     * @param string $var     variable
135
     *
136
     * @return string
137
     */
138
    private function surroundVariableWithBraces($content, $pos, $var)
139
    {
140
        $before = substr($content, 0, $pos);
141
        $after  = substr($content, ($pos + strlen($var)));
142
143
        return $before.'{'.$var.'}'.$after;
144
145
    }//end surroundVariableWithBraces()
146
147
148
    /**
149
     * Fixes the file
150
     *
151
     * @param int    $stackPtr        stack pointer
152
     * @param string $correctVariable correct variable
153
     *
154
     * @return void
155
     */
156
    private function fixPhpCsFile($stackPtr, $correctVariable)
157
    {
158
        $phpCsFile = $this->phpCsFile;
159
160
        $phpCsFile->fixer->beginChangeset();
161
        $phpCsFile->fixer->replaceToken($stackPtr, $correctVariable);
162
        $phpCsFile->fixer->endChangeset();
163
164
    }//end fixPhpCsFile()
165
166
167
}//end class
168