Skip to content

Commit

Permalink
private constants are PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 2, 2022
1 parent 9e5fca9 commit eab2f01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RequestFactory
use Nette\SmartObject;

/** @internal */
private const CHARS = '\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}';
private const ValidChars = '\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}';

/** @var array */
public $urlFilters = [
Expand Down Expand Up @@ -156,7 +156,7 @@ private function getGetPostCookie(Url $url): array
: (empty($_COOKIE) ? [] : $_COOKIE);

// remove invalid characters
$reChars = '#^[' . self::CHARS . ']*+$#Du';
$reChars = '#^[' . self::ValidChars . ']*+$#Du';
if (!$this->binary) {
$list = [&$query, &$post, &$cookies];
foreach ($list as $key => &$val) {
Expand All @@ -169,7 +169,7 @@ private function getGetPostCookie(Url $url): array
$list[] = &$list[$key][$k];

} elseif (is_string($v)) {
$list[$key][$k] = (string) preg_replace('#[^' . self::CHARS . ']+#u', '', $v);
$list[$key][$k] = (string) preg_replace('#[^' . self::ValidChars . ']+#u', '', $v);

} else {
throw new Nette\InvalidStateException(sprintf('Invalid value in $_POST/$_COOKIE in key %s, expected string, %s given.', "'$k'", gettype($v)));
Expand All @@ -187,7 +187,7 @@ private function getGetPostCookie(Url $url): array

private function getFiles(): array
{
$reChars = '#^[' . self::CHARS . ']*+$#Du';
$reChars = '#^[' . self::ValidChars . ']*+$#Du';
$files = [];
$list = [];
foreach ($_FILES ?? [] as $k => $v) {
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class Session
use Nette\SmartObject;

/** Default file lifetime */
private const DEFAULT_FILE_LIFETIME = 3 * Nette\Utils\DateTime::HOUR;
private const DefaultFileLifetime = 3 * Nette\Utils\DateTime::HOUR;

private const SECURITY_OPTIONS = [
private const SecurityOptions = [
'referer_check' => '', // must be disabled because PHP implementation is invalid
'use_cookies' => 1, // must be enabled to prevent Session Hijacking and Fixation
'use_only_cookies' => 1, // must be enabled to prevent Session Fixation
Expand All @@ -47,7 +47,7 @@ class Session
private $options = [
'cookie_samesite' => IResponse::SAME_SITE_LAX,
'cookie_lifetime' => 0, // for a maximum of 3 hours or until the browser is closed
'gc_maxlifetime' => self::DEFAULT_FILE_LIFETIME, // 3 hours
'gc_maxlifetime' => self::DefaultFileLifetime, // 3 hours
];

/** @var IRequest */
Expand Down Expand Up @@ -93,14 +93,14 @@ private function doStart($mustExists = false): void
{
if (session_status() === PHP_SESSION_ACTIVE) { // adapt an existing session
if (!$this->started) {
$this->configure(self::SECURITY_OPTIONS);
$this->configure(self::SecurityOptions);
$this->initialize();
}

return;
}

$this->configure(self::SECURITY_OPTIONS + $this->options);
$this->configure(self::SecurityOptions + $this->options);

if (!session_id()) { // session is started for first time
$id = $this->request->getCookie(session_name());
Expand Down Expand Up @@ -500,7 +500,7 @@ public function setExpiration(?string $time)
{
if ($time === null) {
return $this->setOptions([
'gc_maxlifetime' => self::DEFAULT_FILE_LIFETIME,
'gc_maxlifetime' => self::DefaultFileLifetime,
'cookie_lifetime' => 0,
]);

Expand Down

0 comments on commit eab2f01

Please sign in to comment.