Issues (41)

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.

code/GoogleCustomSearchPage.php (2 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
 * @package googlesitesearch
5
 */
6
class GoogleCustomSearchPage extends Page
7
{
8
    private static $icon = "googlecustomsearch/images/treeicons/GoogleCustomSearchPage";
9
10
    private static $allowed_children = "none";
11
12
    private static $can_be_root = true;
13
14
    private static $description = "Page to search via Google and display search results.";
15
16
    /**
17
     * Standard SS variable.
18
     */
19
    private static $singular_name = "Google Search Results Page";
20
    public function i18n_singular_name()
21
    {
22
        return _t("GoogleCustomSearchPage.SINGULAR_NAME", "Google Search Results Page");
23
    }
24
25
    /**
26
     * Standard SS variable.
27
     */
28
    private static $plural_name = "Google Search Results Pages";
29
    public function i18n_plural_name()
30
    {
31
        return _t("GoogleCustomSearchPage.PLURAL_NAME", "Google Search Results Pages");
32
    }
33
34
    public function getCMSFields()
35
    {
36
        $fields = parent::getCMSFields();
37
        $fields->addFieldToTab("Root.Searches",
38
            new GoogleCustomSearchPage_RecordField("stats", "Search History Last 100 Days")
39
        );
40
        return $fields;
41
    }
42
43
    public function requireDefaultRecords()
44
    {
45
        if ($this->canCreate()) {
46
            DB::alteration_message("Creating a GoogleCustomSearchPage", "created");
47
            $page = new GoogleCustomSearchPage();
48
            $page->writeToStage('Stage');
49
            $page->publish('Stage', 'Live');
50
        }
51
    }
52
53
    public function populateDefaults()
54
    {
55
        parent::populateDefaults();
56
        $this->Title = "Search";
57
        $this->MenuTitle = "Search";
58
        $this->ShowInMenus = 0;
59
        $this->ShowInSearch = 0;
60
        $this->URLSegment = "search";
61
    }
62
63
    public function canCreate($member = null)
64
    {
65
        return GoogleCustomSearchPage::get()->count() ?  false : true;
66
    }
67
}
68
69
class GoogleCustomSearchPage_Controller extends Page_Controller
70
{
71
    private static $allowed_actions = array(
72
        "recordsearch"
73
    );
74
75
    public function init()
76
    {
77
        parent::init();
78
        //register any search
79
        if (isset($_GET["search"])) {
80
            $searchString = Convert::raw2sql($_GET["search"]);
81
            $forwardto = "";
82
            if (isset($_GET["forwardto"])) {
83
                $forwardto = Convert::raw2sql($_GET["forwardto"]);
84
            }
85
            GoogleCustomSearchPage_Record::add_entry($searchString, $forwardto);
0 ignored issues
show
It seems like $searchString defined by \Convert::raw2sql($_GET['search']) on line 80 can also be of type array; however, GoogleCustomSearchPage_Record::add_entry() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $forwardto defined by \Convert::raw2sql($_GET['forwardto']) on line 83 can also be of type array; however, GoogleCustomSearchPage_Record::add_entry() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
86
        }
87
        if ($this->request->param("Action") != "recordsearch") {
88
            Requirements::themedCSS('GoogleCustomSearchPage');
89
            Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
90
            Requirements::javascript('googlecustomsearch/javascript/GoogleCustomSearchPage.js');
91
            $cxKey = Config::inst()->get("GoogleCustomSearchExt", "cx_key");
92
            Requirements::customScript("
93
					GoogleCustomSearchPage.cxKey = '".$cxKey."';
94
				",
95
                "GoogleCustomSearchPage"
96
            );
97
        } else {
98
            echo "registered ...";
99
        }
100
    }
101
102
    /**
103
     * template function,
104
     *
105
     * @ return String
106
     */
107
    public function SearchPhrase()
108
    {
109
        $string = "";
110
        if (isset($_GET['search'])) {
111
            $string = $_GET['search'];
112
        }
113
        return DBField::create_field('HTMLText', $string);
114
    }
115
116
    /**
117
     *
118
     * @return String
119
     */
120
    public function getTitle()
121
    {
122
        if ($searchPhrase = $this->SearchPhrase()->forTemplate()) {
123
            return $this->dataRecord->Title._t("GoogleCustomSearchPage.FOR", " for ").$searchPhrase;
124
        } else {
125
            return $this->dataRecord->Title;
126
        }
127
    }
128
129
    public function recordsearch($request)
130
    {
131
        if (isset($_GET["forwardto"]) && $_GET["forwardto"]) {
132
            return $this->redirect($_GET["forwardto"]);
133
        }
134
    }
135
}
136