Issues (37)

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/Trackers/RefererTracker.php (1 issue)

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 Arcanedev\LaravelTracker\Trackers;
2
3
use Arcanedev\LaravelTracker\Contracts\Parsers\RefererParser;
4
use Arcanedev\LaravelTracker\Contracts\Trackers\RefererTracker as RefererTrackerContract;
5
use Arcanedev\LaravelTracker\Support\BindingManager;
6
use Illuminate\Support\Arr;
7
8
/**
9
 * Class     RefererTracker
10
 *
11
 * @package  Arcanedev\LaravelTracker\Trackers
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class RefererTracker extends AbstractTracker implements RefererTrackerContract
15
{
16
    /* -----------------------------------------------------------------
17
     |  Getters and Setters
18
     | -----------------------------------------------------------------
19
     */
20
21
    /**
22
     * Get the model.
23
     *
24
     * @return \Arcanedev\LaravelTracker\Models\Referer
25
     */
26 3
    protected function getModel()
27
    {
28 3
        return $this->makeModel(BindingManager::MODEL_REFERER);
29
    }
30
31
    /**
32
     * @return \Arcanedev\LaravelTracker\Contracts\Parsers\RefererParser
33
     */
34 9
    private function getRefererParser()
35
    {
36 9
        return $this->make(RefererParser::class);
37
    }
38
39
    /* -----------------------------------------------------------------
40
     |  Main Methods
41
     | -----------------------------------------------------------------
42
     */
43
44
    /**
45
     * Track the referer and return the id.
46
     *
47
     * @param  string  $refererUrl
48
     * @param  string  $pageUrl
49
     *
50
     * @return int|null
51
     */
52 9
    public function track($refererUrl, $pageUrl)
53
    {
54 9
        $firstParsed = $this->getRefererParser()->parseUrl($refererUrl);
55
56 9
        if ($firstParsed) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $firstParsed of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
57
            $attributes = [
58 3
                'url'               => $firstParsed['url'],
59 3
                'host'              => $firstParsed['host'],
60 3
                'domain_id'         => $this->trackDomain($firstParsed['domain']),
61
                'medium'            => null,
62
                'source'            => null,
63
                'search_terms_hash' => null,
64
            ];
65
66 3
            $secondParsed = $this->getRefererParser()->parse($firstParsed['url'], $pageUrl);
67
68 3
            if ($secondParsed->isKnown()) {
69 3
                $attributes['medium']            = $secondParsed->getMedium();
70 3
                $attributes['source']            = $secondParsed->getSource();
71 3
                $attributes['search_terms_hash'] = sha1($secondParsed->getSearchTerm());
72
            }
73
74
            /** @var  \Arcanedev\LaravelTracker\Models\Referer  $referer */
75 3
            $referer = $this->getModel()->newQuery()->firstOrCreate(
76 3
                Arr::only($attributes, ['url', 'search_terms_hash']),
77 2
                $attributes
78
            );
79
80 3
            if ($secondParsed->isKnown()) {
81 3
                $this->trackRefererSearchTerms($referer, $secondParsed->getSearchTerm());
82
            }
83
84 3
            return $referer->id;
85
        }
86
87 6
        return null;
88
    }
89
90
    /**
91
     * Track the domain and get the id.
92
     *
93
     * @param  string  $name
94
     *
95
     * @return int
96
     */
97 3
    private function trackDomain($name)
98
    {
99 3
        return $this->makeModel(BindingManager::MODEL_DOMAIN)
100 3
            ->newQuery()
101 3
            ->firstOrCreate(compact('name'))
102 3
            ->getKey();
103
    }
104
105
    /**
106
     * Store the referer's search terms.
107
     *
108
     * @param  \Arcanedev\LaravelTracker\Contracts\Models\Referer  $referer
109
     * @param  string                                              $searchTerms
110
     */
111 3
    private function trackRefererSearchTerms($referer, $searchTerms)
112
    {
113 3
        $terms = [];
114
115 3
        foreach (explode(' ', $searchTerms) as $term) {
116 3
            $terms[] = $this->makeModel(BindingManager::MODEL_REFERER_SEARCH_TERM)->fill([
117 3
                'search_term' => $term,
118
            ]);
119
        }
120
121 3
        if (count($terms) > 0)
122 3
            $referer->searchTerms()->saveMany($terms);
123
124 3
    }
125
}
126