Issues (15)

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.

lib/Service/AppConfigService.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
/**
4
 * Nextcloud - OCR
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later.
7
 * See the COPYING file.
8
 * 
9
 * @author Janis Koehr <[email protected]>
10
 * @copyright Janis Koehr 2017
11
 */
12
namespace OCA\Ocr\Service;
13
14
use \OCP\IConfig;
15
use OCP\IL10N;
16
use OCA\Ocr\Constants\OcrConstants;
17
use OCA\Ocr\Util\RedisUtil;
18
use OCP\ILogger;
19
20
21
class AppConfigService {
22
23
    /**
24
     *
25
     * @var IConfig
26
     */
27
    private $config;
28
29
    /**
30
     *
31
     * @var IL10N
32
     */
33
    private $l10n;
34
35
    /**
36
     *
37
     * @var RedisUtil
38
     */
39
    private $redisUtil;
40
41
    /**
42
     *
43
     * @var ILogger
44
     */
45
    private $logger;
46
47
    /**
48
     * Constructor
49
     * 
50
     * @param IConfig $config            
51
     * @param IL10N $l10n            
52
     * @param RedisUtil $redisUtil            
53
     * @param ILogger $logger            
54
     */
55 32
    public function __construct(IConfig $config, IL10N $l10n, RedisUtil $redisUtil, ILogger $logger) {
56 32
        $this->config = $config;
57 32
        $this->l10n = $l10n;
58 32
        $this->redisUtil = $redisUtil;
59 32
        $this->logger = $logger;
60 32
    }
61
62
    /**
63
     * Get a value by key
64
     * 
65
     * @param string $key            
66
     * @return string
67
     */
68 2
    public function getAppValue($key) {
69 2
        return $this->config->getAppValue(OcrConstants::APP_NAME, $key);
70
    }
71
72
    /**
73
     * Evaluate if all needed redis related settings are set.
74
     * 
75
     * @return boolean
76
     */
77 4
    public function evaluateRedisSettings() {
78 4
        if ($this->config->getAppValue(OcrConstants::APP_NAME, OcrConstants::REDIS_CONFIG_KEY_HOST) !== '' &&
79 4
                $this->config->getAppValue(OcrConstants::APP_NAME, OcrConstants::REDIS_CONFIG_KEY_PORT) !== '' &&
80 4
                        $this->config->getAppValue(OcrConstants::APP_NAME, OcrConstants::REDIS_CONFIG_KEY_DB) !== '') {
81
            // test the connection and authenticate
82 1
            $this->redisUtil->setupRedisInstance();
83 1
            return true;
84
        } else {
85 3
            throw new NotFoundException($this->l10n->t('Please setup Redis in the administration settings first.'));
86
        }
87
    }
88
89
    /**
90
     * Set a value for the given key.
91
     * 
92
     * @param string $key            
93
     * @param string $value            
94
     * @return string
95
     * @throws NotFoundException
96
     */
97 21
    public function setAppValue($key, $value) {
98 21
        if (empty($key)) {
99 1
            throw new NotFoundException($this->l10n->t('The given settings key is empty.'));
100
        }
101
        switch ($key) {
102 20
            case OcrConstants::LANGUAGES_CONFIG_KEY :
103 5
                $this->checkLanguages($value);
104 3
                break;
105 15
            case OcrConstants::REDIS_CONFIG_KEY_HOST :
106 6
                $this->checkRedisHost($value);
107 3
                break;
108 9
            case OcrConstants::REDIS_CONFIG_KEY_PORT :
109 5
                $this->checkRedisPort($value);
110 1
                break;
111 4
            case OcrConstants::REDIS_CONFIG_KEY_DB :
112 3
                $this->checkRedisDb($value);
113 1
                break;
114
        }
115 9
        return $this->config->setAppValue(OcrConstants::APP_NAME, $key, $value);
116
    }
117
118
    /**
119
     * Checks for the right languages format.
120
     * 
121
     * @param string $value            
122
     * @throws NotFoundException
123
     */
124 5
    private function checkLanguages($value) {
125 5 View Code Duplication
        if (empty($value) ||
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126 5
                 !preg_match('/^[a-zA-Z\_\-\/]+(\;[a-zA-Z\_\-\/]+)*$/', $value)) {
127 2
            throw new NotFoundException($this->l10n->t('The languages are not specified in the correct format.'));
128
        }
129 3
    }
130
131
    /**
132
     * Checks for the right Redis host format.
133
     * 
134
     * @param string $value            
135
     * @throws NotFoundException
136
     */
137 6
    private function checkRedisHost($value) {
138 6 View Code Duplication
        if (empty($value) || !preg_match(
139 5
                '/(^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$)/', 
140 6
                $value)) {
141 3
            throw new NotFoundException($this->l10n->t('The Redis host is not specified in the correct format.'));
142
        }
143 3
    }
144
145
    /**
146
     * Checks for the right Redis port format.
147
     * 
148
     * @param string $value            
149
     * @throws NotFoundException
150
     */
151 5
    private function checkRedisPort($value) {
152 5 View Code Duplication
        if (empty($value) || !($value > 0 && $value < 65535)) {
153 4
            throw new NotFoundException($this->l10n->t('The Redis port number is not specified in the correct format.'));
154
        }
155 1
    }
156
157
    /**
158
     * Checks for the right Redis DB format.
159
     * 
160
     * @param string $value            
161
     * @throws NotFoundException
162
     */
163 3
    private function checkRedisDb($value) {
164 3 View Code Duplication
        if ($value === '' || !preg_match('/^\d*$/', $value)) {
165 2
            throw new NotFoundException($this->l10n->t('The Redis DB is not specified in the correct format.'));
166
        }
167
    }
168
}