Issues (2021)

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.

catalog/download.php (3 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
/**
3
  * osCommerce Online Merchant
4
  *
5
  * @copyright (c) 2016 osCommerce; https://www.oscommerce.com
6
  * @license MIT; https://www.oscommerce.com/license/mit.txt
7
  */
8
9
  use OSC\OM\Hash;
10
  use OSC\OM\OSCOM;
11
12
  include('includes/application_top.php');
13
14
  if (!isset($_SESSION['customer_id'])) die;
15
16
// Check download.php was called with proper GET parameters
17
  if ((isset($_GET['order']) && !is_numeric($_GET['order'])) || (isset($_GET['id']) && !is_numeric($_GET['id'])) ) {
18
    die;
19
  }
20
21
// Check that order_id, customer_id and filename match
22
  $Qdownload = $OSCOM_Db->prepare('select date_format(o.date_purchased, "%Y-%m-%d") as date_purchased_day, opd.download_maxdays, opd.download_count, opd.download_maxdays, opd.orders_products_filename from :table_orders o, :table_orders_products op, :table_orders_products_download opd, :table_orders_status os where o.orders_id = :orders_id and o.customers_id = :customers_id and o.orders_id = op.orders_id and op.orders_products_id = opd.orders_products_id and opd.orders_products_download_id = :orders_products_download_id and opd.orders_products_filename != "" and o.orders_status = os.orders_status_id and os.downloads_flag = "1" and os.language_id = :language_id');
23
  $Qdownload->bindInt(':orders_id', $_GET['order']);
24
  $Qdownload->bindInt(':customers_id', $_SESSION['customer_id']);
25
  $Qdownload->bindInt(':orders_products_download_id', $_GET['id']);
26
  $Qdownload->bindInt(':language_id', $OSCOM_Language->getId());
27
  $Qdownload->execute();
28
29
  if ($Qdownload->fetch() === false) die;
30
31
// MySQL 3.22 does not have INTERVAL
32
  list($dt_year, $dt_month, $dt_day) = explode('-', $Qdownload->value('date_purchased_day'));
33
  $download_timestamp = mktime(23, 59, 59, $dt_month, $dt_day + $Qdownload->valueInt('download_maxdays'), $dt_year);
34
35
// Die if time expired (maxdays = 0 means no time limit)
36
  if (($Qdownload->valueInt('download_maxdays') != 0) && ($download_timestamp <= time())) die;
37
// Die if remaining count is <=0
38
  if ($Qdownload->valueInt('download_count') <= 0) die;
39
// Die if file is not there
40
  if (!is_file(OSCOM::getConfig('dir_root') . 'download/' . $Qdownload->value('orders_products_filename'))) die;
41
42
// Now decrement counter
43
  $Qupdate = $OSCOM_Db->prepare('update :table_orders_products_download set download_count = download_count-1 where orders_products_download_id = :orders_products_download_id');
44
  $Qupdate->bindInt(':orders_products_download_id', $_GET['id']);
45
  $Qupdate->execute();
46
47
// Returns a random name, 16 to 20 characters long
48
// There are more than 10^28 combinations
49
// The directory is "hidden", i.e. starts with '.'
50
function tep_random_name()
51
{
52
  $letters = 'abcdefghijklmnopqrstuvwxyz';
53
  $dirname = '.';
54
  $length = floor(Hash::getRandomInt(16, 20));
55
  for ($i = 1; $i <= $length; $i++) {
56
   $q = floor(Hash::getRandomInt(1, 26));
57
   $dirname .= $letters[$q];
58
  }
59
  return $dirname;
60
}
61
62
// Unlinks all subdirectories and files in $dir
63
// Works only on one subdir level, will not recurse
64
function tep_unlink_temp_dir($dir)
65
{
66
  $h1 = opendir($dir);
67
  while ($subdir = readdir($h1)) {
68
// Ignore non directories
69
    if (!is_dir($dir . $subdir)) continue;
70
// Ignore . and .. and CVS
71
    if ($subdir == '.' || $subdir == '..' || $subdir == 'CVS') continue;
72
// Loop and unlink files in subdirectory
73
    $h2 = opendir($dir . $subdir);
74
    while ($file = readdir($h2)) {
75
      if ($file == '.' || $file == '..') continue;
76
      @unlink($dir . $subdir . '/' . $file);
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...
77
    }
78
    closedir($h2);
79
    @rmdir($dir . $subdir);
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...
80
  }
81
  closedir($h1);
82
}
83
84
85
// Now send the file with header() magic
86
  header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
87
  header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
88
  header("Cache-Control: no-cache, must-revalidate");
89
  header("Pragma: no-cache");
90
  header("Content-Type: Application/octet-stream");
91
  header("Content-disposition: attachment; filename=" . $Qdownload->value('orders_products_filename'));
92
93
  if (DOWNLOAD_BY_REDIRECT == 'true') {
94
// This will work only on Unix/Linux hosts
95
    tep_unlink_temp_dir(OSCOM::getConfig('dir_root') . 'pub/');
96
    $tempdir = tep_random_name();
97
    umask(0000);
98
    mkdir(OSCOM::getConfig('dir_root') . 'pub/' . $tempdir, 0777);
99
    symlink(OSCOM::getConfig('dir_root') . 'download/' . $Qdownload->value('orders_products_filename'), OSCOM::getConfig('dir_root', 'Shop') . 'pub/' . $tempdir . '/' . $Qdownload->value('orders_products_filename'));
100
    if (is_file(OSCOM::getConfig('dir_root') . 'pub/' . $tempdir . '/' . $Qdownload->value('orders_products_filename'))) {
101
      OSCOM::redirect('pub/' . $tempdir . '/' . $Qdownload->value('orders_products_filename'));
102
    }
103
  }
104
105
// Fallback to readfile() delivery method. This will work on all systems, but will need considerable resources
106
  readfile(OSCOM::getConfig('dir_root') . 'download/' . $Qdownload->value('orders_products_filename'));
107
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
108