Issues (4069)

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.

SugarXHprof/xhprof_lib/utils/xhprof_runs.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
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
//
4
//  Copyright (c) 2009 Facebook
5
//
6
//  Licensed under the Apache License, Version 2.0 (the "License");
7
//  you may not use this file except in compliance with the License.
8
//  You may obtain a copy of the License at
9
//
10
//      http://www.apache.org/licenses/LICENSE-2.0
11
//
12
//  Unless required by applicable law or agreed to in writing, software
13
//  distributed under the License is distributed on an "AS IS" BASIS,
14
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
//  See the License for the specific language governing permissions and
16
//  limitations under the License.
17
//
18
19
//
20
// This file defines the interface iXHProfRuns and also provides a default
21
// implementation of the interface (class XHProfRuns).
22
//
23
24
/**
25
 * iXHProfRuns interface for getting/saving a XHProf run.
26
 *
27
 * Clients can either use the default implementation,
28
 * namely XHProfRuns_Default, of this interface or define
29
 * their own implementation.
30
 *
31
 * @author Kannan
32
 */
33
interface iXHProfRuns {
34
35
  /**
36
   * Returns XHProf data given a run id ($run) of a given
37
   * type ($type).
38
   *
39
   * Also, a brief description of the run is returned via the
40
   * $run_desc out parameter.
41
   */
42
  public function get_run($run_id, $type, &$run_desc);
43
44
  /**
45
   * Save XHProf data for a profiler run of specified type
46
   * ($type).
47
   *
48
   * The caller may optionally pass in run_id (which they
49
   * promise to be unique). If a run_id is not passed in,
50
   * the implementation of this method must generated a
51
   * unique run id for this saved XHProf run.
52
   *
53
   * Returns the run id for the saved XHProf run.
54
   *
55
   */
56
  public function save_run($xhprof_data, $type, $run_id = null);
57
}
58
59
60
/**
61
 * XHProfRuns_Default is the default implementation of the
62
 * iXHProfRuns interface for saving/fetching XHProf runs.
63
 *
64
 * It stores/retrieves runs to/from a filesystem directory
65
 * specified by the "xhprof.output_dir" ini parameter.
66
 *
67
 * @author Kannan
68
 */
69
class XHProfRuns_Default implements iXHProfRuns {
0 ignored issues
show
Coding Style Compatibility introduced by
Each interface must be in a file by itself

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
70
71
  private $dir = '';
72
  private $suffix = 'xhprof';
73
74
  private function gen_run_id($type) {
75
    return uniqid();
76
  }
77
78
  private function file_name($run_id, $type) {
79
80
    $file = "$run_id.$type." . $this->suffix;
81
82
    if (!empty($this->dir)) {
83
      $file = $this->dir . "/" . $file;
84
    }
85
    return $file;
86
  }
87
88
  public function __construct($dir = null) {
89
90
    // if user hasn't passed a directory location,
91
    // we use the xhprof.output_dir ini setting
92
    // if specified, else we default to the directory
93
    // in which the error_log file resides.
94
95
    if (empty($dir)) {
96
      $dir = ini_get("xhprof.output_dir");
97
      if (empty($dir)) {
98
99
        // some default that at least works on unix...
100
        $dir = "/tmp";
101
102
        xhprof_error("Warning: Must specify directory location for XHProf runs. ".
103
                     "Trying {$dir} as default. You can either pass the " .
104
                     "directory location as an argument to the constructor ".
105
                     "for XHProfRuns_Default() or set xhprof.output_dir ".
106
                     "ini param.");
107
      }
108
    }
109
    $this->dir = $dir;
110
  }
111
112
  public function get_run($run_id, $type, &$run_desc) {
113
    $file_name = $this->file_name($run_id, $type);
114
115
    if (!file_exists($file_name)) {
116
      xhprof_error("Could not find file $file_name");
117
      $run_desc = "Invalid Run Id = $run_id";
118
      return null;
119
    }
120
121
    $contents = file_get_contents($file_name);
122
    $run_desc = "XHProf Run (Namespace=$type)";
123
    return unserialize($contents);
124
  }
125
126
  public function save_run($xhprof_data, $type, $run_id = null) {
127
128
    // Use PHP serialize function to store the XHProf's
129
    // raw profiler data.
130
    $xhprof_data = serialize($xhprof_data);
131
132
    if ($run_id === null) {
133
      $run_id = $this->gen_run_id($type);
134
    }
135
136
    $file_name = $this->file_name($run_id, $type);
137
    $file = fopen($file_name, 'w');
138
139
    if ($file) {
140
      fwrite($file, $xhprof_data);
141
      fclose($file);
142
    } else {
143
      xhprof_error("Could not open $file_name\n");
144
    }
145
146
    // echo "Saved run in {$file_name}.\nRun id = {$run_id}.\n";
147
    return $run_id;
148
  }
149
150
  function list_runs() {
151
    if (is_dir($this->dir)) {
152
        echo "<hr/>Existing runs:\n<ul>\n";
153
        $files = glob("{$this->dir}/*.{$this->suffix}");
154
        usort($files, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
0 ignored issues
show
Security Best Practice introduced by
The use of create_function is highly discouraged, better use a closure.

create_function can pose a great security vulnerability as it is similar to eval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.

// Instead of
$function = create_function('$a, $b', 'return $a + $b');

// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
155
        foreach ($files as $file) {
156
            list($run,$source) = explode('.', basename($file));
157
            echo '<li><a href="' . htmlentities($_SERVER['SCRIPT_NAME'])
158
                . '?run=' . htmlentities($run) . '&source='
159
                . htmlentities($source) . '">'
160
                . htmlentities(basename($file)) . "</a><small> "
161
                . date("Y-m-d H:i:s", filemtime($file)) . "</small></li>\n";
162
        }
163
        echo "</ul>\n";
164
    }
165
  }
166
}
167