Issues (18)

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/ValueParsers/YearMonthTimeParser.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
namespace ValueParsers;
4
5
use DataValues\TimeValue;
6
7
/**
8
 * A parser that accepts various date formats with month precision. Prefers month/year order when
9
 * both numbers are valid months, e.g. "12/10" is December 2010. Should be called before
10
 * YearTimeParser when you want to accept both formats, because strings like "1 999" may either
11
 * represent a month and a year or a year with digit grouping.
12
 *
13
 * @since 0.8.4
14
 *
15
 * @license GPL-2.0+
16
 * @author Addshore
17
 * @author Thiemo Kreuz
18
 *
19
 * @todo match BCE dates in here
20
 */
21
class YearMonthTimeParser extends StringValueParser {
22
23
	const FORMAT_NAME = 'year-month';
24
25
	/**
26
	 * @var int[] Array mapping localized month names to month numbers (1 to 12).
27
	 */
28
	private $monthNumbers;
29
30
	/**
31
	 * @var ValueParser
32
	 */
33
	private $isoTimestampParser;
34
35
	/**
36
	 * @see StringValueParser::__construct
37
	 *
38
	 * @param MonthNameProvider $monthNameProvider
39
	 * @param ParserOptions|null $options
40
	 */
41 68
	public function __construct(
42
		MonthNameProvider $monthNameProvider,
43
		ParserOptions $options = null
44
	) {
45 68
		parent::__construct( $options );
46
47 68
		$languageCode = $this->getOption( ValueParser::OPT_LANG );
48 68
		$this->monthNumbers = $monthNameProvider->getMonthNumbers( $languageCode );
49 68
		$this->isoTimestampParser = new IsoTimestampParser( null, $this->options );
50 68
	}
51
52
	/**
53
	 * @see StringValueParser::stringParse
54
	 *
55
	 * @param string $value
56
	 *
57
	 * @throws ParseException
58
	 * @return TimeValue
59
	 */
60 61
	protected function stringParse( $value ) {
61
		// Matches year and month separated by a separator.
62
		// \p{L} matches letters outside the ASCII range.
63 61
		if ( !preg_match( '/^(-?[\d\p{L}]+)\s*?[\/\-\s.,]\s*(-?[\d\p{L}]+)$/', trim( $value ), $matches ) ) {
64 11
			throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME );
65
		}
66 50
		list( , $a, $b ) = $matches;
67
68 50
		$aIsInt = preg_match( '/^-?\d+$/', $a );
69 50
		$bIsInt = preg_match( '/^-?\d+$/', $b );
70
71 50
		if ( $aIsInt && $bIsInt ) {
72 30
			if ( $this->canBeMonth( $a ) ) {
73 21
				return $this->getTimeFromYearMonth( $b, $a );
74 9
			} elseif ( $this->canBeMonth( $b ) ) {
75 9
				return $this->getTimeFromYearMonth( $a, $b );
76
			}
77 20
		} elseif ( $aIsInt ) {
78 3
			$month = $this->parseMonth( $b );
79
80 3
			if ( $month ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $month of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
81 3
				return $this->getTimeFromYearMonth( $a, $month );
82
			}
83 17
		} elseif ( $bIsInt ) {
84 16
			$month = $this->parseMonth( $a );
85
86 16
			if ( $month ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $month of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
87 14
				return $this->getTimeFromYearMonth( $b, $month );
88
			}
89
		}
90
91 8
		throw new ParseException( 'Failed to parse year and month', $value, self::FORMAT_NAME );
92
	}
93
94
	/**
95
	 * @param string $month
96
	 *
97
	 * @return int|null
98
	 */
99 19
	private function parseMonth( $month ) {
100 19
		foreach ( $this->monthNumbers as $monthName => $i ) {
101 19
			if ( strcasecmp( $monthName, $month ) === 0 ) {
102 19
				return $i;
103
			}
104
		}
105
106 2
		return null;
107
	}
108
109
	/**
110
	 * @param string $year
111
	 * @param string $month as a canonical month number
112
	 *
113
	 * @return TimeValue
114
	 */
115 42
	private function getTimeFromYearMonth( $year, $month ) {
116 42
		if ( $year[0] !== '-' ) {
117 38
			$year = '+' . $year;
118
		}
119
120 42
		return $this->isoTimestampParser->parse( sprintf( '%s-%02s-00T00:00:00Z', $year, $month ) );
121
	}
122
123
	/**
124
	 * @param string $value
125
	 *
126
	 * @return bool can the given value be a month?
127
	 */
128 30
	private function canBeMonth( $value ) {
129 30
		return $value >= 0 && $value <= 12;
130
	}
131
132
}
133