Issues (50)

Security Analysis    no request data  

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/jwe/impl/ContentEncryptionKeyFactory.php (4 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 namespace jwe\impl;
2
/**
3
 * Copyright 2015 OpenStack Foundation
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 * Unless required by applicable law or agreed to in writing, software
9
 * distributed under the License is distributed on an "AS IS" BASIS,
10
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
 * See the License for the specific language governing permissions and
12
 * limitations under the License.
13
 **/
14
use jwa\cryptographic_algorithms\content_encryption\ContentEncryptionAlgorithm;
15
use jwa\cryptographic_algorithms\EncryptionAlgorithm;
16
use jwe\KeyManagementModeValues;
17
use security\Key;
18
use utils\services\Utils_Registry;
19
/**
20
 * Class ContentEncryptionKeyFactory
21
 *
22
 * Creates the CEK
23
 *
24
 * @package jwe\impl
25
 */
26
final class ContentEncryptionKeyFactory
27
{
28
29
    /**
30
     * @param Key $management_key
31
     * @param $key_management_mode
32
     * @param ContentEncryptionAlgorithm $enc
33
     * @return Key
34
     * @throws \Exception
35
     */
36
    static public function build(Key $management_key, $key_management_mode, ContentEncryptionAlgorithm $enc)
37
    {
38
39
        $cek = null;
0 ignored issues
show
$cek is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
41
        switch ($key_management_mode) {
42
            /**
43
             * When Key Wrapping, Key Encryption, or Key Agreement with Key
44
             * Wrapping are employed, generate a random CEK value
45
             */
46
            case KeyManagementModeValues::KeyWrapping:
47
            case KeyManagementModeValues::KeyEncryption:
48
            case KeyManagementModeValues::KeyAgreementWithKeyWrapping:
49
            {
50
                // calculate it
51
                $generator = Utils_Registry::getInstance()->get(Utils_Registry::RandomNumberGeneratorService);
52
                /**
53
                 * The CEK MUST have a length equal to that required for the
54
                 * content encryption algorithm.
55
                 */
56
                $rnd       = $generator->invoke($enc->getMinKeyLen()/8);
0 ignored issues
show
The call to IService::invoke() has too many arguments starting with $enc->getMinKeyLen() / 8.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
57
                $cek       = new _ContentEncryptionKey($enc->getName(), 'RAW', $rnd);
58
            }
59
            break;
60
            case KeyManagementModeValues::DirectEncryption:
61
            {
62
                $cek = $management_key;
63
            }
64
            break;
65
            case KeyManagementModeValues::DirectKeyAgreement:
66
            {
67
                throw new \Exception('unsupported KKM!');
68
            }
69
            break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
70
            default:
71
            {
72
                throw new \Exception('unsupported KKM!');
73
            }
74
            break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
75
        }
76
        return $cek;
77
    }
78
79
    /**
80
     * @param string $value
81
     * @param EncryptionAlgorithm $alg
82
     * @return Key
83
     */
84
    static public function fromRaw($value, EncryptionAlgorithm $alg){
85
        return  new _ContentEncryptionKey($alg->getName(), 'RAW', $value);
86
    }
87
}