Issues (25)

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/AesKeyWrapAlgorithm.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
2
3
/*
4
 * This file is part of the tmilos/jose-jwt package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\JoseJwt\Jwe;
13
14
use Tmilos\JoseJwt\Error\JoseJwtException;
15
use Tmilos\JoseJwt\Random\RandomGenerator;
16
use Tmilos\JoseJwt\Util\StringUtils;
17
18
class AesKeyWrapAlgorithm implements JweAlgorithm
19
{
20
    /** @var int */
21
    private $kekLengthBits;
22
23
    /** @var string */
24
    private $wrapperClass;
25
26
    /** @var array */
27
    private static $wrapperMap = [
28
        128 => 'AESKW\A128KW',
29
        192 => 'AESKW\A192KW',
30
        256 => 'AESKW\A256KW',
31
    ];
32
33
    /** @var RandomGenerator */
34
    private $randomGenerator;
35
36
    /**
37
     * @param int             $keySize
38
     * @param RandomGenerator $randomGenerator
39
     */
40
    public function __construct($keySize, RandomGenerator $randomGenerator)
41
    {
42
        $this->randomGenerator = $randomGenerator;
43
        $this->kekLengthBits = $keySize;
44
        if (false === array_key_exists($keySize, self::$wrapperMap)) {
45
            throw new JoseJwtException(sprintf('Invalid kek key size "%s"', $keySize));
46
        } else {
47
            $this->wrapperClass = self::$wrapperMap[$keySize];
48
        }
49
    }
50
51
    /**
52
     * @param int             $cekSizeBits
53
     * @param string|resource $kek
54
     * @param array           $header
55
     *
56
     * @return array [cek, encryptedCek]
57
     */
58
    public function wrapNewKey($cekSizeBits, $kek, array $header)
59
    {
60
        $kekLen = StringUtils::length($kek);
0 ignored issues
show
It seems like $kek defined by parameter $kek on line 58 can also be of type resource; however, Tmilos\JoseJwt\Util\StringUtils::length() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
61 View Code Duplication
        if ($kekLen * 8 != $this->kekLengthBits) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
            throw new JoseJwtException(sprintf('AesKeyWrap management algorithm expected key of size %s bits, but was given %s bits', $this->kekLengthBits, $kekLen * 8));
63
        }
64
        if ($cekSizeBits % 8 != 0) {
65
            throw new JoseJwtException('CekSizeBits must be divisible by 8');
66
        }
67
68
        $cek = $this->randomGenerator->get($cekSizeBits / 8);
69
70
        $encryptedCek = $this->aesWrap($kek, $cek);
0 ignored issues
show
It seems like $kek defined by parameter $kek on line 58 can also be of type resource; however, Tmilos\JoseJwt\Jwe\AesKeyWrapAlgorithm::aesWrap() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
71
72
        return [$cek, $encryptedCek];
73
    }
74
75
    /**
76
     * @param string $encryptedCek
77
     * @param string $kek
78
     * @param int    $cekSizeBits
79
     * @param array  $header
80
     *
81
     * @return string
82
     */
83
    public function unwrap($encryptedCek, $kek, $cekSizeBits, array $header)
84
    {
85
        $kekLen = StringUtils::length($kek);
86 View Code Duplication
        if ($kekLen * 8 != $this->kekLengthBits) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
            throw new JoseJwtException(sprintf('AesKeyWrap management algorithm expected key of size %s bits, but was given %s bits', $this->kekLengthBits, $kekLen * 8));
88
        }
89
90
        return $this->aesUnwrap($kek, $encryptedCek);
91
    }
92
93
    /**
94
     * @param string $kek
95
     * @param string $key
96
     *
97
     * @return string
98
     */
99
    private function aesWrap($kek, $key)
100
    {
101
        return call_user_func([$this->wrapperClass, 'wrap'], $kek, $key);
102
    }
103
104
    /**
105
     * @param string $kek
106
     * @param string $wrappedKey
107
     *
108
     * @return string
109
     */
110
    private function aesUnwrap($kek, $wrappedKey)
111
    {
112
        return call_user_func([$this->wrapperClass, 'unwrap'], $kek, $wrappedKey);
113
    }
114
}
115