Issues (26)

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.

src/Language/Language.php (1 issue)

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
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Console\Language;
11
12
use Railt\Io\Readable;
13
use Railt\Lexer\Factory;
14
use Railt\Lexer\LexerInterface;
15
use Railt\Lexer\Result\Eoi;
16
17
/**
18
 * Class Language
19
 */
20
abstract class Language implements LanguageInterface
21
{
22
    /**
23
     * @var string[]
24
     */
25
    public const DEFAULT_COLORS = [
26
        'T_COMMENT'  => 'fg=cyan',
27
        'T_KEYWORD'  => 'fg=magenta',
28
        'T_STRING'   => 'fg=green',
29
        'T_DIGIT'    => 'fg=green',
30
        'T_VARIABLE' => 'fg=yellow',
31
    ];
32
33
    /**
34
     * @var string[]
35
     */
36
    public const DEFAULT_TOKENS = [
37
        'T_WHITESPACE'    => '\s+',
38
    ];
39
40
    /**
41
     * @var LexerInterface
42
     */
43
    private $lexer;
44
45
    /**
46
     * @var array
47
     */
48
    private $colors;
49
50
    /**
51
     * Language constructor.
52
     * @throws \InvalidArgumentException
53
     * @throws \Railt\Lexer\Exception\BadLexemeException
54
     */
55
    public function __construct()
56
    {
57
        $this->lexer  = Factory::create(\array_merge(self::DEFAULT_TOKENS, $this->tokens()), [Eoi::T_NAME]);
58
        $this->colors = \array_merge(self::DEFAULT_COLORS, $this->colors());
59
    }
60
61
    /**
62
     * @return array|string[]
63
     */
64
    abstract public function tokens(): array;
65
66
    /**
67
     * @return array|string[]
68
     */
69
    abstract public function colors(): array;
70
71
    /**
72
     * @param Readable $file
73
     * @param array $extensions
74
     * @return bool
75
     */
76
    protected function matchExtension(Readable $file, array $extensions): bool
77
    {
78
        $ext = \mb_strtolower(\pathinfo($file->getPathname(), \PATHINFO_EXTENSION));
79
80
        return \in_array($ext, $extensions, true);
81
    }
82
83
    /**
84
     * @param Readable $file
85
     * @return iterable
86
     */
87
    public function lex(Readable $file): iterable
88
    {
89
        return $this->lexer->lex($file);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->lexer->lex($file); of type Traversable|Railt\Lexer\TokenInterface[] adds the type Traversable to the return on line 89 which is incompatible with the return type declared by the interface Railt\Console\Language\LanguageInterface::lex of type Railt\Console\Language\i...\Lexer\TokenInterface[].
Loading history...
90
    }
91
92
    /**
93
     * @param string $token
94
     * @param string $content
95
     * @return string
96
     */
97
    public function highlight(string $token, string $content): string
98
    {
99
        $color   = $this->colors[$token] ?? null;
100
        $content = \str_replace('\\', "\u{0000}", $content);
101
        $content = $color === null ? $content : \sprintf('<%s>%s</>', $color, $content);
102
103
        return $content;
104
    }
105
106
    /**
107
     * @param array $tokens
108
     * @return string
109
     */
110
    protected function oneOf(array $tokens): string
111
    {
112
        return \sprintf('(%s)\b', \implode('|', $tokens));
113
    }
114
}
115