Issues (20)

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.

src/services/messages/AuthnRequest.php (2 issues)

Labels

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
namespace flipbox\saml\sp\services\messages;
4
5
use craft\base\Component;
6
use flipbox\keychain\records\KeyChainRecord;
7
use flipbox\saml\core\exceptions\InvalidMetadata;
8
use flipbox\saml\core\helpers\MessageHelper;
9
use flipbox\saml\core\records\AbstractProvider;
10
use flipbox\saml\sp\models\Settings;
11
use flipbox\saml\sp\Saml;
12
use SAML2\AuthnRequest as SamlAuthnRequest;
13
use SAML2\Constants;
14
use SAML2\XML\md\EndpointType;
15
use SAML2\XML\saml\Issuer;
16
use yii\base\Event;
17
18
class AuthnRequest extends Component
19
{
20
21
    const EVENT_AFTER_MESSAGE_CREATED = 'eventAfterMessageCreated';
22
23
    /**
24
     * @param AbstractProvider $identityProvider
25
     * @return \SAML2\XML\md\IndexedEndpointType|null
26
     * @throws InvalidMetadata
27
     */
28 6
    private function firstIdpSsoService(AbstractProvider $identityProvider): EndpointType
29
    {
30 6
        if (!($service = $identityProvider->firstIdpSsoService(Constants::BINDING_HTTP_POST))) {
31
            $service = $identityProvider->firstIdpSsoService();
0 ignored issues
show
Are you sure the assignment to $service is correct as $identityProvider->firstIdpSsoService() (which targets flipbox\saml\core\record...r::firstIdpSsoService()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
32
        }
33
34 6
        if (!$service) {
35
            throw new InvalidMetadata("IdP Metadata is missing SSO Service");
36
        }
37
38 6
        return $service;
39
    }
40
41
    /**
42
     * @param AbstractProvider $myServiceProvider
43
     * @param AbstractProvider $identityProvider
44
     * @return \SAML2\AuthnRequest
45
     * @throws \craft\errors\SiteNotFoundException
46
     */
47 6
    public function create(
48
        AbstractProvider $myServiceProvider,
49
        AbstractProvider $identityProvider
50
    ): SamlAuthnRequest {
51
52 6
        $idpSsoService = $this->firstIdpSsoService($identityProvider);
53
54 6
        $location = $idpSsoService->getLocation();
55
56
        /**
57
         * @var $samlSettings Settings
58
         */
59 6
        $samlSettings = Saml::getInstance()->getSettings();
60
61 6
        $authnRequest = new \SAML2\AuthnRequest();
62
63 6
        $authnRequest->setAssertionConsumerServiceURL(
64 6
            $samlSettings->getDefaultLoginEndpoint()
65
        );
66
67 6
        $authnRequest->setProtocolBinding(
68 6
            $idpSsoService->getBinding()
69
        );
70
71 6
        $authnRequest->setId($requestId = MessageHelper::generateId());
72
73 6
        $authnRequest->setIssueInstant(
74 6
            (new \DateTime())->getTimestamp()
75
        );
76
77 6
        $authnRequest->setDestination(
78 6
            $location
79
        );
80
81 6
        $authnRequest->setRelayState(
82 6
            \Craft::$app->getUser()->getReturnUrl()
0 ignored issues
show
The method getUser does only exist in yii\web\Application, but not in yii\console\Application.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
83
        );
84
85 6
        $authnRequest->setIssuer(
86 6
            $issuer = new Issuer()
87
        );
88
89 6
        $issuer->setValue(
90 6
            Saml::getInstance()->getSettings()->getEntityId()
91
        );
92
93
        /**
94
         * @var KeyChainRecord $pair
95
         */
96 6
        $pair = $myServiceProvider->keychain;
97
98 6
        if ($pair && $samlSettings->signAuthnRequest) {
99 3
            $authnRequest->setSignatureKey(
100 3
                $myServiceProvider->keychainPrivateXmlSecurityKey()
101
            );
102
        }
103
104
        /**
105
         * Kick off event here so people can manipulate this object if needed
106
         */
107 6
        $event = new \flipbox\saml\sp\events\AuthnRequest();
108 6
        $event->message = $authnRequest;
109 6
        $this->trigger(static::EVENT_AFTER_MESSAGE_CREATED, $event);
110
111 6
        return $authnRequest;
112
    }
113
}
114