Issues (10)

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/Command/UpdateTitlesCommand.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
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AniDbFillerBundle\Command;
10
11
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Filesystem\Filesystem;
15
16
/**
17
 * Update list of titles from AniDB.net.
18
 */
19
class UpdateTitlesCommand extends ContainerAwareCommand
20
{
21
    /**
22
     * @var int
23
     */
24
    const CACHE_LIFE_TIME = 86400;
25
26
    protected function configure()
27
    {
28
        $this->setName('animedb:update-titles')
29
            ->setDescription('Update list of titles from AniDB.net');
30
    }
31
32
    /**
33
     * @param InputInterface $input
34
     * @param OutputInterface $output
35
     *
36
     * @return int
37
     */
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $now = time();
41
        $file_csv = $this->getContainer()->getParameter('kernel.cache_dir').'/'.
42
            $this->getContainer()->getParameter('anime_db.ani_db.titles_db');
43
44
        if (!file_exists($file_csv) || filemtime($file_csv) + self::CACHE_LIFE_TIME < $now) {
45
            try {
46
                $file = $this->getOriginDb($output, $now);
47
            } catch (\Exception $e) {
48
                $output->writeln(sprintf('<error>AniDB list titles is not downloaded: %s</error>', $e->getMessage()));
49
50
                return 0;
51
            }
52
53
            $output->writeln('Start assembling database');
54
55
            // clear list titles and add unified title
56
            $fp = gzopen($file, 'r');
57
            $fp_csv = gzopen($file_csv, 'w');
58
            while (!gzeof($fp)) {
59
                $line = trim(gzgets($fp, 4096));
60
                // ignore comments
61
                if ($line[0] == '#') {
62
                    continue;
63
                }
64
                list($aid, $type, $lang, $title) = explode('|', $line);
65
                $lang = substr($lang, 0, 2);
66
                // ignore not supported locales
67
                if ($lang == 'x-') {
68
                    continue;
69
                }
70
                gzwrite($fp_csv, $aid.'|'.$type.'|'.$lang.'|'.$this->getUnifiedTitle($title).'|'.$title."\n");
71
            }
72
            gzclose($fp);
73
            gzclose($fp_csv);
74
            touch($file, $now);
75
            touch($file_csv, $now);
76
77
            $output->writeln('The titles database is updated');
78
        } else {
79
            $output->writeln('Update is not needed');
80
        }
81
82
        return 0;
83
    }
84
85
    /**
86
     * Get original db file.
87
     *
88
     * Download the original db if need and cache it in a system temp dir
89
     *
90
     * @throws \InvalidArgumentException
91
     * @throws \RuntimeException
92
     *
93
     * @param OutputInterface $output
94
     * @param int $now
95
     *
96
     * @return string
97
     */
98
    protected function getOriginDb(OutputInterface $output, $now)
99
    {
100
        $url = $this->getContainer()->getParameter('anime_db.ani_db.import_titles');
101
102
        if (($path = parse_url($url, PHP_URL_PATH)) === false) {
103
            throw new \InvalidArgumentException('Failed parse URL: '.$url);
104
        }
105
106
        /* @var Filesystem $fs */
107
        $fs = $this->getContainer()->get('filesystem');
108
        $filename = sys_get_temp_dir().'/'.pathinfo($path, PATHINFO_BASENAME);
109
110
        if (!$fs->exists($filename) || filemtime($filename) + self::CACHE_LIFE_TIME < $now) {
111
            /* @var $downloader \AnimeDb\Bundle\AppBundle\Service\Downloader */
112
            $downloader = $this->getContainer()->get('anime_db.downloader');
113
            $tmp = tempnam(sys_get_temp_dir(), 'ani_db_titles');
114
            if (!$downloader->download($url, $tmp, true)) {
115
                $fs->remove($tmp);
116
                throw new \RuntimeException('Failed to download the titles database');
117
            }
118
            $fs->rename($tmp, $filename, true);
119
            $output->writeln('The titles database is loaded');
120
        }
121
122
        return $filename;
123
    }
124
125
    /**
126
     * @param string $title
127
     *
128
     * @return string
129
     */
130 View Code Duplication
    protected function getUnifiedTitle($title)
0 ignored issues
show
This method seems to be duplicated in 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...
131
    {
132
        $title = mb_strtolower($title, 'utf8');
133
        $title = preg_replace('/\W+/u', ' ', $title);
134
135
        return trim($title);
136
    }
137
}
138