Issues (1177)

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.

application/libraries/lib_csrf.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
if (!defined('BASEPATH')) {
4
    exit('No direct script access allowed');
5
}
6
7
/**
8
 * Image CMS
9
 * CSRF Library Beta.
10
 */
11
class Lib_csrf
12
{
13
14
    public $ci = NULL;
15
16
    private $enc_key = '';
17
18
    private $tokens = [];     // User token.
19
20
    private $sess_id = NULL;     // Session id.
21
22
    private $hidden_name = 'cms_token';
23
24
    private $max_tokens = 10;
25
26
    public $log_errors = FALSE;
27
28
    public $log_ajax_requests = FALSE;
29
30
    public function __construct() {
31
        $this->ci = &get_instance();
32
33
        $this->_generate_token();
34
35
        if ($this->check_token() === FALSE) {
36
            if ($this->log_errors === TRUE) {
37
                $this->_write_message('Wrong code.');
38
            }
39
40
            $err_text = 'Подозрение на атаку Cross-Site Request Forgery.';
41
            show_error($err_text);
42
            die();
43
        }
44
    }
45
46
    private function addDisabledCsrfUrls() {
47
48
        // Diable CSRF library form web money service
49
        $ci = $this->ci;
50 View Code Duplication
        if ($ci->uri->segment(1) == 'shop' && $ci->uri->segment(2) == 'cart' && $ci->uri->segment(3) == 'view' && $ci->input->get('result') == 'true' && $ci->input->get('pm') > 0) {
51
            define('ICMS_DISBALE_CSRF', true);
52
        }
53
        // Support for robokassa
54 View Code Duplication
        if ($ci->uri->segment(1) == 'shop' && $ci->uri->segment(2) == 'cart' && $ci->uri->segment(3) == 'view' && $ci->input->get('getResult') == 'true') {
55
            define('ICMS_DISBALE_CSRF', true);
56
        }
57
        if ($ci->uri->segment(1) == 'exchange') {
58
            define('ICMS_DISBALE_CSRF', true);
59
        }
60
        // Support for privat
61
        if ($ci->uri->segment(1) == 'shop' && $ci->uri->segment(2) == 'order' && $ci->uri->segment(3) == 'view' && $ci->input->post()) {
62
            define('ICMS_DISBALE_CSRF', true);
63
        }
64 View Code Duplication
        if ($ci->uri->segment(1) == 'shop' && $ci->uri->segment(2) == 'cart' && $ci->uri->segment(3) == 'view' && $ci->input->get('succes') == 'true') {
65
            define('ICMS_DISBALE_CSRF', true);
66
        }
67 View Code Duplication
        if ($ci->uri->segment(1) == 'shop' && $ci->uri->segment(2) == 'cart' && $ci->uri->segment(3) == 'view' && $ci->input->get('fail') == 'true') {
68
            define('ICMS_DISBALE_CSRF', true);
69
        }
70 View Code Duplication
        if ($ci->input->server('HTTP_REFERER') AND strpos($ci->input->server('HTTP_REFERER') . '', 'facebook.com')) {
71
            define('ICMS_DISBALE_CSRF', true);
72
        }
73 View Code Duplication
        if ($ci->input->server('HTTP_REFERER') AND strpos($ci->input->server('HTTP_REFERER') . '', 'facebook.com')) {
74
            define('ICMS_DISBALE_CSRF', true);
75
        }
76
        // Support for privat
77
78
        if ($ci->uri->segment(1) == 'shop' && $ci->uri->segment(2) == 'order' && $ci->uri->segment(3) == 'view') {
79
            define('ICMS_DISBALE_CSRF', true);
80
        }
81
        //new payment system
82
        if (preg_match('/payment_method_/i', $ci->uri->segment(1)) || preg_match('/payment_method_/i', $ci->uri->segment(2))) {
83
            define('ICMS_DISBALE_CSRF', true);
84
        }
85
        if ($ci->uri->segment(1) == 'facebook_store' && $ci->uri->segment(2) == 'auth_from_fb_store') {
86
            define('ICMS_DISBALE_CSRF', true);
87
        }
88
89
        if ($ci->uri->segment(4) == 'xbanners') {
90
            define('ICMS_DISBALE_CSRF', true);
91
        }
92
    }
93
94
    private function check_token() {
95
        $this->addDisabledCsrfUrls();
96
        if (count($_POST) > 0) {
97
            if (defined('ICMS_DISBALE_CSRF') AND ICMS_DISBALE_CSRF === TRUE) {
98
                return TRUE;
99
            }
100
            // Don't check ajax requests
101
            if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
102
                if (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
103
                    if ($this->log_ajax_requests === TRUE) {
104
                        $this->_write_message('Ajax Request');
105
                    }
106
                    return TRUE;
107
                }
108
            }
109
110
            $post_token = $this->ci->input->post($this->hidden_name);
111
112
            if (array_search($post_token, $this->tokens) == FALSE) {
113
                if ($this->tokens[0] != $post_token) {
114
                    return FALSE;
115
                }
116
            }
117
        }
118
119
        return TRUE;
120
    }
121
122
    /**
123
     * Create input hidden
124
     */
125
    public function create_hidden_html() {
126
        return '<input type="hidden" value="' . $this->get_token() . '" name="' . $this->hidden_name . '" />';
127
    }
128
129
    /**
130
     * @param string $text
131
     */
132
    private function _write_message($text) {
133
        $this->ci->load->helper('file');
134
135
        $post_data = '<br/>Post data:<br/>';
136
        foreach ($_POST as $k => $v) {
137
            $post_data .= $k . ': ' . $v . '<br/>';
138
        }
139
140
        $request_uri = 'Request uri: ' . $_SERVER['REQUEST_URI'] . '<br/><br/>';
141
142
        $new_text = '<p>' . date('d-m-Y H:i:s') . ' IP:' . $_SERVER['REMOTE_ADDR'] . ' Referer: ' . $_SERVER['HTTP_REFERER'] . '<br/>' . $request_uri . $text . $post_data . '<br/>________________</p>';
143
144
        @write_file('./application/logs/csrf.html', $new_text, 'a');
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
145
    }
146
147
    private function _generate_token() {
148
        $this->sess_id = $this->_get_sess_id();
149
        $n_token = md5($this->sess_id . $this->enc_key);
150
151
        $this->tokens = $this->ci->session->userdata('ci_tokens');
152
153
        if (is_array($this->tokens) AND count($this->tokens) > $this->max_tokens) {
154
            $this->tokens = array_slice($this->tokens, -3, 3);
155
        }
156
157
        if (is_array($this->tokens)) {
158
            if (array_search($n_token, $this->tokens) === FALSE) {
159
                $this->tokens[] = $n_token;
160
            }
161
        } else {
162
            $this->tokens = [];
163
            $this->tokens[] = $n_token;
164
        }
165
166
        $this->ci->session->set_userdata('ci_tokens', $this->tokens);
167
    }
168
169
    public function get_token() {
170
        if (count($this->tokens) == 0) {
171
            $this->_generate_token();
172
        }
173
        return array_pop($this->tokens);
174
    }
175
176
    private function _get_sess_id() {
177
        return $this->ci->session->userdata('session_id');
178
    }
179
180
}
181
182
/* End of file lib_csfr.php */