Issues (7)

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/Http/Controllers/JsLocalizationController.php (1 issue)

Labels
Severity

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 JsLocalization\Http\Controllers;
4
5
use Illuminate\Routing\Controller;
6
use JsLocalization\Facades\ConfigCachingService;
7
use JsLocalization\Facades\MessageCachingService;
8
use JsLocalization\Http\Responses\StaticFileResponse;
9
10
class JsLocalizationController extends Controller
11
{
12
13
    /**
14
     * Create the JS-Response for all configured translation messages
15
     *
16
     * @return \Illuminate\Http\Response
17
     */
18 2
    public function createJsMessages()
19
    {
20 2
        $contents = $this->getMessagesJson();
21
22 2
        return response($contents)
0 ignored issues
show
The method header() does not exist on Symfony\Component\HttpFoundation\Response. Did you maybe mean sendHeaders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
23 2
            ->header('Content-Type', 'text/javascript')
24 2
            ->setLastModified(MessageCachingService::getLastRefreshTimestamp());
25
    }
26
27
    /**
28
     * @return \Illuminate\Http\Response
29
     */
30 2
    public function createJsConfig()
31
    {
32 2
        $contents = $this->getConfigJson();
33
34
        /** @var \Illuminate\Http\Response $response */
35 2
        $response = response($contents);
36 2
        $response->header('Content-Type', 'text/javascript');
37
38 2
        if (ConfigCachingService::isDisabled()) {
39 1
            $response->setEtag(md5($contents));
40 1
        } else {
41 1
            $response->setLastModified(ConfigCachingService::getLastRefreshTimestamp());
42
        }
43
44 2
        return $response;
45
    }
46
47
    /**
48
     * Deliver the Framework for getting the translation in JS
49
     *
50
     * @return \Illuminate\Http\Response
51
     */
52 1
    public function deliverLocalizationJS()
53
    {
54 1
        $response = new StaticFileResponse( __DIR__."/../../../public/js/localization.min.js" );
55 1
        $response->setPublic();
56 1
        $response->header('Content-Type', 'application/javascript');
57
58 1
        return $response;
59
    }
60
61
    /**
62
     * Deliver one file that combines messages and framework.
63
     * Saves one additional HTTP-Request
64
     *
65
     * @return \Illuminate\Http\Response
66
     */
67 1
    public function deliverAllInOne()
68
    {
69 1
        $contents = file_get_contents( __DIR__."/../../../public/js/localization.min.js" );
70 1
        $contents .= "\n";
71 1
        $contents .= $this->getMessagesJson();
72 1
        $contents .= $this->getConfigJson();
73
74
        /** @var \Illuminate\Http\Response $response */
75 1
        $response = response($contents);
76 1
        $response->header('Content-Type', 'text/javascript');
77
78 1
        if (ConfigCachingService::isDisabled()) {
79
            $response->setEtag(md5($contents));
80
        } else {
81 1
            $response->setLastModified(MessageCachingService::getLastRefreshTimestamp());
82
        }
83
84 1
        return $response;
85
    }
86
87
    /**
88
     * Transforms the cached data to stay compatible to old versions of the package.
89
     *
90
     * @param string $messages
91
     * @return string
92
     */
93 3
    protected function ensureBackwardsCompatibility($messages)
94
    {
95 3
        if (preg_match('/^\\{"[a-z]{2}":/', $messages)) {
96 2
            return $messages;
97
        } else {
98 1
            return '{"' . app()->getLocale() . '":' . $messages . '}';
99
        }
100
    }
101
102
    /**
103
     * Get the configured messages from the translation files
104
     *
105
     * @return string
106
     */
107 3
    protected function getMessagesJson()
108
    {
109 3
        $messages = MessageCachingService::getMessagesJson();
110 3
        $messages = $this->ensureBackwardsCompatibility($messages);
111
112 3
        $contents  = 'Lang.addMessages(' . $messages . ');';
113
114 3
        return $contents;
115
    }
116
117
    /**
118
     * Get the JSON-encoded config properties that shall be passed to the client.
119
     *
120
     * @return string
121
     */
122 3
    protected function getConfigJson()
123
    {
124 3
        $config = ConfigCachingService::getConfigJson();
125
126 3
        $contents = 'Config.addConfig(' . $config . ');';
127
128 3
        return $contents;
129
    }
130
131
}
132