Issues (5)

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/Util/Interpolator.php (1 issue)

Labels
Severity

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
namespace Consolidation\Config\Util;
3
4
use Consolidation\Config\Config;
5
use Consolidation\Config\ConfigInterface;
6
7
/**
8
 * Provides configuration objects with an 'interpolate' method
9
 * that may be used to inject config values into tokens embedded
10
 * in strings..
11
 */
12
class Interpolator
13
{
14
    /**
15
     * interpolate replaces tokens in a string with the correspnding
16
     * value from this config object. Tokens are surrounded by double
17
     * curley braces, e.g. "{{key}}".
18
     *
19
     * Example:
20
     * If the message is 'Hello, {{user.name}}', then the key user.name
21
     * is fetched from the config object, and the token {{user.name}} is
22
     * replaced with the result.
23
     *
24
     * @param string $message Message containing tokens to be replaced
25
     * @param string|bool $default The value to substitute for tokens that
26
     *   are not found in the configuration. If `false`, then missing
27
     *   tokens are not replaced.
28
     * @return string
29
     */
30
    public function interpolate($data, $message, $default = '')
31
    {
32
        $replacements = $this->replacements($data, $message, $default);
0 ignored issues
show
It seems like $default defined by parameter $default on line 30 can also be of type boolean; however, Consolidation\Config\Uti...polator::replacements() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and 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...
33
        return strtr($message, $replacements);
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function mustInterpolate($data, $message)
40
    {
41
        $result = $this->interpolate($data, $message, false);
42
        $tokens = $this->findTokens($result);
43
        if (!empty($tokens)) {
44
            throw new \Exception('The following required keys were not found in configuration: ' . implode(',', $tokens));
45
        }
46
        return $result;
47
    }
48
49
    /**
50
     * findTokens finds all of the tokens in the provided message
51
     *
52
     * @param string $message String with tokens
53
     * @return string[] map of token to key, e.g. {{key}} => key
54
     */
55
    public function findTokens($message)
56
    {
57
        if (!preg_match_all('#{{([a-zA-Z0-9._-]+)}}#', $message, $matches, PREG_SET_ORDER)) {
58
            return [];
59
        }
60
        $tokens = [];
61
        foreach ($matches as $matchSet) {
62
            list($sourceText, $key) = $matchSet;
63
            $tokens[$sourceText] = $key;
64
        }
65
        return $tokens;
66
    }
67
68
    /**
69
     * Replacements looks up all of the replacements in the configuration
70
     * object, given the token keys from the provided message. Keys that
71
     * do not exist in the configuration are replaced with the default value.
72
     */
73
    public function replacements($data, $message, $default = '')
74
    {
75
        $tokens = $this->findTokens($message);
76
77
        $replacements = [];
78
        foreach ($tokens as $sourceText => $key) {
79
            $replacementText = $this->get($data, $key, $default);
80
            if ($replacementText !== false) {
81
                    $replacements[$sourceText] = $replacementText;
82
            }
83
        }
84
        return $replacements;
85
    }
86
87
    protected function get($data, $key, $default)
88
    {
89
        if (is_array($data)) {
90
            return array_key_exists($key, $data) ? $data[$key] : $default;
91
        }
92
        if ($data instanceof ConfigInterface) {
93
            return $data->get($key, $default);
94
        }
95
        throw new \Exception('Bad data type provided to Interpolator');
96
    }
97
}
98