Issues (17)

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.

index.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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
require_once 'common.inc.php';
3
4
use smtech\CanvasICSSync\Toolbox;
5
use smtech\ReflexiveCanvasLTI\LTI\ToolProvider;
6
use smtech\ReflexiveCanvasLTI\Exception\ConfigurationException;
7
8
define('ACTION_CONFIG', 'config');
9
define('ACTION_INSTALL', 'install');
10
define('ACTION_CONSUMERS', 'consumers');
11
define('ACTION_UNSPECIFIED', false);
12
13
/* store any requested actions for future handling */
14
$action = (empty($_REQUEST['action']) ?
15
    ACTION_UNSPECIFIED :
16
    strtolower($_REQUEST['action'])
17
);
18
19
/* action requests only come from outside the LTI! */
20
if ($action) {
21
    unset($_SESSION[ToolProvider::class]);
22
}
23
24
/* authenticate LTI launch request, if present */
25
if ($toolbox->lti_isLaunching()) {
26
    $toolbox->resetSession();
27
    $toolbox->lti_authenticate();
28
    exit;
29
}
30
31
/* if authenticated LTI launch, get the current user profile */
32
if (!empty($_SESSION[ToolProvider::class]['canvas'])) {
33
    try {
34
        $profile = $toolbox->api_get('users/' . $_SESSION[ToolProvider::class]['canvas']['user_id'] . '/profile');
35
    } catch (Exception $e) {
36
        $toolbox->smarty_addMessage(
37
            'Error',
38
            json_decode($e->getMessage(), true),
39
            NotificationMessage::DANGER
40
        );
41
    }
42
    $toolbox->smarty_assign([
43
        'profile' => $profile,
44
    ]);
45
    header('Location: import.php');
46
    exit;
47
48
/* if not authenticated, default to showing credentials */
49
} else {
50
    $action = (empty($action) ?
51
        ACTION_CONFIG :
52
        $action
53
    );
54
}
55
56
/* process any actions */
57
switch ($action) {
58
    /* reset cached install data from config file */
59
    case ACTION_INSTALL:
60
        $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true);
61
        $toolbox =& $_SESSION['toolbox'];
62
63
        /* test to see if we can connect to the API */
64
        try {
65
            $toolbox->getAPI();
66
        } catch (ConfigurationException $e) {
67
            /* if there isn't an API token in config.xml, are there OAuth credentials? */
68
            if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) {
69
                $toolbox->interactiveGetAccessToken();
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class smtech\ReflexiveCanvasLTI\Toolbox as the method interactiveGetAccessToken() does only exist in the following sub-classes of smtech\ReflexiveCanvasLTI\Toolbox: smtech\CanvasICSSync\Toolbox, smtech\StMarksReflexiveCanvasLTI\Toolbox. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
70
                exit;
71
            } else { /* no (understandable) API credentials available -- doh! */
72
                throw $e;
73
            }
74
        }
75
76
        /* load the the database schema */
77
        $toolbox->loadSchema();
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class smtech\ReflexiveCanvasLTI\Toolbox as the method loadSchema() does only exist in the following sub-classes of smtech\ReflexiveCanvasLTI\Toolbox: smtech\CanvasICSSync\Toolbox. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
78
79
        /* finish by opening consumers control panel */
80
        header('Location: consumers.php');
81
        exit;
82
83
    /* show LTI configuration XML file */
84
    case ACTION_CONFIG:
85
        header('Content-type: application/xml');
86
        echo $toolbox->saveConfigurationXML();
87
        exit;
88
}
89